Added [Theme]Resources modules to each of the GWT themes so users can load the public resources associated with a theme without injecting the style sheet.  The Showcase has been updated to take advantage of this by only loading the style sheet for the Standard theme.  In addition, the Showcase is smarter about reloading style sheets in that it will not dump an existing style sheet and then reload the same one.  This patch addresses an issue where the Showcase would crash IE on Vista because of the way it unloaded and reloaded style sheets.

Patch by: jlabanca, rajeev
Review by: rajeev (desk review)



git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@2881 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/samples/showcase/src/com/google/gwt/sample/showcase/Showcase.gwt.xml b/samples/showcase/src/com/google/gwt/sample/showcase/Showcase.gwt.xml
index 9a92cc0..2f4b796 100644
--- a/samples/showcase/src/com/google/gwt/sample/showcase/Showcase.gwt.xml
+++ b/samples/showcase/src/com/google/gwt/sample/showcase/Showcase.gwt.xml
@@ -4,8 +4,8 @@
 	<inherits name='com.google.gwt.user.User'/>
 	<inherits name="com.google.gwt.i18n.I18N"/>
       <inherits name="com.google.gwt.user.theme.standard.Standard"/>
-      <inherits name="com.google.gwt.user.theme.chrome.Chrome"/>
-      <inherits name="com.google.gwt.user.theme.dark.Dark"/>
+      <inherits name="com.google.gwt.user.theme.chrome.ChromeResources"/>
+      <inherits name="com.google.gwt.user.theme.dark.DarkResources"/>
 
 	<!-- Enable debug ID. -->
 	<inherits name="com.google.gwt.user.Debug"/>
diff --git a/samples/showcase/src/com/google/gwt/sample/showcase/client/Showcase.java b/samples/showcase/src/com/google/gwt/sample/showcase/client/Showcase.java
index a3e9215..ab0a75e 100644
--- a/samples/showcase/src/com/google/gwt/sample/showcase/client/Showcase.java
+++ b/samples/showcase/src/com/google/gwt/sample/showcase/client/Showcase.java
@@ -547,6 +547,14 @@
    * Update the style sheets to reflect the current theme and direction.
    */
   private void updateStyleSheets() {
+    // Generate the names of the style sheets to include
+    String gwtStyleSheet = "gwt/" + CUR_THEME + "/" + CUR_THEME + ".css";
+    String showcaseStyleSheet = CUR_THEME + "/Showcase.css";
+    if (LocaleInfo.getCurrentLocale().isRTL()) {
+      gwtStyleSheet = gwtStyleSheet.replace(".css", "_rtl.css");
+      showcaseStyleSheet = showcaseStyleSheet.replace(".css", "_rtl.css");
+    }
+
     // Remove existing style sheets
     HeadElement headElem = getHeadElement();
     NodeList<Node> children = headElem.getChildNodes();
@@ -556,22 +564,31 @@
         Element elem = Element.as(node);
         if (elem.getTagName().equalsIgnoreCase("link")
             && elem.getPropertyString("rel").equalsIgnoreCase("stylesheet")) {
-          headElem.removeChild(elem);
-          i--;
+          String href = elem.getPropertyString("href");
+          // If the style sheet is already loaded, we keep it and set
+          // gwtStyleSheet to null so that we do not load it below.  The same
+          // applies to showcaseStyleSheet.
+          if (gwtStyleSheet != null && href.contains(gwtStyleSheet)) {
+            gwtStyleSheet = null;
+          } else if (showcaseStyleSheet != null
+              && href.contains(showcaseStyleSheet)) {
+            showcaseStyleSheet = null;
+          } else {
+            headElem.removeChild(elem);
+            i--;
+          }
         }
       }
     }
 
     // Add the new style sheets
     String modulePath = GWT.getModuleBaseURL();
-    String gwtPath = modulePath + "gwt/" + CUR_THEME + "/" + CUR_THEME + ".css";
-    String showcasePath = modulePath + CUR_THEME + "/Showcase.css";
-    if (LocaleInfo.getCurrentLocale().isRTL()) {
-      gwtPath = gwtPath.replace(".css", "_rtl.css");
-      showcasePath = showcasePath.replace(".css", "_rtl.css");
+    if (gwtStyleSheet != null) {
+      styleTesterTimer.schedule(25);
+      loadStyleSheet(modulePath + gwtStyleSheet);
     }
-    styleTesterTimer.schedule(25);
-    loadStyleSheet(gwtPath);
-    loadStyleSheet(showcasePath);
+    if (showcaseStyleSheet != null) {
+      loadStyleSheet(modulePath + showcaseStyleSheet);
+    }
   }
 }
diff --git a/user/src/com/google/gwt/user/theme/chrome/ChromeResources.gwt.xml b/user/src/com/google/gwt/user/theme/chrome/ChromeResources.gwt.xml
new file mode 100644
index 0000000..4996cc3
--- /dev/null
+++ b/user/src/com/google/gwt/user/theme/chrome/ChromeResources.gwt.xml
@@ -0,0 +1,19 @@
+<!--
+  Copyright 2008 Google Inc.
+ 
+  Licensed under the Apache License, Version 2.0 (the "License"); you may not
+  use this file except in compliance with the License. You may obtain a copy of
+  the License at
+ 
+  http://www.apache.org/licenses/LICENSE-2.0
+ 
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+  License for the specific language governing permissions and limitations under
+  the License.
+-->
+
+<!-- Includes the public resources used by the the Chrome theme.  This file -->
+<!-- does not inject a style sheet into the application.                    -->
+<module/>
diff --git a/user/src/com/google/gwt/user/theme/dark/DarkResources.gwt.xml b/user/src/com/google/gwt/user/theme/dark/DarkResources.gwt.xml
new file mode 100644
index 0000000..9d80073
--- /dev/null
+++ b/user/src/com/google/gwt/user/theme/dark/DarkResources.gwt.xml
@@ -0,0 +1,19 @@
+<!--
+  Copyright 2008 Google Inc.
+ 
+  Licensed under the Apache License, Version 2.0 (the "License"); you may not
+  use this file except in compliance with the License. You may obtain a copy of
+  the License at
+ 
+  http://www.apache.org/licenses/LICENSE-2.0
+ 
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+  License for the specific language governing permissions and limitations under
+  the License.
+-->
+
+<!-- Includes the public resources used by the the Dark theme.  This file  -->
+<!-- does not inject a style sheet into the application.                   -->
+<module/>
diff --git a/user/src/com/google/gwt/user/theme/standard/StandardResources.gwt.xml b/user/src/com/google/gwt/user/theme/standard/StandardResources.gwt.xml
new file mode 100644
index 0000000..e42eb50
--- /dev/null
+++ b/user/src/com/google/gwt/user/theme/standard/StandardResources.gwt.xml
@@ -0,0 +1,19 @@
+<!--
+  Copyright 2008 Google Inc.
+ 
+  Licensed under the Apache License, Version 2.0 (the "License"); you may not
+  use this file except in compliance with the License. You may obtain a copy of
+  the License at
+ 
+  http://www.apache.org/licenses/LICENSE-2.0
+ 
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+  License for the specific language governing permissions and limitations under
+  the License.
+-->
+
+<!-- Includes the public resources used by the the Standard theme.  This   -->
+<!-- file does not inject a style sheet into the application.              -->
+<module/>