OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // TODO(jacobr): use Lists.dart to remove some of the duplicated functionality. | 5 // TODO(jacobr): use Lists.dart to remove some of the duplicated functionality. |
6 class _ChildrenElementList implements ElementList { | 6 class _ChildrenElementList implements ElementList { |
7 // Raw Element. | 7 // Raw Element. |
8 final _element; | 8 final _element; |
9 final _childElements; | 9 final _childElements; |
10 | 10 |
11 _ChildrenElementList._wrap(var element) | 11 _ChildrenElementList._wrap(var element) |
12 : _childElements = element.children, | 12 : _childElements = element.children, |
13 _element = element; | 13 _element = element; |
14 | 14 |
15 List<Element> _toList() { | 15 List<Element> _toList() { |
16 final output = new List(_childElements.length); | 16 final output = new List(_childElements.length); |
17 for (int i = 0, len = _childElements.length; i < len; i++) { | 17 for (int i = 0, len = _childElements.length; i < len; i++) { |
18 output[i] = LevelDom.wrapElement(_childElements[i]); | 18 output[i] = LevelDom.wrapElement(_childElements[i]); |
19 } | 19 } |
20 return output; | 20 return output; |
21 } | 21 } |
22 | 22 |
23 Element get first() { | 23 Element get first() { |
24 return LevelDom.wrapElement(_element.firstElementChild); | 24 return LevelDom.wrapElement(_element.firstElementChild); |
25 } | 25 } |
26 | 26 |
27 void forEach(void f(Element element)) { | 27 void forEach(void f(Element element)) => _toList().forEach(f); |
28 for (var element in _childElements) { | |
29 f(LevelDom.wrapElement(element)); | |
30 } | |
31 } | |
32 | 28 |
33 Collection map(f(Element element)) { | 29 Collection map(f(Element element)) => _toList().map(f); |
34 List output = new List(); | |
35 forEach((Element element) { | |
36 output.add(f(element)); | |
37 }); | |
38 return output; | |
39 } | |
40 | 30 |
41 Collection<Element> filter(bool f(Element element)) { | 31 Collection<Element> filter(bool f(Element element)) => _toList().filter(f); |
42 List<Element> output = new List<Element>(); | |
43 forEach((Element element) { | |
44 if (f(element)) { | |
45 output.add(element); | |
46 } | |
47 }); | |
48 return output; | |
49 } | |
50 | 32 |
51 bool every(bool f(Element element)) { | 33 bool every(bool f(Element element)) { |
52 for(Element element in this) { | 34 for(Element element in this) { |
53 if (!f(element)) { | 35 if (!f(element)) { |
54 return false; | 36 return false; |
55 } | 37 } |
56 }; | 38 }; |
57 return true; | 39 return true; |
58 } | 40 } |
59 | 41 |
60 bool some(bool f(Element element)) { | 42 bool some(bool f(Element element)) { |
61 for(Element element in this) { | 43 for(Element element in this) { |
62 if (f(element)) { | 44 if (f(element)) { |
63 return true; | 45 return true; |
64 } | 46 } |
65 }; | 47 }; |
66 return false; | 48 return false; |
67 } | 49 } |
68 | 50 |
69 bool isEmpty() { | 51 bool isEmpty() { |
70 return _element.firstElementChild !== null; | 52 return _element.firstElementChild === null; |
71 } | 53 } |
72 | 54 |
73 int get length() { | 55 int get length() { |
74 return _childElements.length; | 56 return _childElements.length; |
75 } | 57 } |
76 | 58 |
77 Element operator [](int index) { | 59 Element operator [](int index) { |
78 return LevelDom.wrapElement(_childElements[index]); | 60 return LevelDom.wrapElement(_childElements[index]); |
79 } | 61 } |
80 | 62 |
(...skipping 22 matching lines...) Expand all Loading... |
103 } | 85 } |
104 | 86 |
105 void sort(int compare(Element a, Element b)) { | 87 void sort(int compare(Element a, Element b)) { |
106 throw const UnsupportedOperationException('TODO(jacobr): should we impl?'); | 88 throw const UnsupportedOperationException('TODO(jacobr): should we impl?'); |
107 } | 89 } |
108 | 90 |
109 void copyFrom(List<Object> src, int srcStart, int dstStart, int count) { | 91 void copyFrom(List<Object> src, int srcStart, int dstStart, int count) { |
110 throw 'Not impl yet. todo(jacobr)'; | 92 throw 'Not impl yet. todo(jacobr)'; |
111 } | 93 } |
112 | 94 |
113 void setRange(int start, int length, List from, [int startFrom = 0]) { | 95 void setRange(int start, int length, List from, [int startFrom = 0]) => |
114 throw const NotImplementedException(); | 96 Lists.setRange(this, start, length, from, startFrom); |
115 } | |
116 | 97 |
117 void removeRange(int start, int length) { | 98 void removeRange(int start, int length) => |
118 throw const NotImplementedException(); | 99 Lists.removeRange(this, start, length, (i) => this[i].remove()); |
119 } | |
120 | 100 |
121 void insertRange(int start, int length, [initialValue = null]) { | 101 void insertRange(int start, int length, [initialValue = null]) { |
122 throw const NotImplementedException(); | 102 throw const NotImplementedException(); |
123 } | 103 } |
124 | 104 |
125 List getRange(int start, int length) { | 105 List getRange(int start, int length) => Lists.getRange(this, start, length); |
126 throw const NotImplementedException(); | |
127 } | |
128 | 106 |
129 int indexOf(Element element, [int start = 0]) { | 107 int indexOf(Element element, [int start = 0]) { |
130 return _Lists.indexOf(this, element, start, this.length); | 108 return Lists.indexOf(this, element, start, this.length); |
131 } | 109 } |
132 | 110 |
133 int lastIndexOf(Element element, [int start = null]) { | 111 int lastIndexOf(Element element, [int start = null]) { |
134 if (start === null) start = length - 1; | 112 if (start === null) start = length - 1; |
135 return _Lists.lastIndexOf(this, element, start); | 113 return Lists.lastIndexOf(this, element, start); |
136 } | 114 } |
137 | 115 |
138 void clear() { | 116 void clear() { |
139 // It is unclear if we want to keep non element nodes? | 117 // It is unclear if we want to keep non element nodes? |
140 _element.textContent = ''; | 118 _element.textContent = ''; |
141 } | 119 } |
142 | 120 |
143 Element removeLast() { | 121 Element removeLast() { |
144 final last = this.last(); | 122 final last = this.last(); |
145 if (last != null) { | 123 if (last != null) { |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 | 754 |
777 ElementEvents get on() { | 755 ElementEvents get on() { |
778 if (_on === null) { | 756 if (_on === null) { |
779 _on = new ElementEventsImplementation._wrap(_ptr); | 757 _on = new ElementEventsImplementation._wrap(_ptr); |
780 } | 758 } |
781 return _on; | 759 return _on; |
782 } | 760 } |
783 | 761 |
784 Element clone(bool deep) => super.clone(deep); | 762 Element clone(bool deep) => super.clone(deep); |
785 } | 763 } |
OLD | NEW |