summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2014-03-04 15:48:32 +0200
committerMarc Englund <marc@vaadin.com>2014-04-03 05:53:38 +0000
commitbff6f60d6522a2f3b9730aec5d30c1f50c2e9fbb (patch)
tree1115bef780f34d02dff0acd14af061db2cc828dd /client
parenta2ac955596346d89c8cd857b06d434f489ba1f2b (diff)
downloadvaadin-framework-bff6f60d6522a2f3b9730aec5d30c1f50c2e9fbb.tar.gz
vaadin-framework-bff6f60d6522a2f3b9730aec5d30c1f50c2e9fbb.zip
Support font icons in ComboBox (#13376)
Change-Id: Idb35b8116c28824c8ced9b8f230e06ba8e7ecaaf
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/ui/VFilterSelect.java71
1 files changed, 39 insertions, 32 deletions
diff --git a/client/src/com/vaadin/client/ui/VFilterSelect.java b/client/src/com/vaadin/client/ui/VFilterSelect.java
index b97eff0fbd..e0ced98394 100644
--- a/client/src/com/vaadin/client/ui/VFilterSelect.java
+++ b/client/src/com/vaadin/client/ui/VFilterSelect.java
@@ -54,11 +54,11 @@ import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.PopupPanel.PositionCallback;
import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;
import com.google.gwt.user.client.ui.TextBox;
+import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.BrowserInfo;
import com.vaadin.client.ComponentConnector;
@@ -122,10 +122,9 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
@Override
public String getDisplayString() {
final StringBuffer sb = new StringBuffer();
- if (iconUri != null) {
- sb.append("<img src=\"");
- sb.append(Util.escapeAttribute(iconUri));
- sb.append("\" alt=\"\" class=\"v-icon\" />");
+ final Icon icon = client.getIcon(iconUri);
+ if (icon != null) {
+ sb.append(icon.getElement().getString());
}
String content;
if ("".equals(caption)) {
@@ -990,7 +989,13 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
}
};
- private final Image selectedItemIcon = new Image();
+ private class IconWidget extends Widget {
+ IconWidget(Icon icon) {
+ setElement(icon.getElement());
+ }
+ }
+
+ private IconWidget selectedItemIcon;
/** For internal use only. May be removed or replaced in the future. */
public ApplicationConnection client;
@@ -1113,21 +1118,6 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
tb = createTextBox();
suggestionPopup = createSuggestionPopup();
- selectedItemIcon.setStyleName("v-icon");
- selectedItemIcon.addLoadHandler(new LoadHandler() {
-
- @Override
- public void onLoad(LoadEvent event) {
- if (BrowserInfo.get().isIE8()) {
- // IE8 needs some help to discover it should reposition the
- // text field
- forceReflow();
- }
- updateRootWidth();
- updateSelectedIconPosition();
- }
- });
-
popupOpener.sinkEvents(Event.ONMOUSEDOWN);
Roles.getButtonRole()
.setAriaHiddenState(popupOpener.getElement(), true);
@@ -1413,20 +1403,36 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
* The URI of the icon
*/
public void setSelectedItemIcon(String iconUri) {
+
if (iconUri == null || iconUri.length() == 0) {
- if (selectedItemIcon.isAttached()) {
+ if (selectedItemIcon != null) {
panel.remove(selectedItemIcon);
- if (BrowserInfo.get().isIE8()) {
- // IE8 needs some help to discover it should reposition the
- // text field
- forceReflow();
- }
- updateRootWidth();
+ selectedItemIcon = null;
+ afterSelectedItemIconChange();
}
} else {
+ if (selectedItemIcon != null) {
+ panel.remove(selectedItemIcon);
+ }
+ selectedItemIcon = new IconWidget(client.getIcon(iconUri));
+ selectedItemIcon.addDomHandler(new LoadHandler() {
+ @Override
+ public void onLoad(LoadEvent event) {
+ afterSelectedItemIconChange();
+ }
+ }, LoadEvent.getType());
panel.insert(selectedItemIcon, 0);
- selectedItemIcon.setUrl(iconUri);
- updateRootWidth();
+ afterSelectedItemIconChange();
+ }
+ }
+
+ private void afterSelectedItemIconChange() {
+ if (BrowserInfo.get().isWebkit() || BrowserInfo.get().isIE8()) {
+ // Some browsers need a nudge to reposition the text field
+ forceReflow();
+ }
+ updateRootWidth();
+ if (selectedItemIcon != null) {
updateSelectedIconPosition();
}
}
@@ -1951,8 +1957,9 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
* locked
*/
if (!tb.getElement().getStyle().getWidth().endsWith("px")) {
- tb.setWidth((tb.getOffsetWidth() - selectedItemIcon
- .getOffsetWidth()) + "px");
+ int iconWidth = selectedItemIcon == null ? 0 : selectedItemIcon
+ .getOffsetWidth();
+ tb.setWidth((tb.getOffsetWidth() - iconWidth) + "px");
}
}
}