Allow flexibilty on root tag of HTMLPanel

Reviewed by: jgw



git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5694 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/HTMLPanel.java b/user/src/com/google/gwt/user/client/ui/HTMLPanel.java
index 1bbdeb6..d9bf52a 100644
--- a/user/src/com/google/gwt/user/client/ui/HTMLPanel.java
+++ b/user/src/com/google/gwt/user/client/ui/HTMLPanel.java
@@ -40,17 +40,30 @@
   }
 
   /**
-   * Creates an HTML panel with the specified HTML contents. Any element within
-   * this HTML that has a specified id can contain a child widget.
+   * Creates an HTML panel with the specified HTML contents inside a DIV
+   * element. Any element within this HTML that has a specified id can contain a
+   * child widget.
    * 
    * @param html the panel's HTML
    */
   public HTMLPanel(String html) {
-    setElement(DOM.createDiv());
-    DOM.setInnerHTML(getElement(), html);
+    this("div", html);
   }
 
   /**
+   * Creates an HTML panel whose root element has the given tag, and with the
+   * specified HTML contents. Any element within this HTML that has a specified
+   * id can contain a child widget.
+   * 
+   * @param tag the tag of the root element
+   * @param html the panel's HTML
+   */
+  public HTMLPanel(String tag, String html) {
+    setElement(DOM.createElement(tag));
+    DOM.setInnerHTML(getElement(), html);
+  }
+  
+  /**
    * Adds a child widget to the panel, contained within the HTML element
    * specified by a given id.
    * 
diff --git a/user/test/com/google/gwt/user/client/ui/HTMLPanelTest.java b/user/test/com/google/gwt/user/client/ui/HTMLPanelTest.java
index 9e7f8ac..5422a58 100644
--- a/user/test/com/google/gwt/user/client/ui/HTMLPanelTest.java
+++ b/user/test/com/google/gwt/user/client/ui/HTMLPanelTest.java
@@ -120,6 +120,25 @@
   }
 
   /**
+   * Tests arbitrary root tag
+   */
+  public void testCustomRootTag() {
+    HTMLPanel hp = new HTMLPanel("table", "<tr><td>Hello <span id='labelHere'></span></td></tr>");
+    InlineLabel label = new InlineLabel("World");
+    hp.addAndReplaceElement(label, "labelHere");
+    
+    Element parent = label.getElement().getParentElement();
+    assertEquals("td", parent.getTagName().toLowerCase());
+
+    parent = parent.getParentElement();
+    assertEquals("tr", parent.getTagName().toLowerCase());
+
+    parent = parent.getParentElement();
+    assertEquals("table", parent.getTagName().toLowerCase());
+    assertEquals(hp.getElement(), parent);
+  }
+  
+  /**
    * Ensure that {@link HTMLPanel#getElementById(String)} behaves properly in
    * both attached and unattached states.
    */