Cells should only fill a CellWidget if they render exactly one topmost element, or the first child will push around the other children. This is a follow-on change to r9884.

Author: tbroyer, jlabanca

Review at http://gwt-code-reviews.appspot.com/1385806

Review by: pdr@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9889 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/cellview/client/CellWidget.java b/user/src/com/google/gwt/user/cellview/client/CellWidget.java
index 84e8660..2a1ab4d 100644
--- a/user/src/com/google/gwt/user/cellview/client/CellWidget.java
+++ b/user/src/com/google/gwt/user/cellview/client/CellWidget.java
@@ -179,10 +179,11 @@
 
     /*
      * The rendered Cell should fill the root element so height and width styles
-     * applied to the widget also apply to the Cell.
+     * applied to the widget also apply to the Cell. If there is exactly one
+     * child element, the height and width are set to 100% to fill the parent.
      */
     Element child = getElement().getFirstChildElement();
-    if (child != null) {
+    if (child != null && child.getNextSiblingElement() == null) {
       child.getStyle().setHeight(100, Unit.PCT);
       child.getStyle().setWidth(100, Unit.PCT);
     }
diff --git a/user/test/com/google/gwt/user/cellview/client/CellWidgetTest.java b/user/test/com/google/gwt/user/cellview/client/CellWidgetTest.java
index 67cb016..8a848e6 100644
--- a/user/test/com/google/gwt/user/cellview/client/CellWidgetTest.java
+++ b/user/test/com/google/gwt/user/cellview/client/CellWidgetTest.java
@@ -16,6 +16,7 @@
 package com.google.gwt.user.cellview.client;
 
 import com.google.gwt.cell.client.AbstractCell;
+import com.google.gwt.cell.client.Cell;
 import com.google.gwt.cell.client.TextButtonCell;
 import com.google.gwt.cell.client.ValueUpdater;
 import com.google.gwt.dom.client.Document;
@@ -156,7 +157,33 @@
   /**
    * Test that a cell that defines an HTML elment can be rendered.
    */
-  public void testRedrawWithInnerChild() {
+  public void testRedrawWithMultipleInnerChildren() {
+    Cell<String> cell = new AbstractCell<String>() {
+      @Override
+      public void render(com.google.gwt.cell.client.Cell.Context context, String value,
+          SafeHtmlBuilder sb) {
+        sb.appendHtmlConstant("<div>").appendEscaped(value).appendHtmlConstant("</div>");
+        sb.appendHtmlConstant("<div>child2</div>");
+      }
+    };
+    CellWidget<String> cw = new CellWidget<String>(cell);
+
+    // Set value without redrawing.
+    cw.setValue("test123", false, false);
+    assertEquals("", cw.getElement().getInnerText());
+
+    // Redraw.
+    cw.redraw();
+    assertTrue(cw.getElement().getInnerText().contains("test123"));
+    Style firstChildStyle = cw.getElement().getFirstChildElement().getStyle();
+    assertFalse(firstChildStyle.getHeight().matches("100(.0)?%"));
+    assertFalse(firstChildStyle.getWidth().matches("100(.0)?%"));
+  }
+
+  /**
+   * Test that a cell that defines an HTML elment can be rendered.
+   */
+  public void testRedrawWithOneInnerChild() {
     CellWidget<String> cw = new CellWidget<String>(new TextButtonCell());
 
     // Set value without redrawing.