Index: lib/dom/templates/html/impl/impl_Document.darttemplate |
diff --git a/lib/dom/templates/html/impl/impl_Document.darttemplate b/lib/dom/templates/html/impl/impl_Document.darttemplate |
new file mode 100644 |
index 0000000000000000000000000000000000000000..722aa29238eb2485f52eae613fd99fa0b1b48f05 |
--- /dev/null |
+++ b/lib/dom/templates/html/impl/impl_Document.darttemplate |
@@ -0,0 +1,46 @@ |
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+class $CLASSNAME extends _NodeImpl |
nweiz
2012/03/28 01:16:17
Why not "class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIV
Jacob
2012/03/28 17:52:54
Because it extends _NodeImpl not _ElementImpl
Als
|
+ implements Document |
+$if FROG |
+ native "*HTMLDocument" |
+$endif |
+ { |
+ |
+$!MEMBERS |
+ // TODO(jacobr): implement all Element methods not on Document. |
+ |
+ _ElementImpl query(String selectors) { |
+ if (const RegExp("^#\\w+\$").hasMatch(selectors)) { |
+ return $dom_getElementById(selectors.substring(1)); |
nweiz
2012/03/28 01:16:17
Is this really faster? That's kind of depressing.
Jacob
2012/03/28 17:52:54
Sad but true.... This is a LOT faster for getEleme
nweiz
2012/03/28 20:29:33
I'm not sure how much we want to care about false
Jacob
2012/03/28 21:01:30
I've added a comment that this has false negatives
|
+ } |
+ return $dom_querySelector(selectors); |
+ } |
+ |
+ _ElementImpl $dom_querySelector(String selectors) native "return this.querySelector(selectors);"; |
nweiz
2012/03/28 01:16:17
Line length. Also, why isn't this autogenerated?
Jacob
2012/03/28 17:52:54
Obeying line length for these native lines does mo
|
+ |
+ ElementList queryAll(String selectors) { |
+ if (const RegExp("""^\\[name=["'][^'"]+['"]\\]\$""").hasMatch(selectors)) { |
+ final mutableMatches = $dom_getElementsByName( |
+ selectors.substring(7,selectors.length - 2)); |
+ int len = mutableMatches.length; |
+ final copyOfMatches = new List<Element>(len); |
+ for (int i = 0; i < len; ++i) { |
+ copyOfMatches[i] = mutableMatches[i]; |
+ } |
+ return new _FrozenElementList._wrap(copyOfMatches); |
+ } else if (const RegExp("^[*a-zA-Z0-9]+\$").hasMatch(selectors)) { |
+ final mutableMatches = $dom_getElementsByTagName(selectors); |
+ int len = mutableMatches.length; |
+ final copyOfMatches = new List<Element>(len); |
+ for (int i = 0; i < len; ++i) { |
+ copyOfMatches[i] = mutableMatches[i]; |
+ } |
+ return new _FrozenElementList._wrap(copyOfMatches); |
+ } else { |
+ return new _FrozenElementList._wrap($dom_querySelectorAll(selectors)); |
+ } |
+ } |
+} |