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