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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 130 } |
131 return last; | 131 return last; |
132 } | 132 } |
133 | 133 |
134 Node last() { | 134 Node last() { |
135 return LevelDom.wrapNode(_node.lastChild); | 135 return LevelDom.wrapNode(_node.lastChild); |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 // TODO(nweiz): when all implementations we target have the same name for the | 139 // TODO(nweiz): when all implementations we target have the same name for the |
140 // coreimpl implementation of List<Node>, extend that rather than wrapping. | 140 // coreimpl implementation of List<E>, extend that rather than wrapping. |
141 class _NodeList implements NodeList { | 141 class _ListWrapper<E> implements List<E> { |
142 List<Node> _list; | 142 List<E> _list; |
143 | 143 |
144 _NodeList(List<Node> this._list); | 144 _ListWrapper(List<E> this._list); |
145 | 145 |
146 Iterator<Node> iterator() => _list.iterator(); | 146 Iterator<E> iterator() => _list.iterator(); |
147 | 147 |
148 void forEach(void f(Node element)) => _list.forEach(f); | 148 void forEach(void f(E element)) => _list.forEach(f); |
149 | 149 |
150 Collection map(f(Node element)) => _list.map(f); | 150 Collection map(f(E element)) => _list.map(f); |
151 | 151 |
152 NodeList filter(bool f(Node element)) => new _NodeList(_list.filter(f)); | 152 List<E> filter(bool f(E element)) => _list.filter(f); |
153 | 153 |
154 bool every(bool f(Node element)) => _list.every(f); | 154 bool every(bool f(E element)) => _list.every(f); |
155 | 155 |
156 bool some(bool f(Node element)) => _list.some(f); | 156 bool some(bool f(E element)) => _list.some(f); |
157 | 157 |
158 bool isEmpty() => _list.isEmpty(); | 158 bool isEmpty() => _list.isEmpty(); |
159 | 159 |
160 int get length() => _list.length; | 160 int get length() => _list.length; |
161 | 161 |
162 Node operator [](int index) => _list[index]; | 162 E operator [](int index) => _list[index]; |
163 | 163 |
164 void operator []=(int index, Node value) { _list[index] = value; } | 164 void operator []=(int index, E value) { _list[index] = value; } |
165 | 165 |
166 void set length(int newLength) { _list.length = newLength; } | 166 void set length(int newLength) { _list.length = newLength; } |
167 | 167 |
168 void add(Node value) => _list.add(value); | 168 void add(E value) => _list.add(value); |
169 | 169 |
170 void addLast(Node value) => _list.addLast(value); | 170 void addLast(E value) => _list.addLast(value); |
171 | 171 |
172 void addAll(Collection<Node> collection) => _list.addAll(collection); | 172 void addAll(Collection<E> collection) => _list.addAll(collection); |
173 | 173 |
174 void sort(int compare(Node a, Node b)) => _list.sort(compare); | 174 void sort(int compare(E a, E b)) => _list.sort(compare); |
175 | 175 |
176 int indexOf(Node element, [int start = 0]) => _list.indexOf(element, start); | 176 int indexOf(E element, [int start = 0]) => _list.indexOf(element, start); |
177 | 177 |
178 int lastIndexOf(Node element, [int start = 0]) => | 178 int lastIndexOf(E element, [int start = 0]) => |
179 _list.lastIndexOf(element, start); | 179 _list.lastIndexOf(element, start); |
180 | 180 |
181 void clear() => _list.clear(); | 181 void clear() => _list.clear(); |
182 | 182 |
183 Node removeLast() => _list.removeLast(); | 183 E removeLast() => _list.removeLast(); |
184 | 184 |
185 Node last() => _list.last(); | 185 E last() => _list.last(); |
186 | 186 |
187 NodeList getRange(int start, int length) => | 187 List<E> getRange(int start, int length) => _list.getRange(start, length); |
188 new _NodeList(_list.getRange(start, length)); | |
189 | 188 |
190 void setRange(int start, int length, List<Node> from, [int startFrom = 0]) => | 189 void setRange(int start, int length, List<E> from, [int startFrom = 0]) => |
191 _list.setRange(start, length, from, startFrom); | 190 _list.setRange(start, length, from, startFrom); |
192 | 191 |
193 void removeRange(int start, int length) => _list.removeRange(start, length); | 192 void removeRange(int start, int length) => _list.removeRange(start, length); |
194 | 193 |
195 void insertRange(int start, int length, [Node initialValue = null]) => | 194 void insertRange(int start, int length, [E initialValue = null]) => |
196 _list.insertRange(start, length, initialValue); | 195 _list.insertRange(start, length, initialValue); |
197 | 196 |
198 Node get first() => _list[0]; | 197 E get first() => _list[0]; |
| 198 } |
| 199 |
| 200 class _NodeList extends _ListWrapper<Node> implements NodeList { |
| 201 _NodeList(List<Node> list) : super(list); |
| 202 |
| 203 NodeList filter(bool f(Node element)) => new _NodeList(super.filter(f)); |
| 204 |
| 205 NodeList getRange(int start, int length) => |
| 206 new _NodeList(super.getRange(start, length)); |
199 } | 207 } |
200 | 208 |
201 class NodeWrappingImplementation extends EventTargetWrappingImplementation imple
ments Node { | 209 class NodeWrappingImplementation extends EventTargetWrappingImplementation imple
ments Node { |
202 NodeList _nodes; | 210 NodeList _nodes; |
203 | 211 |
204 NodeWrappingImplementation._wrap(ptr) : super._wrap(ptr); | 212 NodeWrappingImplementation._wrap(ptr) : super._wrap(ptr); |
205 | 213 |
206 void set nodes(Collection<Node> value) { | 214 void set nodes(Collection<Node> value) { |
207 // Copy list first since we don't want liveness during iteration. | 215 // Copy list first since we don't want liveness during iteration. |
208 List copy = new List.from(value); | 216 List copy = new List.from(value); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 // array. | 269 // array. |
262 Node insertBefore(Node newChild, Node refChild) { | 270 Node insertBefore(Node newChild, Node refChild) { |
263 return LevelDom.wrapNode(_ptr.insertBefore( | 271 return LevelDom.wrapNode(_ptr.insertBefore( |
264 LevelDom.unwrap(newChild), LevelDom.unwrap(refChild))); | 272 LevelDom.unwrap(newChild), LevelDom.unwrap(refChild))); |
265 } | 273 } |
266 | 274 |
267 Node clone(bool deep) { | 275 Node clone(bool deep) { |
268 return LevelDom.wrapNode(_ptr.cloneNode(deep)); | 276 return LevelDom.wrapNode(_ptr.cloneNode(deep)); |
269 } | 277 } |
270 } | 278 } |
OLD | NEW |