Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: client/html/src/NodeWrappingImplementation.dart

Issue 9207020: Add tests for Element#elements. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « client/html/src/Lists.dart ('k') | client/html/src/_Lists.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 class _ChildrenNodeList implements NodeList { 5 class _ChildrenNodeList implements NodeList {
6 // Raw node. 6 // Raw node.
7 final _node; 7 final _node;
8 final _childNodes; 8 final _childNodes;
9 9
10 _ChildrenNodeList._wrap(var node) 10 _ChildrenNodeList._wrap(var node)
11 : _childNodes = node.childNodes, 11 : _childNodes = node.childNodes,
12 _node = node; 12 _node = node;
13 13
14 List<Node> _toList() { 14 List<Node> _toList() {
15 final output = new List(_childNodes.length); 15 final output = new List(_childNodes.length);
16 for (int i = 0, len = _childNodes.length; i < len; i++) { 16 for (int i = 0, len = _childNodes.length; i < len; i++) {
17 output[i] = LevelDom.wrapNode(_childNodes[i]); 17 output[i] = LevelDom.wrapNode(_childNodes[i]);
18 } 18 }
19 return output; 19 return output;
20 } 20 }
21 21
22 Node get first() { 22 Node get first() {
23 return LevelDom.wrapNode(_node.firstChild); 23 return LevelDom.wrapNode(_node.firstChild);
24 } 24 }
25 25
26 void forEach(void f(Node element)) => _toList().forEach(f); 26 void forEach(void f(Node element)) => _toList().forEach(f);
27 27
28 Collection map(f(Node element)) { 28 Collection map(f(Node element)) => _toList().map(f);
29 List output = new List();
30 forEach((Node element) {
31 output.add(f(element));
32 });
33 return output;
34 }
35 29
36 Collection<Node> filter(bool f(Node element)) { 30 Collection<Node> filter(bool f(Node element)) => _toList().filter(f);
37 List<Node> output = new List<Node>();
38 forEach((Node element) {
39 if (f(element)) {
40 output.add(element);
41 }
42 });
43 return output;
44 }
45 31
46 bool every(bool f(Node element)) { 32 bool every(bool f(Node element)) {
47 for(Node element in this) { 33 for(Node element in this) {
48 if (!f(element)) { 34 if (!f(element)) {
49 return false; 35 return false;
50 } 36 }
51 }; 37 };
52 return true; 38 return true;
53 } 39 }
54 40
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 90 }
105 91
106 void sort(int compare(Node a, Node b)) { 92 void sort(int compare(Node a, Node b)) {
107 throw const UnsupportedOperationException('TODO(jacobr): should we impl?'); 93 throw const UnsupportedOperationException('TODO(jacobr): should we impl?');
108 } 94 }
109 95
110 void copyFrom(List<Object> src, int srcStart, int dstStart, int count) { 96 void copyFrom(List<Object> src, int srcStart, int dstStart, int count) {
111 throw 'Not impl yet. todo(jacobr)'; 97 throw 'Not impl yet. todo(jacobr)';
112 } 98 }
113 99
114 void setRange(int start, int length, List from, [int startFrom = 0]) { 100 void setRange(int start, int length, List from, [int startFrom = 0]) =>
115 // TODO(nweiz): remove these IndexOutOfRange checks once Frog has bounds 101 Lists.setRange(this, start, length, from, startFrom);
116 // checking for List indexing
117 if (start < 0) {
118 throw new IndexOutOfRangeException(start);
119 } else if (startFrom < 0) {
120 throw new IndexOutOfRangeException(startFrom);
121 } else if (length < 0) {
122 throw new IllegalArgumentException("negative length $length");
123 } else if (start + length > this.length) {
124 throw new IndexOutOfRangeException(Math.min(this.length, start));
125 } else if (startFrom + length > from.length) {
126 throw new IndexOutOfRangeException(Math.min(from.length, startFrom));
127 }
128 102
129 for (var i = 0; i < length; i++) { 103 void removeRange(int start, int length) =>
130 this[start + i] = from[startFrom + i]; 104 Lists.removeRange(this, start, length, (i) => this[i].remove());
131 }
132 }
133
134 void removeRange(int start, int length) {
135 // TODO(nweiz): remove these IndexOutOfRange checks once Frog has bounds
136 // checking for List indexing
137 if (start < 0) {
138 throw new IndexOutOfRangeException(start);
139 } else if (length < 0) {
140 throw new IllegalArgumentException("negative length $length");
141 } else if (start + length > this.length) {
142 throw new IndexOutOfRangeException(Math.min(this.length, start));
143 }
144
145 for (var i = 0; i < length; i++) {
146 this[start].remove();
147 }
148 }
149 105
150 void insertRange(int start, int length, [initialValue = null]) { 106 void insertRange(int start, int length, [initialValue = null]) {
151 throw const NotImplementedException(); 107 throw const NotImplementedException();
152 } 108 }
153 109
154 List getRange(int start, int length) { 110 List getRange(int start, int length) => Lists.getRange(this, start, length);
155 // TODO(nweiz): remove these IndexOutOfRange checks once Frog has bounds
156 // checking for List indexing
157 if (start < 0) {
158 throw new IndexOutOfRangeException(start);
159 } else if (length < 0) {
160 throw new IllegalArgumentException("negative length $length");
161 } else if (start + length > this.length) {
162 throw new IndexOutOfRangeException(Math.min(this.length, start));
163 }
164
165 var nodes = <Node>[];
166 for (var i = 0; i < length; i++) {
167 nodes.add(this[start + i]);
168 }
169 return nodes;
170 }
171 111
172 int indexOf(Node element, [int start = 0]) { 112 int indexOf(Node element, [int start = 0]) {
173 return _Lists.indexOf(this, element, start, this.length); 113 return Lists.indexOf(this, element, start, this.length);
174 } 114 }
175 115
176 int lastIndexOf(Node element, [int start = null]) { 116 int lastIndexOf(Node element, [int start = null]) {
177 if (start === null) start = length - 1; 117 if (start === null) start = length - 1;
178 return _Lists.lastIndexOf(this, element, start); 118 return Lists.lastIndexOf(this, element, start);
179 } 119 }
180 120
181 void clear() { 121 void clear() {
182 _node.textContent = ''; 122 _node.textContent = '';
183 } 123 }
184 124
185 Node removeLast() { 125 Node removeLast() {
186 final last = this.last(); 126 final last = this.last();
187 if (last != null) { 127 if (last != null) {
188 _node.removeChild(LevelDom.unwrap(last)); 128 _node.removeChild(LevelDom.unwrap(last));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 // array. 198 // array.
259 Node insertBefore(Node newChild, Node refChild) { 199 Node insertBefore(Node newChild, Node refChild) {
260 return LevelDom.wrapNode(_ptr.insertBefore( 200 return LevelDom.wrapNode(_ptr.insertBefore(
261 LevelDom.unwrap(newChild), LevelDom.unwrap(refChild))); 201 LevelDom.unwrap(newChild), LevelDom.unwrap(refChild)));
262 } 202 }
263 203
264 Node clone(bool deep) { 204 Node clone(bool deep) {
265 return LevelDom.wrapNode(_ptr.cloneNode(deep)); 205 return LevelDom.wrapNode(_ptr.cloneNode(deep));
266 } 206 }
267 } 207 }
OLDNEW
« no previous file with comments | « client/html/src/Lists.dart ('k') | client/html/src/_Lists.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698