OLD | NEW |
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 implements Document | 5 class $CLASSNAME extends _NodeImpl implements Document |
6 $if FROG | 6 $if FROG |
7 native "*HTMLDocument" | 7 native "*HTMLDocument" |
8 $endif | 8 $endif |
9 { | 9 { |
10 | 10 |
11 $!MEMBERS | 11 $!MEMBERS |
12 // TODO(jacobr): implement all Element methods not on Document. | 12 // TODO(jacobr): implement all Element methods not on Document. |
13 | 13 |
14 _ElementImpl query(String selectors) { | 14 _ElementImpl query(String selectors) { |
15 // 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 |
16 // false negatives but not false positives. | 16 // false negatives but not false positives. |
17 if (const RegExp("^#[_a-zA-Z]\\w*\$").hasMatch(selectors)) { | 17 if (const RegExp("^#[_a-zA-Z]\\w*\$").hasMatch(selectors)) { |
18 return $dom_getElementById(selectors.substring(1)); | 18 return $dom_getElementById(selectors.substring(1)); |
19 } | 19 } |
20 return $dom_querySelector(selectors); | 20 return $dom_querySelector(selectors); |
21 } | 21 } |
22 | 22 |
23 ElementList queryAll(String selectors) { | 23 List<Element> queryAll(String selectors) { |
24 if (const RegExp("""^\\[name=["'][^'"]+['"]\\]\$""").hasMatch(selectors)) { | 24 if (const RegExp("""^\\[name=["'][^'"]+['"]\\]\$""").hasMatch(selectors)) { |
25 final mutableMatches = $dom_getElementsByName( | 25 final mutableMatches = $dom_getElementsByName( |
26 selectors.substring(7,selectors.length - 2)); | 26 selectors.substring(7,selectors.length - 2)); |
27 int len = mutableMatches.length; | 27 int len = mutableMatches.length; |
28 final copyOfMatches = new List<Element>(len); | 28 final copyOfMatches = new List<Element>(len); |
29 for (int i = 0; i < len; ++i) { | 29 for (int i = 0; i < len; ++i) { |
30 copyOfMatches[i] = mutableMatches[i]; | 30 copyOfMatches[i] = mutableMatches[i]; |
31 } | 31 } |
32 return new _FrozenElementList._wrap(copyOfMatches); | 32 return new _FrozenElementList._wrap(copyOfMatches); |
33 } else if (const RegExp("^[*a-zA-Z0-9]+\$").hasMatch(selectors)) { | 33 } else if (const RegExp("^[*a-zA-Z0-9]+\$").hasMatch(selectors)) { |
34 final mutableMatches = $dom_getElementsByTagName(selectors); | 34 final mutableMatches = $dom_getElementsByTagName(selectors); |
35 int len = mutableMatches.length; | 35 int len = mutableMatches.length; |
36 final copyOfMatches = new List<Element>(len); | 36 final copyOfMatches = new List<Element>(len); |
37 for (int i = 0; i < len; ++i) { | 37 for (int i = 0; i < len; ++i) { |
38 copyOfMatches[i] = mutableMatches[i]; | 38 copyOfMatches[i] = mutableMatches[i]; |
39 } | 39 } |
40 return new _FrozenElementList._wrap(copyOfMatches); | 40 return new _FrozenElementList._wrap(copyOfMatches); |
41 } else { | 41 } else { |
42 return new _FrozenElementList._wrap($dom_querySelectorAll(selectors)); | 42 return new _FrozenElementList._wrap($dom_querySelectorAll(selectors)); |
43 } | 43 } |
44 } | 44 } |
45 } | 45 } |
OLD | NEW |