From 3f60c5e4f72239c44f94f1d8f55191bd596e9893 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Thu, 16 Feb 2012 12:14:30 +0200 Subject: [PATCH] Make VFilterSelect work with border-box & MeasureManager (#8313) --- .../VAADIN/themes/base/select/select.css | 3 + .../VAADIN/themes/reindeer/select/select.css | 2 +- .../terminal/gwt/client/ui/VFilterSelect.java | 127 +++--------------- .../gwt/client/ui/VFilterSelectPaintable.java | 10 +- 4 files changed, 31 insertions(+), 111 deletions(-) diff --git a/WebContent/VAADIN/themes/base/select/select.css b/WebContent/VAADIN/themes/base/select/select.css index 4487bc6a4e..612ffbf69c 100644 --- a/WebContent/VAADIN/themes/base/select/select.css +++ b/WebContent/VAADIN/themes/base/select/select.css @@ -56,6 +56,7 @@ .v-filterselect { white-space: nowrap; text-align: left; + display: inline-block; } .v-filterselect .v-icon { float: left; @@ -65,6 +66,8 @@ .v-popupview-popup .v-filterselect-input { float: left; -webkit-border-radius: 0px; + box-sizing: border-box; + -moz-box-sizing: border-box; } .v-filterselect-prompt .v-filterselect-input { color: #999; diff --git a/WebContent/VAADIN/themes/reindeer/select/select.css b/WebContent/VAADIN/themes/reindeer/select/select.css index a685e3322a..c71de8fbc0 100644 --- a/WebContent/VAADIN/themes/reindeer/select/select.css +++ b/WebContent/VAADIN/themes/reindeer/select/select.css @@ -10,7 +10,7 @@ background: transparent repeat-x; background-image: url(img/center.png); /** sprite-ref: verticals; sprite-alignment: repeat; sprite-margin-bottom: 1px */ border: none; - height: 16px; + height: 24px; } /* More specific selector to override padding */ .v-app input.v-filterselect-input, diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java index 5e061175c0..ec5f90e812 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java @@ -46,9 +46,12 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.EventId; import com.vaadin.terminal.gwt.client.Focusable; +import com.vaadin.terminal.gwt.client.MeasuredSize; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VConsole; +import com.vaadin.terminal.gwt.client.VPaintableMap; +import com.vaadin.terminal.gwt.client.VPaintableWidget; import com.vaadin.terminal.gwt.client.VTooltip; /** @@ -914,9 +917,6 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, // This handles the special case where are not filtering yet and the // selected value has changed on the server-side. See #2119 protected boolean popupOpenerClicked; - private String width = null; - private int textboxPadding = -1; - private int componentPadding = -1; protected int suggestionPopupMinWidth = 0; private int popupWidth = -1; /* @@ -925,7 +925,6 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, */ protected String lastNewItemString; protected boolean focused = false; - private int horizPaddingAndBorder = 2; /** * If set to false, the component should not allow entering text to the @@ -1071,22 +1070,6 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, tb.setText(text); } - /* - * (non-Javadoc) - * - * @see com.google.gwt.user.client.ui.Composite#onAttach() - */ - @Override - protected void onAttach() { - super.onAttach(); - - /* - * We need to recalculate the root width when the select is attached, so - * #2974 won't happen. - */ - updateRootWidth(); - } - /** * Turns prompting on. When prompting is turned on a command prompt is shown * in the text box if nothing has been entered. @@ -1573,44 +1556,14 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, tb.setFocus(true); } - /* - * (non-Javadoc) - * - * @see com.google.gwt.user.client.ui.UIObject#setWidth(java.lang.String) - */ - @Override - public void setWidth(String width) { - if (width == null || width.equals("")) { - this.width = null; - } else { - this.width = width; - } - - horizPaddingAndBorder = Util.setWidthExcludingPaddingAndBorder(this, - width, horizPaddingAndBorder); - - if (initDone) { - updateRootWidth(); - } - } - - /* - * (non-Javadoc) - * - * @see com.google.gwt.user.client.ui.UIObject#setHeight(java.lang.String) - */ - @Override - public void setHeight(String height) { - super.setHeight(height); - Util.setHeightExcludingPaddingAndBorder(tb, height, 3); - } - /** * Calculates the width of the select if the select has undefined width. * Should be called when the width changes or when the icon changes. */ protected void updateRootWidth() { - if (width == null) { + VPaintableWidget paintable = VPaintableMap.get(client).getPaintable( + this); + if (paintable.isUndefinedWidth()) { /* * When the width is not specified we must specify width for root * div so the popupopener won't wrap to the next line and also so @@ -1618,15 +1571,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, */ int tbWidth = Util.getRequiredWidth(tb); - /* - * Note: iconWidth is here calculated as a negative pixel value so - * you should consider this in further calculations. - */ - int iconWidth = selectedItemIcon.isAttached() ? Util - .measureMarginLeft(tb.getElement()) - - Util.measureMarginLeft(selectedItemIcon.getElement()) : 0; - - int w = tbWidth + getPopUpOpenerWidth() + iconWidth; + int w = tbWidth + getNonTextboxSpace(); /* * When the select has a undefined with we need to check that we are @@ -1638,26 +1583,14 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, if ((!initDone || currentPage + 1 < 0) && suggestionPopupMinWidth > w) { setTextboxWidth(suggestionPopupMinWidth); - w = suggestionPopupMinWidth; - } else { - /* - * Firefox3 has its own way of doing rendering so we need to - * specify the width for the TextField to make sure it actually - * is rendered as wide as FF3 says it is - */ - tb.setWidth((tbWidth - getTextboxPadding()) + "px"); } - super.setWidth((w) + "px"); - // Freeze the initial width, so that it won't change even if the - // icon size changes - width = w + "px"; } else { /* * When the width is specified we also want to explicitly specify - * widths for textbox and popupopener + * width for textbox */ - setTextboxWidth(getMainWidth() - getComponentPadding()); + setTextboxWidth(getMainWidth()); } } @@ -1690,47 +1623,23 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, * Sets the text box width in pixels. * * @param componentWidth - * The width of the text box in pixels + * The width of the combo box in pixels */ private void setTextboxWidth(int componentWidth) { - int padding = getTextboxPadding(); - int iconWidth = selectedItemIcon.isAttached() ? Util - .getRequiredWidth(selectedItemIcon) : 0; - - int textboxWidth = componentWidth - padding - getPopUpOpenerWidth() - - iconWidth; + int extraSpace = getNonTextboxSpace(); + int textboxWidth = componentWidth - extraSpace; if (textboxWidth < 0) { textboxWidth = 0; } tb.setWidth(textboxWidth + "px"); } - /** - * Gets the horizontal padding of the text box in pixels. The measurement - * includes the border width. - * - * @return The padding in pixels - */ - private int getTextboxPadding() { - if (textboxPadding < 0) { - textboxPadding = Util.measureHorizontalPaddingAndBorder( - tb.getElement(), 4); - } - return textboxPadding; - } - - /** - * Gets the horizontal padding of the select. The measurement includes the - * border width. - * - * @return The padding in pixels - */ - private int getComponentPadding() { - if (componentPadding < 0) { - componentPadding = Util.measureHorizontalPaddingAndBorder( - getElement(), 3); - } - return componentPadding; + private int getNonTextboxSpace() { + MeasuredSize measuredSize = VPaintableMap.get(client) + .getPaintable(this).getMeasuredSize(); + int extraSpace = getPopUpOpenerWidth() + measuredSize.getPaddingWidth() + + measuredSize.getBorderWidth(); + return extraSpace; } /** diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelectPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelectPaintable.java index eaf9eec16a..374b43914e 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelectPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelectPaintable.java @@ -12,7 +12,8 @@ import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.ui.VFilterSelect.FilterSelectSuggestion; -public class VFilterSelectPaintable extends VAbstractPaintableWidget { +public class VFilterSelectPaintable extends VAbstractPaintableWidget implements + ResizeRequired { /* * (non-Javadoc) @@ -244,4 +245,11 @@ public class VFilterSelectPaintable extends VAbstractPaintableWidget { public VFilterSelect getWidgetForPaintable() { return (VFilterSelect) super.getWidgetForPaintable(); } + + public void onResize() { + VFilterSelect widget = getWidgetForPaintable(); + if (widget.initDone) { + widget.updateRootWidth(); + } + } } -- 2.39.5