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

Side by Side Diff: tools/dom/templates/html/impl/impl_Node.darttemplate

Issue 1348173002: Dartium JS Enabled take 2 (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of $LIBRARYNAME; 5 part of $LIBRARYNAME;
6 6
7 /** 7 /**
8 * Lazy implementation of the child nodes of an element that does not request 8 * Lazy implementation of the child nodes of an element that does not request
9 * the actual child nodes of an element until strictly necessary greatly 9 * the actual child nodes of an element until strictly necessary greatly
10 * improving performance for the typical cases where it is not required. 10 * improving performance for the typical cases where it is not required.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 var result = this[index]; 107 var result = this[index];
108 if (result != null) { 108 if (result != null) {
109 _this._removeChild(result); 109 _this._removeChild(result);
110 } 110 }
111 return result; 111 return result;
112 } 112 }
113 113
114 bool remove(Object object) { 114 bool remove(Object object) {
115 if (object is! Node) return false; 115 if (object is! Node) return false;
116 Node node = object; 116 Node node = object;
117 $if JSINTEROP
118 // We aren't preserving identity of nodes in JSINTEROP mode
119 if (_this != node.parentNode) return false;
120 $else
117 if (!identical(_this, node.parentNode)) return false; 121 if (!identical(_this, node.parentNode)) return false;
122 $endif
118 _this._removeChild(node); 123 _this._removeChild(node);
119 return true; 124 return true;
120 } 125 }
121 126
122 void _filter(bool test(Node node), bool removeMatching) { 127 void _filter(bool test(Node node), bool removeMatching) {
123 // This implementation of removeWhere/retainWhere is more efficient 128 // This implementation of removeWhere/retainWhere is more efficient
124 // than the default in ListBase. Child nodes can be removed in constant 129 // than the default in ListBase. Child nodes can be removed in constant
125 // time. 130 // time.
126 Node child = _this.firstChild; 131 Node child = _this.firstChild;
127 while (child != null) { 132 while (child != null) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 176
172 void fillRange(int start, int end, [Node fill]) { 177 void fillRange(int start, int end, [Node fill]) {
173 throw new UnsupportedError("Cannot fillRange on Node list"); 178 throw new UnsupportedError("Cannot fillRange on Node list");
174 } 179 }
175 // -- end List<Node> mixins. 180 // -- end List<Node> mixins.
176 181
177 // TODO(jacobr): benchmark whether this is more efficient or whether caching 182 // TODO(jacobr): benchmark whether this is more efficient or whether caching
178 // a local copy of childNodes is more efficient. 183 // a local copy of childNodes is more efficient.
179 int get length => _this.childNodes.length; 184 int get length => _this.childNodes.length;
180 185
181 void set length(int value) { 186 set length(int value) {
182 throw new UnsupportedError( 187 throw new UnsupportedError(
183 "Cannot set length on immutable List."); 188 "Cannot set length on immutable List.");
184 } 189 }
185 190
186 Node operator[](int index) => _this.childNodes[index]; 191 Node operator[](int index) => _this.childNodes[index];
187 192
188 List<Node> get rawList => _this.childNodes; 193 List<Node> get rawList => _this.childNodes;
189 } 194 }
190 195
191 196
192 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS { 197 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS {
193 198
194 // Custom element created callback. 199 // Custom element created callback.
195 Node._created() : super._created(); 200 Node._created() : super._created();
196 201
197 /** 202 /**
198 * A modifiable list of this node's children. 203 * A modifiable list of this node's children.
199 */ 204 */
200 List<Node> get nodes { 205 List<Node> get nodes {
201 return new _ChildNodeListLazy(this); 206 return new _ChildNodeListLazy(this);
202 } 207 }
203 208
204 void set nodes(Iterable<Node> value) { 209 set nodes(Iterable<Node> value) {
205 // Copy list first since we don't want liveness during iteration. 210 // Copy list first since we don't want liveness during iteration.
206 // TODO(jacobr): there is a better way to do this. 211 // TODO(jacobr): there is a better way to do this.
207 List copy = new List.from(value); 212 List copy = new List.from(value);
208 text = ''; 213 text = '';
209 for (Node node in copy) { 214 for (Node node in copy) {
210 append(node); 215 append(node);
211 } 216 }
212 } 217 }
213 218
214 /** 219 /**
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 } 275 }
271 276
272 /** 277 /**
273 * Print out a String representation of this Node. 278 * Print out a String representation of this Node.
274 */ 279 */
275 String toString() { 280 String toString() {
276 String value = nodeValue; // Fetch DOM Node property once. 281 String value = nodeValue; // Fetch DOM Node property once.
277 return value == null ? super.toString() : value; 282 return value == null ? super.toString() : value;
278 } 283 }
279 284
280 $if JSINTEROP 285 $if DARTIUM
281 List<Node> _childNodes;
282
283 /** 286 /**
284 * A list of this node's children. 287 * A list of this node's children.
285 * 288 *
286 * ## Other resources 289 * ## Other resources
287 * 290 *
288 * * [Node.childNodes] 291 * * [Node.childNodes]
289 * (https://developer.mozilla.org/en-US/docs/Web/API/Node.childNodes) 292 * (https://developer.mozilla.org/en-US/docs/Web/API/Node.childNodes)
290 * from MDN. 293 * from MDN.
291 */ 294 */
292 @DomName('Node.childNodes') 295 @DomName('Node.childNodes')
293 @DocsEditable() 296 @DocsEditable()
294 List<Node> get childNodes { 297 List<Node> get childNodes => wrap_jso(_blink.BlinkNode.instance.childNodes_Get ter_(unwrap_jso(this)));
295 if (_childNodes == null) {
296 List<Node> nodes = new List<Node>();
297 var jsCollection = _blink.BlinkNode.instance.childNodes_Getter_(unwrap_js o(this));
298 var collectionLen = jsCollection['length'];
299 for (var i = 0; i < collectionLen; i++) {
300 nodes.add(wrap_jso(jsCollection.callMethod('item', [i])));
301 }
302 _childNodes = nodes;
303 }
304 return _childNodes;
305 }
306 $else 298 $else
307 $if DARTIUM
308 /** 299 /**
309 * A list of this node's children. 300 * A list of this node's children.
310 * 301 *
311 * ## Other resources
312 *
313 * * [Node.childNodes]
314 * (https://developer.mozilla.org/en-US/docs/Web/API/Node.childNodes)
315 * from MDN.
316 */
317 @DomName('Node.childNodes')
318 @DocsEditable()
319 List<Node> get childNodes => _blink.BlinkNode.instance.childNodes_Getter_(this );
320 $else
321 /**
322 * A list of this node's children.
323 *
324 * ## Other resources 302 * ## Other resources
325 * 303 *
326 * * [Node.childNodes] 304 * * [Node.childNodes]
327 * (https://developer.mozilla.org/en-US/docs/Web/API/Node.childNodes) 305 * (https://developer.mozilla.org/en-US/docs/Web/API/Node.childNodes)
328 * from MDN. 306 * from MDN.
329 */ 307 */
330 @DomName('Node.childNodes') 308 @DomName('Node.childNodes')
331 @DocsEditable() 309 @DocsEditable()
332 @Returns('NodeList')
333 @Creates('NodeList')
334 final List<Node> childNodes; 310 final List<Node> childNodes;
335 311
336 $endif
337 $endif 312 $endif
338 $!MEMBERS 313 $!MEMBERS
339 } 314 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698