Author: j...@google.com
Date: Thu Feb  5 11:18:14 2009
New Revision: 4639

Modified:
     
branches/snapshot-2009.01.29/user/src/com/google/gwt/user/client/ui/PopupPanel.java
     
branches/snapshot-2009.01.29/user/test/com/google/gwt/user/client/ui/DialogBoxTest.java

Log:
Fixes squirrely case where calling PopupPanel.hide() appears to get into a  
race
condition when it calls onUnload(), which calls hide() again. This is now
cleaned up to only do strictly-necessary cleanup work in onUnload(), and a  
test
added to ensure it works properly in practice.
Patch by: jgw
Review by: rjrjr


Modified:  
branches/snapshot-2009.01.29/user/src/com/google/gwt/user/client/ui/PopupPanel.java
==============================================================================
---  
branches/snapshot-2009.01.29/user/src/com/google/gwt/user/client/ui/PopupPanel.java
      
(original)
+++  
branches/snapshot-2009.01.29/user/src/com/google/gwt/user/client/ui/PopupPanel.java
      
Thu Feb  5 11:18:14 2009
@@ -462,14 +462,10 @@
     *          {...@link CloseHandler#onClose(CloseEvent)} when the popup is  
closed
     */
    public void hide(boolean autoClosed) {
-    if (!showing) {
+    if (!isShowing()) {
        return;
      }
-    showing = false;
-    if (nativePreviewHandlerRegistration != null) {
-      nativePreviewHandlerRegistration.removeHandler();
-      nativePreviewHandlerRegistration = null;
-    }
+    cleanup();

      // Hide the popup
      resizeAnimation.setState(false);
@@ -590,7 +586,10 @@

    @Override
    protected void onUnload() {
-    hide();
+    // Just to be sure, we perform cleanup when the popup is unloaded (i.e.
+    // removed from the DOM). This is normally taken care of in hide(),  
but it
+    // can be missed if someone removes the popup directly from the  
RootPanel.
+    cleanup();
    }

    /**
@@ -896,6 +895,16 @@
        elt.blur();
      }
    }-*/;
+
+  private void cleanup() {
+    // Clear the 'showing' flag and make sure that the event preview is  
cleaned
+    // up.
+    showing = false;
+    if (nativePreviewHandlerRegistration != null) {
+      nativePreviewHandlerRegistration.removeHandler();
+      nativePreviewHandlerRegistration = null;
+    }
+  }

    /**
     * Does the event target one of the partner elements?

Modified:  
branches/snapshot-2009.01.29/user/test/com/google/gwt/user/client/ui/DialogBoxTest.java
==============================================================================
---  
branches/snapshot-2009.01.29/user/test/com/google/gwt/user/client/ui/DialogBoxTest.java
  
(original)
+++  
branches/snapshot-2009.01.29/user/test/com/google/gwt/user/client/ui/DialogBoxTest.java
  
Thu Feb  5 11:18:14 2009
@@ -15,6 +15,8 @@
   */
  package com.google.gwt.user.client.ui;

+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
  import com.google.gwt.user.client.Command;
  import com.google.gwt.user.client.DOM;
  import com.google.gwt.user.client.DeferredCommand;
@@ -68,6 +70,20 @@
      assertEquals("text", dialogBox.getText());
      assertTrue(dialogBox.getHTML().equalsIgnoreCase("<b>text</b>"));
    }
+
+  public void testSimpleCloseButtonOnModalDialog() {
+    final DialogBox dialogBox = new DialogBox(false, true);
+    Button button = new Button();
+    button.addClickHandler(new ClickHandler() {
+      public void onClick(ClickEvent event) {
+        dialogBox.hide();
+      }
+    });
+    dialogBox.add(button);
+    dialogBox.show();
+    button.click();
+    assertFalse(dialogBox.isShowing());
+  }

    public void testDebugId() {
      DialogBox dBox = new DialogBox();
@@ -86,7 +102,6 @@
      // Check the header IDs
      DeferredCommand.addCommand(new Command() {
        public void execute() {
-        String prefix = UIObject.DEBUG_ID_PREFIX;
          UIObjectTest.assertDebugIdContents("myDialogBox-caption",
              "test caption");
          finishTest();

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to