Fixes a bug in PopupPanel where it can enter an invalid state if it is shown while attached to a panel.
http://gwt-code-reviews.appspot.com/298804/show
Review by: spoon@google.com
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@7924 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 8e9dcd2..9d1cd74 100644
--- a/user/src/com/google/gwt/user/client/ui/PopupPanel.java
+++ b/user/src/com/google/gwt/user/client/ui/PopupPanel.java
@@ -1001,6 +1001,11 @@
public void show() {
if (showing) {
return;
+ } else if (isAttached()) {
+ // The popup is attached directly to another panel, so we need to remove
+ // it from its parent before showing it. This is a weird use case, but
+ // since PopupPanel is a Widget, its legal.
+ this.removeFromParent();
}
resizeAnimation.setState(true, false);
}
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 7d4b0f6..4af1d58 100644
--- a/user/test/com/google/gwt/user/client/ui/PopupTest.java
+++ b/user/test/com/google/gwt/user/client/ui/PopupTest.java
@@ -428,7 +428,23 @@
}
/**
- * Test the showing a popup while it is hiding will not result in an illegal
+ * Test that showing a popup while it is attached does not put it in an
+ * invalid state.
+ */
+ public void testShowWhileAttached() {
+ PopupPanel popup = createPopupPanel();
+ RootPanel.get().add(popup);
+ popup.show();
+ assertTrue(popup.isAttached());
+ assertTrue(popup.isShowing());
+
+ popup.hide();
+ assertFalse(popup.isAttached());
+ assertFalse(popup.isShowing());
+ }
+
+ /**
+ * Test that showing a popup while it is hiding will not result in an illegal
* state.
*/
public void testShowWhileHiding() {