Reviewers: pdr,
Description:
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
Please review this at http://gwt-code-reviews.appspot.com/1385806/
Affected files:
M user/src/com/google/gwt/user/cellview/client/CellWidget.java
M user/test/com/google/gwt/user/cellview/client/CellWidgetTest.java
Index: user/src/com/google/gwt/user/cellview/client/CellWidget.java
===================================================================
--- user/src/com/google/gwt/user/cellview/client/CellWidget.java (revision
9887)
+++ user/src/com/google/gwt/user/cellview/client/CellWidget.java (working
copy)
@@ -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);
}
Index: user/test/com/google/gwt/user/cellview/client/CellWidgetTest.java
===================================================================
--- user/test/com/google/gwt/user/cellview/client/CellWidgetTest.java
(revision 9887)
+++ user/test/com/google/gwt/user/cellview/client/CellWidgetTest.java
(working copy)
@@ -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.
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors