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

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

Issue 23055008: Making almost all dom_ methods private. Exceptions will be addressed in a later CL. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 _this.insertAllBefore(iterable, item); 87 _this.insertAllBefore(iterable, item);
88 } 88 }
89 89
90 void setAll(int index, Iterable<Node> iterable) { 90 void setAll(int index, Iterable<Node> iterable) {
91 throw new UnsupportedError("Cannot setAll on Node list"); 91 throw new UnsupportedError("Cannot setAll on Node list");
92 } 92 }
93 93
94 Node removeLast() { 94 Node removeLast() {
95 final result = last; 95 final result = last;
96 if (result != null) { 96 if (result != null) {
97 _this.$dom_removeChild(result); 97 _this._removeChild(result);
98 } 98 }
99 return result; 99 return result;
100 } 100 }
101 101
102 Node removeAt(int index) { 102 Node removeAt(int index) {
103 var result = this[index]; 103 var result = this[index];
104 if (result != null) { 104 if (result != null) {
105 _this.$dom_removeChild(result); 105 _this._removeChild(result);
106 } 106 }
107 return result; 107 return result;
108 } 108 }
109 109
110 bool remove(Object object) { 110 bool remove(Object object) {
111 if (object is! Node) return false; 111 if (object is! Node) return false;
112 Node node = object; 112 Node node = object;
113 if (!identical(_this, node.parentNode)) return false; 113 if (!identical(_this, node.parentNode)) return false;
114 _this.$dom_removeChild(node); 114 _this._removeChild(node);
115 return true; 115 return true;
116 } 116 }
117 117
118 void _filter(bool test(Node node), bool removeMatching) { 118 void _filter(bool test(Node node), bool removeMatching) {
119 // This implementation of removeWhere/retainWhere is more efficient 119 // This implementation of removeWhere/retainWhere is more efficient
120 // 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
121 // time. 121 // time.
122 Node child = _this.firstChild; 122 Node child = _this.firstChild;
123 while (child != null) { 123 while (child != null) {
124 Node nextChild = child.nextNode; 124 Node nextChild = child.nextNode;
125 if (test(child) == removeMatching) { 125 if (test(child) == removeMatching) {
126 _this.$dom_removeChild(child); 126 _this._removeChild(child);
127 } 127 }
128 child = nextChild; 128 child = nextChild;
129 } 129 }
130 } 130 }
131 131
132 void removeWhere(bool test(Node node)) { 132 void removeWhere(bool test(Node node)) {
133 _filter(test, true); 133 _filter(test, true);
134 } 134 }
135 135
136 void retainWhere(bool test(Node node)) { 136 void retainWhere(bool test(Node node)) {
137 _filter(test, false); 137 _filter(test, false);
138 } 138 }
139 139
140 void clear() { 140 void clear() {
141 _this.text = ''; 141 _this.text = '';
142 } 142 }
143 143
144 void operator []=(int index, Node value) { 144 void operator []=(int index, Node value) {
145 _this.$dom_replaceChild(value, this[index]); 145 _this._replaceChild(value, this[index]);
146 } 146 }
147 147
148 Iterator<Node> get iterator => _this.$dom_childNodes.iterator; 148 Iterator<Node> get iterator => _this.$dom_childNodes.iterator;
149 149
150 // From List<Node>: 150 // From List<Node>:
151 151
152 // TODO(jacobr): this could be implemented for child node lists. 152 // TODO(jacobr): this could be implemented for child node lists.
153 // The exception we throw here is misleading. 153 // The exception we throw here is misleading.
154 void sort([Comparator<Node> compare]) { 154 void sort([Comparator<Node> compare]) {
155 throw new UnsupportedError("Cannot sort Node list"); 155 throw new UnsupportedError("Cannot sort Node list");
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 217
218 /** 218 /**
219 * Removes this node from the DOM. 219 * Removes this node from the DOM.
220 */ 220 */
221 @DomName('Node.removeChild') 221 @DomName('Node.removeChild')
222 void remove() { 222 void remove() {
223 // TODO(jacobr): should we throw an exception if parent is already null? 223 // TODO(jacobr): should we throw an exception if parent is already null?
224 // TODO(vsm): Use the native remove when available. 224 // TODO(vsm): Use the native remove when available.
225 if (this.parentNode != null) { 225 if (this.parentNode != null) {
226 final Node parent = this.parentNode; 226 final Node parent = this.parentNode;
227 parentNode.$dom_removeChild(this); 227 parentNode._removeChild(this);
228 } 228 }
229 } 229 }
230 230
231 /** 231 /**
232 * Replaces this node with another node. 232 * Replaces this node with another node.
233 */ 233 */
234 @DomName('Node.replaceChild') 234 @DomName('Node.replaceChild')
235 Node replaceWith(Node otherNode) { 235 Node replaceWith(Node otherNode) {
236 try { 236 try {
237 final Node parent = this.parentNode; 237 final Node parent = this.parentNode;
238 parent.$dom_replaceChild(otherNode, this); 238 parent._replaceChild(otherNode, this);
239 } catch (e) { 239 } catch (e) {
240 240
241 }; 241 };
242 return this; 242 return this;
243 } 243 }
244 244
245 /** 245 /**
246 * Inserts all of the nodes into this node directly before refChild. 246 * Inserts all of the nodes into this node directly before refChild.
247 * 247 *
248 * See also: 248 * See also:
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 Map<String, dynamic> get bindings => 312 Map<String, dynamic> get bindings =>
313 TemplateElement.mdvPackage(this).bindings; 313 TemplateElement.mdvPackage(this).bindings;
314 314
315 /** Gets the template instance that instantiated this node, if any. */ 315 /** Gets the template instance that instantiated this node, if any. */
316 @Experimental() 316 @Experimental()
317 TemplateInstance get templateInstance => 317 TemplateInstance get templateInstance =>
318 TemplateElement.mdvPackage(this).templateInstance; 318 TemplateElement.mdvPackage(this).templateInstance;
319 319
320 $!MEMBERS 320 $!MEMBERS
321 } 321 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698