Chromium Code Reviews| Index: pkg/third_party/html5lib/lib/dom.dart |
| diff --git a/pkg/third_party/html5lib/lib/dom.dart b/pkg/third_party/html5lib/lib/dom.dart |
| index b81c1ff64030980f3283ccff0c64be630b23e9b2..e3256aa03676b16d20a887b83f406c3afde4710b 100644 |
| --- a/pkg/third_party/html5lib/lib/dom.dart |
| +++ b/pkg/third_party/html5lib/lib/dom.dart |
| @@ -651,7 +651,11 @@ class NodeList extends ListProxy<Node> { |
| } |
| void add(Node value) { |
| - super.add(_setParent(value)); |
| + if (value is DocumentFragment) { |
| + addAll(value.nodes); |
| + } else { |
| + super.add(_setParent(value)); |
| + } |
| } |
| void addLast(Node value) => add(value); |
| @@ -666,11 +670,22 @@ class NodeList extends ListProxy<Node> { |
| var list = (collection is NodeList || collection is! List) |
| ? collection.toList() : collection as List; |
| for (var node in list.reversed) _setParent(node); |
| - super.addAll(list); |
| + |
| + for (var node in list) { |
| + if (node is DocumentFragment) { |
| + addAll(node.nodes); |
| + } else { |
| + super.add(node); |
| + } |
| + } |
| } |
| void insert(int index, Node value) { |
| - super.insert(index, _setParent(value)); |
| + if (value is DocumentFragment) { |
| + insertAll(index, value.nodes); |
| + } else { |
| + super.insert(index, _setParent(value)); |
| + } |
| } |
| Node removeLast() => super.removeLast()..parent = null; |
| @@ -683,8 +698,13 @@ class NodeList extends ListProxy<Node> { |
| } |
| void operator []=(int index, Node value) { |
| - this[index].parent = null; |
| - super[index] = _setParent(value); |
| + if (value is DocumentFragment) { |
| + removeAt(index); |
| + insertAll(index, value.nodes); |
| + } else { |
| + this[index].parent = null; |
| + super[index] = _setParent(value); |
| + } |
| } |
| // TODO(jmesserly): These aren't implemented in DOM _NodeListImpl, see |
| @@ -698,8 +718,7 @@ class NodeList extends ListProxy<Node> { |
| // Note: see comment in [addAll]. We need to be careful about the order of |
| // operations if [from] is also a NodeList. |
| for (int i = rangeLength - 1; i >= 0; i--) { |
| - this[start + i].parent = null; |
| - super[start + i] = _setParent(from[startFrom + i]); |
| + this[start + i] = from[startFrom + i]; |
| } |
| } |
| @@ -727,9 +746,12 @@ class NodeList extends ListProxy<Node> { |
| super.retainWhere(test); |
| } |
| - void insertAll(int index, List<Node> nodes) { |
| - for (var node in nodes) _setParent(node); |
| - super.insertAll(index, nodes); |
| + void insertAll(int index, Iterable<Node> collection) { |
| + var list = (collection is NodeList || collection is! List) |
| + ? collection.toList() : collection as List; |
| + for (var node in list) { |
| + insert(index++, node); |
|
Jennifer Messerly
2014/04/04 18:24:55
this is O(N^2) right? would something like this wo
Siggi Cherem (dart-lang)
2014/04/04 19:31:56
Good catch. Made the change, also updated addAll t
|
| + } |
| } |
| } |