When removing a widget from the RootPanel, the RootPanel overwrites the CSS
positioning attributes of the Widget in the changeToStaticPositioning method.
The idea was to revert any changes made by the Panel, but it actually
overwrites the position attribute from a CSS file instead.

This bug also affects the PopupPanel, which uses the left and top attributes to
position itself.  The changeToSTaticPositioning method overwrites the left and
top attributes, effectively repositioning the popup every time it is hidden.

Fix: Instead of setting the position attribute to "static", I set it to an
empty string, reverting back to the original CSS attributes.  I added a couple
of variables to the PopupPanel to save the top and left position as they are
set.  When the PopupPanel is shown, it is automatically repositioned to the
previous location.

Unit Test: I modified PopupTest to take the PopupPanel changes into account by
hiding a PopupPanel, showing it, and verifying it is still in the correct
location.

Issue: 1195
Patch by: jlabanca
Review by: jgw



git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1244 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/AbsolutePanel.java b/user/src/com/google/gwt/user/client/ui/AbsolutePanel.java
index 852707a..b6bed98 100644
--- a/user/src/com/google/gwt/user/client/ui/AbsolutePanel.java
+++ b/user/src/com/google/gwt/user/client/ui/AbsolutePanel.java
@@ -41,8 +41,10 @@
    *
    * @param elem the DOM element 
    */
-  private static void changeToStaticPositioning(Element elem) {  
-    DOM.setStyleAttribute(elem, "position", "static");
+  private static void changeToStaticPositioning(Element elem) {
+    DOM.setStyleAttribute(elem, "left", "");
+    DOM.setStyleAttribute(elem, "top", "");
+    DOM.setStyleAttribute(elem, "position", "");
   }
 
   /**
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 a83c760..996c232 100644
--- a/user/src/com/google/gwt/user/client/ui/PopupPanel.java
+++ b/user/src/com/google/gwt/user/client/ui/PopupPanel.java
@@ -70,6 +70,12 @@
 
   private String desiredWidth;
 
+  // the left style attribute in pixels
+  private int leftPosition = -1;
+  
+  // The top style attribute in pixels
+  private int topPosition = -1; 
+  
   private PopupListenerCollection popupListeners;
 
   /**
@@ -321,6 +327,10 @@
       top = 0;
     }
 
+    // Save the position of the popup
+    leftPosition = left;
+    topPosition = top;
+
     // Set the popup's position manually, allowing setPopupPosition() to be
     // called before show() is called (so a popup can be positioned without it
     // 'jumping' on the screen).
@@ -410,6 +420,9 @@
     // the PopupPanel will appear to 'jump' from its static/relative position
     // to its absolute position (issue #1231).
     DOM.setStyleAttribute(getElement(), "position", "absolute");
+    if (topPosition != -1) {
+      setPopupPosition(leftPosition, topPosition);
+    }
     RootPanel.get().add(this);
 
     impl.onShow(getElement());
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 8bcd81a..6b4f122 100644
--- a/user/test/com/google/gwt/user/client/ui/PopupTest.java
+++ b/user/test/com/google/gwt/user/client/ui/PopupTest.java
@@ -57,6 +57,13 @@
     assertEquals(128, popup.getPopupLeft());
     assertEquals(64, popup.getPopupTop());
 
+    // Make sure that the popup returns to the correct position
+    // after hiding and showing it.
+    popup.hide();
+    popup.show();
+    assertEquals(128, popup.getPopupLeft());
+    assertEquals(64, popup.getPopupTop());
+
     // Make sure that setting the popup's size & position works _after_
     // setting its widget (and that clearing its size properly resizes it to
     // its widget's size).