OLD | NEW |
---|---|
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 implements NodeListWrapper { | 8 implements NodeListWrapper { |
9 // Raw Element. | 9 // Raw Element. |
10 final Element _element; | 10 final Element _element; |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 CssRect get marginEdge; | 257 CssRect get marginEdge; |
258 $!STREAM_GETTER_SIGNATURES | 258 $!STREAM_GETTER_SIGNATURES |
259 } | 259 } |
260 | 260 |
261 // Wrapper over an immutable NodeList to make it implement ElementList. | 261 // Wrapper over an immutable NodeList to make it implement ElementList. |
262 // | 262 // |
263 // Clients are {`Document`, `DocumentFragment`}.`querySelectorAll` which are | 263 // Clients are {`Document`, `DocumentFragment`}.`querySelectorAll` which are |
264 // declared to return `ElementList`. This provides all the static analysis | 264 // declared to return `ElementList`. This provides all the static analysis |
265 // benefit so there is no need for this class have a constrained type parameter. | 265 // benefit so there is no need for this class have a constrained type parameter. |
266 // | 266 // |
267 class _FrozenElementList extends ListBase<Element> | 267 class _FrozenElementList<E extends Element> extends ListBase<E> |
268 implements ElementList<Element>, NodeListWrapper { | 268 implements ElementList<E>, NodeListWrapper { |
269 final List<Node> _nodeList; | 269 final List<Node> _nodeList; |
270 | 270 |
271 $if JSINTEROP | 271 $if JSINTEROP |
272 var dartClass_instance; | 272 var dartClass_instance; |
273 | 273 |
274 _FrozenElementList._wrap(this._nodeList) { | 274 _FrozenElementList._wrap(this._nodeList) { |
275 this.dartClass_instance = this._nodeList; | 275 this.dartClass_instance = this._nodeList; |
276 } | 276 } |
277 $else | 277 $else |
278 _FrozenElementList._wrap(this._nodeList); | 278 _FrozenElementList._wrap(this._nodeList); |
279 $endif | 279 $endif |
280 | 280 |
281 int get length => _nodeList.length; | 281 int get length => _nodeList.length; |
282 | 282 |
283 Element operator [](int index) => _nodeList[index]; | 283 E operator [](int index) => _nodeList[index] as E; |
sra1
2016/04/21 22:43:15
E _asE(Node node) {
E element = node;
return e
| |
284 | 284 |
285 void operator []=(int index, Element value) { | 285 void operator []=(int index, E value) { |
286 throw new UnsupportedError('Cannot modify list'); | 286 throw new UnsupportedError('Cannot modify list'); |
287 } | 287 } |
288 | 288 |
289 set length(int newLength) { | 289 set length(int newLength) { |
290 throw new UnsupportedError('Cannot modify list'); | 290 throw new UnsupportedError('Cannot modify list'); |
291 } | 291 } |
292 | 292 |
293 void sort([Comparator<Element> compare]) { | 293 void sort([Comparator<E> compare]) { |
294 throw new UnsupportedError('Cannot sort list'); | 294 throw new UnsupportedError('Cannot sort list'); |
295 } | 295 } |
296 | 296 |
297 void shuffle([Random random]) { | 297 void shuffle([Random random]) { |
298 throw new UnsupportedError('Cannot shuffle list'); | 298 throw new UnsupportedError('Cannot shuffle list'); |
299 } | 299 } |
300 | 300 |
301 Element get first => _nodeList.first; | 301 E get first => _nodeList.first as E; |
sra1
2016/04/21 22:43:15
=> _asE(_nodeList.first);
| |
302 | 302 |
303 Element get last => _nodeList.last; | 303 E get last => _nodeList.last as E; |
304 | 304 |
305 Element get single => _nodeList.single; | 305 E get single => _nodeList.single as E; |
306 | 306 |
307 CssClassSet get classes => new _MultiElementCssClassSet(this); | 307 CssClassSet get classes => new _MultiElementCssClassSet(this); |
308 | 308 |
309 CssStyleDeclarationBase get style => | 309 CssStyleDeclarationBase get style => |
310 new _CssStyleDeclarationSet(this); | 310 new _CssStyleDeclarationSet(this); |
311 | 311 |
312 set classes(Iterable<String> value) { | 312 set classes(Iterable<String> value) { |
313 // TODO(sra): This might be faster for Sets: | 313 // TODO(sra): This might be faster for Sets: |
314 // | 314 // |
315 // new _MultiElementCssClassSet(this).writeClasses(value) | 315 // new _MultiElementCssClassSet(this).writeClasses(value) |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 * group of selectors. | 604 * group of selectors. |
605 * | 605 * |
606 * [selectors] should be a string using CSS selector syntax. | 606 * [selectors] should be a string using CSS selector syntax. |
607 * | 607 * |
608 * var items = element.querySelectorAll('.itemClassName'); | 608 * var items = element.querySelectorAll('.itemClassName'); |
609 * | 609 * |
610 * For details about CSS selector syntax, see the | 610 * For details about CSS selector syntax, see the |
611 * [CSS selector specification](http://www.w3.org/TR/css3-selectors/). | 611 * [CSS selector specification](http://www.w3.org/TR/css3-selectors/). |
612 */ | 612 */ |
613 @DomName('Element.querySelectorAll') | 613 @DomName('Element.querySelectorAll') |
614 ElementList<Element> querySelectorAll(String selectors) => | 614 ElementList<Element /*=T*/> querySelectorAll/*<T extends Element>*/(String sel ectors) => |
615 new _FrozenElementList._wrap(_querySelectorAll(selectors)); | 615 new _FrozenElementList/*<T>*/._wrap(_querySelectorAll(selectors)); |
616 | 616 |
617 /** | 617 /** |
618 * Alias for [querySelector]. Note this function is deprecated because its | 618 * Alias for [querySelector]. Note this function is deprecated because its |
619 * semantics will be changing in the future. | 619 * semantics will be changing in the future. |
620 */ | 620 */ |
621 @deprecated | 621 @deprecated |
622 @DomName('Element.querySelector') | 622 @DomName('Element.querySelector') |
623 @Experimental() | 623 @Experimental() |
624 Element query(String relativeSelectors) => querySelector(relativeSelectors); | 624 Element query(String relativeSelectors) => querySelector(relativeSelectors); |
625 | 625 |
626 /** | 626 /** |
627 * Alias for [querySelectorAll]. Note this function is deprecated because its | 627 * Alias for [querySelectorAll]. Note this function is deprecated because its |
628 * semantics will be changing in the future. | 628 * semantics will be changing in the future. |
629 */ | 629 */ |
630 @deprecated | 630 @deprecated |
631 @DomName('Element.querySelectorAll') | 631 @DomName('Element.querySelectorAll') |
632 @Experimental() | 632 @Experimental() |
633 ElementList<Element> queryAll(String relativeSelectors) => | 633 ElementList<Element /*=T*/> queryAll/*<T extends Element>*/(String relativeSel ectors) => |
634 querySelectorAll(relativeSelectors); | 634 querySelectorAll(relativeSelectors); |
635 | 635 |
636 /** | 636 /** |
637 * The set of CSS classes applied to this element. | 637 * The set of CSS classes applied to this element. |
638 * | 638 * |
639 * This set makes it easy to add, remove or toggle the classes applied to | 639 * This set makes it easy to add, remove or toggle the classes applied to |
640 * this element. | 640 * this element. |
641 * | 641 * |
642 * element.classes.add('selected'); | 642 * element.classes.add('selected'); |
643 * element.classes.toggle('isOnline'); | 643 * element.classes.toggle('isOnline'); |
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1669 const ScrollAlignment._internal(this._value); | 1669 const ScrollAlignment._internal(this._value); |
1670 toString() => 'ScrollAlignment.$_value'; | 1670 toString() => 'ScrollAlignment.$_value'; |
1671 | 1671 |
1672 /// Attempt to align the element to the top of the scrollable area. | 1672 /// Attempt to align the element to the top of the scrollable area. |
1673 static const TOP = const ScrollAlignment._internal('TOP'); | 1673 static const TOP = const ScrollAlignment._internal('TOP'); |
1674 /// Attempt to center the element in the scrollable area. | 1674 /// Attempt to center the element in the scrollable area. |
1675 static const CENTER = const ScrollAlignment._internal('CENTER'); | 1675 static const CENTER = const ScrollAlignment._internal('CENTER'); |
1676 /// Attempt to align the element to the bottom of the scrollable area. | 1676 /// Attempt to align the element to the bottom of the scrollable area. |
1677 static const BOTTOM = const ScrollAlignment._internal('BOTTOM'); | 1677 static const BOTTOM = const ScrollAlignment._internal('BOTTOM'); |
1678 } | 1678 } |
OLD | NEW |