Author: j...@google.com Date: Fri Feb 6 11:11:50 2009 New Revision: 4654 Modified: releases/1.6/user/src/com/google/gwt/user/client/ui/PopupPanel.java releases/1.6/user/test/com/google/gwt/user/client/ui/DialogBoxTest.java
Log: Merge of c4628, c4639 from branches/snapshot-2009.01.29. Modified: releases/1.6/user/src/com/google/gwt/user/client/ui/PopupPanel.java ============================================================================== --- releases/1.6/user/src/com/google/gwt/user/client/ui/PopupPanel.java (original) +++ releases/1.6/user/src/com/google/gwt/user/client/ui/PopupPanel.java Fri Feb 6 11:11:50 2009 @@ -463,14 +463,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); @@ -589,6 +585,14 @@ return true; } + @Override + protected void onUnload() { + // 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(); + } + /** * Remove an autoHide partner. * @@ -889,6 +893,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: releases/1.6/user/test/com/google/gwt/user/client/ui/DialogBoxTest.java ============================================================================== --- releases/1.6/user/test/com/google/gwt/user/client/ui/DialogBoxTest.java (original) +++ releases/1.6/user/test/com/google/gwt/user/client/ui/DialogBoxTest.java Fri Feb 6 11:11:50 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 -~----------~----~----~----~------~----~------~--~---