OffsetWidth not including padding/margins

180 views
Skip to first unread message

decitrig

unread,
Dec 5, 2011, 2:40:00 PM12/5/11
to google-we...@googlegroups.com
I have a PopupPanel with a Label inside. I'm trying to center the popup horizontally, so I'm calling setPopupPositionAndShow. In the callback, however, the offsetWidth and offsetHeight arguments don't take into account any margins or padding, whether I set them on the popup or the label: the values are always for the text of the label only. Besides the arguments to the callback, I get the same (incorrect) results from calling getOffsetWidth/Height on the label or the popup directly. PopupPanel#center() also does not work correctly. Tested on both Chrome and Firefox.

Here's the code I'm using to set the position:
    messageLabel.setText(message);
    popup.setPopupPositionAndShow(new PositionCallback() {
      @Override
      public void setPosition(int offsetWidth, int offsetHeight) {
        popup.setPopupPosition((Window.getClientWidth() - offsetWidth) / 2, popupTop);
      }
    });

The PopupPanel is in a UiBinder; not sure if that's relevant. Am I doing something wrong, or should I file a bug?

Paul Stockley

unread,
Dec 5, 2011, 5:29:21 PM12/5/11
to google-we...@googlegroups.com
That's the expected behavior, check the DOM reference for OffsetWidth/OffsetHeight. 

decitrig

unread,
Dec 5, 2011, 5:39:25 PM12/5/11
to google-we...@googlegroups.com
It is?

UIObject API:

getOffsetWidth

public int getOffsetWidth()
Gets the object's offset width in pixels. This is the total width of the object, including decorations such as border, margin, and padding.

Returns:
the object's offset width

Mozilla DOM docs:
https://developer.mozilla.org/en/DOM/element.offsetWidth
"Typically, an element's offsetWidth is a measurement which includes the element borders, the element horizontal padding, the element vertical scrollbar (if present, if rendered) and the element CSS width."
Reply all
Reply to author
Forward
0 new messages