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;
/**
// 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;
/*
*/
protected String lastNewItemString;
protected boolean focused = false;
- private int horizPaddingAndBorder = 2;
/**
* If set to false, the component should not allow entering text to the
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.
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
*/
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
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());
}
}
* 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;
}
/**