Skip to content

Commit

Permalink
webadmin: Use leak-free dialog re-position on Window resize
Browse files Browse the repository at this point in the history
Change-Id: Ic12c323f2b4e9428e090b50a9b5030389bbbdb76
Related-To: ArcBees/GWTP#823
Signed-off-by: Vojtech Szocs <vszocs@redhat.com>
  • Loading branch information
vojtechszocs committed Jul 4, 2017
1 parent 81a2d4b commit 6eed144
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.HandlerRegistration;
import com.gwtplatform.mvp.client.PopupView;
import com.gwtplatform.mvp.client.PresenterWidget;

Expand Down Expand Up @@ -37,6 +38,11 @@ public interface ViewDef extends PopupView {
*/
void setPopupKeyPressHandler(PopupNativeKeyPressHandler handler);

/**
* @return The handler used to re-position the dialog on Window resize.
*/
HandlerRegistration getRepositionOnWindowResizeHandler();

}

// Number of popups currently active (visible)
Expand Down Expand Up @@ -70,6 +76,8 @@ protected void onBind() {
getView().hide();
}
}));

registerHandler(getView().getRepositionOnWindowResizeHandler());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.ovirt.engine.ui.common.presenter.AbstractPopupPresenterWidget;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.PopupPanel;
import com.gwtplatform.mvp.client.PopupViewImpl;
Expand Down Expand Up @@ -31,9 +33,10 @@ protected final void initWidget(IsWidget widget) {
}

/**
* Return false to work around GWT-P memory leak. The resize handler implementation is broken,
* so turn it off
* TODO-GWT return false to work around GWTP memory leak
* The resize handler implementation is broken, so turn it off.
* See: https://github.com/ArcBees/GWTP/issues/823
* Once fixed, remove {@link #getRepositionOnWindowResizeHandler} workaround.
*/
@Override
protected boolean repositionOnWindowResize() {
Expand Down Expand Up @@ -62,4 +65,13 @@ public T asWidget() {
return (T) super.asWidget();
}

@Override
public HandlerRegistration getRepositionOnWindowResizeHandler() {
return Window.addResizeHandler(event -> {
if (asPopupPanel().isShowing()) {
showAndReposition();
}
});
}

}

0 comments on commit 6eed144

Please sign in to comment.