Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /// The Dart HTML library. | 1 /// The Dart HTML library. |
| 2 library dart.dom.html; | 2 library dart.dom.html; |
| 3 | 3 |
| 4 import 'dart:async'; | 4 import 'dart:async'; |
| 5 import 'dart:collection'; | 5 import 'dart:collection'; |
| 6 import 'dart:_collection-dev'; | 6 import 'dart:_collection-dev'; |
| 7 import 'dart:html_common'; | 7 import 'dart:html_common'; |
| 8 import 'dart:indexed_db'; | 8 import 'dart:indexed_db'; |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 import 'dart:json' as json; | 10 import 'dart:json' as json; |
| (...skipping 7009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7020 } | 7020 } |
| 7021 | 7021 |
| 7022 Element get single { | 7022 Element get single { |
| 7023 if (length > 1) throw new StateError("More than one element"); | 7023 if (length > 1) throw new StateError("More than one element"); |
| 7024 return first; | 7024 return first; |
| 7025 } | 7025 } |
| 7026 } | 7026 } |
| 7027 | 7027 |
| 7028 /** | 7028 /** |
| 7029 * An immutable list containing HTML elements. This list contains some | 7029 * An immutable list containing HTML elements. This list contains some |
| 7030 * additional methods for ease of CSS manipulation on a group of elements. | 7030 * additional methods when compared to regular lists for ease of CSS |
| 7031 * manipulation on a group of elements. | |
| 7031 */ | 7032 */ |
| 7032 abstract class ElementList<T extends Element> extends ListBase<T> { | 7033 abstract class ElementList<T extends Element> extends ListBase<T> { |
| 7033 /** | 7034 /** |
| 7034 * The union of all CSS classes applied to the elements in this list. | 7035 * The union of all CSS classes applied to the elements in this list. |
| 7035 * | 7036 * |
| 7036 * This set makes it easy to add, remove or toggle (add if not present, remove | 7037 * This set makes it easy to add, remove or toggle (add if not present, remove |
| 7037 * if present) the classes applied to a collection of elements. | 7038 * if present) the classes applied to a collection of elements. |
| 7038 * | 7039 * |
| 7039 * htmlList.classes.add('selected'); | 7040 * htmlList.classes.add('selected'); |
| 7040 * htmlList.classes.toggle('isOnline'); | 7041 * htmlList.classes.toggle('isOnline'); |
| 7041 * htmlList.classes.remove('selected'); | 7042 * htmlList.classes.remove('selected'); |
| 7042 */ | 7043 */ |
| 7043 CssClassSet get classes; | 7044 CssClassSet get classes; |
| 7044 | 7045 |
| 7045 /** Replace the classes with `value` for every element in this list. */ | 7046 /** Replace the classes with `value` for every element in this list. */ |
| 7046 set classes(Iterable<String> value); | 7047 set classes(Iterable<String> value); |
| 7048 | |
| 7049 /** | |
| 7050 * Access dimensions and position of the first Element's content in this list. | |
|
blois
2013/05/22 01:18:07
If it's just the first item's, then why have it he
| |
| 7051 * | |
| 7052 * Setting the height or width properties will set the height or width | |
| 7053 * property for all elements in the list. This returns a rectangle with the | |
| 7054 * dimenions actually available for content | |
| 7055 * in this element, in pixels, regardless of this element's box-sizing | |
| 7056 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle | |
| 7057 * will return the same numerical height if the element is hidden or not. | |
| 7058 */ | |
| 7059 CssRect get contentEdge; | |
| 7060 | |
| 7061 /** | |
| 7062 * Access dimensions and position of the first Element's content + padding box | |
| 7063 * in this list. | |
| 7064 * | |
| 7065 * This returns a rectangle with the dimenions actually available for content | |
| 7066 * in this element, in pixels, regardless of this element's box-sizing | |
| 7067 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle | |
| 7068 * will return the same numerical height if the element is hidden or not. This | |
| 7069 * can be used to retrieve jQuery's `innerHeight` value for an element. This | |
| 7070 * is also a rectangle equalling the dimensions of clientHeight and | |
| 7071 * clientWidth. | |
| 7072 */ | |
| 7073 CssRect get paddingEdge; | |
| 7074 | |
| 7075 /** | |
| 7076 * Access dimensions and position of the first Element's content + padding + | |
| 7077 * border box in this list. | |
| 7078 * | |
| 7079 * This returns a rectangle with the dimenions actually available for content | |
| 7080 * in this element, in pixels, regardless of this element's box-sizing | |
| 7081 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle | |
| 7082 * will return the same numerical height if the element is hidden or not. This | |
| 7083 * can be used to retrieve jQuery's `outerHeight` value for an element. | |
| 7084 */ | |
| 7085 CssRect get borderEdge; | |
| 7086 | |
| 7087 /** | |
| 7088 * Access dimensions and position of the first Element's content + padding + | |
| 7089 * border + margin box in this list. | |
| 7090 * | |
| 7091 * This returns a rectangle with the dimenions actually available for content | |
| 7092 * in this element, in pixels, regardless of this element's box-sizing | |
| 7093 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle | |
| 7094 * will return the same numerical height if the element is hidden or not. This | |
| 7095 * can be used to retrieve jQuery's `outerHeight` value for an element. | |
| 7096 */ | |
| 7097 CssRect get marginEdge; | |
| 7047 } | 7098 } |
| 7048 | 7099 |
| 7049 // TODO(jacobr): this is an inefficient implementation but it is hard to see | 7100 // TODO(jacobr): this is an inefficient implementation but it is hard to see |
| 7050 // a better option given that we cannot quite force NodeList to be an | 7101 // a better option given that we cannot quite force NodeList to be an |
| 7051 // ElementList as there are valid cases where a NodeList JavaScript object | 7102 // ElementList as there are valid cases where a NodeList JavaScript object |
| 7052 // contains Node objects that are not Elements. | 7103 // contains Node objects that are not Elements. |
| 7053 class _FrozenElementList<T extends Element> extends ListBase<T> implements Eleme ntList { | 7104 class _FrozenElementList<T extends Element> extends ListBase<T> implements Eleme ntList { |
| 7054 final List<Node> _nodeList; | 7105 final List<Node> _nodeList; |
| 7106 // The subset of _nodeList that are Elements. | |
| 7107 List<Element> _elementList; | |
| 7055 | 7108 |
| 7056 _FrozenElementList._wrap(this._nodeList); | 7109 _FrozenElementList._wrap(this._nodeList) { |
| 7110 _elementList = _nodeList.where((e) => e is Element); | |
| 7111 } | |
| 7057 | 7112 |
| 7058 int get length => _nodeList.length; | 7113 int get length => _nodeList.length; |
| 7059 | 7114 |
| 7060 Element operator [](int index) => _nodeList[index]; | 7115 Element operator [](int index) => _nodeList[index]; |
| 7061 | 7116 |
| 7062 void operator []=(int index, Element value) { | 7117 void operator []=(int index, Element value) { |
| 7063 throw new UnsupportedError('Cannot modify list'); | 7118 throw new UnsupportedError('Cannot modify list'); |
| 7064 } | 7119 } |
| 7065 | 7120 |
| 7066 void set length(int newLength) { | 7121 void set length(int newLength) { |
| 7067 throw new UnsupportedError('Cannot modify list'); | 7122 throw new UnsupportedError('Cannot modify list'); |
| 7068 } | 7123 } |
| 7069 | 7124 |
| 7070 void sort([Comparator<Element> compare]) { | 7125 void sort([Comparator<Element> compare]) { |
| 7071 throw new UnsupportedError('Cannot sort list'); | 7126 throw new UnsupportedError('Cannot sort list'); |
| 7072 } | 7127 } |
| 7073 | 7128 |
| 7074 Element get first => _nodeList.first; | 7129 Element get first => _nodeList.first; |
| 7075 | 7130 |
| 7076 Element get last => _nodeList.last; | 7131 Element get last => _nodeList.last; |
| 7077 | 7132 |
| 7078 Element get single => _nodeList.single; | 7133 Element get single => _nodeList.single; |
| 7079 | 7134 |
| 7080 CssClassSet get classes => new _MultiElementCssClassSet( | 7135 CssClassSet get classes => new _MultiElementCssClassSet(_elementList); |
| 7081 _nodeList.where((e) => e is Element)); | |
| 7082 | 7136 |
| 7083 void set classes(Iterable<String> value) { | 7137 void set classes(Iterable<String> value) { |
| 7084 _nodeList.where((e) => e is Element).forEach((e) => e.classes = value); | 7138 _elementList.forEach((e) => e.classes = value); |
| 7085 } | 7139 } |
| 7140 | |
| 7141 /** | |
| 7142 * Access this element's content position. | |
|
blois
2013/05/22 01:18:07
This just implements the API, right? If so, duplic
| |
| 7143 * | |
| 7144 * This returns a rectangle with the dimenions actually available for content | |
| 7145 * in this element, in pixels, regardless of this element's box-sizing | |
| 7146 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle | |
| 7147 * will return the same numerical height if the element is hidden or not. | |
| 7148 */ | |
| 7149 CssRect get contentEdge => new _ContentCssListRect(_elementList); | |
| 7150 | |
| 7151 /** | |
| 7152 * Access the dimensions and position of this element's content + padding box. | |
| 7153 * | |
| 7154 * This returns a rectangle with the dimenions actually available for content | |
| 7155 * in this element, in pixels, regardless of this element's box-sizing | |
| 7156 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle | |
| 7157 * will return the same numerical height if the element is hidden or not. This | |
| 7158 * can be used to retrieve jQuery's `innerHeight` value for an element. This | |
| 7159 * is also a rectangle equalling the dimensions of clientHeight and | |
| 7160 * clientWidth. | |
| 7161 */ | |
| 7162 CssRect get paddingEdge => _elementList.first.paddingEdge; | |
| 7163 | |
| 7164 /** | |
| 7165 * Access the dimensions and position of this element's content + padding + | |
| 7166 * border box. | |
| 7167 * | |
| 7168 * This returns a rectangle with the dimenions actually available for content | |
| 7169 * in this element, in pixels, regardless of this element's box-sizing | |
| 7170 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle | |
| 7171 * will return the same numerical height if the element is hidden or not. This | |
| 7172 * can be used to retrieve jQuery's `outerHeight` value for an element. | |
| 7173 */ | |
| 7174 CssRect get borderEdge => _elementList.first.borderEdge; | |
| 7175 | |
| 7176 /** | |
| 7177 * Access the dimensions and position of this element's content + padding + | |
| 7178 * border + margin box. | |
| 7179 * | |
| 7180 * This returns a rectangle with the dimenions actually available for content | |
| 7181 * in this element, in pixels, regardless of this element's box-sizing | |
| 7182 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle | |
| 7183 * will return the same numerical height if the element is hidden or not. This | |
| 7184 * can be used to retrieve jQuery's `outerHeight` value for an element. | |
| 7185 */ | |
| 7186 CssRect get marginEdge => _elementList.first.marginEdge; | |
| 7086 } | 7187 } |
| 7087 | 7188 |
| 7088 /** | 7189 /** |
| 7089 * An abstract class, which all HTML elements extend. | 7190 * An abstract class, which all HTML elements extend. |
| 7090 */ | 7191 */ |
| 7091 @DomName('Element') | 7192 @DomName('Element') |
| 7092 abstract class Element extends Node implements ElementTraversal native "Element" { | 7193 abstract class Element extends Node implements ElementTraversal native "Element" { |
| 7093 | 7194 |
| 7094 /** | 7195 /** |
| 7095 * Creates an HTML element from a valid fragment of HTML. | 7196 * Creates an HTML element from a valid fragment of HTML. |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7500 } else if (JS('bool', '!!#.webkitMatchesSelector', this)) { | 7601 } else if (JS('bool', '!!#.webkitMatchesSelector', this)) { |
| 7501 return JS('bool', '#.webkitMatchesSelector(#)', this, selectors); | 7602 return JS('bool', '#.webkitMatchesSelector(#)', this, selectors); |
| 7502 } else if (JS('bool', '!!#.mozMatchesSelector', this)) { | 7603 } else if (JS('bool', '!!#.mozMatchesSelector', this)) { |
| 7503 return JS('bool', '#.mozMatchesSelector(#)', this, selectors); | 7604 return JS('bool', '#.mozMatchesSelector(#)', this, selectors); |
| 7504 } else if (JS('bool', '!!#.msMatchesSelector', this)) { | 7605 } else if (JS('bool', '!!#.msMatchesSelector', this)) { |
| 7505 return JS('bool', '#.msMatchesSelector(#)', this, selectors); | 7606 return JS('bool', '#.msMatchesSelector(#)', this, selectors); |
| 7506 } | 7607 } |
| 7507 throw new UnsupportedError("Not supported on this platform"); | 7608 throw new UnsupportedError("Not supported on this platform"); |
| 7508 } | 7609 } |
| 7509 | 7610 |
| 7611 /** | |
| 7612 * Access this element's content position. | |
| 7613 * | |
| 7614 * This returns a rectangle with the dimenions actually available for content | |
| 7615 * in this element, in pixels, regardless of this element's box-sizing | |
| 7616 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle | |
| 7617 * will return the same numerical height if the element is hidden or not. | |
| 7618 */ | |
| 7619 CssRect get contentEdge => new _ContentCssRect(this); | |
| 7620 | |
| 7621 /** | |
| 7622 * Access the dimensions and position of this element's content + padding box. | |
| 7623 * | |
| 7624 * This returns a rectangle with the dimenions actually available for content | |
| 7625 * in this element, in pixels, regardless of this element's box-sizing | |
| 7626 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle | |
| 7627 * will return the same numerical height if the element is hidden or not. This | |
| 7628 * can be used to retrieve jQuery's `innerHeight` value for an element. This | |
| 7629 * is also a rectangle equalling the dimensions of clientHeight and | |
| 7630 * clientWidth. | |
| 7631 */ | |
| 7632 CssRect get paddingEdge => new _PaddingCssRect(this); | |
| 7633 | |
| 7634 /** | |
| 7635 * Access the dimensions and position of this element's content + padding + | |
| 7636 * border box. | |
| 7637 * | |
| 7638 * This returns a rectangle with the dimenions actually available for content | |
| 7639 * in this element, in pixels, regardless of this element's box-sizing | |
| 7640 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle | |
| 7641 * will return the same numerical height if the element is hidden or not. This | |
| 7642 * can be used to retrieve jQuery's `outerHeight` value for an element. | |
| 7643 */ | |
| 7644 CssRect get borderEdge => new _BorderCssRect(this); | |
| 7645 | |
| 7646 /** | |
| 7647 * Access the dimensions and position of this element's content + padding + | |
| 7648 * border + margin box. | |
| 7649 * | |
| 7650 * This returns a rectangle with the dimenions actually available for content | |
| 7651 * in this element, in pixels, regardless of this element's box-sizing | |
| 7652 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle | |
| 7653 * will return the same numerical height if the element is hidden or not. This | |
| 7654 * can be used to retrieve jQuery's `outerHeight` value for an element. | |
| 7655 */ | |
| 7656 CssRect get marginEdge => new _MarginCssRect(this); | |
| 7510 | 7657 |
| 7511 @DomName('Element.abortEvent') | 7658 @DomName('Element.abortEvent') |
| 7512 @DocsEditable | 7659 @DocsEditable |
| 7513 static const EventStreamProvider<Event> abortEvent = const EventStreamProvider <Event>('abort'); | 7660 static const EventStreamProvider<Event> abortEvent = const EventStreamProvider <Event>('abort'); |
| 7514 | 7661 |
| 7515 @DomName('Element.beforecopyEvent') | 7662 @DomName('Element.beforecopyEvent') |
| 7516 @DocsEditable | 7663 @DocsEditable |
| 7517 static const EventStreamProvider<Event> beforeCopyEvent = const EventStreamPro vider<Event>('beforecopy'); | 7664 static const EventStreamProvider<Event> beforeCopyEvent = const EventStreamPro vider<Event>('beforecopy'); |
| 7518 | 7665 |
| 7519 @DomName('Element.beforecutEvent') | 7666 @DomName('Element.beforecutEvent') |
| (...skipping 15089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 22609 } | 22756 } |
| 22610 } | 22757 } |
| 22611 return s; | 22758 return s; |
| 22612 } | 22759 } |
| 22613 | 22760 |
| 22614 void writeClasses(Set<String> s) { | 22761 void writeClasses(Set<String> s) { |
| 22615 List list = new List.from(s); | 22762 List list = new List.from(s); |
| 22616 _element.$dom_className = s.join(' '); | 22763 _element.$dom_className = s.join(' '); |
| 22617 } | 22764 } |
| 22618 } | 22765 } |
| 22766 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 22767 // for details. All rights reserved. Use of this source code is governed by a | |
| 22768 // BSD-style license that can be found in the LICENSE file. | |
| 22769 | |
| 22770 | |
| 22771 class _ContentCssRect extends CssRect { | |
| 22772 | |
| 22773 _ContentCssRect(element) : super(element); | |
| 22774 int get height => _element.offsetHeight + | |
| 22775 _addOrSubtractToBoxModel(CssRect._HEIGHT, 'content'); | |
| 22776 | |
| 22777 int get width => _element.offsetWidth + | |
| 22778 _addOrSubtractToBoxModel(CssRect._WIDTH, 'content'); | |
| 22779 | |
| 22780 /** | |
| 22781 * Set the height to `newHeight`. | |
| 22782 * | |
| 22783 * Values of newHeight that are less than zero are converted to effectively | |
| 22784 * setting the height to 0. This is equivalent to the `height` | |
| 22785 * function in jQuery and the calculated `height` css value, converted to an | |
| 22786 * int in pixels. | |
| 22787 */ | |
| 22788 void set height(Dimension newHeight) { | |
| 22789 if (newHeight.value < 0) newHeight = new Dimension.px(0); | |
| 22790 _element.style.height = newHeight.toString(); | |
| 22791 } | |
| 22792 | |
| 22793 /** | |
| 22794 * Set the current computed width in pixels of this element. | |
| 22795 * | |
| 22796 * This is equivalent to the `width` function in jQuery and the calculated | |
| 22797 * `width` css value, converted to a dimensionless int in pixels. | |
| 22798 */ | |
| 22799 void set width(Dimension newWidth) { | |
| 22800 if (newWidth.value < 0) newWidth = new Dimension.px(0); | |
| 22801 _element.style.width = newWidth.toString(); | |
| 22802 } | |
| 22803 | |
| 22804 int get left() => _element.getBoundingClientRect().left - | |
| 22805 _addOrSubtractToBoxModel(['left'], 'content'); | |
| 22806 int get top() => _element.getBoundingClientRect().top - | |
| 22807 _addOrSubtractToBoxModel(['top'], 'content'); | |
| 22808 } | |
| 22809 | |
| 22810 class _ContentCssListRect extends _ContentCssRect { | |
| 22811 List<Element> _elementList; | |
| 22812 | |
| 22813 _ContentCssListRect(elementList) : super(elementList.first) { | |
| 22814 _elementList = elementList; | |
| 22815 } | |
| 22816 | |
| 22817 /** | |
| 22818 * Set the height to `newHeight`. | |
| 22819 * | |
| 22820 * Values of newHeight that are less than zero are converted to effectively | |
| 22821 * setting the height to 0. This is equivalent to the `height` | |
| 22822 * function in jQuery and the calculated `height` css value, converted to an | |
| 22823 * int in pixels. | |
| 22824 */ | |
| 22825 void set height(Dimension newHeight) { | |
| 22826 _elementList.forEach((e) => e.contentEdge.height = newHeight); | |
| 22827 } | |
| 22828 | |
| 22829 /** | |
| 22830 * Set the current computed width in pixels of this element. | |
| 22831 * | |
| 22832 * This is equivalent to the `width` function in jQuery and the calculated | |
| 22833 * `width` css value, converted to a dimensionless int in pixels. | |
| 22834 */ | |
| 22835 void set width(Dimension newWidth) { | |
| 22836 _elementList.forEach((e) => e.contentEdge.width = newWidth); | |
| 22837 } | |
| 22838 } | |
| 22839 | |
| 22840 class _PaddingCssRect extends CssRect { | |
| 22841 _PaddingCssRect(element) : super(element); | |
| 22842 int get height => _element.offsetHeight + | |
| 22843 _addOrSubtractToBoxModel(CssRect._HEIGHT, 'padding'); | |
| 22844 int get width => _element.offsetWidth + | |
| 22845 _addOrSubtractToBoxModel(CssRect._WIDTH, 'padding'); | |
| 22846 | |
| 22847 int get left() => _element.getBoundingClientRect().left - | |
| 22848 _addOrSubtractToBoxModel(['left'], 'padding'); | |
| 22849 int get top() => _element.getBoundingClientRect().top - | |
| 22850 _addOrSubtractToBoxModel(['top'], 'padding'); | |
| 22851 } | |
| 22852 | |
| 22853 class _BorderCssRect extends CssRect { | |
| 22854 _BorderCssRect(element) : super(element); | |
| 22855 int get height() => _element.offsetHeight; | |
| 22856 int get width() => _element.offsetWidth; | |
| 22857 | |
| 22858 int get left() => _element.getBoundingClientRect().left; | |
| 22859 int get top() => _element.getBoundingClientRect().top; | |
| 22860 } | |
| 22861 | |
| 22862 class _MarginCssRect extends CssRect { | |
| 22863 _MarginCssRect(element) : super(element); | |
| 22864 int get height() => _element.offsetHeight + | |
| 22865 _addOrSubtractToBoxModel(CssRect._HEIGHT, 'margin'); | |
| 22866 int get width() => | |
| 22867 _element.offsetWidth + _addOrSubtractToBoxModel(CssRect._WIDTH, 'margin'); | |
| 22868 | |
| 22869 int get left() => _element.getBoundingClientRect().left - | |
| 22870 _addOrSubtractToBoxModel(['left'], 'margin'); | |
| 22871 int get top() => _element.getBoundingClientRect().top - | |
| 22872 _addOrSubtractToBoxModel(['top'], 'margin'); | |
| 22873 } | |
| 22874 | |
| 22875 /** | |
| 22876 * A class for representing CSS dimensions. | |
| 22877 * | |
| 22878 * In contrast to the more general purpose [Rect] class, this class's values are | |
|
blois
2013/05/22 01:18:07
Why not a mutable rect interface then?
| |
| 22879 * mutable, so one can change the height of an element programmatically. | |
| 22880 * | |
| 22881 * SPECIAL NOTE: Do _not_ use these methods of setting height for animations, as | |
| 22882 * they will trigger a redraw of the layout. For deferred layout options, see | |
| 22883 * the LayoutManager. | |
| 22884 */ | |
| 22885 abstract class CssRect extends RectBase implements Rect { | |
| 22886 Element _element; | |
| 22887 | |
| 22888 CssRect(this._element); | |
| 22889 | |
| 22890 int get left(); | |
| 22891 | |
| 22892 int get top(); | |
| 22893 | |
| 22894 /** | |
| 22895 * The height of this rectangle. | |
| 22896 * | |
| 22897 * This is equivalent to the `height` function in jQuery and the calculated | |
| 22898 * `height` css value, converted to a dimensionless int in pixels. Unlike | |
| 22899 * [getBoundingClientRect], `height` will return the same numerical width if | |
| 22900 * the element is hidden or not. | |
| 22901 */ | |
| 22902 int get height(); | |
| 22903 | |
| 22904 /** | |
| 22905 * The width of this rectangle. | |
| 22906 * | |
| 22907 * This is equivalent to the `width` function in jQuery and the calculated | |
| 22908 * `width` css value, converted to a dimensionless int in pixels. Unlike | |
| 22909 * [getBoundingClientRect], `width` will return the same numerical width if | |
| 22910 * the element is hidden or not. | |
| 22911 */ | |
| 22912 int get width(); | |
| 22913 | |
| 22914 /** | |
| 22915 * Set the height to `newHeight`. | |
| 22916 * | |
| 22917 * Values of newHeight that are less than zero are converted to effectively | |
| 22918 * setting the height to 0. Note that only the content height can be set via | |
| 22919 * this method. | |
| 22920 */ | |
| 22921 void set height(Dimension newHeight) { | |
| 22922 throw new UnsupportedError("Can only set height for content rect."); | |
| 22923 } | |
| 22924 | |
| 22925 /** | |
| 22926 * Set the current computed width in pixels of this element. | |
| 22927 * | |
| 22928 * Note that only the content width can be set via this method. | |
| 22929 */ | |
| 22930 void set width(Dimension newWidth) { | |
| 22931 throw new UnsupportedError("Can only set width for content rect."); | |
| 22932 } | |
| 22933 | |
| 22934 /** | |
| 22935 * Return a value that is used to modify the initial height or width | |
| 22936 * measurement of an element. Depending on the value (ideally an enum) passed | |
| 22937 * to augmentingMeasurement, we may need to add or subtract margin, padding, | |
| 22938 * or border values, depending on the measurement we're trying to obtain. | |
| 22939 */ | |
| 22940 int _addOrSubtractToBoxModel(List<String> dimensions, | |
| 22941 String augmentingMeasurement) { | |
| 22942 // getComputedStyle always returns pixel values (hence, computed), so we're | |
| 22943 // always dealing with pixels in this method. | |
| 22944 var styles = _element.getComputedStyle(); | |
| 22945 | |
| 22946 var val = 0; | |
| 22947 | |
| 22948 for (String measurement in dimensions) { | |
| 22949 // The border-box and default box model both exclude margin in the regular | |
| 22950 // height/width calculation, so add it if we want it for this measurement. | |
| 22951 if (augmentingMeasurement == "margin") { | |
| 22952 val += new Dimension.css(styles.getPropertyValue( | |
| 22953 '$augmentingMeasurement-$measurement')).value; | |
| 22954 } | |
| 22955 | |
| 22956 // The border-box includes padding and border, so remove it if we want | |
| 22957 // just the content itself. | |
| 22958 if (augmentingMeasurement == 'content') { | |
| 22959 val -= new Dimension.css( | |
| 22960 styles.getPropertyValue('padding-$measurement')).value; | |
| 22961 } | |
| 22962 | |
| 22963 // At this point, we don't wan't to augment with border or margin, | |
| 22964 // so remove border. | |
| 22965 if (augmentingMeasurement != 'margin') { | |
| 22966 val -= new Dimension.css(styles.getPropertyValue( | |
| 22967 'border-${measurement}-width')).value; | |
| 22968 } | |
| 22969 } | |
| 22970 return val; | |
| 22971 } | |
| 22972 | |
| 22973 final static _HEIGHT = ['top', 'bottom']; | |
| 22974 final static _WIDTH = ['right', 'left']; | |
| 22975 } | |
| 22976 | |
| 22977 /** Class representing a distance measurement in CSS. */ | |
| 22978 class Dimension { | |
| 22979 num _value; | |
| 22980 String _unit; | |
| 22981 | |
| 22982 /** Set this CSS Dimension to a percentage `value`. */ | |
| 22983 Dimension.percent(this._value) : _unit = '%'; | |
| 22984 | |
| 22985 /** Set this CSS Dimension to a pixel `value`. */ | |
| 22986 Dimension.px(this._value) : _unit = 'px'; | |
| 22987 | |
| 22988 /** Set this CSS Dimension to a pica `value`. */ | |
| 22989 Dimension.pc(this._value) : _unit = 'pc'; | |
| 22990 | |
| 22991 /** Set this CSS Dimension to a point `value`. */ | |
| 22992 Dimension.pt(this._value) : _unit = 'pt'; | |
| 22993 | |
| 22994 /** Set this CSS Dimension to an inch `value`. */ | |
| 22995 Dimension.inch(this._value) : _unit = 'in'; | |
| 22996 | |
| 22997 /** Set this CSS Dimension to a centimeter `value`. */ | |
| 22998 Dimension.cm(this._value) : _unit = 'cm'; | |
| 22999 | |
| 23000 /** Set this CSS Dimension to a millimeter `value`. */ | |
| 23001 Dimension.mm(this._value) : _unit = 'mm'; | |
| 23002 | |
| 23003 /** | |
| 23004 * Set this CSS Dimension to the specified number of ems. | |
| 23005 * | |
| 23006 * 1em is equal to the current font size. (So 2ems is equal to double the font | |
| 23007 * size). This is useful for producing website layouts that scale nicely with | |
| 23008 * the user's desired font size. | |
| 23009 */ | |
| 23010 Dimension.em(this._value) : _unit = 'em'; | |
| 23011 | |
| 23012 /** | |
| 23013 * Set this CSS Dimension to the specified number of x-heights. | |
| 23014 * | |
| 23015 * One ex is equal to the the x-height of a font's baseline to its mean line, | |
| 23016 * generally the height of the letter "x" in the font, which is usually about | |
| 23017 * half the font-size. | |
| 23018 */ | |
| 23019 Dimension.ex(this._value) : _unit = 'ex'; | |
| 23020 | |
| 23021 /** Construct a Dimension object from the valid CSS string `cssValue`. */ | |
| 23022 Dimension.css(String cssValue) { | |
| 23023 if (cssValue == '') cssValue = '0px'; | |
| 23024 if (cssValue.endsWith('%')) { | |
| 23025 _unit = '%'; | |
| 23026 _value = int.parse(cssValue.substring(0, cssValue.length-1)); | |
| 23027 } else { | |
| 23028 _value = int.parse(cssValue.substring(0, cssValue.length - 2)); | |
| 23029 _unit = cssValue.substring(cssValue.length - 2); | |
| 23030 } | |
| 23031 } | |
| 23032 | |
| 23033 /** Print out the CSS String representation of this value. */ | |
| 23034 String toString() { | |
| 23035 return '${_value}${_unit}'; | |
| 23036 } | |
| 23037 | |
| 23038 /** Return a unitless, numerical value of this CSS value. */ | |
| 23039 num get value => this._value; | |
| 23040 } | |
| 22619 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 23041 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 22620 // for details. All rights reserved. Use of this source code is governed by a | 23042 // for details. All rights reserved. Use of this source code is governed by a |
| 22621 // BSD-style license that can be found in the LICENSE file. | 23043 // BSD-style license that can be found in the LICENSE file. |
| 22622 | 23044 |
| 22623 | 23045 |
| 22624 typedef EventListener(Event event); | 23046 typedef EventListener(Event event); |
| 22625 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 23047 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 22626 // for details. All rights reserved. Use of this source code is governed by a | 23048 // for details. All rights reserved. Use of this source code is governed by a |
| 22627 // BSD-style license that can be found in the LICENSE file. | 23049 // BSD-style license that can be found in the LICENSE file. |
| 22628 | 23050 |
| (...skipping 1589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 24218 * Indicates the document and all subresources have been loaded. | 24640 * Indicates the document and all subresources have been loaded. |
| 24219 */ | 24641 */ |
| 24220 static const String COMPLETE = "complete"; | 24642 static const String COMPLETE = "complete"; |
| 24221 } | 24643 } |
| 24222 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 24644 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 24223 // for details. All rights reserved. Use of this source code is governed by a | 24645 // for details. All rights reserved. Use of this source code is governed by a |
| 24224 // BSD-style license that can be found in the LICENSE file. | 24646 // BSD-style license that can be found in the LICENSE file. |
| 24225 | 24647 |
| 24226 | 24648 |
| 24227 /** | 24649 /** |
| 24228 * A class for representing two-dimensional rectangles. | 24650 * A base class for representing two-dimensional rectangles. This will hopefully |
| 24651 * be moved merged with the dart:math Rect. | |
| 24229 */ | 24652 */ |
| 24230 class Rect { | 24653 // TODO(efortuna): Merge with Math rect after finalizing with Florian. |
| 24231 final num left; | 24654 abstract class RectBase { |
| 24232 final num top; | 24655 num get left; |
| 24233 final num width; | 24656 num get top; |
| 24234 final num height; | 24657 num get width; |
| 24235 | 24658 num get height; |
| 24236 const Rect(this.left, this.top, this.width, this.height); | |
| 24237 | |
| 24238 factory Rect.fromPoints(Point a, Point b) { | |
| 24239 var left; | |
| 24240 var width; | |
| 24241 if (a.x < b.x) { | |
| 24242 left = a.x; | |
| 24243 width = b.x - left; | |
| 24244 } else { | |
| 24245 left = b.x; | |
| 24246 width = a.x - left; | |
| 24247 } | |
| 24248 var top; | |
| 24249 var height; | |
| 24250 if (a.y < b.y) { | |
| 24251 top = a.y; | |
| 24252 height = b.y - top; | |
| 24253 } else { | |
| 24254 top = b.y; | |
| 24255 height = a.y - top; | |
| 24256 } | |
| 24257 | |
| 24258 return new Rect(left, top, width, height); | |
| 24259 } | |
| 24260 | 24659 |
| 24261 num get right => left + width; | 24660 num get right => left + width; |
| 24262 num get bottom => top + height; | 24661 num get bottom => top + height; |
| 24263 | 24662 |
| 24264 // NOTE! All code below should be common with Rect. | 24663 // NOTE! All code below should be common with Rect. |
| 24265 // TODO: implement with mixins when available. | |
| 24266 | 24664 |
| 24267 String toString() { | 24665 String toString() { |
| 24268 return '($left, $top, $width, $height)'; | 24666 return '($left, $top, $width, $height)'; |
| 24269 } | 24667 } |
| 24270 | 24668 |
| 24271 bool operator ==(other) { | 24669 bool operator ==(other) { |
| 24272 if (other is !Rect) return false; | 24670 if (other is !Rect) return false; |
| 24273 return left == other.left && top == other.top && width == other.width && | 24671 return left == other.left && top == other.top && width == other.width && |
| 24274 height == other.height; | 24672 height == other.height; |
| 24275 } | 24673 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 24346 * Truncates coordinates to integers and returns the result as a new | 24744 * Truncates coordinates to integers and returns the result as a new |
| 24347 * rectangle. | 24745 * rectangle. |
| 24348 */ | 24746 */ |
| 24349 Rect toInt() => new Rect(left.toInt(), top.toInt(), width.toInt(), | 24747 Rect toInt() => new Rect(left.toInt(), top.toInt(), width.toInt(), |
| 24350 height.toInt()); | 24748 height.toInt()); |
| 24351 | 24749 |
| 24352 Point get topLeft => new Point(this.left, this.top); | 24750 Point get topLeft => new Point(this.left, this.top); |
| 24353 Point get bottomRight => new Point(this.left + this.width, | 24751 Point get bottomRight => new Point(this.left + this.width, |
| 24354 this.top + this.height); | 24752 this.top + this.height); |
| 24355 } | 24753 } |
| 24754 | |
| 24755 | |
| 24756 | |
| 24757 /** | |
| 24758 * A class for representing two-dimensional rectangles. | |
| 24759 */ | |
| 24760 class Rect extends RectBase { | |
| 24761 final num left; | |
| 24762 final num top; | |
| 24763 final num width; | |
| 24764 final num height; | |
| 24765 | |
| 24766 const Rect(this.left, this.top, this.width, this.height); | |
| 24767 | |
| 24768 factory Rect.fromPoints(Point a, Point b) { | |
| 24769 var left; | |
| 24770 var width; | |
| 24771 if (a.x < b.x) { | |
| 24772 left = a.x; | |
| 24773 width = b.x - left; | |
| 24774 } else { | |
| 24775 left = b.x; | |
| 24776 width = a.x - left; | |
| 24777 } | |
| 24778 var top; | |
| 24779 var height; | |
| 24780 if (a.y < b.y) { | |
| 24781 top = a.y; | |
| 24782 height = b.y - top; | |
| 24783 } else { | |
| 24784 top = b.y; | |
| 24785 height = a.y - top; | |
| 24786 } | |
| 24787 | |
| 24788 return new Rect(left, top, width, height); | |
| 24789 } | |
| 24790 } | |
| 24356 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 24791 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 24357 // for details. All rights reserved. Use of this source code is governed by a | 24792 // for details. All rights reserved. Use of this source code is governed by a |
| 24358 // BSD-style license that can be found in the LICENSE file. | 24793 // BSD-style license that can be found in the LICENSE file. |
| 24359 | 24794 |
| 24360 | 24795 |
| 24361 class _HttpRequestUtils { | 24796 class _HttpRequestUtils { |
| 24362 | 24797 |
| 24363 // Helper for factory HttpRequest.get | 24798 // Helper for factory HttpRequest.get |
| 24364 static HttpRequest get(String url, | 24799 static HttpRequest get(String url, |
| 24365 onComplete(HttpRequest request), | 24800 onComplete(HttpRequest request), |
| (...skipping 1207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 25573 _position = nextPosition; | 26008 _position = nextPosition; |
| 25574 return true; | 26009 return true; |
| 25575 } | 26010 } |
| 25576 _current = null; | 26011 _current = null; |
| 25577 _position = _array.length; | 26012 _position = _array.length; |
| 25578 return false; | 26013 return false; |
| 25579 } | 26014 } |
| 25580 | 26015 |
| 25581 T get current => _current; | 26016 T get current => _current; |
| 25582 } | 26017 } |
| OLD | NEW |