Revision: 6094
Author: [email protected]
Date: Tue Sep  8 07:17:09 2009
Log: Fixes an issue in StyleInjector where it could try to inject more than  
30 style sheets in IE if a style sheet already existed.  We now look at the  
total number of style sheets instead of just the number that were injected  
by StyleInjector.

Patch by: mathewar
Review by: jlabanca


http://code.google.com/p/google-web-toolkit/source/detail?r=6094

Modified:
  /trunk/user/src/com/google/gwt/dom/client/StyleInjector.java

=======================================
--- /trunk/user/src/com/google/gwt/dom/client/StyleInjector.java        Mon Apr 
 6  
07:07:28 2009
+++ /trunk/user/src/com/google/gwt/dom/client/StyleInjector.java        Tue Sep 
 8  
07:17:09 2009
@@ -95,7 +95,7 @@
      @Override
      public StyleElement injectStyleSheet(String contents) {
        int idx = STYLE_ELEMENTS.length();
-      if (idx < MAX_STYLE_SHEETS) {
+      if (getDocumentStyleCount() < MAX_STYLE_SHEETS) {
          // Just create a new style element and add it to the list
          StyleElement style = createElement();
          setContents(style, contents);
@@ -115,6 +115,14 @@
              shortestIdx = i;
            }
          }
+
+        /**
+         * This assertion can fail if the max number of style elements  
exist
+         * before this module can inject any style elements, so  
STYLE_ELEMENTS
+         * will be empty. However, the fix would degrade performance for  
the
+         * general case.
+         * TODO(jlabanca): Can we handle this scenario efficiently?
+         */
          assert shortestIdx != -1;

          StyleElement style = STYLE_ELEMENTS.get(shortestIdx);
@@ -165,6 +173,10 @@
      private native StyleElement createElement() /*-{
        return $doc.createStyleSheet();
      }-*/;
+
+    private native int getDocumentStyleCount() /*-{
+      return $doc.styleSheets.length;
+    }-*/;
    }

    /**

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to