Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The doCenter method doesn't center correctly the popup when the popup is hidden #302

Merged
merged 2 commits into from
Aug 8, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,36 @@ protected PopupPanel asPopupPanel() {
* This method centers the popup panel, temporarily making it visible if
* needed.
*/
private void doCenter() {
protected void doCenter() {
// We can't use Element.center() method as it will show the popup
// by default and not only centering it. This is resulting in onAttach()
// being called twice when using setInSlot() or addToPopupSlot() in PresenterWidget

PopupPanel popup = asPopupPanel();
Element elem = popup.getElement();

boolean isShowing = popup.isShowing();
// If left/top are set from a previous doCenter() call, and our content
// has changed, we may get a bogus getOffsetWidth because our new content
// is wrapping (giving a lower offset width) then it would without the
// previous left. Clearing left/top to avoids this.
PopupPanel popup = asPopupPanel();
Element elem = popup.getElement();
elem.getStyle().clearLeft();
elem.getStyle().clearTop();

// the popup should be added to the dom in order to get correct values for offsetWidth/offsetHeight
if (!isShowing) {
popup.setVisible(false);
popup.show();
}

int left = (Window.getClientWidth() - popup.getOffsetWidth()) >> 1;
int top = (Window.getClientHeight() - popup.getOffsetHeight()) >> 1;

if (!isShowing) {
popup.hide();
popup.setVisible(true);
}

popup.setPopupPosition(Math.max(Window.getScrollLeft() + left, 0), Math.max(
Window.getScrollTop() + top, 0));
}
Expand Down