]> source.dussan.org Git - gwtquery.git/commitdiff
- Added a customized linker which puts the doctype to the iframe with the gwt code
authorManolo Carrasco <manolo@apache.org>
Mon, 21 Jun 2010 13:42:30 +0000 (13:42 +0000)
committerManolo Carrasco <manolo@apache.org>
Mon, 21 Jun 2010 13:42:30 +0000 (13:42 +0000)
- Added new selector classes for Ie8.
- Little re-factor in SelectorEngine.
Thanks to @johnthuss who spoted out the issue and sent a great patch.
Fixes issue37

gwtquery-core/src/main/java/com/google/gwt/query/Query.gwt.xml
gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java
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 [new file with mode: 0644]
gwtquery-core/src/main/java/com/google/gwt/query/linker/IFrameWithDocTypeLinker.java [new file with mode: 0644]
gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorCssToXPath.java
gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorJS.java
gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorJSOptimal.java
gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNative.java
gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE8.java [new file with mode: 0644]
gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTest.java

index 6f3cb86304d53f20ee64e813f540d34370bb36cf..88c60f0a266b0bf35884beb1d801498809a9c88f 100644 (file)
     <generate-with class="com.google.gwt.query.rebind.SelectorGeneratorNative">\r
         <when-type-assignable class="com.google.gwt.query.client.Selectors"/>\r
         <when-property-is name="selectorCapability" value="native"/>\r
-        <none>\r
-           <when-property-is name="user.agent" value="ie8"/>\r
-        </none>\r
     </generate-with>\r
+
+    <generate-with class="com.google.gwt.query.rebind.SelectorGeneratorNativeIE8">\r
+        <when-type-assignable class="com.google.gwt.query.client.Selectors"/>\r
+        <when-property-is name="selectorCapability" value="native"/>
+        <when-property-is name="user.agent" value="ie8"/>\r
+    </generate-with>
 \r
     <replace-with class="com.google.gwt.query.client.impl.DocumentStyleImpl">\r
-        <when-type-assignable\r
-                class="com.google.gwt.query.client.impl.DocumentStyleImpl"/>\r
+        <when-type-assignable class="com.google.gwt.query.client.impl.DocumentStyleImpl"/>\r
     </replace-with>\r
 \r
     <replace-with class="com.google.gwt.query.client.impl.DocumentStyleImplIE">\r
-        <when-type-assignable\r
-                class="com.google.gwt.query.client.impl.DocumentStyleImpl"/>\r
+        <when-type-assignable class="com.google.gwt.query.client.impl.DocumentStyleImpl"/>\r
         <any>\r
                <when-property-is name="user.agent" value="ie6"/>\r
                <when-property-is name="user.agent" value="ie8"/>\r
@@ -59,8 +60,7 @@
     </replace-with>\r
 \r
     <replace-with class="com.google.gwt.query.client.impl.SelectorEngineSizzle">\r
-        <when-type-assignable\r
-                class="com.google.gwt.query.client.impl.SelectorEngineImpl"/>\r
+        <when-type-assignable class="com.google.gwt.query.client.impl.SelectorEngineImpl"/>\r
     </replace-with>\r
 \r
     <replace-with class="com.google.gwt.query.client.impl.SelectorEngineCssToXPath">\r
         </any>\r
     </replace-with>\r
 \r
-    <replace-with class="com.google.gwt.query.client.impl.SelectorEngineNative">\r
-        <when-type-assignable\r
-                class="com.google.gwt.query.client.impl.SelectorEngineImpl"/>\r
+    <replace-with class="com.google.gwt.query.client.impl.SelectorEngineNativeIE8">\r
+        <when-type-assignable class="com.google.gwt.query.client.impl.SelectorEngineImpl"/>\r
+        <when-property-is name="selectorCapability" value="native"/>\r
+    </replace-with>\r
+    \r
+    <replace-with class="com.google.gwt.query.client.impl.SelectorEngineNativeIE8">\r
+        <when-type-assignable class="com.google.gwt.query.client.impl.SelectorEngineImpl"/>\r
         <when-property-is name="selectorCapability" value="native"/>\r
-        <none>\r
-           <when-property-is name="user.agent" value="ie8"/>\r
-        </none>\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
     <entry-point class='com.google.gwt.query.client.css.CSS'/>\r
 \r
index 16e93d83113958f997e925c014d9a04d7f787629..e7a3c67b498404c1f06d28fa597b7842a97dce1d 100644 (file)
@@ -380,9 +380,14 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   private static native <T extends Node> T[] reinterpretCast(NodeList<T> nl) /*-{\r
     return nl;\r
   }-*/;\r
+  \r
+  private static SelectorEngine engine;\r
 \r
   private static NodeList<Element> select(String selector, Node context) {\r
-    NodeList<Element> n = new SelectorEngine().select(selector, context);\r
+    if (engine == null) {\r
+      engine = new SelectorEngine();\r
+    }\r
+    NodeList<Element> n = engine.select(selector, context);\r
     JSArray res = copyNodeList(n);\r
     return res;\r
   }\r
index c1feeb6f36afd21ff0fd9ddae2d7f4a3266e8385..1fd286e8c77aa67b6394b9c52aa675c55effdc71 100644 (file)
@@ -65,16 +65,27 @@ public class SelectorEngine {
       return r;\r
   }-*/;\r
 \r
-  private SelectorEngineImpl impl;\r
+  protected SelectorEngineImpl impl;\r
+\r
+  protected Node root = Document.get();\r
 \r
   public SelectorEngine() {\r
     impl = (SelectorEngineImpl) GWT.create(SelectorEngineImpl.class);\r
   }\r
 \r
+  public Node getRoot() {\r
+    return root;\r
+  }\r
+  \r
   public NodeList<Element> select(String selector, Node ctx) {\r
     return impl.select(selector, ctx);\r
   }\r
-\r
\r
+  public void setRoot(Node root) {\r
+    assert root != null;\r
+    this.root = root;\r
+  }\r
+  \r
   protected JSArray veryQuickId(Node context, String id) {\r
     JSArray r = JSArray.create();\r
     if (context.getNodeType() == Node.DOCUMENT_NODE) {\r
@@ -86,15 +97,4 @@ public class SelectorEngine {
     }\r
   }\r
   \r
-  protected Node root = Document.get();\r
\r
-  public void setRoot(Node root) {\r
-    assert root != null;\r
-    this.root = root;\r
-  }\r
-  \r
-  public Node getRoot() {\r
-    return root;\r
-  }\r
-  \r
 }\r
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java
new file mode 100644 (file)
index 0000000..81de55a
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2009 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.
+ */
+package com.google.gwt.query.client.impl;
+
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.Node;
+import com.google.gwt.dom.client.NodeList;
+import com.google.gwt.query.client.SelectorEngine;
+
+/**
+ * Runtime selector engine implementation for browsers with native
+ * querySelectorAll support.
+ */
+public class SelectorEngineNativeIE8 extends SelectorEngineSizzle {
+  
+  public static String NATIVE_EXCEPTIONS_REGEXP = ".*(:contains|!=|:checked|:not|:nth-|:last-|:only-).*";
+  
+  public NodeList<Element> select(String selector, Node ctx) {
+    if (selector.matches(NATIVE_EXCEPTIONS_REGEXP)) {
+      return super.select(selector, ctx); 
+    } else {
+      return SelectorEngine.querySelectorAll(selector, ctx);
+    }
+  }
+}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/linker/IFrameWithDocTypeLinker.java b/gwtquery-core/src/main/java/com/google/gwt/query/linker/IFrameWithDocTypeLinker.java
new file mode 100644 (file)
index 0000000..9a620f4
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2009 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.
+ */
+package com.google.gwt.query.linker;
+
+import com.google.gwt.core.ext.LinkerContext;
+import com.google.gwt.core.ext.TreeLogger;
+import com.google.gwt.core.linker.IFrameLinker;
+import com.google.gwt.core.ext.linker.LinkerOrder;
+
+/**
+ * Adds doctype to the iframe used to load the application.
+ * Without this code, IE8 does not enable document.querySelectorAll feature.
+ */
+@LinkerOrder(LinkerOrder.Order.PRIMARY)
+public class IFrameWithDocTypeLinker extends IFrameLinker {
+
+  private static final String DOCTYPE = "<!doctype html>\n";
+
+  protected String getModulePrefix(TreeLogger logger, LinkerContext context,
+      String strongName) {
+    return DOCTYPE + super.getModulePrefix(logger, context, strongName);
+  }
+
+  @Override
+  protected String getModulePrefix(TreeLogger logger, LinkerContext context,
+      String strongName, int numFragments) {
+    return DOCTYPE
+        + super.getModulePrefix(logger, context, strongName, numFragments);
+  }
+}
index 04582af60b4ffb0f1850df30e9231e0ffd83bdba..4033fd3fed5af640a3de6617c09e3a5f3e2d78ee 100644 (file)
@@ -80,7 +80,7 @@ public class SelectorGeneratorCssToXPath extends SelectorGeneratorBase {
   }\r
 \r
   protected String getImplSuffix() {\r
-    return "XPath" + super.getImplSuffix();\r
+    return "CssToXPath" + super.getImplSuffix();\r
   }\r
 \r
 }\r
index 3cb7010e04e9e8a675df0d66bcc9341d7ebba997..6a7b5f6467c729fab6d0869aff9881be30fa9501 100644 (file)
@@ -34,10 +34,8 @@ public class SelectorGeneratorJS extends SelectorGeneratorBase {
   protected void generateMethodBody(SourceWriter sw, JMethod method,\r
       TreeLogger treeLogger, boolean hasContext)\r
       throws UnableToCompleteException {\r
-\r
     String selector = method.getAnnotation(Selector.class).value();\r
-\r
-    sw.println("return " + wrap(method,\r
-        "new SelectorEngine().select(\"" + selector + "\", root)") + ";");\r
+    sw.println("return "\r
+        + wrap(method, "impl.select(\"" + selector + "\", root)") + ";");\r
   }\r
 }\r
index 064f371288a1d34b998979f0b718a33da90e39b8..65a85da8a58a6240f30bcef5c7c4a5f71824edec 100644 (file)
@@ -74,7 +74,7 @@ public class SelectorGeneratorJSOptimal extends SelectorGeneratorBase {
     String selector = method.getAnnotation(Selector.class).value();\r
 \r
     sw.println("return " + wrap(method,\r
-        "new SelectorEngine().select(\"" + selector + "\", root)") + ";");\r
+        "impl.select(\"" + selector + "\", root)") + ";");\r
 //    sw.println("JSArray n = JSArray.create();");\r
 //    if(!hasContext) { \r
 //      sw.println("Node root = Document.get();");\r
index 7efaee11a4bcfd4fc110a691ab29b5503d154854..74a9b8a9be4be26470cc2bfbe8d40afd3bdfa962 100644 (file)
@@ -31,6 +31,7 @@ public class SelectorGeneratorNative extends SelectorGeneratorCssToXPath {
   protected void generateMethodBody(SourceWriter sw, JMethod method,\r
       TreeLogger treeLogger, boolean hasContext)\r
       throws UnableToCompleteException {\r
+\r
     String selector = method.getAnnotation(Selector.class).value();\r
     if (selector.matches(SelectorEngineNative.NATIVE_EXCEPTIONS_REGEXP)) {\r
       super.generateMethodBody(sw, method, treeLogger, hasContext);\r
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE8.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE8.java
new file mode 100644 (file)
index 0000000..6549ac5
--- /dev/null
@@ -0,0 +1,52 @@
+/*\r
+ * Copyright 2009 Google Inc.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not\r
+ * use this file except in compliance with the License. You may obtain a copy of\r
+ * the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\r
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r
+ * License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+package com.google.gwt.query.rebind;\r
+\r
+import com.google.gwt.core.ext.TreeLogger;\r
+import com.google.gwt.core.ext.UnableToCompleteException;\r
+import com.google.gwt.core.ext.typeinfo.JMethod;\r
+import com.google.gwt.query.client.Selector;\r
+import com.google.gwt.query.client.impl.SelectorEngineNativeIE8;\r
+import com.google.gwt.user.rebind.SourceWriter;\r
+\r
+/**\r
+ * Compile time selector generator which delegates to native browser methods.\r
+ */\r
+public class SelectorGeneratorNativeIE8 extends SelectorGeneratorJS {\r
+\r
+  @Override\r
+  protected void generateMethodBody(SourceWriter sw, JMethod method,\r
+      TreeLogger treeLogger, boolean hasContext)\r
+      throws UnableToCompleteException {\r
+    String selector = method.getAnnotation(Selector.class).value();\r
+    if (selector.matches(SelectorEngineNativeIE8.NATIVE_EXCEPTIONS_REGEXP)) {\r
+      super.generateMethodBody(sw, method, treeLogger, hasContext);\r
+    } else {\r
+      sw.println("return "\r
+          + wrap(method, "querySelectorAll(\"" + selector + "\", root)") + ";");\r
+    }\r
+  }\r
+\r
+  @Override\r
+  protected String getImplSuffix() {\r
+    return "IE8" + super.getImplSuffix();\r
+  }\r
+\r
+  @Override\r
+  protected boolean hasGetElementsByClassName() {\r
+    return false;\r
+  }\r
+}
\ No newline at end of file
index 7992136e1fc32067a44df1f8aa899eb171ed1422..4bf5142f7db91925f69cbf7f768b66485d5fedec 100644 (file)
@@ -101,7 +101,7 @@ public class GQueryEffectsTest extends GWTTestCase {
     final GQuery g = $("#idtest").css("position", "absolute");
     final Offset o = g.offset();
     
-    final int duration = 800;
+    final int duration = 1000;
     g.as(Effects.Effects).
         animate($$("left: '+=100'"), duration, Easing.LINEAR).
         animate($$("top: '+=100'"), duration, Easing.LINEAR).