Fix for #2253 - Use getBoundingClientRect() for measuring elements when available.

svn changeset:6090/svn branch:trunk
This commit is contained in:
Artur Signell 2008-12-05 10:34:30 +00:00
parent c0d846ba0a
commit 9a602ddcc7

View File

@ -189,8 +189,9 @@ public class ChildComponentContainer extends Panel {
* Widget wrapper includes margin which the widget offsetWidth/Height
* does not include
*/
int w = widgetDIV.getOffsetWidth();
int h = widgetDIV.getOffsetHeight();
int w = getRequiredWidth(widgetDIV);
int h = getRequiredHeight(widgetDIV);
widgetSize.setWidth(w);
widgetSize.setHeight(h);
@ -199,6 +200,32 @@ public class ChildComponentContainer extends Panel {
}
public static native int getRequiredWidth(
com.google.gwt.dom.client.Element element)
/*-{
var width;
if (element.getBoundingClientRect != null) {
var rect = element.getBoundingClientRect();
width = Math.ceil(rect.right - rect.left);
} else {
width = elem.offsetWidth;
}
return width;
}-*/;
public static native int getRequiredHeight(
com.google.gwt.dom.client.Element element)
/*-{
var height;
if (element.getBoundingClientRect != null) {
var rect = element.getBoundingClientRect();
height = Math.ceil(rect.bottom - rect.top);
} else {
height = elem.offsetHeight;
}
return height;
}-*/;
public void setMarginLeft(int marginLeft) {
containerMarginLeft = marginLeft;
getElement().getStyle().setPropertyPx("paddingLeft", marginLeft);