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

Side by Side Diff: sdk/lib/html/dart2js/html_dart2js.dart

Issue 15507007: Provide cross-browser Rects for box model dimensions for Elements. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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 /// The Dart HTML library. 1 /// The Dart HTML library.
2 /// 2 ///
3 /// For examples, see 3 /// For examples, see
4 /// [Dart HTML5 Samples](https://github.com/dart-lang/dart-html5-samples) 4 /// [Dart HTML5 Samples](https://github.com/dart-lang/dart-html5-samples)
5 /// on Github. 5 /// on Github.
6 library dart.dom.html; 6 library dart.dom.html;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:collection'; 9 import 'dart:collection';
10 import 'dart:_collection-dev' hide Symbol, deprecated; 10 import 'dart:_collection-dev' hide Symbol, deprecated;
(...skipping 7900 matching lines...) Expand 10 before | Expand all | Expand 10 after
7911 } 7911 }
7912 7912
7913 Element get single { 7913 Element get single {
7914 if (length > 1) throw new StateError("More than one element"); 7914 if (length > 1) throw new StateError("More than one element");
7915 return first; 7915 return first;
7916 } 7916 }
7917 } 7917 }
7918 7918
7919 /** 7919 /**
7920 * An immutable list containing HTML elements. This list contains some 7920 * An immutable list containing HTML elements. This list contains some
7921 * additional methods for ease of CSS manipulation on a group of elements. 7921 * additional methods when compared to regular lists for ease of CSS
7922 * manipulation on a group of elements.
7922 */ 7923 */
7923 abstract class ElementList<T extends Element> extends ListBase<T> { 7924 abstract class ElementList<T extends Element> extends ListBase<T> {
7924 /** 7925 /**
7925 * The union of all CSS classes applied to the elements in this list. 7926 * The union of all CSS classes applied to the elements in this list.
7926 * 7927 *
7927 * This set makes it easy to add, remove or toggle (add if not present, remove 7928 * This set makes it easy to add, remove or toggle (add if not present, remove
7928 * if present) the classes applied to a collection of elements. 7929 * if present) the classes applied to a collection of elements.
7929 * 7930 *
7930 * htmlList.classes.add('selected'); 7931 * htmlList.classes.add('selected');
7931 * htmlList.classes.toggle('isOnline'); 7932 * htmlList.classes.toggle('isOnline');
7932 * htmlList.classes.remove('selected'); 7933 * htmlList.classes.remove('selected');
7933 */ 7934 */
7934 CssClassSet get classes; 7935 CssClassSet get classes;
7935 7936
7936 /** Replace the classes with `value` for every element in this list. */ 7937 /** Replace the classes with `value` for every element in this list. */
7937 set classes(Iterable<String> value); 7938 set classes(Iterable<String> value);
7939
7940 /**
7941 * Access dimensions and position of the Elements in this list.
7942 *
7943 * Setting the height or width properties will set the height or width
7944 * property for all elements in the list. This returns a rectangle with the
7945 * dimenions actually available for content
7946 * in this element, in pixels, regardless of this element's box-sizing
7947 * property. Getting the height or width returns the height or width of the
7948 * first Element in this list.
7949 *
7950 * Unlike [getBoundingClientRect], the dimensions of this rectangle
7951 * will return the same numerical height if the element is hidden or not.
7952 */
7953 @Experimental()
7954 CssRect get contentEdge;
7955
7956 /**
7957 * Access dimensions and position of the first Element's content + padding box
7958 * in this list.
7959 *
7960 * This returns a rectangle with the dimenions actually available for content
7961 * in this element, in pixels, regardless of this element's box-sizing
7962 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
7963 * will return the same numerical height if the element is hidden or not. This
7964 * can be used to retrieve jQuery's `innerHeight` value for an element. This
7965 * is also a rectangle equalling the dimensions of clientHeight and
7966 * clientWidth.
7967 */
7968 @Experimental()
7969 CssRect get paddingEdge;
7970
7971 /**
7972 * Access dimensions and position of the first Element's content + padding +
7973 * border box in this list.
7974 *
7975 * This returns a rectangle with the dimenions actually available for content
7976 * in this element, in pixels, regardless of this element's box-sizing
7977 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
7978 * will return the same numerical height if the element is hidden or not. This
7979 * can be used to retrieve jQuery's `outerHeight` value for an element.
7980 */
7981 @Experimental()
7982 CssRect get borderEdge;
7983
7984 /**
7985 * Access dimensions and position of the first Element's content + padding +
7986 * border + margin box in this list.
7987 *
7988 * This returns a rectangle with the dimenions actually available for content
7989 * in this element, in pixels, regardless of this element's box-sizing
7990 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
7991 * will return the same numerical height if the element is hidden or not. This
7992 * can be used to retrieve jQuery's `outerHeight` value for an element.
7993 */
7994 @Experimental()
7995 CssRect get marginEdge;
7938 } 7996 }
7939 7997
7940 // TODO(jacobr): this is an inefficient implementation but it is hard to see 7998 // TODO(jacobr): this is an inefficient implementation but it is hard to see
7941 // a better option given that we cannot quite force NodeList to be an 7999 // a better option given that we cannot quite force NodeList to be an
7942 // ElementList as there are valid cases where a NodeList JavaScript object 8000 // ElementList as there are valid cases where a NodeList JavaScript object
7943 // contains Node objects that are not Elements. 8001 // contains Node objects that are not Elements.
7944 class _FrozenElementList<T extends Element> extends ListBase<T> implements Eleme ntList { 8002 class _FrozenElementList<T extends Element> extends ListBase<T> implements Eleme ntList {
7945 final List<Node> _nodeList; 8003 final List<Node> _nodeList;
8004 // The subset of _nodeList that are Elements.
8005 List<Element> _elementList;
7946 8006
7947 _FrozenElementList._wrap(this._nodeList); 8007 _FrozenElementList._wrap(this._nodeList) {
8008 _elementList = _nodeList.where((e) => e is Element);
8009 }
7948 8010
7949 int get length => _nodeList.length; 8011 int get length => _nodeList.length;
7950 8012
7951 Element operator [](int index) => _nodeList[index]; 8013 Element operator [](int index) => _nodeList[index];
7952 8014
7953 void operator []=(int index, Element value) { 8015 void operator []=(int index, Element value) {
7954 throw new UnsupportedError('Cannot modify list'); 8016 throw new UnsupportedError('Cannot modify list');
7955 } 8017 }
7956 8018
7957 void set length(int newLength) { 8019 void set length(int newLength) {
7958 throw new UnsupportedError('Cannot modify list'); 8020 throw new UnsupportedError('Cannot modify list');
7959 } 8021 }
7960 8022
7961 void sort([Comparator<Element> compare]) { 8023 void sort([Comparator<Element> compare]) {
7962 throw new UnsupportedError('Cannot sort list'); 8024 throw new UnsupportedError('Cannot sort list');
7963 } 8025 }
7964 8026
7965 Element get first => _nodeList.first; 8027 Element get first => _nodeList.first;
7966 8028
7967 Element get last => _nodeList.last; 8029 Element get last => _nodeList.last;
7968 8030
7969 Element get single => _nodeList.single; 8031 Element get single => _nodeList.single;
7970 8032
7971 CssClassSet get classes => new _MultiElementCssClassSet( 8033 CssClassSet get classes => new _MultiElementCssClassSet(_elementList);
7972 _nodeList.where((e) => e is Element));
7973 8034
7974 void set classes(Iterable<String> value) { 8035 void set classes(Iterable<String> value) {
7975 _nodeList.where((e) => e is Element).forEach((e) => e.classes = value); 8036 _elementList.forEach((e) => e.classes = value);
7976 } 8037 }
8038
8039 CssRect get contentEdge => new _ContentCssListRect(_elementList);
8040
8041 CssRect get paddingEdge => _elementList.first.paddingEdge;
8042
8043 CssRect get borderEdge => _elementList.first.borderEdge;
8044
8045 CssRect get marginEdge => _elementList.first.marginEdge;
7977 } 8046 }
7978 8047
7979 /** 8048 /**
7980 * An abstract class, which all HTML elements extend. 8049 * An abstract class, which all HTML elements extend.
7981 */ 8050 */
7982 @DomName('Element') 8051 @DomName('Element')
7983 abstract class Element extends Node implements ElementTraversal native "Element" { 8052 abstract class Element extends Node implements ElementTraversal native "Element" {
7984 8053
7985 /** 8054 /**
7986 * Creates an HTML element from a valid fragment of HTML. 8055 * Creates an HTML element from a valid fragment of HTML.
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
8668 @Experimental() 8737 @Experimental()
8669 bool get isTemplate => tagName == 'TEMPLATE' || _isAttributeTemplate; 8738 bool get isTemplate => tagName == 'TEMPLATE' || _isAttributeTemplate;
8670 8739
8671 void _ensureTemplate() { 8740 void _ensureTemplate() {
8672 if (!isTemplate) { 8741 if (!isTemplate) {
8673 throw new UnsupportedError('$this is not a template.'); 8742 throw new UnsupportedError('$this is not a template.');
8674 } 8743 }
8675 TemplateElement.decorate(this); 8744 TemplateElement.decorate(this);
8676 } 8745 }
8677 8746
8747 /**
8748 * Access this element's content position.
8749 *
8750 * This returns a rectangle with the dimenions actually available for content
8751 * in this element, in pixels, regardless of this element's box-sizing
8752 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
8753 * will return the same numerical height if the element is hidden or not.
8754 *
8755 * Important note: use of this method _will_ perform CSS calculations that can
Jennifer Messerly 2013/07/16 22:03:16 I like this note, but we might want to soften the
Emily Fortuna 2013/07/18 22:45:02 Done.
8756 * trigger a browser reflow. Therefore, use of this property for animation
8757 * calculations is strongly discouraged.
8758 */
8759 @Experimental()
8760 CssRect get contentEdge => new _ContentCssRect(this);
8761
8762 /**
8763 * Access the dimensions and position of this element's content + padding box.
8764 *
8765 * This returns a rectangle with the dimenions actually available for content
8766 * in this element, in pixels, regardless of this element's box-sizing
8767 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
8768 * will return the same numerical height if the element is hidden or not. This
8769 * can be used to retrieve jQuery's `innerHeight` value for an element. This
Jennifer Messerly 2013/07/16 22:03:16 I wonder if we should link the jQuery docs? ...
Emily Fortuna 2013/07/18 22:45:02 Done.
8770 * is also a rectangle equalling the dimensions of clientHeight and
8771 * clientWidth.
8772 *
8773 * Important note: use of this method _will_ perform CSS calculations that can
8774 * trigger a browser reflow. Therefore, use of this property for animation
8775 * calculations is strongly discouraged.
8776 */
8777 @Experimental()
8778 CssRect get paddingEdge => new _PaddingCssRect(this);
8779
8780 /**
8781 * Access the dimensions and position of this element's content + padding +
8782 * border box.
8783 *
8784 * This returns a rectangle with the dimenions actually available for content
8785 * in this element, in pixels, regardless of this element's box-sizing
8786 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
8787 * will return the same numerical height if the element is hidden or not. This
8788 * can be used to retrieve jQuery's `outerHeight` value for an element.
8789 *
8790 * Important note: use of this method _will_ perform CSS calculations that can
8791 * trigger a browser reflow. Therefore, use of this property for animation
8792 * calculations is strongly discouraged.
8793 */
8794 @Experimental()
8795 CssRect get borderEdge => new _BorderCssRect(this);
8796
8797 /**
8798 * Access the dimensions and position of this element's content + padding +
8799 * border + margin box.
8800 *
8801 * This returns a rectangle with the dimenions actually available for content
8802 * in this element, in pixels, regardless of this element's box-sizing
8803 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
8804 * will return the same numerical height if the element is hidden or not. This
8805 * can be used to retrieve jQuery's `outerHeight` value for an element.
8806 *
8807 * Important note: use of this method _will_ perform CSS calculations that can
8808 * trigger a browser reflow. Therefore, use of this property for animation
8809 * calculations is strongly discouraged.
8810 */
8811 @Experimental()
8812 CssRect get marginEdge => new _MarginCssRect(this);
8678 // To suppress missing implicit constructor warnings. 8813 // To suppress missing implicit constructor warnings.
8679 factory Element._() { throw new UnsupportedError("Not supported"); } 8814 factory Element._() { throw new UnsupportedError("Not supported"); }
8680 8815
8681 @DomName('Element.abortEvent') 8816 @DomName('Element.abortEvent')
8682 @DocsEditable() 8817 @DocsEditable()
8683 static const EventStreamProvider<Event> abortEvent = const EventStreamProvider <Event>('abort'); 8818 static const EventStreamProvider<Event> abortEvent = const EventStreamProvider <Event>('abort');
8684 8819
8685 @DomName('Element.beforecopyEvent') 8820 @DomName('Element.beforecopyEvent')
8686 @DocsEditable() 8821 @DocsEditable()
8687 static const EventStreamProvider<Event> beforeCopyEvent = const EventStreamPro vider<Event>('beforecopy'); 8822 static const EventStreamProvider<Event> beforeCopyEvent = const EventStreamPro vider<Event>('beforecopy');
(...skipping 18007 matching lines...) Expand 10 before | Expand all | Expand 10 after
26695 } 26830 }
26696 } 26831 }
26697 return s; 26832 return s;
26698 } 26833 }
26699 26834
26700 void writeClasses(Set<String> s) { 26835 void writeClasses(Set<String> s) {
26701 List list = new List.from(s); 26836 List list = new List.from(s);
26702 _element.className = s.join(' '); 26837 _element.className = s.join(' ');
26703 } 26838 }
26704 } 26839 }
26840 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
26841 // for details. All rights reserved. Use of this source code is governed by a
26842 // BSD-style license that can be found in the LICENSE file.
26843
26844
26845 class _ContentCssRect extends CssRect {
26846
26847 _ContentCssRect(element) : super(element);
Jennifer Messerly 2013/07/16 22:03:16 newline after this?
Emily Fortuna 2013/07/18 22:45:02 Done.
26848 num get height => _element.offsetHeight +
26849 _addOrSubtractToBoxModel(CssRect._HEIGHT, 'content');
26850
26851 num get width => _element.offsetWidth +
26852 _addOrSubtractToBoxModel(CssRect._WIDTH, 'content');
26853
26854 /**
26855 * Set the height to `newHeight`.
26856 *
26857 * Values of newHeight that are less than zero are converted to effectively
26858 * setting the height to 0. This is equivalent to the `height`
26859 * function in jQuery and the calculated `height` css value, converted to a
26860 * num in pixels.
26861 */
26862 void set height(Dimension newHeight) {
26863 if (newHeight.value < 0) newHeight = new Dimension.px(0);
26864 _element.style.height = newHeight.toString();
26865 }
26866
26867 /**
26868 * Set the current computed width in pixels of this element.
26869 *
26870 * This is equivalent to the `width` function in jQuery and the calculated
26871 * `width` css value, converted to a dimensionless num in pixels.
26872 */
26873 void set width(Dimension newWidth) {
26874 if (newWidth.value < 0) newWidth = new Dimension.px(0);
26875 _element.style.width = newWidth.toString();
26876 }
26877
26878 num get left() => _element.getBoundingClientRect().left -
26879 _addOrSubtractToBoxModel(['left'], 'content');
26880 num get top() => _element.getBoundingClientRect().top -
26881 _addOrSubtractToBoxModel(['top'], 'content');
26882 }
26883
26884 class _ContentCssListRect extends _ContentCssRect {
26885 List<Element> _elementList;
26886
26887 _ContentCssListRect(elementList) : super(elementList.first) {
26888 _elementList = elementList;
26889 }
26890
26891 /**
26892 * Set the height to `newHeight`.
26893 *
26894 * Values of newHeight that are less than zero are converted to effectively
26895 * setting the height to 0. This is equivalent to the `height`
26896 * function in jQuery and the calculated `height` css value, converted to a
26897 * num in pixels.
26898 */
26899 void set height(Dimension newHeight) {
26900 _elementList.forEach((e) => e.contentEdge.height = newHeight);
26901 }
26902
26903 /**
26904 * Set the current computed width in pixels of this element.
26905 *
26906 * This is equivalent to the `width` function in jQuery and the calculated
26907 * `width` css value, converted to a dimensionless num in pixels.
26908 */
26909 void set width(Dimension newWidth) {
26910 _elementList.forEach((e) => e.contentEdge.width = newWidth);
26911 }
26912 }
26913
26914 class _PaddingCssRect extends CssRect {
26915 _PaddingCssRect(element) : super(element);
26916 num get height => _element.offsetHeight +
26917 _addOrSubtractToBoxModel(CssRect._HEIGHT, 'padding');
26918 num get width => _element.offsetWidth +
26919 _addOrSubtractToBoxModel(CssRect._WIDTH, 'padding');
26920
26921 num get left() => _element.getBoundingClientRect().left -
26922 _addOrSubtractToBoxModel(['left'], 'padding');
26923 num get top() => _element.getBoundingClientRect().top -
26924 _addOrSubtractToBoxModel(['top'], 'padding');
26925 }
26926
26927 class _BorderCssRect extends CssRect {
26928 _BorderCssRect(element) : super(element);
26929 num get height() => _element.offsetHeight;
26930 num get width() => _element.offsetWidth;
26931
26932 num get left() => _element.getBoundingClientRect().left;
26933 num get top() => _element.getBoundingClientRect().top;
26934 }
26935
26936 class _MarginCssRect extends CssRect {
26937 _MarginCssRect(element) : super(element);
26938 num get height() => _element.offsetHeight +
26939 _addOrSubtractToBoxModel(CssRect._HEIGHT, 'margin');
26940 num get width() =>
26941 _element.offsetWidth + _addOrSubtractToBoxModel(CssRect._WIDTH, 'margin');
26942
26943 num get left() => _element.getBoundingClientRect().left -
26944 _addOrSubtractToBoxModel(['left'], 'margin');
26945 num get top() => _element.getBoundingClientRect().top -
26946 _addOrSubtractToBoxModel(['top'], 'margin');
26947 }
26948
26949 /**
26950 * A class for representing CSS dimensions.
26951 *
26952 * In contrast to the more general purpose [Rect] class, this class's values are
26953 * mutable, so one can change the height of an element programmatically.
26954 *
26955 * SPECIAL NOTE: Do _not_ use these methods of setting or getting dimensions
26956 * for animations, as they will trigger a redraw of the layout.
26957 */
26958 abstract class CssRect extends RectBase implements Rect {
26959 Element _element;
26960
26961 CssRect(this._element);
26962
26963 num get left();
26964
26965 num get top();
26966
26967 /**
26968 * The height of this rectangle.
26969 *
26970 * This is equivalent to the `height` function in jQuery and the calculated
26971 * `height` css value, converted to a dimensionless num in pixels. Unlike
26972 * [getBoundingClientRect], `height` will return the same numerical width if
26973 * the element is hidden or not.
26974 */
26975 num get height();
26976
26977 /**
26978 * The width of this rectangle.
26979 *
26980 * This is equivalent to the `width` function in jQuery and the calculated
26981 * `width` css value, converted to a dimensionless num in pixels. Unlike
26982 * [getBoundingClientRect], `width` will return the same numerical width if
26983 * the element is hidden or not.
26984 */
26985 num get width();
26986
26987 /**
26988 * Set the height to `newHeight`.
26989 *
26990 * Values of newHeight that are less than zero are converted to effectively
26991 * setting the height to 0. Note that only the content height can be set via
26992 * this method.
26993 */
26994 void set height(Dimension newHeight) {
26995 throw new UnsupportedError("Can only set height for content rect.");
26996 }
26997
26998 /**
26999 * Set the current computed width in pixels of this element.
27000 *
27001 * Note that only the content width can be set via this method.
27002 */
27003 void set width(Dimension newWidth) {
27004 throw new UnsupportedError("Can only set width for content rect.");
27005 }
27006
27007 /**
27008 * Return a value that is used to modify the initial height or width
27009 * measurement of an element. Depending on the value (ideally an enum) passed
27010 * to augmentingMeasurement, we may need to add or subtract margin, padding,
27011 * or border values, depending on the measurement we're trying to obtain.
27012 */
27013 num _addOrSubtractToBoxModel(List<String> dimensions,
27014 String augmentingMeasurement) {
27015 // getComputedStyle always returns pixel values (hence, computed), so we're
27016 // always dealing with pixels in this method.
27017 var styles = _element.getComputedStyle();
27018
27019 var val = 0;
27020
27021 for (String measurement in dimensions) {
27022 // The border-box and default box model both exclude margin in the regular
27023 // height/width calculation, so add it if we want it for this measurement.
27024 if (augmentingMeasurement == 'margin') {
27025 val += new Dimension._(styles.getPropertyValue(
27026 '$augmentingMeasurement-$measurement')).value;
27027 }
27028
27029 // The border-box includes padding and border, so remove it if we want
27030 // just the content itself.
27031 if (augmentingMeasurement == 'content') {
27032 val -= new Dimension._(
27033 styles.getPropertyValue('padding-$measurement')).value;
27034 }
27035
27036 // At this point, we don't wan't to augment with border or margin,
27037 // so remove border.
27038 if (augmentingMeasurement != 'margin') {
27039 val -= new Dimension._(styles.getPropertyValue(
27040 'border-${measurement}-width')).value;
27041 }
27042 }
27043 return val;
27044 }
27045
27046 final static _HEIGHT = ['top', 'bottom'];
27047 final static _WIDTH = ['right', 'left'];
27048 }
27049
27050 /** Class representing a distance measurement in CSS. */
27051 @Experimental()
27052 class Dimension {
27053 num _value;
27054 String _unit;
27055
27056 /** Set this CSS Dimension to a percentage `value`. */
27057 Dimension.percent(this._value) : _unit = '%';
27058
27059 /** Set this CSS Dimension to a pixel `value`. */
27060 Dimension.px(this._value) : _unit = 'px';
27061
27062 /** Set this CSS Dimension to a pica `value`. */
27063 Dimension.pc(this._value) : _unit = 'pc';
27064
27065 /** Set this CSS Dimension to a point `value`. */
27066 Dimension.pt(this._value) : _unit = 'pt';
27067
27068 /** Set this CSS Dimension to an inch `value`. */
27069 Dimension.inch(this._value) : _unit = 'in';
27070
27071 /** Set this CSS Dimension to a centimeter `value`. */
27072 Dimension.cm(this._value) : _unit = 'cm';
27073
27074 /** Set this CSS Dimension to a millimeter `value`. */
27075 Dimension.mm(this._value) : _unit = 'mm';
27076
27077 /**
27078 * Set this CSS Dimension to the specified number of ems.
27079 *
27080 * 1em is equal to the current font size. (So 2ems is equal to double the font
27081 * size). This is useful for producing website layouts that scale nicely with
27082 * the user's desired font size.
27083 */
27084 Dimension.em(this._value) : _unit = 'em';
27085
27086 /**
27087 * Set this CSS Dimension to the specified number of x-heights.
27088 *
27089 * One ex is equal to the the x-height of a font's baseline to its mean line,
27090 * generally the height of the letter "x" in the font, which is usually about
27091 * half the font-size.
27092 */
27093 Dimension.ex(this._value) : _unit = 'ex';
27094
27095 /**
27096 * Construct a Dimension object from the CSS string `cssValue`, in pixels.
27097 * This constructor is only called on output from getComputedValue, which we
27098 * know to be pixels.
27099 */
27100 Dimension._(String pixels = '0px') {
27101 if (pixels.contains('.')) {
27102 _value = double.parse(pixels.substring(0, pixels.length - 2));
27103 } else {
27104 _value = int.parse(pixels.substring(0, pixels.length - 2));
27105 }
27106 _unit = 'px';
27107 }
27108
27109 /** Print out the CSS String representation of this value. */
27110 String toString() {
27111 return '${_value}${_unit}';
27112 }
27113
27114 /** Return a unitless, numerical value of this CSS value. */
27115 num get value => this._value;
27116 }
26705 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 27117 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
26706 // for details. All rights reserved. Use of this source code is governed by a 27118 // for details. All rights reserved. Use of this source code is governed by a
26707 // BSD-style license that can be found in the LICENSE file. 27119 // BSD-style license that can be found in the LICENSE file.
26708 27120
26709 27121
26710 typedef EventListener(Event event); 27122 typedef EventListener(Event event);
26711 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 27123 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
26712 // for details. All rights reserved. Use of this source code is governed by a 27124 // for details. All rights reserved. Use of this source code is governed by a
26713 // BSD-style license that can be found in the LICENSE file. 27125 // BSD-style license that can be found in the LICENSE file.
26714 27126
(...skipping 1497 matching lines...) Expand 10 before | Expand all | Expand 10 after
28212 * Indicates the document and all subresources have been loaded. 28624 * Indicates the document and all subresources have been loaded.
28213 */ 28625 */
28214 static const String COMPLETE = "complete"; 28626 static const String COMPLETE = "complete";
28215 } 28627 }
28216 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 28628 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
28217 // for details. All rights reserved. Use of this source code is governed by a 28629 // for details. All rights reserved. Use of this source code is governed by a
28218 // BSD-style license that can be found in the LICENSE file. 28630 // BSD-style license that can be found in the LICENSE file.
28219 28631
28220 28632
28221 /** 28633 /**
28222 * A class for representing two-dimensional rectangles. 28634 * A base class for representing two-dimensional rectangles. This will hopefully
28635 * be moved merged with the dart:math Rect.
28223 */ 28636 */
28224 class Rect { 28637 // TODO(efortuna): Merge with Math rect after finalizing with Florian.
28225 final num left; 28638 abstract class RectBase {
28226 final num top; 28639 num get left;
28227 final num width; 28640 num get top;
28228 final num height; 28641 num get width;
28229 28642 num get height;
28230 const Rect(this.left, this.top, this.width, this.height);
28231
28232 factory Rect.fromPoints(Point a, Point b) {
28233 var left;
28234 var width;
28235 if (a.x < b.x) {
28236 left = a.x;
28237 width = b.x - left;
28238 } else {
28239 left = b.x;
28240 width = a.x - left;
28241 }
28242 var top;
28243 var height;
28244 if (a.y < b.y) {
28245 top = a.y;
28246 height = b.y - top;
28247 } else {
28248 top = b.y;
28249 height = a.y - top;
28250 }
28251
28252 return new Rect(left, top, width, height);
28253 }
28254 28643
28255 num get right => left + width; 28644 num get right => left + width;
28256 num get bottom => top + height; 28645 num get bottom => top + height;
28257 28646
28258 // NOTE! All code below should be common with Rect. 28647 // NOTE! All code below should be common with Rect.
28259 // TODO: implement with mixins when available.
28260 28648
28261 String toString() { 28649 String toString() {
28262 return '($left, $top, $width, $height)'; 28650 return '($left, $top, $width, $height)';
28263 } 28651 }
28264 28652
28265 bool operator ==(other) { 28653 bool operator ==(other) {
28266 if (other is !Rect) return false; 28654 if (other is !Rect) return false;
28267 return left == other.left && top == other.top && width == other.width && 28655 return left == other.left && top == other.top && width == other.width &&
28268 height == other.height; 28656 height == other.height;
28269 } 28657 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
28343 * Truncates coordinates to integers and returns the result as a new 28731 * Truncates coordinates to integers and returns the result as a new
28344 * rectangle. 28732 * rectangle.
28345 */ 28733 */
28346 Rect toInt() => new Rect(left.toInt(), top.toInt(), width.toInt(), 28734 Rect toInt() => new Rect(left.toInt(), top.toInt(), width.toInt(),
28347 height.toInt()); 28735 height.toInt());
28348 28736
28349 Point get topLeft => new Point(this.left, this.top); 28737 Point get topLeft => new Point(this.left, this.top);
28350 Point get bottomRight => new Point(this.left + this.width, 28738 Point get bottomRight => new Point(this.left + this.width,
28351 this.top + this.height); 28739 this.top + this.height);
28352 } 28740 }
28741
28742
28743
28744 /**
28745 * A class for representing two-dimensional rectangles.
28746 */
28747 class Rect extends RectBase {
28748 final num left;
28749 final num top;
28750 final num width;
28751 final num height;
28752
28753 const Rect(this.left, this.top, this.width, this.height);
28754
28755 factory Rect.fromPoints(Point a, Point b) {
28756 var left;
28757 var width;
28758 if (a.x < b.x) {
28759 left = a.x;
28760 width = b.x - left;
28761 } else {
28762 left = b.x;
28763 width = a.x - left;
28764 }
28765 var top;
28766 var height;
28767 if (a.y < b.y) {
28768 top = a.y;
28769 height = b.y - top;
28770 } else {
28771 top = b.y;
28772 height = a.y - top;
28773 }
28774
28775 return new Rect(left, top, width, height);
28776 }
28777 }
28353 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 28778 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
28354 // for details. All rights reserved. Use of this source code is governed by a 28779 // for details. All rights reserved. Use of this source code is governed by a
28355 // BSD-style license that can be found in the LICENSE file. 28780 // BSD-style license that can be found in the LICENSE file.
28356 28781
28357 28782
28358 class _HttpRequestUtils { 28783 class _HttpRequestUtils {
28359 28784
28360 // Helper for factory HttpRequest.get 28785 // Helper for factory HttpRequest.get
28361 static HttpRequest get(String url, 28786 static HttpRequest get(String url,
28362 onComplete(HttpRequest request), 28787 onComplete(HttpRequest request),
(...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after
29465 _position = nextPosition; 29890 _position = nextPosition;
29466 return true; 29891 return true;
29467 } 29892 }
29468 _current = null; 29893 _current = null;
29469 _position = _array.length; 29894 _position = _array.length;
29470 return false; 29895 return false;
29471 } 29896 }
29472 29897
29473 T get current => _current; 29898 T get current => _current;
29474 } 29899 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/html/dartium/html_dartium.dart » ('j') | tests/html/element_dimensions_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698