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

Side by Side Diff: lib/dom/templates/html/impl/impl_Element.darttemplate

Issue 10928060: Partially migrate from old getter syntax to new one. (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) 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 // TODO(jacobr): use _Lists.dart to remove some of the duplicated 5 // TODO(jacobr): use _Lists.dart to remove some of the duplicated
6 // functionality. 6 // functionality.
7 class _ChildrenElementList implements ElementList { 7 class _ChildrenElementList implements ElementList {
8 // Raw Element. 8 // Raw Element.
9 final _ElementImpl _element; 9 final _ElementImpl _element;
10 final _HTMLCollectionImpl _childElements; 10 final _HTMLCollectionImpl _childElements;
11 11
12 _ChildrenElementList._wrap(_ElementImpl element) 12 _ChildrenElementList._wrap(_ElementImpl element)
13 : _childElements = element.$dom_children, 13 : _childElements = element.$dom_children,
14 _element = element; 14 _element = element;
15 15
16 List<Element> _toList() { 16 List<Element> _toList() {
17 final output = new List(_childElements.length); 17 final output = new List(_childElements.length);
18 for (int i = 0, len = _childElements.length; i < len; i++) { 18 for (int i = 0, len = _childElements.length; i < len; i++) {
19 output[i] = _childElements[i]; 19 output[i] = _childElements[i];
20 } 20 }
21 return output; 21 return output;
22 } 22 }
23 23
24 _ElementImpl get first() { 24 _ElementImpl get first {
25 return _element.$dom_firstElementChild; 25 return _element.$dom_firstElementChild;
26 } 26 }
27 27
28 void forEach(void f(Element element)) { 28 void forEach(void f(Element element)) {
29 for (_ElementImpl element in _childElements) { 29 for (_ElementImpl element in _childElements) {
30 f(element); 30 f(element);
31 } 31 }
32 } 32 }
33 33
34 ElementList filter(bool f(Element element)) { 34 ElementList filter(bool f(Element element)) {
(...skipping 29 matching lines...) Expand all
64 for (Element el in this) { 64 for (Element el in this) {
65 out.add(f(el)); 65 out.add(f(el));
66 } 66 }
67 return out; 67 return out;
68 } 68 }
69 69
70 bool isEmpty() { 70 bool isEmpty() {
71 return _element.$dom_firstElementChild == null; 71 return _element.$dom_firstElementChild == null;
72 } 72 }
73 73
74 int get length() { 74 int get length {
75 return _childElements.length; 75 return _childElements.length;
76 } 76 }
77 77
78 _ElementImpl operator [](int index) { 78 _ElementImpl operator [](int index) {
79 return _childElements[index]; 79 return _childElements[index];
80 } 80 }
81 81
82 void operator []=(int index, _ElementImpl value) { 82 void operator []=(int index, _ElementImpl value) {
83 _element.$dom_replaceChild(value, _childElements[index]); 83 _element.$dom_replaceChild(value, _childElements[index]);
84 } 84 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 // TODO(jacobr): this is an inefficient implementation but it is hard to see 153 // TODO(jacobr): this is an inefficient implementation but it is hard to see
154 // a better option given that we cannot quite force NodeList to be an 154 // a better option given that we cannot quite force NodeList to be an
155 // ElementList as there are valid cases where a NodeList JavaScript object 155 // ElementList as there are valid cases where a NodeList JavaScript object
156 // contains Node objects that are not Elements. 156 // contains Node objects that are not Elements.
157 class _FrozenElementList implements ElementList { 157 class _FrozenElementList implements ElementList {
158 final List<Node> _nodeList; 158 final List<Node> _nodeList;
159 159
160 _FrozenElementList._wrap(this._nodeList); 160 _FrozenElementList._wrap(this._nodeList);
161 161
162 Element get first() { 162 Element get first {
163 return _nodeList[0]; 163 return _nodeList[0];
164 } 164 }
165 165
166 void forEach(void f(Element element)) { 166 void forEach(void f(Element element)) {
167 for (Element el in this) { 167 for (Element el in this) {
168 f(el); 168 f(el);
169 } 169 }
170 } 170 }
171 171
172 Collection map(f(Element element)) { 172 Collection map(f(Element element)) {
(...skipping 25 matching lines...) Expand all
198 for(Element element in this) { 198 for(Element element in this) {
199 if (f(element)) { 199 if (f(element)) {
200 return true; 200 return true;
201 } 201 }
202 }; 202 };
203 return false; 203 return false;
204 } 204 }
205 205
206 bool isEmpty() => _nodeList.isEmpty(); 206 bool isEmpty() => _nodeList.isEmpty();
207 207
208 int get length() => _nodeList.length; 208 int get length => _nodeList.length;
209 209
210 Element operator [](int index) => _nodeList[index]; 210 Element operator [](int index) => _nodeList[index];
211 211
212 void operator []=(int index, Element value) { 212 void operator []=(int index, Element value) {
213 throw const UnsupportedOperationException(''); 213 throw const UnsupportedOperationException('');
214 } 214 }
215 215
216 void set length(int newLength) { 216 void set length(int newLength) {
217 _nodeList.length = newLength; 217 _nodeList.length = newLength;
218 } 218 }
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 final values = new List<String>(attributes.length); 373 final values = new List<String>(attributes.length);
374 for (int i = 0, len = attributes.length; i < len; i++) { 374 for (int i = 0, len = attributes.length; i < len; i++) {
375 values[i] = attributes[i].value; 375 values[i] = attributes[i].value;
376 } 376 }
377 return values; 377 return values;
378 } 378 }
379 379
380 /** 380 /**
381 * The number of {key, value} pairs in the map. 381 * The number of {key, value} pairs in the map.
382 */ 382 */
383 int get length() { 383 int get length {
384 return _element.$dom_attributes.length; 384 return _element.$dom_attributes.length;
385 } 385 }
386 386
387 /** 387 /**
388 * Returns true if there is no {key, value} pair in the map. 388 * Returns true if there is no {key, value} pair in the map.
389 */ 389 */
390 bool isEmpty() { 390 bool isEmpty() {
391 return length == 0; 391 return length == 0;
392 } 392 }
393 } 393 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 Collection<String> getValues() { 448 Collection<String> getValues() {
449 final values = new List<String>(); 449 final values = new List<String>();
450 $dom_attributes.forEach((String key, String value) { 450 $dom_attributes.forEach((String key, String value) {
451 if (_matches(key)) { 451 if (_matches(key)) {
452 values.add(value); 452 values.add(value);
453 } 453 }
454 }); 454 });
455 return values; 455 return values;
456 } 456 }
457 457
458 int get length() => getKeys().length; 458 int get length => getKeys().length;
459 459
460 // TODO: Use lazy iterator when it is available on Map. 460 // TODO: Use lazy iterator when it is available on Map.
461 bool isEmpty() => length == 0; 461 bool isEmpty() => length == 0;
462 462
463 // Helpers. 463 // Helpers.
464 String _attr(String key) => 'data-$key'; 464 String _attr(String key) => 'data-$key';
465 bool _matches(String key) => key.startsWith('data-'); 465 bool _matches(String key) => key.startsWith('data-');
466 String _strip(String key) => key.substring(5); 466 String _strip(String key) => key.substring(5);
467 } 467 }
468 468
(...skipping 17 matching lines...) Expand all
486 Collection map(f(String element)) => _read().map(f); 486 Collection map(f(String element)) => _read().map(f);
487 487
488 Collection<String> filter(bool f(String element)) => _read().filter(f); 488 Collection<String> filter(bool f(String element)) => _read().filter(f);
489 489
490 bool every(bool f(String element)) => _read().every(f); 490 bool every(bool f(String element)) => _read().every(f);
491 491
492 bool some(bool f(String element)) => _read().some(f); 492 bool some(bool f(String element)) => _read().some(f);
493 493
494 bool isEmpty() => _read().isEmpty(); 494 bool isEmpty() => _read().isEmpty();
495 495
496 bool get isFrozen() => false; 496 bool get isFrozen => false;
497 497
498 int get length() =>_read().length; 498 int get length =>_read().length;
499 499
500 // interface Collection - END 500 // interface Collection - END
501 501
502 // interface Set - BEGIN 502 // interface Set - BEGIN
503 bool contains(String value) => _read().contains(value); 503 bool contains(String value) => _read().contains(value);
504 504
505 void add(String value) { 505 void add(String value) {
506 // TODO - figure out if we need to do any validation here 506 // TODO - figure out if we need to do any validation here
507 // or if the browser natively does enough 507 // or if the browser natively does enough
508 _modify((s) => s.add(value)); 508 _modify((s) => s.add(value));
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 List list = new List.from(s); 601 List list = new List.from(s);
602 return Strings.join(list, ' '); 602 return Strings.join(list, ' ');
603 } 603 }
604 } 604 }
605 605
606 class _SimpleClientRect implements ClientRect { 606 class _SimpleClientRect implements ClientRect {
607 final num left; 607 final num left;
608 final num top; 608 final num top;
609 final num width; 609 final num width;
610 final num height; 610 final num height;
611 num get right() => left + width; 611 num get right => left + width;
612 num get bottom() => top + height; 612 num get bottom => top + height;
613 613
614 const _SimpleClientRect(this.left, this.top, this.width, this.height); 614 const _SimpleClientRect(this.left, this.top, this.width, this.height);
615 615
616 bool operator ==(ClientRect other) { 616 bool operator ==(ClientRect other) {
617 return other !== null && left == other.left && top == other.top 617 return other !== null && left == other.left && top == other.top
618 && width == other.width && height == other.height; 618 && width == other.width && height == other.height;
619 } 619 }
620 620
621 String toString() => "($left, $top, $width, $height)"; 621 String toString() => "($left, $top, $width, $height)";
622 } 622 }
(...skipping 24 matching lines...) Expand all
647 element.$dom_offsetTop, 647 element.$dom_offsetTop,
648 element.$dom_offsetWidth, 648 element.$dom_offsetWidth,
649 element.$dom_offsetHeight), 649 element.$dom_offsetHeight),
650 scroll = new _SimpleClientRect(element.$dom_scrollLeft, 650 scroll = new _SimpleClientRect(element.$dom_scrollLeft,
651 element.$dom_scrollTop, 651 element.$dom_scrollTop,
652 element.$dom_scrollWidth, 652 element.$dom_scrollWidth,
653 element.$dom_scrollHeight), 653 element.$dom_scrollHeight),
654 _boundingClientRect = element.$dom_getBoundingClientRect(), 654 _boundingClientRect = element.$dom_getBoundingClientRect(),
655 _clientRects = element.$dom_getClientRects(); 655 _clientRects = element.$dom_getClientRects();
656 656
657 _ClientRectImpl get bounding() => _boundingClientRect; 657 _ClientRectImpl get bounding => _boundingClientRect;
658 658
659 // TODO(jacobr): cleanup. 659 // TODO(jacobr): cleanup.
660 List<ClientRect> get clientRects() { 660 List<ClientRect> get clientRects {
661 final out = new List(_clientRects.length); 661 final out = new List(_clientRects.length);
662 for (num i = 0; i < _clientRects.length; i++) { 662 for (num i = 0; i < _clientRects.length; i++) {
663 out[i] = _clientRects.item(i); 663 out[i] = _clientRects.item(i);
664 } 664 }
665 return out; 665 return out;
666 } 666 }
667 } 667 }
668 668
669 class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { 669 class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
670 670
671 /** 671 /**
672 * @domName Element.hasAttribute, Element.getAttribute, Element.setAttribute, 672 * @domName Element.hasAttribute, Element.getAttribute, Element.setAttribute,
673 * Element.removeAttribute 673 * Element.removeAttribute
674 */ 674 */
675 _ElementAttributeMap get attributes() => new _ElementAttributeMap(this); 675 _ElementAttributeMap get attributes => new _ElementAttributeMap(this);
676 676
677 void set attributes(Map<String, String> value) { 677 void set attributes(Map<String, String> value) {
678 Map<String, String> attributes = this.attributes; 678 Map<String, String> attributes = this.attributes;
679 attributes.clear(); 679 attributes.clear();
680 for (String key in value.getKeys()) { 680 for (String key in value.getKeys()) {
681 attributes[key] = value[key]; 681 attributes[key] = value[key];
682 } 682 }
683 } 683 }
684 684
685 void set elements(Collection<Element> value) { 685 void set elements(Collection<Element> value) {
686 final elements = this.elements; 686 final elements = this.elements;
687 elements.clear(); 687 elements.clear();
688 elements.addAll(value); 688 elements.addAll(value);
689 } 689 }
690 690
691 ElementList get elements() => new _ChildrenElementList._wrap(this); 691 ElementList get elements => new _ChildrenElementList._wrap(this);
692 692
693 _ElementImpl query(String selectors) => $dom_querySelector(selectors); 693 _ElementImpl query(String selectors) => $dom_querySelector(selectors);
694 694
695 List<Element> queryAll(String selectors) => 695 List<Element> queryAll(String selectors) =>
696 new _FrozenElementList._wrap($dom_querySelectorAll(selectors)); 696 new _FrozenElementList._wrap($dom_querySelectorAll(selectors));
697 697
698 _CssClassSet get classes() => new _CssClassSet(this); 698 _CssClassSet get classes => new _CssClassSet(this);
699 699
700 void set classes(Collection<String> value) { 700 void set classes(Collection<String> value) {
701 _CssClassSet classSet = classes; 701 _CssClassSet classSet = classes;
702 classSet.clear(); 702 classSet.clear();
703 classSet.addAll(value); 703 classSet.addAll(value);
704 } 704 }
705 705
706 Map<String, String> get dataAttributes() => 706 Map<String, String> get dataAttributes =>
707 new _DataAttributeMap(attributes); 707 new _DataAttributeMap(attributes);
708 708
709 void set dataAttributes(Map<String, String> value) { 709 void set dataAttributes(Map<String, String> value) {
710 final dataAttributes = this.dataAttributes; 710 final dataAttributes = this.dataAttributes;
711 dataAttributes.clear(); 711 dataAttributes.clear();
712 for (String key in value.getKeys()) { 712 for (String key in value.getKeys()) {
713 dataAttributes[key] = value[key]; 713 dataAttributes[key] = value[key];
714 } 714 }
715 } 715 }
716 716
717 Future<ElementRect> get rect() { 717 Future<ElementRect> get rect {
718 return _createMeasurementFuture( 718 return _createMeasurementFuture(
719 () => new _ElementRectImpl(this), 719 () => new _ElementRectImpl(this),
720 new Completer<ElementRect>()); 720 new Completer<ElementRect>());
721 } 721 }
722 722
723 Future<CSSStyleDeclaration> get computedStyle() { 723 Future<CSSStyleDeclaration> get computedStyle {
724 // TODO(jacobr): last param should be null, see b/5045788 724 // TODO(jacobr): last param should be null, see b/5045788
725 return getComputedStyle(''); 725 return getComputedStyle('');
726 } 726 }
727 727
728 Future<CSSStyleDeclaration> getComputedStyle(String pseudoElement) { 728 Future<CSSStyleDeclaration> getComputedStyle(String pseudoElement) {
729 return _createMeasurementFuture( 729 return _createMeasurementFuture(
730 () => _window.$dom_getComputedStyle(this, pseudoElement), 730 () => _window.$dom_getComputedStyle(this, pseudoElement),
731 new Completer<CSSStyleDeclaration>()); 731 new Completer<CSSStyleDeclaration>());
732 } 732 }
733 733
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 873
874 /** @domName Document.createElement */ 874 /** @domName Document.createElement */
875 $if DART2JS 875 $if DART2JS
876 // Optimization to improve performance until the dart2js compiler inlines this 876 // Optimization to improve performance until the dart2js compiler inlines this
877 // method. 877 // method.
878 factory Element.tag(String tag) native "return document.createElement(tag)"; 878 factory Element.tag(String tag) native "return document.createElement(tag)";
879 $else 879 $else
880 factory Element.tag(String tag) => _document.$dom_createElement(tag); 880 factory Element.tag(String tag) => _document.$dom_createElement(tag);
881 $endif 881 $endif
882 } 882 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698