| 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 var item = this[index]; | 86 throw new UnimplementedError(); |
| 87 _this.insertAllBefore(iterable, item); | |
| 88 } | 87 } |
| 89 | 88 |
| 90 void setAll(int index, Iterable<Node> iterable) { | 89 void setAll(int index, Iterable<Node> iterable) { |
| 91 throw new UnsupportedError("Cannot setAll on Node list"); | 90 throw new UnimplementedError(); |
| 92 } | 91 } |
| 93 | 92 |
| 94 Node removeLast() { | 93 Node removeLast() { |
| 95 final result = last; | 94 final result = last; |
| 96 if (result != null) { | 95 if (result != null) { |
| 97 _this.$dom_removeChild(result); | 96 _this.$dom_removeChild(result); |
| 98 } | 97 } |
| 99 return result; | 98 return result; |
| 100 } | 99 } |
| 101 | 100 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 void clear() { | 138 void clear() { |
| 140 _this.text = ''; | 139 _this.text = ''; |
| 141 } | 140 } |
| 142 | 141 |
| 143 void operator []=(int index, Node value) { | 142 void operator []=(int index, Node value) { |
| 144 _this.$dom_replaceChild(value, this[index]); | 143 _this.$dom_replaceChild(value, this[index]); |
| 145 } | 144 } |
| 146 | 145 |
| 147 Iterator<Node> get iterator => _this.$dom_childNodes.iterator; | 146 Iterator<Node> get iterator => _this.$dom_childNodes.iterator; |
| 148 | 147 |
| 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 |
| 149 // From List<Node>: | 154 // From List<Node>: |
| 150 | 155 |
| 151 // TODO(jacobr): this could be implemented for child node lists. | 156 // TODO(jacobr): this could be implemented for child node lists. |
| 152 // The exception we throw here is misleading. | 157 // The exception we throw here is misleading. |
| 153 void sort([Comparator<Node> compare]) { | 158 void sort([int compare(Node a, Node b)]) { |
| 154 throw new UnsupportedError("Cannot sort Node list"); | 159 throw new UnsupportedError("Cannot sort immutable List."); |
| 155 } | 160 } |
| 156 | 161 |
| 157 // FIXME: implement these. | 162 // FIXME: implement these. |
| 158 void setRange(int start, int end, Iterable<Node> iterable, | 163 void setRange(int start, int end, Iterable<Node> iterable, |
| 159 [int skipCount = 0]) { | 164 [int skipCount = 0]) { |
| 160 throw new UnsupportedError("Cannot setRange on Node list"); | 165 throw new UnsupportedError( |
| 166 "Cannot setRange on immutable List."); |
| 167 } |
| 168 void removeRange(int start, int end) { |
| 169 throw new UnsupportedError( |
| 170 "Cannot removeRange on immutable List."); |
| 161 } | 171 } |
| 162 | 172 |
| 163 void fillRange(int start, int end, [Node fill]) { | 173 Iterable<Node> getRange(int start, int end) { |
| 164 throw new UnsupportedError("Cannot fillRange on Node list"); | 174 throw new UnimplementedError("NodeList.getRange"); |
| 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(); |
| 165 } | 195 } |
| 166 // -- end List<Node> mixins. | 196 // -- end List<Node> mixins. |
| 167 | 197 |
| 168 // TODO(jacobr): benchmark whether this is more efficient or whether caching | 198 // TODO(jacobr): benchmark whether this is more efficient or whether caching |
| 169 // a local copy of $dom_childNodes is more efficient. | 199 // a local copy of $dom_childNodes is more efficient. |
| 170 int get length => _this.$dom_childNodes.length; | 200 int get length => _this.$dom_childNodes.length; |
| 171 | 201 |
| 172 void set length(int value) { | 202 void set length(int value) { |
| 173 throw new UnsupportedError( | 203 throw new UnsupportedError( |
| 174 "Cannot set length on immutable List."); | 204 "Cannot set length on immutable List."); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 } | 360 } |
| 331 | 361 |
| 332 /** | 362 /** |
| 333 * Print out a String representation of this Node. | 363 * Print out a String representation of this Node. |
| 334 */ | 364 */ |
| 335 String toString() => localName == null ? | 365 String toString() => localName == null ? |
| 336 (nodeValue == null ? super.toString() : nodeValue) : localName; | 366 (nodeValue == null ? super.toString() : nodeValue) : localName; |
| 337 | 367 |
| 338 $!MEMBERS | 368 $!MEMBERS |
| 339 } | 369 } |
| OLD | NEW |