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 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 return last; | 126 return last; |
127 } | 127 } |
128 | 128 |
129 Element last() { | 129 Element last() { |
130 return LevelDom.wrapElement(_element.lastElementChild); | 130 return LevelDom.wrapElement(_element.lastElementChild); |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 class FrozenElementList implements ElementList { | 134 class FrozenElementList implements ElementList { |
135 final _ptr; | 135 final _ptr; |
136 List<Element> _list; | |
137 | 136 |
138 FrozenElementList._wrap(this._ptr); | 137 FrozenElementList._wrap(this._ptr); |
139 | 138 |
140 List<Element> _toList() { | |
141 if (_list == null) { | |
142 _list = new List(_ptr.length); | |
143 for (int i = 0, len = _ptr.length; i < len; i++) { | |
144 _list[i] = LevelDom.wrapElement(_ptr[i]); | |
145 } | |
146 } | |
147 return _list; | |
148 } | |
149 | |
150 Element get first() { | 139 Element get first() { |
151 return this[0]; | 140 return this[0]; |
152 } | 141 } |
153 | 142 |
154 void forEach(void f(Element element)) => _toList().forEach(f); | 143 void forEach(void f(Element element)) { |
| 144 for (Element el in this) { |
| 145 f(el); |
| 146 } |
| 147 } |
155 | 148 |
156 Collection map(f(Element element)) => _toList().map(f); | 149 Collection map(f(Element element)) { |
| 150 var out = []; |
| 151 for (Element el in this) { |
| 152 out.add(f(el)); |
| 153 } |
| 154 return out; |
| 155 } |
157 | 156 |
158 Collection<Element> filter(bool f(Element element)) => _toList().filter(f); | 157 Collection<Element> filter(bool f(Element element)) { |
| 158 var out = []; |
| 159 for (Element el in this) { |
| 160 if (f(el)) out.add(el); |
| 161 } |
| 162 return out; |
| 163 } |
159 | 164 |
160 bool every(bool f(Element element)) { | 165 bool every(bool f(Element element)) { |
161 for(Element element in this) { | 166 for(Element element in this) { |
162 if (!f(element)) { | 167 if (!f(element)) { |
163 return false; | 168 return false; |
164 } | 169 } |
165 }; | 170 }; |
166 return true; | 171 return true; |
167 } | 172 } |
168 | 173 |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 | 766 |
762 ElementEvents get on() { | 767 ElementEvents get on() { |
763 if (_on === null) { | 768 if (_on === null) { |
764 _on = new ElementEventsImplementation._wrap(_ptr); | 769 _on = new ElementEventsImplementation._wrap(_ptr); |
765 } | 770 } |
766 return _on; | 771 return _on; |
767 } | 772 } |
768 | 773 |
769 Element clone(bool deep) => super.clone(deep); | 774 Element clone(bool deep) => super.clone(deep); |
770 } | 775 } |
OLD | NEW |