OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 _ChildrenNodeList implements NodeList { | 5 class _ChildrenNodeList implements NodeList { |
6 // Raw node. | 6 // Raw node. |
7 final _node; | 7 final _node; |
8 final _childNodes; | 8 final _childNodes; |
9 | 9 |
10 _ChildrenNodeList._wrap(var node) | 10 _ChildrenNodeList._wrap(var node) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 | 50 |
51 bool some(bool f(Node element)) { | 51 bool some(bool f(Node element)) { |
52 for(Node element in this) { | 52 for(Node element in this) { |
53 if (f(element)) { | 53 if (f(element)) { |
54 return true; | 54 return true; |
55 } | 55 } |
56 }; | 56 }; |
57 return false; | 57 return false; |
58 } | 58 } |
59 | 59 |
60 /** @domName Node.hasChildNodes */ | |
Jacob
2011/11/21 23:12:11
isEmpty should be
return !_nod.hasChildNodes();
nweiz
2011/11/22 01:11:09
Done.
| |
60 bool isEmpty() { | 61 bool isEmpty() { |
61 return _node.hasChildNodes(); | 62 return _node.hasChildNodes(); |
62 } | 63 } |
63 | 64 |
64 int get length() { | 65 int get length() { |
65 return _childNodes.length; | 66 return _childNodes.length; |
66 } | 67 } |
67 | 68 |
68 Node operator [](int index) { | 69 Node operator [](int index) { |
69 return LevelDom.wrapNode(_childNodes[index]); | 70 return LevelDom.wrapNode(_childNodes[index]); |
70 } | 71 } |
71 | 72 |
72 void operator []=(int index, Node value) { | 73 void operator []=(int index, Node value) { |
73 _childNodes[index] = LevelDom.unwrap(value); | 74 _childNodes[index] = LevelDom.unwrap(value); |
74 } | 75 } |
75 | 76 |
76 void set length(int newLength) { | 77 void set length(int newLength) { |
77 throw new UnsupportedOperationException(''); | 78 throw new UnsupportedOperationException(''); |
78 } | 79 } |
79 | 80 |
81 /** @domName Node.appendChild */ | |
80 Node add(Node value) { | 82 Node add(Node value) { |
81 _node.appendChild(LevelDom.unwrap(value)); | 83 _node.appendChild(LevelDom.unwrap(value)); |
82 return value; | 84 return value; |
83 } | 85 } |
84 | 86 |
85 Node addLast(Node value) { | 87 Node addLast(Node value) { |
86 _node.appendChild(LevelDom.unwrap(value)); | 88 _node.appendChild(LevelDom.unwrap(value)); |
87 return value; | 89 return value; |
88 } | 90 } |
89 | 91 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 } | 191 } |
190 | 192 |
191 Node remove() { | 193 Node remove() { |
192 // TODO(jacobr): should we throw an exception if parent is already null? | 194 // TODO(jacobr): should we throw an exception if parent is already null? |
193 if (_ptr.parentNode !== null) { | 195 if (_ptr.parentNode !== null) { |
194 _ptr.parentNode.removeChild(_ptr); | 196 _ptr.parentNode.removeChild(_ptr); |
195 } | 197 } |
196 return this; | 198 return this; |
197 } | 199 } |
198 | 200 |
201 /** @domName Node.contains */ | |
Jacob
2011/11/21 23:12:11
should be Element.contains
nweiz
2011/11/22 01:11:09
Element.contains doesn't exist in the DOM API.
| |
199 bool contains(Node otherNode) { | 202 bool contains(Node otherNode) { |
200 // TODO: Feature detect and use built in. | 203 // TODO: Feature detect and use built in. |
201 while (otherNode != null && otherNode != this) { | 204 while (otherNode != null && otherNode != this) { |
202 otherNode = otherNode.parent; | 205 otherNode = otherNode.parent; |
203 } | 206 } |
204 return otherNode == this; | 207 return otherNode == this; |
205 } | 208 } |
206 | 209 |
207 // TODO(jacobr): remove when/if List supports a method similar to | 210 // TODO(jacobr): remove when/if List supports a method similar to |
208 // insertBefore or we switch NodeList to implement LinkedList rather than | 211 // insertBefore or we switch NodeList to implement LinkedList rather than |
209 // array. | 212 // array. |
210 Node insertBefore(Node newChild, Node refChild) { | 213 Node insertBefore(Node newChild, Node refChild) { |
211 return LevelDom.wrapNode(_ptr.insertBefore( | 214 return LevelDom.wrapNode(_ptr.insertBefore( |
212 LevelDom.unwrap(newChild), LevelDom.unwrap(refChild))); | 215 LevelDom.unwrap(newChild), LevelDom.unwrap(refChild))); |
213 } | 216 } |
214 | 217 |
215 Node clone(bool deep) { | 218 Node clone(bool deep) { |
216 return LevelDom.wrapNode(_ptr.cloneNode(deep)); | 219 return LevelDom.wrapNode(_ptr.cloneNode(deep)); |
217 } | 220 } |
218 } | 221 } |
OLD | NEW |