Revision: 8596
Author: [email protected]
Date: Fri Aug 20 04:56:10 2010
Log: Allow to keep size of Widget on DeckPanel.
Review: http://gwt-code-reviews.appspot.com/732802

Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=8596

Modified:
 /trunk/user/src/com/google/gwt/user/client/ui/DeckPanel.java
 /trunk/user/test/com/google/gwt/user/client/ui/DeckPanelTest.java

=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/DeckPanel.java Tue Sep 1 19:11:26 2009 +++ /trunk/user/src/com/google/gwt/user/client/ui/DeckPanel.java Fri Aug 20 04:56:10 2010
@@ -341,7 +341,15 @@
   private void finishWidgetInitialization(Element container, Widget w) {
     UIObject.setVisible(container, false);
     DOM.setStyleAttribute(container, "height", "100%");
-    w.setSize("100%", "100%");
+
+    // Set 100% by default.
+    Element element = w.getElement();
+    if (DOM.getStyleAttribute(element, "width").equals("")) {
+      w.setWidth("100%");
+    }
+    if (DOM.getStyleAttribute(element, "height").equals("")) {
+      w.setHeight("100%");
+    }

     // Issue 2510: Hiding the widget isn't necessary because we hide its
     // wrapper, but it's in here for legacy support.
=======================================
--- /trunk/user/test/com/google/gwt/user/client/ui/DeckPanelTest.java Wed Mar 24 05:13:52 2010 +++ /trunk/user/test/com/google/gwt/user/client/ui/DeckPanelTest.java Fri Aug 20 04:56:10 2010
@@ -16,6 +16,8 @@

 package com.google.gwt.user.client.ui;

+import com.google.gwt.user.client.DOM;
+
 /**
  * Test for {...@link DeckPanel}.
  */
@@ -99,6 +101,46 @@
     // Verify content.onLoad was actually called
     assertEquals("attached", content.getText());
   }
+
+  /**
+   * Test that style width/height is set to 100% by default.
+   */
+  public void testWidgetDefaultSizeOnAdd() {
+    DeckPanel deck = new DeckPanel();
+    RootPanel.get().add(deck);
+
+    // Prepare widget, no width/height initially
+    Label content = new Label("content");
+    assertEquals("", content.getElement().getStyle().getWidth());
+    assertEquals("", content.getElement().getStyle().getHeight());
+
+    // Add a widget to the DeckPanel
+    deck.add(content);
+
+    // Verify width/height
+    assertEquals("100%", content.getElement().getStyle().getWidth());
+    assertEquals("100%", content.getElement().getStyle().getHeight());
+  }
+
+  /**
+   * Test that existing width/height is kept as is during add.
+   */
+  public void testWidgetKeepSizeOnAdd() {
+    DeckPanel deck = new DeckPanel();
+    RootPanel.get().add(deck);
+
+    // Prepare widget, with width/height
+    Label content = new Label("content");
+    DOM.setStyleAttribute(content.getElement(), "width", "5cm");
+    DOM.setStyleAttribute(content.getElement(), "height", "30mm");
+
+    // Add a widget to the DeckPanel
+    deck.add(content);
+
+    // Verify width/height
+ assertEquals("5cm", DOM.getStyleAttribute(content.getElement(), "width")); + assertEquals("30mm", DOM.getStyleAttribute(content.getElement(), "height"));
+  }

   @Override
   protected DeckPanel createPanel() {

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

Reply via email to