Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: lib/dom/templates/html/impl/impl_Document.darttemplate

Issue 10447091: Cleanup NodeSelectors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class $CLASSNAME extends _NodeImpl 5 class $CLASSNAME extends _NodeImpl implements Document
6 implements Document
7 $if FROG 6 $if FROG
8 native "*HTMLDocument" 7 native "*HTMLDocument"
9 $endif 8 $endif
10 { 9 {
11 10
12 $!MEMBERS 11 $!MEMBERS
13 // TODO(jacobr): implement all Element methods not on Document. 12 // TODO(jacobr): implement all Element methods not on Document.
14 13
15 _ElementImpl query(String selectors) { 14 _ElementImpl query(String selectors) {
16 // It is fine for our RegExp to detect element id query selectors to have 15 // It is fine for our RegExp to detect element id query selectors to have
17 // false negatives but not false positives. 16 // false negatives but not false positives.
18 if (const RegExp("^#[_a-zA-Z]\\w*\$").hasMatch(selectors)) { 17 if (const RegExp("^#[_a-zA-Z]\\w*\$").hasMatch(selectors)) {
19 return $dom_getElementById(selectors.substring(1)); 18 return $dom_getElementById(selectors.substring(1));
20 } 19 }
21 return $dom_querySelector(selectors); 20 return $dom_querySelector(selectors);
22 } 21 }
23 22
24 // TODO(jacobr): autogenerate this method.
25 $if FROG
26 _ElementImpl $dom_querySelector(String selectors) native "return this.querySel ector(selectors);";
27 $else
28 _ElementImpl $dom_querySelector(String selectors) native "Document_querySelect or_Callback";
29 $endif
30
31 ElementList queryAll(String selectors) { 23 ElementList queryAll(String selectors) {
32 if (const RegExp("""^\\[name=["'][^'"]+['"]\\]\$""").hasMatch(selectors)) { 24 if (const RegExp("""^\\[name=["'][^'"]+['"]\\]\$""").hasMatch(selectors)) {
33 final mutableMatches = $dom_getElementsByName( 25 final mutableMatches = $dom_getElementsByName(
34 selectors.substring(7,selectors.length - 2)); 26 selectors.substring(7,selectors.length - 2));
35 int len = mutableMatches.length; 27 int len = mutableMatches.length;
36 final copyOfMatches = new List<Element>(len); 28 final copyOfMatches = new List<Element>(len);
37 for (int i = 0; i < len; ++i) { 29 for (int i = 0; i < len; ++i) {
38 copyOfMatches[i] = mutableMatches[i]; 30 copyOfMatches[i] = mutableMatches[i];
39 } 31 }
40 return new _FrozenElementList._wrap(copyOfMatches); 32 return new _FrozenElementList._wrap(copyOfMatches);
41 } else if (const RegExp("^[*a-zA-Z0-9]+\$").hasMatch(selectors)) { 33 } else if (const RegExp("^[*a-zA-Z0-9]+\$").hasMatch(selectors)) {
42 final mutableMatches = $dom_getElementsByTagName(selectors); 34 final mutableMatches = $dom_getElementsByTagName(selectors);
43 int len = mutableMatches.length; 35 int len = mutableMatches.length;
44 final copyOfMatches = new List<Element>(len); 36 final copyOfMatches = new List<Element>(len);
45 for (int i = 0; i < len; ++i) { 37 for (int i = 0; i < len; ++i) {
46 copyOfMatches[i] = mutableMatches[i]; 38 copyOfMatches[i] = mutableMatches[i];
47 } 39 }
48 return new _FrozenElementList._wrap(copyOfMatches); 40 return new _FrozenElementList._wrap(copyOfMatches);
49 } else { 41 } else {
50 return new _FrozenElementList._wrap($dom_querySelectorAll(selectors)); 42 return new _FrozenElementList._wrap($dom_querySelectorAll(selectors));
51 } 43 }
52 } 44 }
53 } 45 }
OLDNEW
« no previous file with comments | « lib/dom/scripts/systemnative.py ('k') | lib/dom/templates/html/impl/impl_DocumentFragment.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698