Changes PopupPanel.center() to prefer keeping the top-left of a popup on-screen.
Patch by: Isaac Truett
Review: http://gwt-code-reviews.appspot.com/56810
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5929 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/PopupPanel.java b/user/src/com/google/gwt/user/client/ui/PopupPanel.java
index 1a2e62e..623f193 100644
--- a/user/src/com/google/gwt/user/client/ui/PopupPanel.java
+++ b/user/src/com/google/gwt/user/client/ui/PopupPanel.java
@@ -389,7 +389,7 @@
int left = (Window.getClientWidth() - getOffsetWidth()) >> 1;
int top = (Window.getClientHeight() - getOffsetHeight()) >> 1;
- setPopupPosition(Window.getScrollLeft() + left, Window.getScrollTop() + top);
+ setPopupPosition(Math.max(Window.getScrollLeft() + left, 0), Math.max(Window.getScrollTop() + top, 0));
if (!initiallyShowing) {
setAnimationEnabled(initiallyAnimated);
diff --git a/user/test/com/google/gwt/user/client/ui/PopupTest.java b/user/test/com/google/gwt/user/client/ui/PopupTest.java
index 1281c0a..44631cf 100644
--- a/user/test/com/google/gwt/user/client/ui/PopupTest.java
+++ b/user/test/com/google/gwt/user/client/ui/PopupTest.java
@@ -35,15 +35,15 @@
private static class TestablePopupPanel extends PopupPanel {
private int onLoadCount;
+ public void assertOnLoadCount(int expected) {
+ assertEquals(expected, onLoadCount);
+ }
+
@Override
public Element getContainerElement() {
return super.getContainerElement();
}
- public void assertOnLoadCount(int expected) {
- assertEquals(expected, onLoadCount);
- }
-
@Override
public void onLoad() {
super.onLoad();
@@ -113,6 +113,20 @@
}
/**
+ * Tests that a large PopupPanel is not positioned off the top or left edges
+ * of the browser window, making part of the panel unreachable.
+ */
+ public void testCenterLargePopup() {
+ PopupPanel popup = new PopupPanel();
+ popup.setHeight("1000px");
+ popup.setWidth("1000px");
+ popup.setWidget(new Label("foo"));
+ popup.center();
+ assertEquals(0, popup.getAbsoluteTop());
+ assertEquals(0, popup.getAbsoluteLeft());
+ }
+
+ /**
* Issue 2463: If a {@link PopupPanel} contains a dependent {@link PopupPanel}
* that is hidden or shown in the onDetach or onAttach method, we could run
* into conflicts with the animations. The {@link MenuBar} exhibits this
@@ -182,28 +196,6 @@
}
}
- /**
- * Test the showing a popup while it is hiding will not result in an illegal
- * state.
- */
- public void testShowWhileHiding() {
- PopupPanel popup = createPopupPanel();
-
- // Show the popup
- popup.setAnimationEnabled(false);
- popup.show();
- assertTrue(popup.isShowing());
-
- // Start hiding the popup
- popup.setAnimationEnabled(true);
- popup.hide();
- assertFalse(popup.isShowing());
-
- // Show the popup while its hiding
- popup.show();
- assertTrue(popup.isShowing());
- }
-
@DoNotRunWith(Platform.Htmlunit)
public void testPopup() {
// Get rid of window margins so we can test absolute position.
@@ -278,6 +270,28 @@
}
/**
+ * Test the showing a popup while it is hiding will not result in an illegal
+ * state.
+ */
+ public void testShowWhileHiding() {
+ PopupPanel popup = createPopupPanel();
+
+ // Show the popup
+ popup.setAnimationEnabled(false);
+ popup.show();
+ assertTrue(popup.isShowing());
+
+ // Start hiding the popup
+ popup.setAnimationEnabled(true);
+ popup.hide();
+ assertFalse(popup.isShowing());
+
+ // Show the popup while its hiding
+ popup.show();
+ assertTrue(popup.isShowing());
+ }
+
+ /**
* Create a new PopupPanel.
*/
protected PopupPanel createPopupPanel() {