| 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 html; |    5 part of html; | 
|    6  |    6  | 
|    7 // TODO(jacobr): use _Lists.dart to remove some of the duplicated |    7 // TODO(jacobr): use _Lists.dart to remove some of the duplicated | 
|    8 // functionality. |    8 // functionality. | 
|    9 class _ChildrenElementList implements List { |    9 class _ChildrenElementList implements List { | 
|   10   // Raw Element. |   10   // Raw Element. | 
|   11   final Element _element; |   11   final Element _element; | 
|   12   final HtmlCollection _childElements; |   12   final HtmlCollection _childElements; | 
|   13  |   13  | 
|   14   _ChildrenElementList._wrap(Element element) |   14   _ChildrenElementList._wrap(Element element) | 
|   15     : _childElements = element.$dom_children, |   15     : _childElements = element.$dom_children, | 
|   16       _element = element; |   16       _element = element; | 
|   17  |   17  | 
|   18   List<Element> toList() { |   18   List<Element> toList() { | 
|   19     final output = new List<Element>.fixedLength(_childElements.length); |   19     final output = new List<Element>.fixedLength(_childElements.length); | 
|   20     for (int i = 0, len = _childElements.length; i < len; i++) { |   20     for (int i = 0, len = _childElements.length; i < len; i++) { | 
|   21       output[i] = _childElements[i]; |   21       output[i] = _childElements[i]; | 
|   22     } |   22     } | 
|   23     return output; |   23     return output; | 
|   24   } |   24   } | 
|   25  |   25  | 
|   26   Set<Element> toSet() { |   26   Set<Element> toSet() { | 
|   27     final output = new Set<Element>(_childElements.length); |   27     final output = new Set<Element>(); | 
|   28     for (int i = 0, len = _childElements.length; i < len; i++) { |   28     for (int i = 0, len = _childElements.length; i < len; i++) { | 
|   29       output.add(_childElements[i]); |   29       output.add(_childElements[i]); | 
|   30     } |   30     } | 
|   31     return output; |   31     return output; | 
|   32   } |   32   } | 
|   33  |   33  | 
|   34   bool contains(Element element) => _childElements.contains(element); |   34   bool contains(Element element) => _childElements.contains(element); | 
|   35  |   35  | 
|   36   void forEach(void f(Element element)) { |   36   void forEach(void f(Element element)) { | 
|   37     for (Element element in _childElements) { |   37     for (Element element in _childElements) { | 
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  203     if (result == null) throw new StateError("No elements"); |  203     if (result == null) throw new StateError("No elements"); | 
|  204     return result; |  204     return result; | 
|  205   } |  205   } | 
|  206  |  206  | 
|  207   Element get single { |  207   Element get single { | 
|  208     if (length > 1) throw new StateError("More than one element"); |  208     if (length > 1) throw new StateError("More than one element"); | 
|  209     return first; |  209     return first; | 
|  210   } |  210   } | 
|  211  |  211  | 
|  212   Element min([int compare(Element a, Element b)]) { |  212   Element min([int compare(Element a, Element b)]) { | 
|  213     return _Collections.minInList(this, compare); |  213     return Collections.min(this, compare); | 
|  214   } |  214   } | 
|  215  |  215  | 
|  216   Element max([int compare(Element a, Element b)]) { |  216   Element max([int compare(Element a, Element b)]) { | 
|  217     return _Collections.maxInList(this, compare); |  217     return Collections.max(this, compare); | 
|  218   } |  218   } | 
|  219 } |  219 } | 
|  220  |  220  | 
|  221 // TODO(jacobr): this is an inefficient implementation but it is hard to see |  221 // TODO(jacobr): this is an inefficient implementation but it is hard to see | 
|  222 // a better option given that we cannot quite force NodeList to be an |  222 // a better option given that we cannot quite force NodeList to be an | 
|  223 // ElementList as there are valid cases where a NodeList JavaScript object |  223 // ElementList as there are valid cases where a NodeList JavaScript object | 
|  224 // contains Node objects that are not Elements. |  224 // contains Node objects that are not Elements. | 
|  225 class _FrozenElementList implements List { |  225 class _FrozenElementList implements List { | 
|  226   final List<Node> _nodeList; |  226   final List<Node> _nodeList; | 
|  227  |  227  | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  262  |  262  | 
|  263   bool any(bool f(Element element)) { |  263   bool any(bool f(Element element)) { | 
|  264     for(Element element in this) { |  264     for(Element element in this) { | 
|  265       if (f(element)) { |  265       if (f(element)) { | 
|  266         return true; |  266         return true; | 
|  267       } |  267       } | 
|  268     }; |  268     }; | 
|  269     return false; |  269     return false; | 
|  270   } |  270   } | 
|  271  |  271  | 
 |  272   List<Element> toList() => new List<Element>.from(this); | 
 |  273   Set<Element> toSet() => new Set<Element>.from(this); | 
 |  274  | 
|  272   List<Element> take(int n) { |  275   List<Element> take(int n) { | 
|  273     return new ListView<Element>(this, 0, n); |  276     return new ListView<Element>(this, 0, n); | 
|  274   } |  277   } | 
|  275  |  278  | 
|  276   Iterable<Element> takeWhile(bool test(T value)) { |  279   Iterable<Element> takeWhile(bool test(Element value)) { | 
|  277     return new TakeWhileIterable<Element>(this, test); |  280     return new TakeWhileIterable<Element>(this, test); | 
|  278   } |  281   } | 
|  279  |  282  | 
|  280   List<Element> skip(int n) { |  283   List<Element> skip(int n) { | 
|  281     return new ListView<Element>(this, n, null); |  284     return new ListView<Element>(this, n, null); | 
|  282   } |  285   } | 
|  283  |  286  | 
|  284   Iterable<Element> skipWhile(bool test(T value)) { |  287   Iterable<Element> skipWhile(bool test(Element value)) { | 
|  285     return new SkipWhileIterable<Element>(this, test); |  288     return new SkipWhileIterable<Element>(this, test); | 
|  286   } |  289   } | 
|  287  |  290  | 
|  288   Element firstMatching(bool test(Element value), {Element orElse()}) { |  291   Element firstMatching(bool test(Element value), {Element orElse()}) { | 
|  289     return Collections.firstMatching(this, test, orElse); |  292     return Collections.firstMatching(this, test, orElse); | 
|  290   } |  293   } | 
|  291  |  294  | 
|  292   Element lastMatching(bool test(Element value), {Element orElse()}) { |  295   Element lastMatching(bool test(Element value), {Element orElse()}) { | 
|  293     return Collections.lastMatchingInList(this, test, orElse); |  296     return Collections.lastMatchingInList(this, test, orElse); | 
|  294   } |  297   } | 
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  371     throw new UnsupportedError(''); |  374     throw new UnsupportedError(''); | 
|  372   } |  375   } | 
|  373  |  376  | 
|  374   Element get first => _nodeList.first; |  377   Element get first => _nodeList.first; | 
|  375  |  378  | 
|  376   Element get last => _nodeList.last; |  379   Element get last => _nodeList.last; | 
|  377  |  380  | 
|  378   Element get single => _nodeList.single; |  381   Element get single => _nodeList.single; | 
|  379  |  382  | 
|  380   Element min([int compare(Element a, Element b)]) { |  383   Element min([int compare(Element a, Element b)]) { | 
|  381     return _Collections.minInList(this, compare); |  384     return Collections.min(this, compare); | 
|  382   } |  385   } | 
|  383  |  386  | 
|  384   Element max([int compare(Element a, Element b)]) { |  387   Element max([int compare(Element a, Element b)]) { | 
|  385     return _Collections.maxInList(this, compare); |  388     return Collections.max(this, compare); | 
|  386   } |  389   } | 
|  387 } |  390 } | 
|  388  |  391  | 
|  389 class _FrozenElementListIterator implements Iterator<Element> { |  392 class _FrozenElementListIterator implements Iterator<Element> { | 
|  390   final _FrozenElementList _list; |  393   final _FrozenElementList _list; | 
|  391   int _index = -1; |  394   int _index = -1; | 
|  392   Element _current; |  395   Element _current; | 
|  393  |  396  | 
|  394   _FrozenElementListIterator(this._list); |  397   _FrozenElementListIterator(this._list); | 
|  395  |  398  | 
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  897 $if DART2JS |  900 $if DART2JS | 
|  898   // Optimization to improve performance until the dart2js compiler inlines this |  901   // Optimization to improve performance until the dart2js compiler inlines this | 
|  899   // method. |  902   // method. | 
|  900   static dynamic createElement_tag(String tag) => |  903   static dynamic createElement_tag(String tag) => | 
|  901       JS('Element', 'document.createElement(#)', tag); |  904       JS('Element', 'document.createElement(#)', tag); | 
|  902 $else |  905 $else | 
|  903   static Element createElement_tag(String tag) => |  906   static Element createElement_tag(String tag) => | 
|  904       document.$dom_createElement(tag); |  907       document.$dom_createElement(tag); | 
|  905 $endif |  908 $endif | 
|  906 } |  909 } | 
| OLD | NEW |