Chromium Code Reviews| 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) |
| 11 : _childNodes = node.childNodes, | 11 : _childNodes = node.childNodes, |
| 12 _node = node; | 12 _node = node; |
| 13 | 13 |
| 14 List<Node> _toList() { | 14 List<Node> _toList() { |
| 15 final output = new List(_childNodes.length); | 15 final output = new List(_childNodes.length); |
| 16 for (int i = 0, len = _childNodes.length; i < len; i++) { | 16 for (int i = 0, len = _childNodes.length; i < len; i++) { |
| 17 output[i] = LevelDom.wrapNode(_childNodes[i]); | 17 output[i] = LevelDom.wrapNode(_childNodes[i]); |
| 18 } | 18 } |
| 19 return output; | 19 return output; |
| 20 } | 20 } |
| 21 | 21 |
| 22 Node get first() { | 22 Node get first() { |
| 23 return LevelDom.wrapNode(_node.firstChild); | 23 return LevelDom.wrapNode(_node.firstChild); |
| 24 } | 24 } |
| 25 | 25 |
| 26 void forEach(void f(Node element)) { | 26 void forEach(void f(Node element)) { |
| 27 for (var node in _childNodes) { | 27 for (int i = 0, len = _childNodes.length; i < len; i++) { |
|
Jacob
2011/12/14 23:00:13
what if the children change while iterating?
to be
nweiz
2011/12/14 23:21:38
That makes me realize, this could be implemented m
| |
| 28 f(LevelDom.wrapNode(node)); | 28 f(LevelDom.wrapNode(_childNodes[i])); |
| 29 } | 29 } |
| 30 } | 30 } |
| 31 | 31 |
| 32 Collection<Node> filter(bool f(Node element)) { | 32 Collection<Node> filter(bool f(Node element)) { |
| 33 List<Node> output = new List<Node>(); | 33 List<Node> output = new List<Node>(); |
| 34 forEach((Node element) { | 34 forEach((Node element) { |
| 35 if (f(element)) { | 35 if (f(element)) { |
| 36 output.add(element); | 36 output.add(element); |
| 37 } | 37 } |
| 38 }); | 38 }); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 // array. | 212 // array. |
| 213 Node insertBefore(Node newChild, Node refChild) { | 213 Node insertBefore(Node newChild, Node refChild) { |
| 214 return LevelDom.wrapNode(_ptr.insertBefore( | 214 return LevelDom.wrapNode(_ptr.insertBefore( |
| 215 LevelDom.unwrap(newChild), LevelDom.unwrap(refChild))); | 215 LevelDom.unwrap(newChild), LevelDom.unwrap(refChild))); |
| 216 } | 216 } |
| 217 | 217 |
| 218 Node clone(bool deep) { | 218 Node clone(bool deep) { |
| 219 return LevelDom.wrapNode(_ptr.cloneNode(deep)); | 219 return LevelDom.wrapNode(_ptr.cloneNode(deep)); |
| 220 } | 220 } |
| 221 } | 221 } |
| OLD | NEW |