| OLD | NEW |
| 1 /// A simple tree API that results from parsing html. Intended to be compatible | 1 /// A simple tree API that results from parsing html. Intended to be compatible |
| 2 /// with dart:html, but it is missing many types and APIs. | 2 /// with dart:html, but it is missing many types and APIs. |
| 3 library dom; | 3 library dom; |
| 4 | 4 |
| 5 // TODO(jmesserly): lots to do here. Originally I wanted to generate this using | 5 // TODO(jmesserly): lots to do here. Originally I wanted to generate this using |
| 6 // our Blink IDL generator, but another idea is to directly use the excellent | 6 // our Blink IDL generator, but another idea is to directly use the excellent |
| 7 // http://dom.spec.whatwg.org/ and http://html.spec.whatwg.org/ and just | 7 // http://dom.spec.whatwg.org/ and http://html.spec.whatwg.org/ and just |
| 8 // implement that. | 8 // implement that. |
| 9 | 9 |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 return result; | 802 return result; |
| 803 } | 803 } |
| 804 } | 804 } |
| 805 | 805 |
| 806 /// An indexable collection of a node's descendants in the document tree, | 806 /// An indexable collection of a node's descendants in the document tree, |
| 807 /// filtered so that only elements are in the collection. | 807 /// filtered so that only elements are in the collection. |
| 808 // TODO(jmesserly): this was copied from dart:html | 808 // TODO(jmesserly): this was copied from dart:html |
| 809 // TODO(jmesserly): "implements List<Element>" is a workaround for analyzer bug. | 809 // TODO(jmesserly): "implements List<Element>" is a workaround for analyzer bug. |
| 810 class FilteredElementList extends IterableBase<Element> with ListMixin<Element> | 810 class FilteredElementList extends IterableBase<Element> with ListMixin<Element> |
| 811 implements List<Element> { | 811 implements List<Element> { |
| 812 final Node _node; | |
| 813 final List<Node> _childNodes; | 812 final List<Node> _childNodes; |
| 814 | 813 |
| 815 /// Creates a collection of the elements that descend from a node. | 814 /// Creates a collection of the elements that descend from a node. |
| 816 /// | 815 /// |
| 817 /// Example usage: | 816 /// Example usage: |
| 818 /// | 817 /// |
| 819 /// var filteredElements = new FilteredElementList(query("#container")); | 818 /// var filteredElements = new FilteredElementList(query("#container")); |
| 820 /// // filteredElements is [a, b, c]. | 819 /// // filteredElements is [a, b, c]. |
| 821 FilteredElementList(Node node) | 820 FilteredElementList(Node node) |
| 822 : _childNodes = node.nodes, | 821 : _childNodes = node.nodes; |
| 823 _node = node; | 822 |
| 824 | 823 |
| 825 // We can't memoize this, since it's possible that children will be messed | 824 // We can't memoize this, since it's possible that children will be messed |
| 826 // with externally to this class. | 825 // with externally to this class. |
| 827 // | 826 // |
| 828 // TODO(nweiz): we don't always need to create a new list. For example | 827 // TODO(nweiz): we don't always need to create a new list. For example |
| 829 // forEach, every, any, ... could directly work on the _childNodes. | 828 // forEach, every, any, ... could directly work on the _childNodes. |
| 830 List<Element> get _filtered => | 829 List<Element> get _filtered => |
| 831 new List<Element>.from(_childNodes.where((n) => n is Element)); | 830 new List<Element>.from(_childNodes.where((n) => n is Element)); |
| 832 | 831 |
| 833 void forEach(void f(Element element)) { | 832 void forEach(void f(Element element)) { |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 | 1000 |
| 1002 class _ConcatTextVisitor extends TreeVisitor { | 1001 class _ConcatTextVisitor extends TreeVisitor { |
| 1003 final _str = new StringBuffer(); | 1002 final _str = new StringBuffer(); |
| 1004 | 1003 |
| 1005 String toString() => _str.toString(); | 1004 String toString() => _str.toString(); |
| 1006 | 1005 |
| 1007 visitText(Text node) { | 1006 visitText(Text node) { |
| 1008 _str.write(node.data); | 1007 _str.write(node.data); |
| 1009 } | 1008 } |
| 1010 } | 1009 } |
| OLD | NEW |