| 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 // Raw Element. | 8 // Raw Element. |
| 9 final Element _element; | 9 final Element _element; |
| 10 final HtmlCollection _childElements; | 10 final HtmlCollection _childElements; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 132 } |
| 133 | 133 |
| 134 Element get single { | 134 Element get single { |
| 135 if (length > 1) throw new StateError("More than one element"); | 135 if (length > 1) throw new StateError("More than one element"); |
| 136 return first; | 136 return first; |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 /** | 140 /** |
| 141 * An immutable list containing HTML elements. This list contains some | 141 * An immutable list containing HTML elements. This list contains some |
| 142 * additional methods for ease of CSS manipulation on a group of elements. | 142 * additional methods when compared to regular lists for ease of CSS |
| 143 * manipulation on a group of elements. |
| 143 */ | 144 */ |
| 144 abstract class ElementList<T extends Element> extends ListBase<T> { | 145 abstract class ElementList<T extends Element> extends ListBase<T> { |
| 145 /** | 146 /** |
| 146 * The union of all CSS classes applied to the elements in this list. | 147 * The union of all CSS classes applied to the elements in this list. |
| 147 * | 148 * |
| 148 * This set makes it easy to add, remove or toggle (add if not present, remove | 149 * This set makes it easy to add, remove or toggle (add if not present, remove |
| 149 * if present) the classes applied to a collection of elements. | 150 * if present) the classes applied to a collection of elements. |
| 150 * | 151 * |
| 151 * htmlList.classes.add('selected'); | 152 * htmlList.classes.add('selected'); |
| 152 * htmlList.classes.toggle('isOnline'); | 153 * htmlList.classes.toggle('isOnline'); |
| 153 * htmlList.classes.remove('selected'); | 154 * htmlList.classes.remove('selected'); |
| 154 */ | 155 */ |
| 155 CssClassSet get classes; | 156 CssClassSet get classes; |
| 156 | 157 |
| 157 /** Replace the classes with `value` for every element in this list. */ | 158 /** Replace the classes with `value` for every element in this list. */ |
| 158 set classes(Iterable<String> value); | 159 set classes(Iterable<String> value); |
| 160 |
| 161 /** |
| 162 * Access dimensions and position of the first Element's content in this list. |
| 163 * |
| 164 * Setting the height or width properties will set the height or width |
| 165 * property for all elements in the list. This returns a rectangle with the |
| 166 * dimenions actually available for content |
| 167 * in this element, in pixels, regardless of this element's box-sizing |
| 168 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle |
| 169 * will return the same numerical height if the element is hidden or not. |
| 170 */ |
| 171 CssRect get contentEdge; |
| 172 |
| 173 /** |
| 174 * Access dimensions and position of the first Element's content + padding box
|
| 175 * in this list. |
| 176 * |
| 177 * This returns a rectangle with the dimenions actually available for content |
| 178 * in this element, in pixels, regardless of this element's box-sizing |
| 179 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle |
| 180 * will return the same numerical height if the element is hidden or not. This |
| 181 * can be used to retrieve jQuery's `innerHeight` value for an element. This |
| 182 * is also a rectangle equalling the dimensions of clientHeight and |
| 183 * clientWidth. |
| 184 */ |
| 185 CssRect get paddingEdge; |
| 186 |
| 187 /** |
| 188 * Access dimensions and position of the first Element's content + padding + |
| 189 * border box in this list. |
| 190 * |
| 191 * This returns a rectangle with the dimenions actually available for content |
| 192 * in this element, in pixels, regardless of this element's box-sizing |
| 193 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle |
| 194 * will return the same numerical height if the element is hidden or not. This |
| 195 * can be used to retrieve jQuery's `outerHeight` value for an element. |
| 196 */ |
| 197 CssRect get borderEdge; |
| 198 |
| 199 /** |
| 200 * Access dimensions and position of the first Element's content + padding + |
| 201 * border + margin box in this list. |
| 202 * |
| 203 * This returns a rectangle with the dimenions actually available for content |
| 204 * in this element, in pixels, regardless of this element's box-sizing |
| 205 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle |
| 206 * will return the same numerical height if the element is hidden or not. This |
| 207 * can be used to retrieve jQuery's `outerHeight` value for an element. |
| 208 */ |
| 209 CssRect get marginEdge; |
| 159 } | 210 } |
| 160 | 211 |
| 161 // TODO(jacobr): this is an inefficient implementation but it is hard to see | 212 // TODO(jacobr): this is an inefficient implementation but it is hard to see |
| 162 // a better option given that we cannot quite force NodeList to be an | 213 // a better option given that we cannot quite force NodeList to be an |
| 163 // ElementList as there are valid cases where a NodeList JavaScript object | 214 // ElementList as there are valid cases where a NodeList JavaScript object |
| 164 // contains Node objects that are not Elements. | 215 // contains Node objects that are not Elements. |
| 165 class _FrozenElementList<T extends Element> extends ListBase<T> implements Eleme
ntList { | 216 class _FrozenElementList<T extends Element> extends ListBase<T> implements Eleme
ntList { |
| 166 final List<Node> _nodeList; | 217 final List<Node> _nodeList; |
| 218 // The subset of _nodeList that are Elements. |
| 219 List<Element> _elementList; |
| 167 | 220 |
| 168 _FrozenElementList._wrap(this._nodeList); | 221 _FrozenElementList._wrap(this._nodeList) { |
| 222 _elementList = _nodeList.where((e) => e is Element); |
| 223 } |
| 169 | 224 |
| 170 int get length => _nodeList.length; | 225 int get length => _nodeList.length; |
| 171 | 226 |
| 172 Element operator [](int index) => _nodeList[index]; | 227 Element operator [](int index) => _nodeList[index]; |
| 173 | 228 |
| 174 void operator []=(int index, Element value) { | 229 void operator []=(int index, Element value) { |
| 175 throw new UnsupportedError('Cannot modify list'); | 230 throw new UnsupportedError('Cannot modify list'); |
| 176 } | 231 } |
| 177 | 232 |
| 178 void set length(int newLength) { | 233 void set length(int newLength) { |
| 179 throw new UnsupportedError('Cannot modify list'); | 234 throw new UnsupportedError('Cannot modify list'); |
| 180 } | 235 } |
| 181 | 236 |
| 182 void sort([Comparator<Element> compare]) { | 237 void sort([Comparator<Element> compare]) { |
| 183 throw new UnsupportedError('Cannot sort list'); | 238 throw new UnsupportedError('Cannot sort list'); |
| 184 } | 239 } |
| 185 | 240 |
| 186 Element get first => _nodeList.first; | 241 Element get first => _nodeList.first; |
| 187 | 242 |
| 188 Element get last => _nodeList.last; | 243 Element get last => _nodeList.last; |
| 189 | 244 |
| 190 Element get single => _nodeList.single; | 245 Element get single => _nodeList.single; |
| 191 | 246 |
| 192 CssClassSet get classes => new _MultiElementCssClassSet( | 247 CssClassSet get classes => new _MultiElementCssClassSet(_elementList); |
| 193 _nodeList.where((e) => e is Element)); | |
| 194 | 248 |
| 195 void set classes(Iterable<String> value) { | 249 void set classes(Iterable<String> value) { |
| 196 _nodeList.where((e) => e is Element).forEach((e) => e.classes = value); | 250 _elementList.forEach((e) => e.classes = value); |
| 197 } | 251 } |
| 252 |
| 253 /** |
| 254 * Access this element's content position. |
| 255 * |
| 256 * This returns a rectangle with the dimenions actually available for content |
| 257 * in this element, in pixels, regardless of this element's box-sizing |
| 258 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle |
| 259 * will return the same numerical height if the element is hidden or not. |
| 260 */ |
| 261 CssRect get contentEdge => new _ContentCssListRect(_elementList); |
| 262 |
| 263 /** |
| 264 * Access the dimensions and position of this element's content + padding box. |
| 265 * |
| 266 * This returns a rectangle with the dimenions actually available for content |
| 267 * in this element, in pixels, regardless of this element's box-sizing |
| 268 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle |
| 269 * will return the same numerical height if the element is hidden or not. This |
| 270 * can be used to retrieve jQuery's `innerHeight` value for an element. This |
| 271 * is also a rectangle equalling the dimensions of clientHeight and |
| 272 * clientWidth. |
| 273 */ |
| 274 CssRect get paddingEdge => _elementList.first.paddingEdge; |
| 275 |
| 276 /** |
| 277 * Access the dimensions and position of this element's content + padding + |
| 278 * border box. |
| 279 * |
| 280 * This returns a rectangle with the dimenions actually available for content |
| 281 * in this element, in pixels, regardless of this element's box-sizing |
| 282 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle |
| 283 * will return the same numerical height if the element is hidden or not. This |
| 284 * can be used to retrieve jQuery's `outerHeight` value for an element. |
| 285 */ |
| 286 CssRect get borderEdge => _elementList.first.borderEdge; |
| 287 |
| 288 /** |
| 289 * Access the dimensions and position of this element's content + padding + |
| 290 * border + margin box. |
| 291 * |
| 292 * This returns a rectangle with the dimenions actually available for content |
| 293 * in this element, in pixels, regardless of this element's box-sizing |
| 294 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle |
| 295 * will return the same numerical height if the element is hidden or not. This |
| 296 * can be used to retrieve jQuery's `outerHeight` value for an element. |
| 297 */ |
| 298 CssRect get marginEdge => _elementList.first.marginEdge; |
| 198 } | 299 } |
| 199 | 300 |
| 200 /** | 301 /** |
| 201 * An abstract class, which all HTML elements extend. | 302 * An abstract class, which all HTML elements extend. |
| 202 */ | 303 */ |
| 203 $(ANNOTATIONS)abstract class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 304 $(ANNOTATIONS)abstract class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
| 204 | 305 |
| 205 /** | 306 /** |
| 206 * Creates an HTML element from a valid fragment of HTML. | 307 * Creates an HTML element from a valid fragment of HTML. |
| 207 * | 308 * |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 } else if (JS('bool', '!!#.mozMatchesSelector', this)) { | 719 } else if (JS('bool', '!!#.mozMatchesSelector', this)) { |
| 619 return JS('bool', '#.mozMatchesSelector(#)', this, selectors); | 720 return JS('bool', '#.mozMatchesSelector(#)', this, selectors); |
| 620 } else if (JS('bool', '!!#.msMatchesSelector', this)) { | 721 } else if (JS('bool', '!!#.msMatchesSelector', this)) { |
| 621 return JS('bool', '#.msMatchesSelector(#)', this, selectors); | 722 return JS('bool', '#.msMatchesSelector(#)', this, selectors); |
| 622 } | 723 } |
| 623 throw new UnsupportedError("Not supported on this platform"); | 724 throw new UnsupportedError("Not supported on this platform"); |
| 624 } | 725 } |
| 625 $else | 726 $else |
| 626 $endif | 727 $endif |
| 627 | 728 |
| 729 /** |
| 730 * Access this element's content position. |
| 731 * |
| 732 * This returns a rectangle with the dimenions actually available for content |
| 733 * in this element, in pixels, regardless of this element's box-sizing |
| 734 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle |
| 735 * will return the same numerical height if the element is hidden or not. |
| 736 */ |
| 737 CssRect get contentEdge => new _ContentCssRect(this); |
| 738 |
| 739 /** |
| 740 * Access the dimensions and position of this element's content + padding box. |
| 741 * |
| 742 * This returns a rectangle with the dimenions actually available for content |
| 743 * in this element, in pixels, regardless of this element's box-sizing |
| 744 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle |
| 745 * will return the same numerical height if the element is hidden or not. This |
| 746 * can be used to retrieve jQuery's `innerHeight` value for an element. This |
| 747 * is also a rectangle equalling the dimensions of clientHeight and |
| 748 * clientWidth. |
| 749 */ |
| 750 CssRect get paddingEdge => new _PaddingCssRect(this); |
| 751 |
| 752 /** |
| 753 * Access the dimensions and position of this element's content + padding + |
| 754 * border box. |
| 755 * |
| 756 * This returns a rectangle with the dimenions actually available for content |
| 757 * in this element, in pixels, regardless of this element's box-sizing |
| 758 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle |
| 759 * will return the same numerical height if the element is hidden or not. This |
| 760 * can be used to retrieve jQuery's `outerHeight` value for an element. |
| 761 */ |
| 762 CssRect get borderEdge => new _BorderCssRect(this); |
| 763 |
| 764 /** |
| 765 * Access the dimensions and position of this element's content + padding + |
| 766 * border + margin box. |
| 767 * |
| 768 * This returns a rectangle with the dimenions actually available for content |
| 769 * in this element, in pixels, regardless of this element's box-sizing |
| 770 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle |
| 771 * will return the same numerical height if the element is hidden or not. This |
| 772 * can be used to retrieve jQuery's `outerHeight` value for an element. |
| 773 */ |
| 774 CssRect get marginEdge => new _MarginCssRect(this); |
| 628 $!MEMBERS | 775 $!MEMBERS |
| 629 } | 776 } |
| 630 | 777 |
| 631 final _START_TAG_REGEXP = new RegExp('<(\\w+)'); | 778 final _START_TAG_REGEXP = new RegExp('<(\\w+)'); |
| 632 class _ElementFactoryProvider { | 779 class _ElementFactoryProvider { |
| 633 static const _CUSTOM_PARENT_TAG_MAP = const { | 780 static const _CUSTOM_PARENT_TAG_MAP = const { |
| 634 'body' : 'html', | 781 'body' : 'html', |
| 635 'head' : 'html', | 782 'head' : 'html', |
| 636 'caption' : 'table', | 783 'caption' : 'table', |
| 637 'td': 'tr', | 784 'td': 'tr', |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 const ScrollAlignment._internal(this._value); | 924 const ScrollAlignment._internal(this._value); |
| 778 toString() => 'ScrollAlignment.$_value'; | 925 toString() => 'ScrollAlignment.$_value'; |
| 779 | 926 |
| 780 /// Attempt to align the element to the top of the scrollable area. | 927 /// Attempt to align the element to the top of the scrollable area. |
| 781 static const TOP = const ScrollAlignment._internal('TOP'); | 928 static const TOP = const ScrollAlignment._internal('TOP'); |
| 782 /// Attempt to center the element in the scrollable area. | 929 /// Attempt to center the element in the scrollable area. |
| 783 static const CENTER = const ScrollAlignment._internal('CENTER'); | 930 static const CENTER = const ScrollAlignment._internal('CENTER'); |
| 784 /// Attempt to align the element to the bottom of the scrollable area. | 931 /// Attempt to align the element to the bottom of the scrollable area. |
| 785 static const BOTTOM = const ScrollAlignment._internal('BOTTOM'); | 932 static const BOTTOM = const ScrollAlignment._internal('BOTTOM'); |
| 786 } | 933 } |
| OLD | NEW |