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

Side by Side Diff: lib/html/templates/html/impl/impl_DocumentFragment.darttemplate

Issue 10979063: Removing ElementList. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Syncing. Created 8 years, 2 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) 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 FilteredElementList implements ElementList { 5 class _FilteredElementList implements List {
6 final Node _node; 6 final Node _node;
7 final NodeList _childNodes; 7 final NodeList _childNodes;
8 8
9 FilteredElementList(Node node): _childNodes = node.nodes, _node = node; 9 _FilteredElementList(Node node): _childNodes = node.nodes, _node = node;
10 10
11 // We can't memoize this, since it's possible that children will be messed 11 // We can't memoize this, since it's possible that children will be messed
12 // with externally to this class. 12 // with externally to this class.
13 // 13 //
14 // TODO(nweiz): Do we really need to copy the list to make the types work out? 14 // TODO(nweiz): Do we really need to copy the list to make the types work out?
15 List<Element> get _filtered => 15 List<Element> get _filtered =>
16 new List.from(_childNodes.filter((n) => n is Element)); 16 new List.from(_childNodes.filter((n) => n is Element));
17 17
18 // Don't use _filtered.first so we can short-circuit once we find an element.
19 Element get first {
20 for (final node in _childNodes) {
21 if (node is Element) {
22 return node;
23 }
24 }
25 return null;
26 }
27
28 void forEach(void f(Element element)) { 18 void forEach(void f(Element element)) {
29 _filtered.forEach(f); 19 _filtered.forEach(f);
30 } 20 }
31 21
32 void operator []=(int index, Element value) { 22 void operator []=(int index, Element value) {
33 this[index].replaceWith(value); 23 this[index].replaceWith(value);
34 } 24 }
35 25
36 void set length(int newLength) { 26 void set length(int newLength) {
37 final len = this.length; 27 final len = this.length;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 void _write(Set s) { 118 void _write(Set s) {
129 throw const UnsupportedOperationException( 119 throw const UnsupportedOperationException(
130 'frozen class set cannot be modified'); 120 'frozen class set cannot be modified');
131 } 121 }
132 Set<String> _read() => new Set<String>(); 122 Set<String> _read() => new Set<String>();
133 123
134 bool get frozen => true; 124 bool get frozen => true;
135 } 125 }
136 126
137 class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { 127 class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
138 ElementList _elements; 128 List<Element> _elements;
139 129
140 ElementList get elements { 130 List<Element> get elements {
141 if (_elements == null) { 131 if (_elements == null) {
142 _elements = new FilteredElementList(this); 132 _elements = new _FilteredElementList(this);
143 } 133 }
144 return _elements; 134 return _elements;
145 } 135 }
146 136
147 // TODO: The type of value should be Collection<Element>. See http://b/5392897 137 // TODO: The type of value should be Collection<Element>. See http://b/5392897
148 void set elements(value) { 138 void set elements(value) {
149 // Copy list first since we don't want liveness during iteration. 139 // Copy list first since we don't want liveness during iteration.
150 List copy = new List.from(value); 140 List copy = new List.from(value);
151 final elements = this.elements; 141 final elements = this.elements;
152 elements.clear(); 142 elements.clear();
(...skipping 24 matching lines...) Expand all
177 // Copy list first since we don't want liveness during iteration. 167 // Copy list first since we don't want liveness during iteration.
178 List nodes = new List.from(e.nodes); 168 List nodes = new List.from(e.nodes);
179 this.nodes.addAll(nodes); 169 this.nodes.addAll(nodes);
180 } 170 }
181 171
182 Node _insertAdjacentNode(String where, Node node) { 172 Node _insertAdjacentNode(String where, Node node) {
183 switch (where.toLowerCase()) { 173 switch (where.toLowerCase()) {
184 case "beforebegin": return null; 174 case "beforebegin": return null;
185 case "afterend": return null; 175 case "afterend": return null;
186 case "afterbegin": 176 case "afterbegin":
187 this.insertBefore(node, this.nodes.first); 177 var first = this.nodes.length > 0 ? this.nodes[0] : null;
178 this.insertBefore(node, first);
188 return node; 179 return node;
189 case "beforeend": 180 case "beforeend":
190 this.nodes.add(node); 181 this.nodes.add(node);
191 return node; 182 return node;
192 default: 183 default:
193 throw new ArgumentError("Invalid position ${where}"); 184 throw new ArgumentError("Invalid position ${where}");
194 } 185 }
195 } 186 }
196 187
197 Element insertAdjacentElement(String where, Element element) 188 Element insertAdjacentElement(String where, Element element)
(...skipping 28 matching lines...) Expand all
226 bool get draggable => false; 217 bool get draggable => false;
227 bool get hidden => false; 218 bool get hidden => false;
228 bool get spellcheck => false; 219 bool get spellcheck => false;
229 bool get translate => false; 220 bool get translate => false;
230 int get tabIndex => -1; 221 int get tabIndex => -1;
231 String get id => ""; 222 String get id => "";
232 String get title => ""; 223 String get title => "";
233 String get tagName => ""; 224 String get tagName => "";
234 String get webkitdropzone => ""; 225 String get webkitdropzone => "";
235 String get webkitRegionOverflow => ""; 226 String get webkitRegionOverflow => "";
236 Element get $m_firstElementChild() => elements.first(); 227 Element get $m_firstElementChild {
228 if (elements.length > 0) {
229 return elements[0];
230 }
231 return null;
232 }
237 Element get $m_lastElementChild() => elements.last(); 233 Element get $m_lastElementChild() => elements.last();
238 Element get nextElementSibling => null; 234 Element get nextElementSibling => null;
239 Element get previousElementSibling => null; 235 Element get previousElementSibling => null;
240 Element get offsetParent => null; 236 Element get offsetParent => null;
241 Element get parent => null; 237 Element get parent => null;
242 Map<String, String> get attributes => const {}; 238 Map<String, String> get attributes => const {};
243 CSSClassSet get classes => new _FrozenCSSClassSet(); 239 CSSClassSet get classes => new _FrozenCSSClassSet();
244 Map<String, String> get dataAttributes => const {}; 240 Map<String, String> get dataAttributes => const {};
245 CSSStyleDeclaration get style => new Element.tag('div').style; 241 CSSStyleDeclaration get style => new Element.tag('div').style;
246 Future<CSSStyleDeclaration> get computedStyle => 242 Future<CSSStyleDeclaration> get computedStyle =>
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 "WebKit drop zone can't be set for document fragments."); 348 "WebKit drop zone can't be set for document fragments.");
353 } 349 }
354 350
355 void set webkitRegionOverflow(String value) { 351 void set webkitRegionOverflow(String value) {
356 throw new UnsupportedOperationException( 352 throw new UnsupportedOperationException(
357 "WebKit region overflow can't be set for document fragments."); 353 "WebKit region overflow can't be set for document fragments.");
358 } 354 }
359 355
360 $!MEMBERS 356 $!MEMBERS
361 } 357 }
OLDNEW
« no previous file with comments | « lib/html/templates/html/dartium/html_dartium.darttemplate ('k') | lib/html/templates/html/impl/impl_Element.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698