Optimizes new HTMLPanel(tag, "")
Review at http://gwt-code-reviews.appspot.com/1670803
Review by: jlabanca@google.com
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10923 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 f88bd81..8146a61 100644
--- a/user/src/com/google/gwt/user/client/ui/HTMLPanel.java
+++ b/user/src/com/google/gwt/user/client/ui/HTMLPanel.java
@@ -101,6 +101,12 @@
* @param html the panel's HTML
*/
public HTMLPanel(String tag, String html) {
+ // Optimization for when the HTML is empty.
+ if ("".equals(html)) {
+ setElement(Document.get().createElement(tag));
+ return;
+ }
+
/*
* IE has very arbitrary rules about what will and will not accept
* innerHTML. <table> and <tbody> simply won't, the property is read only.
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 b4ea7c0..b9ec57e 100644
--- a/user/test/com/google/gwt/user/client/ui/HTMLPanelTest.java
+++ b/user/test/com/google/gwt/user/client/ui/HTMLPanelTest.java
@@ -358,6 +358,17 @@
}
/**
+ * Tests h3 root tag with initially empty HTML contents.
+ */
+ public void testCustomRootTagEmptyHtml() {
+ HTMLPanel hp = new HTMLPanel("h3", "");
+
+ Element element = hp.getElement();
+ assertEquals("h3", element.getTagName().toLowerCase());
+ assertEquals("", element.getInnerText());
+ }
+
+ /**
* Ensure that {@link HTMLPanel#getElementById(String)} behaves properly in
* both attached and unattached states.
*/