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

Side by Side Diff: tools/dom/templates/html/impl/impl_Element.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 class _ChildrenElementList extends ListBase<Element> { 7 class _ChildrenElementList extends ListBase<Element> {
8 // Raw Element. 8 // Raw Element.
9 final Element _element; 9 final Element _element;
10 final HtmlCollection _childElements; 10 final HtmlCollection _childElements;
11 11
12 _ChildrenElementList._wrap(Element element) 12 _ChildrenElementList._wrap(Element element)
13 : _childElements = element.$dom_children, 13 : _childElements = element._children,
14 _element = element; 14 _element = element;
15 15
16 bool contains(Object element) => _childElements.contains(element); 16 bool contains(Object element) => _childElements.contains(element);
17 17
18 18
19 bool get isEmpty { 19 bool get isEmpty {
20 return _element.$dom_firstElementChild == null; 20 return _element._firstElementChild == null;
21 } 21 }
22 22
23 int get length { 23 int get length {
24 return _childElements.length; 24 return _childElements.length;
25 } 25 }
26 26
27 Element operator [](int index) { 27 Element operator [](int index) {
28 return _childElements[index]; 28 return _childElements[index];
29 } 29 }
30 30
31 void operator []=(int index, Element value) { 31 void operator []=(int index, Element value) {
32 _element.$dom_replaceChild(value, _childElements[index]); 32 _element._replaceChild(value, _childElements[index]);
33 } 33 }
34 34
35 void set length(int newLength) { 35 void set length(int newLength) {
36 // TODO(jacobr): remove children when length is reduced. 36 // TODO(jacobr): remove children when length is reduced.
37 throw new UnsupportedError('Cannot resize element lists'); 37 throw new UnsupportedError('Cannot resize element lists');
38 } 38 }
39 39
40 Element add(Element value) { 40 Element add(Element value) {
41 _element.append(value); 41 _element.append(value);
42 return value; 42 return value;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 86 }
87 87
88 void fillRange(int start, int end, [Element fillValue]) { 88 void fillRange(int start, int end, [Element fillValue]) {
89 throw new UnimplementedError(); 89 throw new UnimplementedError();
90 } 90 }
91 91
92 bool remove(Object object) { 92 bool remove(Object object) {
93 if (object is Element) { 93 if (object is Element) {
94 Element element = object; 94 Element element = object;
95 if (identical(element.parentNode, _element)) { 95 if (identical(element.parentNode, _element)) {
96 _element.$dom_removeChild(element); 96 _element._removeChild(element);
97 return true; 97 return true;
98 } 98 }
99 } 99 }
100 return false; 100 return false;
101 } 101 }
102 102
103 void insert(int index, Element element) { 103 void insert(int index, Element element) {
104 if (index < 0 || index > length) { 104 if (index < 0 || index > length) {
105 throw new RangeError.range(index, 0, length); 105 throw new RangeError.range(index, 0, length);
106 } 106 }
107 if (index == length) { 107 if (index == length) {
108 _element.append(element); 108 _element.append(element);
109 } else { 109 } else {
110 _element.insertBefore(element, this[index]); 110 _element.insertBefore(element, this[index]);
111 } 111 }
112 } 112 }
113 113
114 void setAll(int index, Iterable<Element> iterable) { 114 void setAll(int index, Iterable<Element> iterable) {
115 throw new UnimplementedError(); 115 throw new UnimplementedError();
116 } 116 }
117 117
118 void clear() { 118 void clear() {
119 // It is unclear if we want to keep non element nodes? 119 // It is unclear if we want to keep non element nodes?
120 _element.text = ''; 120 _element.text = '';
121 } 121 }
122 122
123 Element removeAt(int index) { 123 Element removeAt(int index) {
124 final result = this[index]; 124 final result = this[index];
125 if (result != null) { 125 if (result != null) {
126 _element.$dom_removeChild(result); 126 _element._removeChild(result);
127 } 127 }
128 return result; 128 return result;
129 } 129 }
130 130
131 Element removeLast() { 131 Element removeLast() {
132 final result = this.last; 132 final result = this.last;
133 if (result != null) { 133 if (result != null) {
134 _element.$dom_removeChild(result); 134 _element._removeChild(result);
135 } 135 }
136 return result; 136 return result;
137 } 137 }
138 138
139 Element get first { 139 Element get first {
140 Element result = _element.$dom_firstElementChild; 140 Element result = _element._firstElementChild;
141 if (result == null) throw new StateError("No elements"); 141 if (result == null) throw new StateError("No elements");
142 return result; 142 return result;
143 } 143 }
144 144
145 145
146 Element get last { 146 Element get last {
147 Element result = _element.$dom_lastElementChild; 147 Element result = _element._lastElementChild;
148 if (result == null) throw new StateError("No elements"); 148 if (result == null) throw new StateError("No elements");
149 return result; 149 return result;
150 } 150 }
151 151
152 Element get single { 152 Element get single {
153 if (length > 1) throw new StateError("More than one element"); 153 if (length > 1) throw new StateError("More than one element");
154 return first; 154 return first;
155 } 155 }
156 } 156 }
157 157
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 535
536 /** 536 /**
537 * Finds all descendent elements of this element that match the specified 537 * Finds all descendent elements of this element that match the specified
538 * group of selectors. 538 * group of selectors.
539 * 539 *
540 * [selectors] should be a string using CSS selector syntax. 540 * [selectors] should be a string using CSS selector syntax.
541 * 541 *
542 * var items = element.query('.itemClassName'); 542 * var items = element.query('.itemClassName');
543 */ 543 */
544 ElementList queryAll(String selectors) => 544 ElementList queryAll(String selectors) =>
545 new _FrozenElementList._wrap($dom_querySelectorAll(selectors)); 545 new _FrozenElementList._wrap(_querySelectorAll(selectors));
546 546
547 /** 547 /**
548 * The set of CSS classes applied to this element. 548 * The set of CSS classes applied to this element.
549 * 549 *
550 * This set makes it easy to add, remove or toggle the classes applied to 550 * This set makes it easy to add, remove or toggle the classes applied to
551 * this element. 551 * this element.
552 * 552 *
553 * element.classes.add('selected'); 553 * element.classes.add('selected');
554 * element.classes.toggle('isOnline'); 554 * element.classes.toggle('isOnline');
555 * element.classes.remove('selected'); 555 * element.classes.remove('selected');
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 * See also: 620 * See also:
621 * 621 *
622 * * [CSS Inheritance and Cascade](http://docs.webplatform.org/wiki/tutorials/ inheritance_and_cascade) 622 * * [CSS Inheritance and Cascade](http://docs.webplatform.org/wiki/tutorials/ inheritance_and_cascade)
623 * * [Pseudo-elements](http://docs.webplatform.org/wiki/css/selectors/pseudo-e lements) 623 * * [Pseudo-elements](http://docs.webplatform.org/wiki/css/selectors/pseudo-e lements)
624 */ 624 */
625 CssStyleDeclaration getComputedStyle([String pseudoElement]) { 625 CssStyleDeclaration getComputedStyle([String pseudoElement]) {
626 if (pseudoElement == null) { 626 if (pseudoElement == null) {
627 pseudoElement = ''; 627 pseudoElement = '';
628 } 628 }
629 // TODO(jacobr): last param should be null, see b/5045788 629 // TODO(jacobr): last param should be null, see b/5045788
630 return window.$dom_getComputedStyle(this, pseudoElement); 630 return window._getComputedStyle(this, pseudoElement);
631 } 631 }
632 632
633 /** 633 /**
634 * Gets the position of this element relative to the client area of the page. 634 * Gets the position of this element relative to the client area of the page.
635 */ 635 */
636 Rect get client => new Rect(clientLeft, clientTop, clientWidth, clientHeight); 636 Rect get client => new Rect(clientLeft, clientTop, clientWidth, clientHeight);
637 637
638 /** 638 /**
639 * Gets the offset of this element relative to its offsetParent. 639 * Gets the offset of this element relative to its offsetParent.
640 */ 640 */
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 // Note: return type is `dynamic` for convenience to suppress warnings when 693 // Note: return type is `dynamic` for convenience to suppress warnings when
694 // members of the component are used. The actual type is a subtype of Element. 694 // members of the component are used. The actual type is a subtype of Element.
695 get xtag => _xtag != null ? _xtag : this; 695 get xtag => _xtag != null ? _xtag : this;
696 696
697 void set xtag(Element value) { 697 void set xtag(Element value) {
698 _xtag = value; 698 _xtag = value;
699 } 699 }
700 700
701 @DomName('Element.localName') 701 @DomName('Element.localName')
702 @DocsEditable() 702 @DocsEditable()
703 String get localName => $dom_localName; 703 String get localName => _localName;
704 704
705 @DomName('Element.namespaceUri') 705 @DomName('Element.namespaceUri')
706 @DocsEditable() 706 @DocsEditable()
707 String get namespaceUri => $dom_namespaceUri; 707 String get namespaceUri => _namespaceUri;
708 708
709 String toString() => localName; 709 String toString() => localName;
710 710
711 /** 711 /**
712 * Scrolls this element into view. 712 * Scrolls this element into view.
713 * 713 *
714 * Only one of of the alignment options may be specified at a time. 714 * Only one of of the alignment options may be specified at a time.
715 * 715 *
716 * If no options are specified then this will attempt to scroll the minimum 716 * If no options are specified then this will attempt to scroll the minimum
717 * amount needed to bring the element into view. 717 * amount needed to bring the element into view.
718 * 718 *
719 * Note that alignCenter is currently only supported on WebKit platforms. If 719 * Note that alignCenter is currently only supported on WebKit platforms. If
720 * alignCenter is specified but not supported then this will fall back to 720 * alignCenter is specified but not supported then this will fall back to
721 * alignTop. 721 * alignTop.
722 * 722 *
723 * See also: 723 * See also:
724 * 724 *
725 * * [scrollIntoView](http://docs.webplatform.org/wiki/dom/methods/scrollIntoV iew) 725 * * [scrollIntoView](http://docs.webplatform.org/wiki/dom/methods/scrollIntoV iew)
726 * * [scrollIntoViewIfNeeded](http://docs.webplatform.org/wiki/dom/methods/scr ollIntoViewIfNeeded) 726 * * [scrollIntoViewIfNeeded](http://docs.webplatform.org/wiki/dom/methods/scr ollIntoViewIfNeeded)
727 */ 727 */
728 void scrollIntoView([ScrollAlignment alignment]) { 728 void scrollIntoView([ScrollAlignment alignment]) {
729 var hasScrollIntoViewIfNeeded = false; 729 var hasScrollIntoViewIfNeeded = false;
730 $if DART2JS 730 $if DART2JS
731 hasScrollIntoViewIfNeeded = 731 hasScrollIntoViewIfNeeded =
732 JS('bool', '!!(#.scrollIntoViewIfNeeded)', this); 732 JS('bool', '!!(#.scrollIntoViewIfNeeded)', this);
733 $endif 733 $endif
734 if (alignment == ScrollAlignment.TOP) { 734 if (alignment == ScrollAlignment.TOP) {
735 this.$dom_scrollIntoView(true); 735 this._scrollIntoView(true);
736 } else if (alignment == ScrollAlignment.BOTTOM) { 736 } else if (alignment == ScrollAlignment.BOTTOM) {
737 this.$dom_scrollIntoView(false); 737 this._scrollIntoView(false);
738 } else if (hasScrollIntoViewIfNeeded) { 738 } else if (hasScrollIntoViewIfNeeded) {
739 if (alignment == ScrollAlignment.CENTER) { 739 if (alignment == ScrollAlignment.CENTER) {
740 this.$dom_scrollIntoViewIfNeeded(true); 740 this._scrollIntoViewIfNeeded(true);
741 } else { 741 } else {
742 this.$dom_scrollIntoViewIfNeeded(); 742 this._scrollIntoViewIfNeeded();
743 } 743 }
744 } else { 744 } else {
745 this.$dom_scrollIntoView(); 745 this._scrollIntoView();
746 } 746 }
747 } 747 }
748 748
749 $if DART2JS 749 $if DART2JS
750 @DomName('Element.mouseWheelEvent') 750 @DomName('Element.mouseWheelEvent')
751 static const EventStreamProvider<WheelEvent> mouseWheelEvent = 751 static const EventStreamProvider<WheelEvent> mouseWheelEvent =
752 const _CustomEventStreamProvider<WheelEvent>( 752 const _CustomEventStreamProvider<WheelEvent>(
753 Element._determineMouseWheelEventType); 753 Element._determineMouseWheelEventType);
754 754
755 static String _determineMouseWheelEventType(EventTarget e) { 755 static String _determineMouseWheelEventType(EventTarget e) {
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 const ScrollAlignment._internal(this._value); 1323 const ScrollAlignment._internal(this._value);
1324 toString() => 'ScrollAlignment.$_value'; 1324 toString() => 'ScrollAlignment.$_value';
1325 1325
1326 /// Attempt to align the element to the top of the scrollable area. 1326 /// Attempt to align the element to the top of the scrollable area.
1327 static const TOP = const ScrollAlignment._internal('TOP'); 1327 static const TOP = const ScrollAlignment._internal('TOP');
1328 /// Attempt to center the element in the scrollable area. 1328 /// Attempt to center the element in the scrollable area.
1329 static const CENTER = const ScrollAlignment._internal('CENTER'); 1329 static const CENTER = const ScrollAlignment._internal('CENTER');
1330 /// Attempt to align the element to the bottom of the scrollable area. 1330 /// Attempt to align the element to the bottom of the scrollable area.
1331 static const BOTTOM = const ScrollAlignment._internal('BOTTOM'); 1331 static const BOTTOM = const ScrollAlignment._internal('BOTTOM');
1332 } 1332 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698