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

Side by Side Diff: lib/html/src/DocumentFragmentWrappingImplementation.dart

Issue 10919146: Get rid of a lot of () for getters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 | 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 ElementList {
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. 18 // Don't use _filtered.first so we can short-circuit once we find an element.
19 Element get first() { 19 Element get first {
20 for (var node in _childNodes) { 20 for (var node in _childNodes) {
21 if (node is Element) { 21 if (node is Element) {
22 return node; 22 return node;
23 } 23 }
24 } 24 }
25 return null; 25 return null;
26 } 26 }
27 27
28 void forEach(void f(Element element)) { 28 void forEach(void f(Element element)) {
29 _filtered.forEach(f); 29 _filtered.forEach(f);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 last.remove(); 84 last.remove();
85 } 85 }
86 return last; 86 return last;
87 } 87 }
88 88
89 Collection map(f(Element element)) => _filtered.map(f); 89 Collection map(f(Element element)) => _filtered.map(f);
90 Collection<Element> filter(bool f(Element element)) => _filtered.filter(f); 90 Collection<Element> filter(bool f(Element element)) => _filtered.filter(f);
91 bool every(bool f(Element element)) => _filtered.every(f); 91 bool every(bool f(Element element)) => _filtered.every(f);
92 bool some(bool f(Element element)) => _filtered.some(f); 92 bool some(bool f(Element element)) => _filtered.some(f);
93 bool isEmpty() => _filtered.isEmpty(); 93 bool isEmpty() => _filtered.isEmpty();
94 int get length() => _filtered.length; 94 int get length => _filtered.length;
95 Element operator [](int index) => _filtered[index]; 95 Element operator [](int index) => _filtered[index];
96 Iterator<Element> iterator() => _filtered.iterator(); 96 Iterator<Element> iterator() => _filtered.iterator();
97 List<Element> getRange(int start, int length) => 97 List<Element> getRange(int start, int length) =>
98 _filtered.getRange(start, length); 98 _filtered.getRange(start, length);
99 int indexOf(Element element, [int start = 0]) => 99 int indexOf(Element element, [int start = 0]) =>
100 _filtered.indexOf(element, start); 100 _filtered.indexOf(element, start);
101 101
102 int lastIndexOf(Element element, [int start = null]) { 102 int lastIndexOf(Element element, [int start = null]) {
103 if (start === null) start = length - 1; 103 if (start === null) start = length - 1;
104 return _filtered.lastIndexOf(element, start); 104 return _filtered.lastIndexOf(element, start);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 var fragment = new DocumentFragment(); 175 var fragment = new DocumentFragment();
176 var e = new SVGSVGElement(); 176 var e = new SVGSVGElement();
177 e.innerHTML = svg; 177 e.innerHTML = svg;
178 178
179 // Copy list first since we don't want liveness during iteration. 179 // Copy list first since we don't want liveness during iteration.
180 List nodes = new List.from(e.nodes); 180 List nodes = new List.from(e.nodes);
181 fragment.nodes.addAll(nodes); 181 fragment.nodes.addAll(nodes);
182 return fragment; 182 return fragment;
183 } 183 }
184 184
185 ElementList get elements() { 185 ElementList get elements {
186 if (_elements == null) { 186 if (_elements == null) {
187 _elements = new FilteredElementList(this); 187 _elements = new FilteredElementList(this);
188 } 188 }
189 return _elements; 189 return _elements;
190 } 190 }
191 191
192 void set elements(Collection<Element> value) { 192 void set elements(Collection<Element> value) {
193 // Copy list first since we don't want liveness during iteration. 193 // Copy list first since we don't want liveness during iteration.
194 List copy = new List.from(value); 194 List copy = new List.from(value);
195 final elements = this.elements; 195 final elements = this.elements;
196 elements.clear(); 196 elements.clear();
197 elements.addAll(copy); 197 elements.addAll(copy);
198 } 198 }
199 199
200 String get innerHTML() { 200 String get innerHTML {
201 var e = new Element.tag("div"); 201 var e = new Element.tag("div");
202 e.nodes.add(this.clone(true)); 202 e.nodes.add(this.clone(true));
203 return e.innerHTML; 203 return e.innerHTML;
204 } 204 }
205 205
206 String get outerHTML() => innerHTML; 206 String get outerHTML => innerHTML;
207 207
208 // TODO(nweiz): Do we want to support some variant of innerHTML for XML and/or 208 // TODO(nweiz): Do we want to support some variant of innerHTML for XML and/or
209 // SVG strings? 209 // SVG strings?
210 void set innerHTML(String value) { 210 void set innerHTML(String value) {
211 this.nodes.clear(); 211 this.nodes.clear();
212 212
213 var e = new Element.tag("div"); 213 var e = new Element.tag("div");
214 e.innerHTML = value; 214 e.innerHTML = value;
215 215
216 // Copy list first since we don't want liveness during iteration. 216 // Copy list first since we don't want liveness during iteration.
(...skipping 22 matching lines...) Expand all
239 void insertAdjacentText([String where = null, String text = null]) { 239 void insertAdjacentText([String where = null, String text = null]) {
240 this._insertAdjacentNode(where, new Text(text)); 240 this._insertAdjacentNode(where, new Text(text));
241 } 241 }
242 242
243 void insertAdjacentHTML( 243 void insertAdjacentHTML(
244 [String position_OR_where = null, String text = null]) { 244 [String position_OR_where = null, String text = null]) {
245 this._insertAdjacentNode( 245 this._insertAdjacentNode(
246 position_OR_where, new DocumentFragment.html(text)); 246 position_OR_where, new DocumentFragment.html(text));
247 } 247 }
248 248
249 ElementEvents get on() { 249 ElementEvents get on {
250 if (_on === null) { 250 if (_on === null) {
251 _on = new ElementEventsImplementation._wrap(_ptr); 251 _on = new ElementEventsImplementation._wrap(_ptr);
252 } 252 }
253 return _on; 253 return _on;
254 } 254 }
255 255
256 Future<ElementRect> get rect() { 256 Future<ElementRect> get rect {
257 return _createMeasurementFuture(() => const EmptyElementRect(), 257 return _createMeasurementFuture(() => const EmptyElementRect(),
258 new Completer<ElementRect>()); 258 new Completer<ElementRect>());
259 } 259 }
260 260
261 Element query(String selectors) => 261 Element query(String selectors) =>
262 LevelDom.wrapElement(_ptr.querySelector(selectors)); 262 LevelDom.wrapElement(_ptr.querySelector(selectors));
263 263
264 ElementList queryAll(String selectors) => 264 ElementList queryAll(String selectors) =>
265 LevelDom.wrapElementList(_ptr.querySelectorAll(selectors)); 265 LevelDom.wrapElementList(_ptr.querySelectorAll(selectors));
266 266
267 // If we can come up with a semi-reasonable default value for an Element 267 // If we can come up with a semi-reasonable default value for an Element
268 // getter, we'll use it. In general, these return the same values as an 268 // getter, we'll use it. In general, these return the same values as an
269 // element that has no parent. 269 // element that has no parent.
270 String get contentEditable() => "false"; 270 String get contentEditable => "false";
271 bool get isContentEditable() => false; 271 bool get isContentEditable => false;
272 bool get draggable() => false; 272 bool get draggable => false;
273 bool get hidden() => false; 273 bool get hidden => false;
274 bool get spellcheck() => false; 274 bool get spellcheck => false;
275 int get tabIndex() => -1; 275 int get tabIndex => -1;
276 String get id() => ""; 276 String get id => "";
277 String get title() => ""; 277 String get title => "";
278 String get tagName() => ""; 278 String get tagName => "";
279 String get webkitdropzone() => ""; 279 String get webkitdropzone => "";
280 Element get firstElementChild() => elements.first(); 280 Element get firstElementChild => elements.first();
281 Element get lastElementChild() => elements.last(); 281 Element get lastElementChild => elements.last();
282 Element get nextElementSibling() => null; 282 Element get nextElementSibling => null;
283 Element get previousElementSibling() => null; 283 Element get previousElementSibling => null;
284 Element get offsetParent() => null; 284 Element get offsetParent => null;
285 Element get parent() => null; 285 Element get parent => null;
286 Map<String, String> get attributes() => const {}; 286 Map<String, String> get attributes => const {};
287 CSSClassSet get classes() => null; 287 CSSClassSet get classes => null;
288 Map<String, String> get dataAttributes() => const {}; 288 Map<String, String> get dataAttributes => const {};
289 CSSStyleDeclaration get style() => new EmptyStyleDeclaration(); 289 CSSStyleDeclaration get style => new EmptyStyleDeclaration();
290 Future<CSSStyleDeclaration> get computedStyle() => 290 Future<CSSStyleDeclaration> get computedStyle =>
291 _emptyStyleFuture(); 291 _emptyStyleFuture();
292 Future<CSSStyleDeclaration> getComputedStyle(String pseudoElement) => 292 Future<CSSStyleDeclaration> getComputedStyle(String pseudoElement) =>
293 _emptyStyleFuture(); 293 _emptyStyleFuture();
294 bool matchesSelector([String selectors]) => false; 294 bool matchesSelector([String selectors]) => false;
295 295
296 // Imperative Element methods are made into no-ops, as they are on parentless 296 // Imperative Element methods are made into no-ops, as they are on parentless
297 // elements. 297 // elements.
298 void blur() {} 298 void blur() {}
299 void focus() {} 299 void focus() {}
300 void scrollByLines([int lines]) {} 300 void scrollByLines([int lines]) {}
(...skipping 15 matching lines...) Expand all
316 void set dataAttributes(Map<String, String> value) { 316 void set dataAttributes(Map<String, String> value) {
317 throw new UnsupportedOperationException( 317 throw new UnsupportedOperationException(
318 "Data attributes can't be set for document fragments."); 318 "Data attributes can't be set for document fragments.");
319 } 319 }
320 320
321 void set contentEditable(String value) { 321 void set contentEditable(String value) {
322 throw new UnsupportedOperationException( 322 throw new UnsupportedOperationException(
323 "Content editable can't be set for document fragments."); 323 "Content editable can't be set for document fragments.");
324 } 324 }
325 325
326 String get dir() { 326 String get dir {
327 throw new UnsupportedOperationException( 327 throw new UnsupportedOperationException(
328 "Document fragments don't support text direction."); 328 "Document fragments don't support text direction.");
329 } 329 }
330 330
331 void set dir(String value) { 331 void set dir(String value) {
332 throw new UnsupportedOperationException( 332 throw new UnsupportedOperationException(
333 "Document fragments don't support text direction."); 333 "Document fragments don't support text direction.");
334 } 334 }
335 335
336 void set draggable(bool value) { 336 void set draggable(bool value) {
337 throw new UnsupportedOperationException( 337 throw new UnsupportedOperationException(
338 "Draggable can't be set for document fragments."); 338 "Draggable can't be set for document fragments.");
339 } 339 }
340 340
341 void set hidden(bool value) { 341 void set hidden(bool value) {
342 throw new UnsupportedOperationException( 342 throw new UnsupportedOperationException(
343 "Hidden can't be set for document fragments."); 343 "Hidden can't be set for document fragments.");
344 } 344 }
345 345
346 void set id(String value) { 346 void set id(String value) {
347 throw new UnsupportedOperationException( 347 throw new UnsupportedOperationException(
348 "ID can't be set for document fragments."); 348 "ID can't be set for document fragments.");
349 } 349 }
350 350
351 String get lang() { 351 String get lang {
352 throw new UnsupportedOperationException( 352 throw new UnsupportedOperationException(
353 "Document fragments don't support language."); 353 "Document fragments don't support language.");
354 } 354 }
355 355
356 void set lang(String value) { 356 void set lang(String value) {
357 throw new UnsupportedOperationException( 357 throw new UnsupportedOperationException(
358 "Document fragments don't support language."); 358 "Document fragments don't support language.");
359 } 359 }
360 360
361 void set scrollLeft(int value) { 361 void set scrollLeft(int value) {
(...skipping 21 matching lines...) Expand all
383 "Title can't be set for document fragments."); 383 "Title can't be set for document fragments.");
384 } 384 }
385 385
386 void set webkitdropzone(String value) { 386 void set webkitdropzone(String value) {
387 throw new UnsupportedOperationException( 387 throw new UnsupportedOperationException(
388 "WebKit drop zone can't be set for document fragments."); 388 "WebKit drop zone can't be set for document fragments.");
389 } 389 }
390 390
391 DocumentFragment clone(bool deep) => super.clone(deep); 391 DocumentFragment clone(bool deep) => super.clone(deep);
392 } 392 }
OLDNEW
« no previous file with comments | « lib/html/src/DeviceOrientationEventWrappingImplementation.dart ('k') | lib/html/src/ErrorEvent.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698