* given element, provided that it has been measured. These elements are
* guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
*
* -1 is returned if the element has not been measured. If 0 is returned, it
* might indicate that the element is not attached to the DOM.
+ * <p>
+ * The value returned by this method is always rounded up. To get the exact
+ * outer width, use {@link #getOuterHeightDouble(Element)}
*
* @param element
* the element to get the measured size for
* borders) of the element in pixels.
*/
public final int getOuterHeight(Element element) {
+ assert needsMeasure(element) : "Getting measurement for element that is not measured";
+ return (int) Math.ceil(getMeasuredSize(element, nullSize)
+ .getOuterHeight());
+ }
+
+ /**
+ * Gets the outer height (including margins, paddings and borders) of the
+ * given element, provided that it has been measured. These elements are
+ * guaranteed to be measured:
+ * <ul>
+ * <li>ManagedLayouts and their child Connectors
+ * <li>Elements for which there is at least one ElementResizeListener
+ * <li>Elements for which at least one ManagedLayout has registered a
+ * dependency
+ * </ul>
+ *
+ * -1 is returned if the element has not been measured. If 0 is returned, it
+ * might indicate that the element is not attached to the DOM.
+ *
+ * @param element
+ * the element to get the measured size for
+ * @return the measured outer height (including margins, paddings and
+ * borders) of the element in pixels.
+ */
+ public final double getOuterHeightDouble(Element element) {
assert needsMeasure(element) : "Getting measurement for element that is not measured";
return getMeasuredSize(element, nullSize).getOuterHeight();
}
* given element, provided that it has been measured. These elements are
* guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
*
* -1 is returned if the element has not been measured. If 0 is returned, it
* might indicate that the element is not attached to the DOM.
+ * <p>
+ * The value returned by this method is always rounded up. To get the exact
+ * outer width, use {@link #getOuterWidthDouble(Element)}
*
* @param element
* the element to get the measured size for
* borders) of the element in pixels.
*/
public final int getOuterWidth(Element element) {
+ assert needsMeasure(element) : "Getting measurement for element that is not measured";
+ return (int) Math.ceil(getMeasuredSize(element, nullSize)
+ .getOuterWidth());
+ }
+
+ /**
+ * Gets the outer width (including margins, paddings and borders) of the
+ * given element, provided that it has been measured. These elements are
+ * guaranteed to be measured:
+ * <ul>
+ * <li>ManagedLayouts and their child Connectors
+ * <li>Elements for which there is at least one ElementResizeListener
+ * <li>Elements for which at least one ManagedLayout has registered a
+ * dependency
+ * </ul>
+ *
+ * -1 is returned if the element has not been measured. If 0 is returned, it
+ * might indicate that the element is not attached to the DOM.
+ *
+ * @param element
+ * the element to get the measured size for
+ * @return the measured outer width (including margins, paddings and
+ * borders) of the element in pixels.
+ */
+ public final double getOuterWidthDouble(Element element) {
assert needsMeasure(element) : "Getting measurement for element that is not measured";
return getMeasuredSize(element, nullSize).getOuterWidth();
}
* given element, provided that it has been measured. These elements are
* guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
*
* -1 is returned if the element has not been measured. If 0 is returned, it
* might indicate that the element is not attached to the DOM.
+ * <p>
+ * The value returned by this method is always rounded up. To get the exact
+ * outer width, use {@link #getInnerHeightDouble(Element)}
*
* @param element
* the element to get the measured size for
* borders) of the element in pixels.
*/
public final int getInnerHeight(Element element) {
+ assert needsMeasure(element) : "Getting measurement for element that is not measured";
+ return (int) Math.ceil(getMeasuredSize(element, nullSize)
+ .getInnerHeight());
+ }
+
+ /**
+ * Gets the inner height (excluding margins, paddings and borders) of the
+ * given element, provided that it has been measured. These elements are
+ * guaranteed to be measured:
+ * <ul>
+ * <li>ManagedLayouts and their child Connectors
+ * <li>Elements for which there is at least one ElementResizeListener
+ * <li>Elements for which at least one ManagedLayout has registered a
+ * dependency
+ * </ul>
+ *
+ * -1 is returned if the element has not been measured. If 0 is returned, it
+ * might indicate that the element is not attached to the DOM.
+ *
+ * @param element
+ * the element to get the measured size for
+ * @return the measured inner height (excluding margins, paddings and
+ * borders) of the element in pixels.
+ */
+ public final double getInnerHeightDouble(Element element) {
assert needsMeasure(element) : "Getting measurement for element that is not measured";
return getMeasuredSize(element, nullSize).getInnerHeight();
}
* given element, provided that it has been measured. These elements are
* guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
*
* -1 is returned if the element has not been measured. If 0 is returned, it
* might indicate that the element is not attached to the DOM.
+ * <p>
+ * The value returned by this method is always rounded up. To get the exact
+ * outer width, use {@link #getOuterHeightDouble(Element)}
*
* @param element
* the element to get the measured size for
* borders) of the element in pixels.
*/
public final int getInnerWidth(Element element) {
+ assert needsMeasure(element) : "Getting measurement for element that is not measured";
+ return (int) Math.ceil(getMeasuredSize(element, nullSize)
+ .getInnerWidth());
+ }
+
+ /**
+ * Gets the inner width (excluding margins, paddings and borders) of the
+ * given element, provided that it has been measured. These elements are
+ * guaranteed to be measured:
+ * <ul>
+ * <li>ManagedLayouts and their child Connectors
+ * <li>Elements for which there is at least one ElementResizeListener
+ * <li>Elements for which at least one ManagedLayout has registered a
+ * dependency
+ * </ul>
+ *
+ * -1 is returned if the element has not been measured. If 0 is returned, it
+ * might indicate that the element is not attached to the DOM.
+ *
+ * @param element
+ * the element to get the measured size for
+ * @return the measured inner width (excluding margins, paddings and
+ * borders) of the element in pixels.
+ */
+ public final double getInnerWidthDouble(Element element) {
assert needsMeasure(element) : "Getting measurement for element that is not measured";
return getMeasuredSize(element, nullSize).getInnerWidth();
}
* provided that it has been measured. These elements are guaranteed to be
* measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
* element, provided that it has been measured. These elements are
* guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
* provided that it has been measured. These elements are guaranteed to be
* measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
* Gets the top border of the given element, provided that it has been
* measured. These elements are guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
* Gets the left border of the given element, provided that it has been
* measured. These elements are guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
* Gets the bottom border of the given element, provided that it has been
* measured. These elements are guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
* Gets the right border of the given element, provided that it has been
* measured. These elements are guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
* element, provided that it has been measured. These elements are
* guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
* Gets the top padding of the given element, provided that it has been
* measured. These elements are guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
* Gets the left padding of the given element, provided that it has been
* measured. These elements are guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
* Gets the bottom padding of the given element, provided that it has been
* measured. These elements are guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
* Gets the right padding of the given element, provided that it has been
* measured. These elements are guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
* Gets the top margin of the given element, provided that it has been
* measured. These elements are guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
* Gets the right margin of the given element, provided that it has been
* measured. These elements are guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
* Gets the bottom margin of the given element, provided that it has been
* measured. These elements are guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
* Gets the left margin of the given element, provided that it has been
* measured. These elements are guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
* Gets the combined top & bottom margin of the given element, provided that
* they have been measured. These elements are guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
* Gets the combined left & right margin of the given element, provided that
* they have been measured. These elements are guaranteed to be measured:
* <ul>
- * <li>ManagedLayotus and their child Connectors
+ * <li>ManagedLayouts and their child Connectors
* <li>Elements for which there is at least one ElementResizeListener
* <li>Elements for which at least one ManagedLayout has registered a
* dependency
}
}
- private int width = -1;
- private int height = -1;
+ private double width = -1;
+ private double height = -1;
private int[] paddings = new int[4];
private int[] borders = new int[4];
private FastStringSet dependents = FastStringSet.create();
- public int getOuterHeight() {
+ public double getOuterHeight() {
return height;
}
- public int getOuterWidth() {
+ public double getOuterWidth() {
return width;
}
return sizes[0] + sizes[2];
}
- public int getInnerHeight() {
+ public double getInnerHeight() {
return height - sumHeights(margins) - sumHeights(borders)
- sumHeights(paddings);
}
- public int getInnerWidth() {
+ public double getInnerWidth() {
return width - sumWidths(margins) - sumWidths(borders)
- sumWidths(paddings);
}
- public boolean setOuterHeight(int height) {
+ public boolean setOuterHeight(double height) {
if (this.height != height) {
this.height = height;
return true;
}
}
- public boolean setOuterWidth(int width) {
+ public boolean setOuterWidth(double width) {
if (this.width != width) {
this.width = width;
return true;
Profiler.leave("Measure borders");
Profiler.enter("Measure height");
- int requiredHeight = WidgetUtil.getRequiredHeight(element);
- int marginHeight = sumHeights(margins);
- int oldHeight = height;
- int oldWidth = width;
- if (setOuterHeight(requiredHeight + marginHeight)) {
+ double requiredHeight = WidgetUtil.getRequiredHeightDouble(element);
+ double outerHeight = requiredHeight + sumHeights(margins);
+ double oldHeight = height;
+ if (setOuterHeight(outerHeight)) {
debugSizeChange(element, "Height (outer)", oldHeight, height);
heightChanged = true;
}
Profiler.leave("Measure height");
Profiler.enter("Measure width");
- int requiredWidth = WidgetUtil.getRequiredWidth(element);
- int marginWidth = sumWidths(margins);
- if (setOuterWidth(requiredWidth + marginWidth)) {
+ double requiredWidth = WidgetUtil.getRequiredWidthDouble(element);
+ double outerWidth = requiredWidth + sumWidths(margins);
+ double oldWidth = width;
+ if (setOuterWidth(outerWidth)) {
debugSizeChange(element, "Width (outer)", oldWidth, width);
widthChanged = true;
}
}
private void debugSizeChange(Element element, String sizeChangeType,
- int changedFrom, int changedTo) {
+ double changedFrom, double changedTo) {
debugSizeChange(element, sizeChangeType, String.valueOf(changedFrom),
String.valueOf(changedTo));
}
return reqWidth;
}
+ /**
+ * Gets the border-box width for the given element, i.e. element width +
+ * border + padding.
+ *
+ * @param element
+ * The element to check
+ * @return The border-box width for the element
+ */
+ public static double getRequiredWidthDouble(
+ com.google.gwt.dom.client.Element element) {
+ double reqWidth = getRequiredWidthBoundingClientRectDouble(element);
+ if (BrowserInfo.get().isIE() && !BrowserInfo.get().isIE8()) {
+ double csWidth = getRequiredWidthComputedStyleDouble(element);
+ if (csWidth > reqWidth && csWidth < (reqWidth + 1)) {
+ // IE9 rounds reqHeight to integers BUT sometimes reports wrong
+ // csHeight it seems, so we only use csHeight if it is within a
+ // rounding error
+ return csWidth;
+ }
+ }
+ return reqWidth;
+ }
+
/**
* Gets the border-box height for the given element, i.e. element height +
* border + padding. Always rounds up to nearest integer.
return reqHeight;
}
+ /**
+ * Gets the border-box height for the given element, i.e. element height +
+ * border + padding.
+ *
+ * @param element
+ * The element to check
+ * @return The border-box height for the element
+ */
+ public static double getRequiredHeightDouble(
+ com.google.gwt.dom.client.Element element) {
+ double reqHeight = getRequiredHeightBoundingClientRectDouble(element);
+ if (BrowserInfo.get().isIE() && !BrowserInfo.get().isIE8()) {
+ double csHeight = getRequiredHeightComputedStyleDouble(element);
+ if (csHeight > reqHeight && csHeight < (reqHeight + 1)) {
+ // IE9 rounds reqHeight to integers BUT sometimes reports wrong
+ // csHeight it seems, so we only use csHeight if it is within a
+ // rounding error
+ return csHeight;
+ }
+ }
+ return reqHeight;
+ }
+
/**
* Calculates the width of the element's bounding rectangle.
* <p>
}
}-*/;
- public static native int getRequiredHeightComputedStyle(
+ public static int getRequiredHeightComputedStyle(
+ com.google.gwt.dom.client.Element element) {
+ return (int) Math.ceil(getRequiredHeightComputedStyleDouble(element));
+ }
+
+ public static native double getRequiredHeightComputedStyleDouble(
com.google.gwt.dom.client.Element element)
/*-{
var cs = element.ownerDocument.defaultView.getComputedStyle(element);
var heightPx = cs.height;
if(heightPx == 'auto'){
// Fallback for inline elements
- return @com.vaadin.client.WidgetUtil::getRequiredHeightBoundingClientRect(Lcom/google/gwt/dom/client/Element;)(element);
+ return @com.vaadin.client.WidgetUtil::getRequiredHeightBoundingClientRectDouble(Lcom/google/gwt/dom/client/Element;)(element);
}
var height = parseFloat(heightPx); // Will automatically skip "px" suffix
var border = parseFloat(cs.borderTopWidth) + parseFloat(cs.borderBottomWidth); // Will automatically skip "px" suffix
var padding = parseFloat(cs.paddingTop) + parseFloat(cs.paddingBottom); // Will automatically skip "px" suffix
- return Math.ceil(height+border+padding);
+ return height+border+padding;
}-*/;
- public static native int getRequiredWidthComputedStyle(
+ public static int getRequiredWidthComputedStyle(
+ com.google.gwt.dom.client.Element element) {
+ return (int) Math.ceil(getRequiredWidthComputedStyleDouble(element));
+ }
+
+ public static native int getRequiredWidthComputedStyleDouble(
com.google.gwt.dom.client.Element element)
/*-{
var cs = element.ownerDocument.defaultView.getComputedStyle(element);
var widthPx = cs.width;
if(widthPx == 'auto'){
// Fallback for inline elements
- return @com.vaadin.client.WidgetUtil::getRequiredWidthBoundingClientRect(Lcom/google/gwt/dom/client/Element;)(element);
+ return @com.vaadin.client.WidgetUtil::getRequiredWidthBoundingClientRectDouble(Lcom/google/gwt/dom/client/Element;)(element);
}
var width = parseFloat(widthPx); // Will automatically skip "px" suffix
var border = parseFloat(cs.borderLeftWidth) + parseFloat(cs.borderRightWidth); // Will automatically skip "px" suffix
var padding = parseFloat(cs.paddingLeft) + parseFloat(cs.paddingRight); // Will automatically skip "px" suffix
- return Math.ceil(width+border+padding);
+ return width+border+padding;
}-*/;
/**