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

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

Issue 17909002: Exposing Node.firstChild and Node.lastChild. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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 | « tools/dom/src/TemplateBindings.dart ('k') | no next file » | 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) 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 16 matching lines...) Expand all
27 return result; 27 return result;
28 } 28 }
29 Node get single { 29 Node get single {
30 int l = this.length; 30 int l = this.length;
31 if (l == 0) throw new StateError("No elements"); 31 if (l == 0) throw new StateError("No elements");
32 if (l > 1) throw new StateError("More than one element"); 32 if (l > 1) throw new StateError("More than one element");
33 return JS('Node|Null', '#.firstChild', _this); 33 return JS('Node|Null', '#.firstChild', _this);
34 } 34 }
35 $else 35 $else
36 Node get first { 36 Node get first {
37 Node result = _this.$dom_firstChild; 37 Node result = _this.firstChild;
38 if (result == null) throw new StateError("No elements"); 38 if (result == null) throw new StateError("No elements");
39 return result; 39 return result;
40 } 40 }
41 Node get last { 41 Node get last {
42 Node result = _this.$dom_lastChild; 42 Node result = _this.lastChild;
43 if (result == null) throw new StateError("No elements"); 43 if (result == null) throw new StateError("No elements");
44 return result; 44 return result;
45 } 45 }
46 Node get single { 46 Node get single {
47 int l = this.length; 47 int l = this.length;
48 if (l == 0) throw new StateError("No elements"); 48 if (l == 0) throw new StateError("No elements");
49 if (l > 1) throw new StateError("More than one element"); 49 if (l > 1) throw new StateError("More than one element");
50 return _this.$dom_firstChild; 50 return _this.firstChild;
51 } 51 }
52 $endif 52 $endif
53 53
54 void add(Node value) { 54 void add(Node value) {
55 _this.append(value); 55 _this.append(value);
56 } 56 }
57 57
58 void addAll(Iterable<Node> iterable) { 58 void addAll(Iterable<Node> iterable) {
59 if (iterable is _ChildNodeListLazy) { 59 if (iterable is _ChildNodeListLazy) {
60 _ChildNodeListLazy otherList = iterable; 60 _ChildNodeListLazy otherList = iterable;
61 if (!identical(otherList._this, _this)) { 61 if (!identical(otherList._this, _this)) {
62 // Optimized route for copying between nodes. 62 // Optimized route for copying between nodes.
63 for (var i = 0, len = otherList.length; i < len; ++i) { 63 for (var i = 0, len = otherList.length; i < len; ++i) {
64 // Should use $dom_firstChild, Bug 8886. 64 _this.append(otherList._this.firstChild);
65 _this.append(otherList[0]);
66 } 65 }
67 } 66 }
68 return; 67 return;
69 } 68 }
70 for (Node node in iterable) { 69 for (Node node in iterable) {
71 _this.append(node); 70 _this.append(node);
72 } 71 }
73 } 72 }
74 73
75 void insert(int index, Node node) { 74 void insert(int index, Node node) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 Node node = object; 112 Node node = object;
114 if (!identical(_this, node.parentNode)) return false; 113 if (!identical(_this, node.parentNode)) return false;
115 _this.$dom_removeChild(node); 114 _this.$dom_removeChild(node);
116 return true; 115 return true;
117 } 116 }
118 117
119 void _filter(bool test(Node node), bool removeMatching) { 118 void _filter(bool test(Node node), bool removeMatching) {
120 // This implementation of removeWhere/retainWhere is more efficient 119 // This implementation of removeWhere/retainWhere is more efficient
121 // than the default in ListBase. Child nodes can be removed in constant 120 // than the default in ListBase. Child nodes can be removed in constant
122 // time. 121 // time.
123 Node child = _this.$dom_firstChild; 122 Node child = _this.firstChild;
124 while (child != null) { 123 while (child != null) {
125 Node nextChild = child.nextNode; 124 Node nextChild = child.nextNode;
126 if (test(child) == removeMatching) { 125 if (test(child) == removeMatching) {
127 _this.$dom_removeChild(child); 126 _this.$dom_removeChild(child);
128 } 127 }
129 child = nextChild; 128 child = nextChild;
130 } 129 }
131 } 130 }
132 131
133 void removeWhere(bool test(Node node)) { 132 void removeWhere(bool test(Node node)) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 */ 229 */
231 Node insertAllBefore(Iterable<Node> newNodes, Node refChild) { 230 Node insertAllBefore(Iterable<Node> newNodes, Node refChild) {
232 if (newNodes is _ChildNodeListLazy) { 231 if (newNodes is _ChildNodeListLazy) {
233 _ChildNodeListLazy otherList = newNodes; 232 _ChildNodeListLazy otherList = newNodes;
234 if (identical(otherList._this, this)) { 233 if (identical(otherList._this, this)) {
235 throw new ArgumentError(newNodes); 234 throw new ArgumentError(newNodes);
236 } 235 }
237 236
238 // Optimized route for copying between nodes. 237 // Optimized route for copying between nodes.
239 for (var i = 0, len = otherList.length; i < len; ++i) { 238 for (var i = 0, len = otherList.length; i < len; ++i) {
240 // Should use $dom_firstChild, Bug 8886. 239 this.insertBefore(otherList._this.firstChild, refChild);
241 this.insertBefore(otherList[0], refChild);
242 } 240 }
243 } else { 241 } else {
244 for (var node in newNodes) { 242 for (var node in newNodes) {
245 this.insertBefore(node, refChild); 243 this.insertBefore(node, refChild);
246 } 244 }
247 } 245 }
248 } 246 }
249 247
250 /** 248 /**
251 * Print out a String representation of this Node. 249 * Print out a String representation of this Node.
(...skipping 22 matching lines...) Expand all
274 TemplateInstance _templateInstance; 272 TemplateInstance _templateInstance;
275 273
276 /** Gets the template instance that instantiated this node, if any. */ 274 /** Gets the template instance that instantiated this node, if any. */
277 @Experimental 275 @Experimental
278 TemplateInstance get templateInstance => 276 TemplateInstance get templateInstance =>
279 _templateInstance != null ? _templateInstance : 277 _templateInstance != null ? _templateInstance :
280 (parent != null ? parent.templateInstance : null); 278 (parent != null ? parent.templateInstance : null);
281 279
282 $!MEMBERS 280 $!MEMBERS
283 } 281 }
OLDNEW
« no previous file with comments | « tools/dom/src/TemplateBindings.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698