| 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 part of $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Lazy implementation of the child nodes of an element that does not request | 8 * Lazy implementation of the child nodes of an element that does not request |
| 9 * the actual child nodes of an element until strictly necessary greatly | 9 * the actual child nodes of an element until strictly necessary greatly |
| 10 * improving performance for the typical cases where it is not required. | 10 * improving performance for the typical cases where it is not required. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 throw new RangeError.range(index, 0, length); | 76 throw new RangeError.range(index, 0, length); |
| 77 } | 77 } |
| 78 if (index == length) { | 78 if (index == length) { |
| 79 _this.append(node); | 79 _this.append(node); |
| 80 } else { | 80 } else { |
| 81 _this.insertBefore(node, this[index]); | 81 _this.insertBefore(node, this[index]); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 void insertAll(int index, Iterable<Node> iterable) { | 85 void insertAll(int index, Iterable<Node> iterable) { |
| 86 throw new UnimplementedError(); | 86 var item = this[index]; |
| 87 _this.insertAllBefore(iterable, item); |
| 87 } | 88 } |
| 88 | 89 |
| 89 void setAll(int index, Iterable<Node> iterable) { | 90 void setAll(int index, Iterable<Node> iterable) { |
| 90 throw new UnimplementedError(); | 91 throw new UnsupportedError("Cannot setAll on Node list"); |
| 91 } | 92 } |
| 92 | 93 |
| 93 Node removeLast() { | 94 Node removeLast() { |
| 94 final result = last; | 95 final result = last; |
| 95 if (result != null) { | 96 if (result != null) { |
| 96 _this.$dom_removeChild(result); | 97 _this.$dom_removeChild(result); |
| 97 } | 98 } |
| 98 return result; | 99 return result; |
| 99 } | 100 } |
| 100 | 101 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 void clear() { | 139 void clear() { |
| 139 _this.text = ''; | 140 _this.text = ''; |
| 140 } | 141 } |
| 141 | 142 |
| 142 void operator []=(int index, Node value) { | 143 void operator []=(int index, Node value) { |
| 143 _this.$dom_replaceChild(value, this[index]); | 144 _this.$dom_replaceChild(value, this[index]); |
| 144 } | 145 } |
| 145 | 146 |
| 146 Iterator<Node> get iterator => _this.$dom_childNodes.iterator; | 147 Iterator<Node> get iterator => _this.$dom_childNodes.iterator; |
| 147 | 148 |
| 148 List<Node> toList({ bool growable: true }) => | |
| 149 new List<Node>.from(this, growable: growable); | |
| 150 Set<Node> toSet() => new Set<Node>.from(this); | |
| 151 | |
| 152 bool get isEmpty => this.length == 0; | |
| 153 | |
| 154 // From List<Node>: | 149 // From List<Node>: |
| 155 | 150 |
| 156 // TODO(jacobr): this could be implemented for child node lists. | 151 // TODO(jacobr): this could be implemented for child node lists. |
| 157 // The exception we throw here is misleading. | 152 // The exception we throw here is misleading. |
| 158 void sort([int compare(Node a, Node b)]) { | 153 void sort([Comparator<Node> compare]) { |
| 159 throw new UnsupportedError("Cannot sort immutable List."); | 154 throw new UnsupportedError("Cannot sort Node list"); |
| 160 } | 155 } |
| 161 | 156 |
| 162 // FIXME: implement these. | 157 // FIXME: implement these. |
| 163 void setRange(int start, int end, Iterable<Node> iterable, | 158 void setRange(int start, int end, Iterable<Node> iterable, |
| 164 [int skipCount = 0]) { | 159 [int skipCount = 0]) { |
| 165 throw new UnsupportedError( | 160 throw new UnsupportedError("Cannot setRange on Node list"); |
| 166 "Cannot setRange on immutable List."); | |
| 167 } | |
| 168 void removeRange(int start, int end) { | |
| 169 throw new UnsupportedError( | |
| 170 "Cannot removeRange on immutable List."); | |
| 171 } | 161 } |
| 172 | 162 |
| 173 Iterable<Node> getRange(int start, int end) { | 163 void fillRange(int start, int end, [Node fill]) { |
| 174 throw new UnimplementedError("NodeList.getRange"); | 164 throw new UnsupportedError("Cannot fillRange on Node list"); |
| 175 } | |
| 176 | |
| 177 void replaceRange(int start, int end, Iterable<Node> iterable) { | |
| 178 throw new UnimplementedError("NodeList.replaceRange"); | |
| 179 } | |
| 180 | |
| 181 void fillRange(int start, int end, [Node fillValue]) { | |
| 182 throw new UnimplementedError("NodeList.fillRange"); | |
| 183 } | |
| 184 | |
| 185 List<Node> sublist(int start, [int end]) { | |
| 186 if (end == null) end == length; | |
| 187 return Lists.getRange(this, start, end, <Node>[]); | |
| 188 } | |
| 189 | |
| 190 String toString() { | |
| 191 StringBuffer buffer = new StringBuffer('['); | |
| 192 buffer.writeAll(this, ', '); | |
| 193 buffer.write(']'); | |
| 194 return buffer.toString(); | |
| 195 } | 165 } |
| 196 // -- end List<Node> mixins. | 166 // -- end List<Node> mixins. |
| 197 | 167 |
| 198 // TODO(jacobr): benchmark whether this is more efficient or whether caching | 168 // TODO(jacobr): benchmark whether this is more efficient or whether caching |
| 199 // a local copy of $dom_childNodes is more efficient. | 169 // a local copy of $dom_childNodes is more efficient. |
| 200 int get length => _this.$dom_childNodes.length; | 170 int get length => _this.$dom_childNodes.length; |
| 201 | 171 |
| 202 void set length(int value) { | 172 void set length(int value) { |
| 203 throw new UnsupportedError( | 173 throw new UnsupportedError( |
| 204 "Cannot set length on immutable List."); | 174 "Cannot set length on immutable List."); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 } | 330 } |
| 361 | 331 |
| 362 /** | 332 /** |
| 363 * Print out a String representation of this Node. | 333 * Print out a String representation of this Node. |
| 364 */ | 334 */ |
| 365 String toString() => localName == null ? | 335 String toString() => localName == null ? |
| 366 (nodeValue == null ? super.toString() : nodeValue) : localName; | 336 (nodeValue == null ? super.toString() : nodeValue) : localName; |
| 367 | 337 |
| 368 $!MEMBERS | 338 $!MEMBERS |
| 369 } | 339 } |
| OLD | NEW |