Build fix; makes a PopupPanel "remember" what size the user asked for. This allows a user to set a size first and then add a child widget (which historically works). Also changes expected/actual in PopupTest.
Review by: jgw (desk check)
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1155 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 c17a23f..1e511dc 100644
--- a/user/src/com/google/gwt/user/client/ui/PopupPanel.java
+++ b/user/src/com/google/gwt/user/client/ui/PopupPanel.java
@@ -45,6 +45,11 @@
private static final PopupImpl impl = (PopupImpl) GWT.create(PopupImpl.class);
private boolean autoHide, modal, showing;
+
+ // Used to track requested size across changing child widgets
+ private String desiredHeight;
+ private String desiredWidth;
+
private PopupListenerCollection popupListeners;
/**
@@ -245,17 +250,12 @@
}
}
- /**
- * Calls {@link Widget#setHeight(String)} on this panel's widget. If this
- * panel does not have a widget, then this call does nothing.
- *
- * @param height the new height of this panel's widget, in CSS units (e.g.
- * "10px", "1em")
- */
public void setHeight(String height) {
- Widget childWidget = getWidget();
- if (childWidget != null) {
- childWidget.setHeight(height);
+ desiredHeight = height;
+ maybeUpdateSize();
+ // If the user cleared the size, revert to not trying to control children.
+ if (height.length() == 0) {
+ desiredHeight = null;
}
}
@@ -314,17 +314,17 @@
impl.setVisible(getElement(), visible);
}
- /**
- * Calls {@link Widget#setWidth(String)} on this panel's widget. If this panel
- * does not have a widget, then this call does nothing.
- *
- * @param width the new width of this panel's widget, in CSS units (e.g.
- * "10px", "1em")
- */
+ public void setWidget(Widget w) {
+ super.setWidget(w);
+ maybeUpdateSize();
+ }
+
public void setWidth(String width) {
- Widget childWidget = getWidget();
- if (childWidget != null) {
- childWidget.setWidth(width);
+ desiredWidth = width;
+ maybeUpdateSize();
+ // If the user cleared the size, revert to not trying to control children.
+ if (width.length() == 0) {
+ desiredWidth = null;
}
}
@@ -384,4 +384,22 @@
popupListeners.firePopupClosed(this, autoClosed);
}
}
+
+ /**
+ * We control size by setting our child widget's size. However, if we don't
+ * currently have a child, we record the size the user wanted so that when we
+ * do get a child, we can set it correctly. Until size is explicitly cleared,
+ * any child put into the popup will be given that size.
+ */
+ private void maybeUpdateSize() {
+ Widget w = getWidget();
+ if (w != null) {
+ if (desiredHeight != null) {
+ w.setHeight(desiredHeight);
+ }
+ if (desiredWidth != null) {
+ w.setWidth(desiredWidth);
+ }
+ }
+ }
}
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 f82d363..6549c90 100644
--- a/user/test/com/google/gwt/user/client/ui/PopupTest.java
+++ b/user/test/com/google/gwt/user/client/ui/PopupTest.java
@@ -41,10 +41,10 @@
popup.setWidget(lbl);
popup.show();
- assertEquals(popup.getOffsetWidth(), 384);
- assertEquals(popup.getOffsetHeight(), 128);
- assertEquals(popup.getPopupLeft(), 128);
- assertEquals(popup.getPopupTop(), 64);
+ assertEquals(384, popup.getOffsetWidth());
+ assertEquals(128, popup.getOffsetHeight());
+ 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
@@ -52,10 +52,10 @@
popup.setSize("", "");
popup.setPopupPosition(16, 16);
- assertEquals(popup.getOffsetWidth(), lbl.getOffsetWidth());
- assertEquals(popup.getOffsetHeight(), lbl.getOffsetHeight());
- assertEquals(popup.getAbsoluteLeft(), 16);
- assertEquals(popup.getAbsoluteTop(), 16);
+ assertEquals(lbl.getOffsetWidth(), popup.getOffsetWidth());
+ assertEquals(lbl.getOffsetHeight(), popup.getOffsetHeight());
+ assertEquals(16, popup.getAbsoluteLeft());
+ assertEquals(16, popup.getAbsoluteTop());
// Ensure that hiding the popup fires the appropriate events.
delayTestFinish(1000);