]> source.dussan.org Git - gwtquery.git/commitdiff
- Fixing FF to use Native implementation instead of IE8
authorManolo Carrasco <manolo@apache.org>
Sat, 7 Aug 2010 09:04:18 +0000 (09:04 +0000)
committerManolo Carrasco <manolo@apache.org>
Sat, 7 Aug 2010 09:04:18 +0000 (09:04 +0000)
- Catch exception when IE8 using the native implementation fais, in order to failback to js selectors (fixes issue45)
- Change javascript code for the property-provider selectorCapability to use $doc instead of document

gwtquery-core/src/main/java/com/google/gwt/query/Query.gwt.xml
gwtquery-core/src/main/java/com/google/gwt/query/client/SelectorEngine.java
gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java
gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE8.java

index 7843c9751a7638fc55c8c71cfdebb9a681bb9f30..05cf506dad0ac566f92b855468a7ae06c7647215 100644 (file)
@@ -7,9 +7,15 @@
                      values="native,js"/>\r
     <property-provider name="selectorCapability">\r
         <![CDATA[\r
-         // useful for benchmarking tests when you want to force non-accelerated queries\r
-         if(window.location.href.indexOf("_selector_force_js") != -1) return "js"; \r
-         if(document.querySelectorAll && /native/.test(String(document.querySelectorAll))) return "native";\r
+         // Select javascript permutation when the user wants to\r
+         // force non-accelerated queries (for benchmarking tests)\r
+         if ($doc.location.href.indexOf("_selector_force_js") != -1) \r
+           return "js"; \r
+           \r
+         // Select the native permutation if querySelectorAll is available\r
+         if ($doc.querySelectorAll && /native/.test(String($doc.querySelectorAll))) \r
+           return "native";\r
+           \r
          return "js";\r
         ]]>\r
     </property-provider>\r
@@ -74,7 +80,7 @@
         </any>\r
     </replace-with>\r
 \r
-    <replace-with class="com.google.gwt.query.client.impl.SelectorEngineNativeIE8">\r
+    <replace-with class="com.google.gwt.query.client.impl.SelectorEngineNative">\r
         <when-type-assignable class="com.google.gwt.query.client.impl.SelectorEngineImpl"/>\r
         <when-property-is name="selectorCapability" value="native"/>\r
     </replace-with>\r
         <when-property-is name="selectorCapability" value="native"/>\r
         <when-property-is name="user.agent" value="ie8"/>\r
     </replace-with>\r
-
-    <define-linker name="stddoctype" class="com.google.gwt.query.linker.IFrameWithDocTypeLinker"/>
-    <add-linker name="stddoctype"/>
-\r
+    \r
+    <define-linker name="stddoctype" class="com.google.gwt.query.linker.IFrameWithDocTypeLinker"/>\r
+    <add-linker name="stddoctype"/>\r
+    
     <entry-point class='com.google.gwt.query.client.css.CSS'/>\r
 \r
 </module>\r
index 8f0c39affd9692bfd2320f06b38b39f167b85d94..ba57f0c83de2f9933527fa0b1e1e6ec9e09a7f2a 100644 (file)
@@ -39,6 +39,21 @@ public class SelectorEngine {
   public static native Node getPreviousSibling(Node n) /*-{\r
        return n.previousSibling || null; \r
     }-*/;\r
+  \r
+  private static boolean degradate = false;\r
+  \r
+  public NodeList<Element> querySelectorAllIE8(String selector, Node ctx) {\r
+    if (degradate) {\r
+      return impl.select(selector, ctx);\r
+    } \r
+    try {\r
+      return querySelectorAll(selector, ctx);\r
+    } catch (Exception e) {\r
+      System.out.println("IE8 Degradating to dynamic implementation, it seems IE8 is not running in standars mode");\r
+      degradate = true;\r
+      return querySelectorAll(selector, ctx);\r
+    }\r
+  }\r
 \r
   public static native NodeList<Element> querySelectorAll(String selector,\r
       Node ctx) /*-{\r
@@ -67,6 +82,7 @@ public class SelectorEngine {
 \r
   public SelectorEngine() {\r
     impl = (SelectorEngineImpl) GWT.create(SelectorEngineImpl.class);\r
+    // System.out.println("SelectorEngineImpl used: " + impl.getClass().getName());\r
   }\r
 \r
   public Node getRoot() {\r
index 81de55a6fdcdf3cff05a03a869733d1499ddabb1..cf911e2ba93e347d8325f2a170644d7b423cfbe7 100644 (file)
@@ -27,12 +27,21 @@ import com.google.gwt.query.client.SelectorEngine;
 public class SelectorEngineNativeIE8 extends SelectorEngineSizzle {
   
   public static String NATIVE_EXCEPTIONS_REGEXP = ".*(:contains|!=|:checked|:not|:nth-|:last-|:only-).*";
+
+  private static boolean degradate = false;
   
   public NodeList<Element> select(String selector, Node ctx) {
-    if (selector.matches(NATIVE_EXCEPTIONS_REGEXP)) {
+    if (degradate || selector.matches(NATIVE_EXCEPTIONS_REGEXP)) {
       return super.select(selector, ctx); 
     } else {
-      return SelectorEngine.querySelectorAll(selector, ctx);
+      try {
+        return SelectorEngine.querySelectorAll(selector, ctx);
+      } catch (Exception e) {
+        System.out.println("IE8 Degradating to dynamic implementation, it seems IE8 is not running in standars mode");
+        degradate = true;
+        return super.select(selector, ctx); 
+      }
     }
   }
+  
 }
index 6549ac5ee11515a0720c5a58dc6e345edc0064d4..3051374824bf00d38752e3fde6f70513f9102a57 100644 (file)
@@ -36,7 +36,7 @@ public class SelectorGeneratorNativeIE8 extends SelectorGeneratorJS {
       super.generateMethodBody(sw, method, treeLogger, hasContext);\r
     } else {\r
       sw.println("return "\r
-          + wrap(method, "querySelectorAll(\"" + selector + "\", root)") + ";");\r
+          + wrap(method, "querySelectorAllIE8(\"" + selector + "\", root)") + ";");\r
     }\r
   }\r
 \r