diff options
author | Manolo Carrasco <manolo@apache.org> | 2011-09-07 07:40:58 +0000 |
---|---|---|
committer | Manolo Carrasco <manolo@apache.org> | 2011-09-07 07:40:58 +0000 |
commit | 043676d4d704ff99ae176f5981a38e078080bdb2 (patch) | |
tree | 781f672f37c2e801551cb0b99416f31744d549fe /gwtquery-core | |
parent | b5faa441fdd728be45f1360e4f5d51d11641f5e7 (diff) | |
download | gwtquery-043676d4d704ff99ae176f5981a38e078080bdb2.tar.gz gwtquery-043676d4d704ff99ae176f5981a38e078080bdb2.zip |
Use IE9 optimizations, fixes issue103
Diffstat (limited to 'gwtquery-core')
9 files changed, 102 insertions, 17 deletions
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 aa3e57b7..0b88c8a6 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 @@ -37,6 +37,10 @@ <when-type-assignable class="com.google.gwt.query.client.Selectors"/>
<when-property-is name="user.agent" value="ie8"/>
</generate-with> + <generate-with class="com.google.gwt.query.rebind.SelectorGeneratorNativeIE9">
+ <when-type-assignable class="com.google.gwt.query.client.Selectors"/>
+ <when-property-is name="user.agent" value="ie9"/>
+ </generate-with>
<!-- Document Style -->
<replace-with class="com.google.gwt.query.client.impl.DocumentStyleImpl">
@@ -47,6 +51,7 @@ <any>
<when-property-is name="user.agent" value="ie6"/>
<when-property-is name="user.agent" value="ie8"/>
+ <when-property-is name="user.agent" value="ie9"/>
</any>
</replace-with>
@@ -57,16 +62,22 @@ <replace-with class="com.google.gwt.query.client.impl.SelectorEngineSizzleIE">
<when-type-assignable class="com.google.gwt.query.client.impl.HasSelector"/>
<any>
- <when-property-is name="user.agent" value="ie8"/>
<when-property-is name="user.agent" value="ie6"/>
+ <when-property-is name="user.agent" value="ie8"/>
+ <when-property-is name="user.agent" value="ie9"/>
</any>
</replace-with>
+
<replace-with class="com.google.gwt.query.client.impl.SelectorEngineSizzle">
<when-type-assignable class="com.google.gwt.query.client.impl.SelectorEngineImpl"/>
</replace-with>
<replace-with class="com.google.gwt.query.client.impl.SelectorEngineSizzleIE">
<when-type-assignable class="com.google.gwt.query.client.impl.SelectorEngineImpl"/>
- <when-property-is name="user.agent" value="ie6"/>
+ <any>
+ <when-property-is name="user.agent" value="ie6"/>
+ <when-property-is name="user.agent" value="ie8"/>
+ <when-property-is name="user.agent" value="ie9"/>
+ </any>
</replace-with>
<replace-with class="com.google.gwt.query.client.impl.SelectorEngineNative">
<when-type-assignable class="com.google.gwt.query.client.impl.SelectorEngineImpl"/>
@@ -74,31 +85,36 @@ <when-property-is name="user.agent" value="gecko1_8"/>
<when-property-is name="user.agent" value="opera"/>
<when-property-is name="user.agent" value="safari"/>
+ <when-property-is name="user.agent" value="ie9"/>
</any>
</replace-with>
<replace-with class="com.google.gwt.query.client.impl.SelectorEngineNativeIE8">
<when-type-assignable class="com.google.gwt.query.client.impl.SelectorEngineImpl"/>
- <when-property-is name="user.agent" value="ie8"/>
+ <any>
+ <when-property-is name="user.agent" value="ie8"/>
+ </any>
</replace-with>
<!-- UI implementations -->
- <replace-with
- class="com.google.gwt.query.client.plugins.UiPlugin.GQueryUiImplTrident">
- <when-type-is
- class="com.google.gwt.query.client.plugins.UiPlugin.GQueryUiImpl" />
+ <replace-with class="com.google.gwt.query.client.plugins.UiPlugin.GQueryUiImpl">
+ <when-type-is class="com.google.gwt.query.client.plugins.UiPlugin.GQueryUiImpl" />
+ </replace-with>
+ <replace-with class="com.google.gwt.query.client.plugins.UiPlugin.GQueryUiImplTrident">
+ <when-type-is class="com.google.gwt.query.client.plugins.UiPlugin.GQueryUiImpl" />
<any>
<when-property-is name="user.agent" value="ie6" />
<when-property-is name="user.agent" value="ie8" />
+ <when-property-is name="user.agent" value="ie9" />
</any>
</replace-with>
<!-- Attribute setter implementations -->
- <replace-with
- class="com.google.gwt.query.client.impl.AttributeTridentImpl">
- <when-type-is
- class="com.google.gwt.query.client.impl.AttributeImpl" />
+ <replace-with class="com.google.gwt.query.client.impl.AttributeImpl">
+ <when-type-is class="com.google.gwt.query.client.impl.AttributeImpl" />
+ </replace-with>
+ <replace-with class="com.google.gwt.query.client.impl.AttributeTridentImpl">
+ <when-type-is class="com.google.gwt.query.client.impl.AttributeImpl" />
<when-property-is name="user.agent" value="ie6" />
-
</replace-with>
<!-- IE8 needs the iframe where the js of app is loaded set to standard in order
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/QueryMin.gwt.xml b/gwtquery-core/src/main/java/com/google/gwt/query/QueryMin.gwt.xml index 652e282f..d5eba98d 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/QueryMin.gwt.xml +++ b/gwtquery-core/src/main/java/com/google/gwt/query/QueryMin.gwt.xml @@ -54,7 +54,10 @@ </replace-with>
<replace-with class="com.google.gwt.query.client.impl.SelectorEngineNativeMinIE8">
<when-type-assignable class="com.google.gwt.query.client.impl.SelectorEngineImpl"/>
- <when-property-is name="user.agent" value="ie8"/>
+ <any>
+ <when-property-is name="user.agent" value="ie8"/>
+ <when-property-is name="user.agent" value="ie9"/>
+ </any>
<when-property-is name="selectorCapability" value="native"/>
</replace-with>
</module>
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java index 46de0000..bda3a655 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java @@ -165,4 +165,8 @@ public class SelectorEngine implements HasSelector { /native/.test(String($doc.querySelectorAll)) ? true : false;
}-*/;
+ public static native boolean hasXpathEvaluate() /*-{
+ return $doc.evaluate ? true : false;
+ }-*/;
+
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java index 9b172917..7b33ede6 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java @@ -224,10 +224,14 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { SelectorEngine.xpathEvaluate(xsel, ctx, elm);
return JsUtils.unique(elm.<JsArray<Element>> cast()).cast();
} catch (Exception e) {
+ if (!SelectorEngine.hasXpathEvaluate()) {
+ throw new RuntimeException("This Browser does not support Xpath selectors.", e);
+ }
System.err.println("ERROR: xpathEvaluate invalid xpath expression:"
+ xsel + " css-selector:" + sel + "\n");
e.printStackTrace();
return elm;
}
}
+
}
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 index 9c405cd6..4f0df2a1 100644 --- 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 @@ -29,7 +29,7 @@ import com.google.gwt.dom.client.NodeList; */ public class SelectorEngineNativeIE8 extends SelectorEngineSizzleIE { - public static String NATIVE_EXCEPTIONS_REGEXP = ".*(:contains|!=|:checked|:not|:nth-|:only-|:first|:last|:even|:odd).*"; + public static String NATIVE_EXCEPTIONS_REGEXP = ".*(:contains|!=|:not|:nth-|:only-|:first|:last|:even|:odd).*"; public NodeList<Element> select(String selector, Node ctx) { if (!SelectorEngine.hasQuerySelector || selector.matches(NATIVE_EXCEPTIONS_REGEXP)) { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java index e08f81f1..8a7409b9 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java @@ -33,7 +33,7 @@ public class SelectorEngineNativeMin extends SelectorEngineImpl { try { return SelectorEngine.querySelectorAllImpl(selector, ctx); } catch (Exception e) { - Window.alert("Selector '" + selector + "' is unsupported in this Native engine, do not use this syntax or configure your module to use JS fallback"); + Window.alert("GwtQuery: Selector '" + selector + "' is unsupported in this Native engine, do not use this syntax or configure your module to use JS fallback"); return null; } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java index 932503ce..9c05459c 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java @@ -33,7 +33,7 @@ public class SelectorEngineNativeMinIE8 extends SelectorEngineImpl { try { return SelectorEngine.querySelectorAllImpl(selector, ctx); } catch (Exception e) { - Window.alert("Selector '" + selector + "' is unsupported in this IE8 engine, check that you are in 'standards mode' or configure your module to use JS fallback"); + Window.alert("GwtQuery: Selector '" + selector + "' is unsupported in this IE8 engine, check that you are in 'standards mode' or configure your module to use JS fallback"); return null; } } 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 index a734715f..b97cd899 100644 --- 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 @@ -32,7 +32,10 @@ public class SelectorGeneratorNativeIE8 extends SelectorGeneratorJS { TreeLogger treeLogger, boolean hasContext)
throws UnableToCompleteException {
String selector = method.getAnnotation(Selector.class).value();
- if (selector.matches(SelectorEngineNativeIE8.NATIVE_EXCEPTIONS_REGEXP)) {
+ if (selector.matches("#[\\w\\-]+")) {
+ sw.println("return "
+ + wrap(method, "veryQuickId(\"" + selector.substring(1) + "\", root)") + ";");
+ } else if (selector.matches(SelectorEngineNativeIE8.NATIVE_EXCEPTIONS_REGEXP)) {
super.generateMethodBody(sw, method, treeLogger, hasContext);
} else {
sw.println("return "
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE9.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE9.java new file mode 100644 index 00000000..ae76e4e9 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE9.java @@ -0,0 +1,55 @@ +/*
+ * Copyright 2011, The gwtquery team.
+ *
+ * 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.SelectorEngineNative;
+import com.google.gwt.user.rebind.SourceWriter;
+
+/**
+ * Compile time selector generator which delegates to native browser methods.
+ */
+public class SelectorGeneratorNativeIE9 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("#[\\w\\-]+")) {
+ sw.println("return "
+ + wrap(method, "veryQuickId(\"" + selector.substring(1) + "\", root)") + ";");
+ } else if (selector.matches(SelectorEngineNative.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 |