From: Manolo Carrasco Date: Mon, 21 Jun 2010 13:42:30 +0000 (+0000) Subject: - Added a customized linker which puts the doctype to the iframe with the gwt code X-Git-Tag: release-1.3.2~682 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3cfcf82b4607d375bbcf7e663fd989c8720a05aa;p=gwtquery.git - Added a customized linker which puts the doctype to the iframe with the gwt code - 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 --- diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/Query.gwt.xml b/gwtquery-core/src/main/java/com/google/gwt/query/Query.gwt.xml index 6f3cb863..88c60f0a 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/Query.gwt.xml +++ b/gwtquery-core/src/main/java/com/google/gwt/query/Query.gwt.xml @@ -39,19 +39,20 @@ - - - + + + + + + - + - + @@ -59,8 +60,7 @@ - + @@ -76,14 +76,19 @@ - - + + + + + + + - - - + + + + diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java index 16e93d83..e7a3c67b 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java @@ -380,9 +380,14 @@ public class GQuery implements Lazy { private static native T[] reinterpretCast(NodeList nl) /*-{ return nl; }-*/; + + private static SelectorEngine engine; private static NodeList select(String selector, Node context) { - NodeList n = new SelectorEngine().select(selector, context); + if (engine == null) { + engine = new SelectorEngine(); + } + NodeList n = engine.select(selector, context); JSArray res = copyNodeList(n); return res; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/SelectorEngine.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/SelectorEngine.java index c1feeb6f..1fd286e8 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/SelectorEngine.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/SelectorEngine.java @@ -65,16 +65,27 @@ public class SelectorEngine { return r; }-*/; - private SelectorEngineImpl impl; + protected SelectorEngineImpl impl; + + protected Node root = Document.get(); public SelectorEngine() { impl = (SelectorEngineImpl) GWT.create(SelectorEngineImpl.class); } + public Node getRoot() { + return root; + } + public NodeList select(String selector, Node ctx) { return impl.select(selector, ctx); } - + + public void setRoot(Node root) { + assert root != null; + this.root = root; + } + protected JSArray veryQuickId(Node context, String id) { JSArray r = JSArray.create(); if (context.getNodeType() == Node.DOCUMENT_NODE) { @@ -86,15 +97,4 @@ public class SelectorEngine { } } - protected Node root = Document.get(); - - public void setRoot(Node root) { - assert root != null; - this.root = root; - } - - public Node getRoot() { - return root; - } - } 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 index 00000000..81de55a6 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java @@ -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 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 index 00000000..9a620f42 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/linker/IFrameWithDocTypeLinker.java @@ -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 = "\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); + } +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorCssToXPath.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorCssToXPath.java index 04582af6..4033fd3f 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorCssToXPath.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorCssToXPath.java @@ -80,7 +80,7 @@ public class SelectorGeneratorCssToXPath extends SelectorGeneratorBase { } protected String getImplSuffix() { - return "XPath" + super.getImplSuffix(); + return "CssToXPath" + super.getImplSuffix(); } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorJS.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorJS.java index 3cb7010e..6a7b5f64 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorJS.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorJS.java @@ -34,10 +34,8 @@ public class SelectorGeneratorJS extends SelectorGeneratorBase { protected void generateMethodBody(SourceWriter sw, JMethod method, TreeLogger treeLogger, boolean hasContext) throws UnableToCompleteException { - String selector = method.getAnnotation(Selector.class).value(); - - sw.println("return " + wrap(method, - "new SelectorEngine().select(\"" + selector + "\", root)") + ";"); + sw.println("return " + + wrap(method, "impl.select(\"" + selector + "\", root)") + ";"); } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorJSOptimal.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorJSOptimal.java index 064f3712..65a85da8 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorJSOptimal.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorJSOptimal.java @@ -74,7 +74,7 @@ public class SelectorGeneratorJSOptimal extends SelectorGeneratorBase { String selector = method.getAnnotation(Selector.class).value(); sw.println("return " + wrap(method, - "new SelectorEngine().select(\"" + selector + "\", root)") + ";"); + "impl.select(\"" + selector + "\", root)") + ";"); // sw.println("JSArray n = JSArray.create();"); // if(!hasContext) { // sw.println("Node root = Document.get();"); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNative.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNative.java index 7efaee11..74a9b8a9 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNative.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNative.java @@ -31,6 +31,7 @@ public class SelectorGeneratorNative extends SelectorGeneratorCssToXPath { protected void generateMethodBody(SourceWriter sw, JMethod method, TreeLogger treeLogger, boolean hasContext) throws UnableToCompleteException { + String selector = method.getAnnotation(Selector.class).value(); if (selector.matches(SelectorEngineNative.NATIVE_EXCEPTIONS_REGEXP)) { super.generateMethodBody(sw, method, treeLogger, hasContext); 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 index 00000000..6549ac5e --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE8.java @@ -0,0 +1,52 @@ +/* + * 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.rebind; + +import com.google.gwt.core.ext.TreeLogger; +import com.google.gwt.core.ext.UnableToCompleteException; +import com.google.gwt.core.ext.typeinfo.JMethod; +import com.google.gwt.query.client.Selector; +import com.google.gwt.query.client.impl.SelectorEngineNativeIE8; +import com.google.gwt.user.rebind.SourceWriter; + +/** + * Compile time selector generator which delegates to native browser methods. + */ +public class SelectorGeneratorNativeIE8 extends SelectorGeneratorJS { + + @Override + protected void generateMethodBody(SourceWriter sw, JMethod method, + TreeLogger treeLogger, boolean hasContext) + throws UnableToCompleteException { + String selector = method.getAnnotation(Selector.class).value(); + if (selector.matches(SelectorEngineNativeIE8.NATIVE_EXCEPTIONS_REGEXP)) { + super.generateMethodBody(sw, method, treeLogger, hasContext); + } else { + sw.println("return " + + wrap(method, "querySelectorAll(\"" + selector + "\", root)") + ";"); + } + } + + @Override + protected String getImplSuffix() { + return "IE8" + super.getImplSuffix(); + } + + @Override + protected boolean hasGetElementsByClassName() { + return false; + } +} \ No newline at end of file diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTest.java index 7992136e..4bf5142f 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTest.java @@ -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).