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

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

Issue 19786005: Reapply Box Model convenience classes (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
« no previous file with comments | « no previous file | sdk/lib/html/dartium/html_dartium.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 3502 matching lines...) Expand 10 before | Expand all | Expand 10 after
3513 String get boxShadow => 3513 String get boxShadow =>
3514 getPropertyValue('box-shadow'); 3514 getPropertyValue('box-shadow');
3515 3515
3516 /** Sets the value of "box-shadow" */ 3516 /** Sets the value of "box-shadow" */
3517 void set boxShadow(String value) { 3517 void set boxShadow(String value) {
3518 setProperty('box-shadow', value, ''); 3518 setProperty('box-shadow', value, '');
3519 } 3519 }
3520 3520
3521 /** Gets the value of "box-sizing" */ 3521 /** Gets the value of "box-sizing" */
3522 String get boxSizing => 3522 String get boxSizing =>
3523 getPropertyValue('box-sizing'); 3523 getPropertyValue('${Device.cssPrefix}box-sizing');
3524 3524
3525 /** Sets the value of "box-sizing" */ 3525 /** Sets the value of "box-sizing" */
3526 void set boxSizing(String value) { 3526 void set boxSizing(String value) {
3527 setProperty('box-sizing', value, ''); 3527 setProperty('${Device.cssPrefix}box-sizing', value, '');
3528 } 3528 }
3529 3529
3530 /** Gets the value of "caption-side" */ 3530 /** Gets the value of "caption-side" */
3531 String get captionSide => 3531 String get captionSide =>
3532 getPropertyValue('caption-side'); 3532 getPropertyValue('caption-side');
3533 3533
3534 /** Sets the value of "caption-side" */ 3534 /** Sets the value of "caption-side" */
3535 void set captionSide(String value) { 3535 void set captionSide(String value) {
3536 setProperty('caption-side', value, ''); 3536 setProperty('caption-side', value, '');
3537 } 3537 }
(...skipping 4374 matching lines...) Expand 10 before | Expand all | Expand 10 after
7912 } 7912 }
7913 7913
7914 Element get single { 7914 Element get single {
7915 if (length > 1) throw new StateError("More than one element"); 7915 if (length > 1) throw new StateError("More than one element");
7916 return first; 7916 return first;
7917 } 7917 }
7918 } 7918 }
7919 7919
7920 /** 7920 /**
7921 * An immutable list containing HTML elements. This list contains some 7921 * An immutable list containing HTML elements. This list contains some
7922 * additional methods for ease of CSS manipulation on a group of elements. 7922 * additional methods when compared to regular lists for ease of CSS
7923 * manipulation on a group of elements.
7923 */ 7924 */
7924 abstract class ElementList<T extends Element> extends ListBase<T> { 7925 abstract class ElementList<T extends Element> extends ListBase<T> {
7925 /** 7926 /**
7926 * The union of all CSS classes applied to the elements in this list. 7927 * The union of all CSS classes applied to the elements in this list.
7927 * 7928 *
7928 * This set makes it easy to add, remove or toggle (add if not present, remove 7929 * This set makes it easy to add, remove or toggle (add if not present, remove
7929 * if present) the classes applied to a collection of elements. 7930 * if present) the classes applied to a collection of elements.
7930 * 7931 *
7931 * htmlList.classes.add('selected'); 7932 * htmlList.classes.add('selected');
7932 * htmlList.classes.toggle('isOnline'); 7933 * htmlList.classes.toggle('isOnline');
7933 * htmlList.classes.remove('selected'); 7934 * htmlList.classes.remove('selected');
7934 */ 7935 */
7935 CssClassSet get classes; 7936 CssClassSet get classes;
7936 7937
7937 /** Replace the classes with `value` for every element in this list. */ 7938 /** Replace the classes with `value` for every element in this list. */
7938 set classes(Iterable<String> value); 7939 set classes(Iterable<String> value);
7940
7941 /**
7942 * Access dimensions and position of the Elements in this list.
7943 *
7944 * Setting the height or width properties will set the height or width
7945 * property for all elements in the list. This returns a rectangle with the
7946 * dimenions actually available for content
7947 * in this element, in pixels, regardless of this element's box-sizing
7948 * property. Getting the height or width returns the height or width of the
7949 * first Element in this list.
7950 *
7951 * Unlike [getBoundingClientRect], the dimensions of this rectangle
7952 * will return the same numerical height if the element is hidden or not.
7953 */
7954 @Experimental()
7955 CssRect get contentEdge;
7956
7957 /**
7958 * Access dimensions and position of the first Element's content + padding box
7959 * in this list.
7960 *
7961 * This returns a rectangle with the dimenions actually available for content
7962 * in this element, in pixels, regardless of this element's box-sizing
7963 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
7964 * will return the same numerical height if the element is hidden or not. This
7965 * can be used to retrieve jQuery's `innerHeight` value for an element. This
7966 * is also a rectangle equalling the dimensions of clientHeight and
7967 * clientWidth.
7968 */
7969 @Experimental()
7970 CssRect get paddingEdge;
7971
7972 /**
7973 * Access dimensions and position of the first Element's content + padding +
7974 * border box in this list.
7975 *
7976 * This returns a rectangle with the dimenions actually available for content
7977 * in this element, in pixels, regardless of this element's box-sizing
7978 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
7979 * will return the same numerical height if the element is hidden or not. This
7980 * can be used to retrieve jQuery's `outerHeight` value for an element.
7981 */
7982 @Experimental()
7983 CssRect get borderEdge;
7984
7985 /**
7986 * Access dimensions and position of the first Element's content + padding +
7987 * border + margin box in this list.
7988 *
7989 * This returns a rectangle with the dimenions actually available for content
7990 * in this element, in pixels, regardless of this element's box-sizing
7991 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
7992 * will return the same numerical height if the element is hidden or not. This
7993 * can be used to retrieve jQuery's `outerHeight` value for an element.
7994 */
7995 @Experimental()
7996 CssRect get marginEdge;
7939 } 7997 }
7940 7998
7941 // TODO(jacobr): this is an inefficient implementation but it is hard to see 7999 // TODO(jacobr): this is an inefficient implementation but it is hard to see
7942 // a better option given that we cannot quite force NodeList to be an 8000 // a better option given that we cannot quite force NodeList to be an
7943 // ElementList as there are valid cases where a NodeList JavaScript object 8001 // ElementList as there are valid cases where a NodeList JavaScript object
7944 // contains Node objects that are not Elements. 8002 // contains Node objects that are not Elements.
7945 class _FrozenElementList<T extends Element> extends ListBase<T> implements Eleme ntList { 8003 class _FrozenElementList<T extends Element> extends ListBase<T> implements Eleme ntList {
7946 final List<Node> _nodeList; 8004 final List<Node> _nodeList;
8005 // The subset of _nodeList that are Elements.
8006 List<Element> _elementList;
7947 8007
7948 _FrozenElementList._wrap(this._nodeList); 8008 _FrozenElementList._wrap(this._nodeList) {
8009 _elementList = _nodeList.where((e) => e is Element).toList();
8010 }
7949 8011
7950 int get length => _nodeList.length; 8012 int get length => _nodeList.length;
7951 8013
7952 Element operator [](int index) => _nodeList[index]; 8014 Element operator [](int index) => _nodeList[index];
7953 8015
7954 void operator []=(int index, Element value) { 8016 void operator []=(int index, Element value) {
7955 throw new UnsupportedError('Cannot modify list'); 8017 throw new UnsupportedError('Cannot modify list');
7956 } 8018 }
7957 8019
7958 void set length(int newLength) { 8020 void set length(int newLength) {
7959 throw new UnsupportedError('Cannot modify list'); 8021 throw new UnsupportedError('Cannot modify list');
7960 } 8022 }
7961 8023
7962 void sort([Comparator<Element> compare]) { 8024 void sort([Comparator<Element> compare]) {
7963 throw new UnsupportedError('Cannot sort list'); 8025 throw new UnsupportedError('Cannot sort list');
7964 } 8026 }
7965 8027
7966 Element get first => _nodeList.first; 8028 Element get first => _nodeList.first;
7967 8029
7968 Element get last => _nodeList.last; 8030 Element get last => _nodeList.last;
7969 8031
7970 Element get single => _nodeList.single; 8032 Element get single => _nodeList.single;
7971 8033
7972 CssClassSet get classes => new _MultiElementCssClassSet( 8034 CssClassSet get classes => new _MultiElementCssClassSet(_elementList);
7973 _nodeList.where((e) => e is Element));
7974 8035
7975 void set classes(Iterable<String> value) { 8036 void set classes(Iterable<String> value) {
7976 _nodeList.where((e) => e is Element).forEach((e) => e.classes = value); 8037 _elementList.forEach((e) => e.classes = value);
7977 } 8038 }
8039
8040 CssRect get contentEdge => new _ContentCssListRect(_elementList);
8041
8042 CssRect get paddingEdge => _elementList.first.paddingEdge;
8043
8044 CssRect get borderEdge => _elementList.first.borderEdge;
8045
8046 CssRect get marginEdge => _elementList.first.marginEdge;
7978 } 8047 }
7979 8048
7980 /** 8049 /**
7981 * An abstract class, which all HTML elements extend. 8050 * An abstract class, which all HTML elements extend.
7982 */ 8051 */
7983 @DomName('Element') 8052 @DomName('Element')
7984 abstract class Element extends Node implements ElementTraversal native "Element" { 8053 abstract class Element extends Node implements ElementTraversal native "Element" {
7985 8054
7986 /** 8055 /**
7987 * Creates an HTML element from a valid fragment of HTML. 8056 * Creates an HTML element from a valid fragment of HTML.
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
8669 @Experimental() 8738 @Experimental()
8670 bool get isTemplate => tagName == 'TEMPLATE' || _isAttributeTemplate; 8739 bool get isTemplate => tagName == 'TEMPLATE' || _isAttributeTemplate;
8671 8740
8672 void _ensureTemplate() { 8741 void _ensureTemplate() {
8673 if (!isTemplate) { 8742 if (!isTemplate) {
8674 throw new UnsupportedError('$this is not a template.'); 8743 throw new UnsupportedError('$this is not a template.');
8675 } 8744 }
8676 TemplateElement.decorate(this); 8745 TemplateElement.decorate(this);
8677 } 8746 }
8678 8747
8748 /**
8749 * Access this element's content position.
8750 *
8751 * This returns a rectangle with the dimenions actually available for content
8752 * in this element, in pixels, regardless of this element's box-sizing
8753 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
8754 * will return the same numerical height if the element is hidden or not.
8755 *
8756 * _Important_ _note_: use of this method _will_ perform CSS calculations that
8757 * can trigger a browser reflow. Therefore, use of this property _during_ an
8758 * animation frame is discouraged. See also:
8759 * [Browser Reflow](https://developers.google.com/speed/articles/reflow)
8760 */
8761 @Experimental()
8762 CssRect get contentEdge => new _ContentCssRect(this);
8763
8764 /**
8765 * Access the dimensions and position of this element's content + padding box.
8766 *
8767 * This returns a rectangle with the dimenions actually available for content
8768 * in this element, in pixels, regardless of this element's box-sizing
8769 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
8770 * will return the same numerical height if the element is hidden or not. This
8771 * can be used to retrieve jQuery's
8772 * [innerHeight](http://api.jquery.com/innerHeight/) value for an element.
8773 * This is also a rectangle equalling the dimensions of clientHeight and
8774 * clientWidth.
8775 *
8776 * _Important_ _note_: use of this method _will_ perform CSS calculations that
8777 * can trigger a browser reflow. Therefore, use of this property _during_ an
8778 * animation frame is discouraged. See also:
8779 * [Browser Reflow](https://developers.google.com/speed/articles/reflow)
8780 */
8781 @Experimental()
8782 CssRect get paddingEdge => new _PaddingCssRect(this);
8783
8784 /**
8785 * Access the dimensions and position of this element's content + padding +
8786 * border box.
8787 *
8788 * This returns a rectangle with the dimenions actually available for content
8789 * in this element, in pixels, regardless of this element's box-sizing
8790 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
8791 * will return the same numerical height if the element is hidden or not. This
8792 * can be used to retrieve jQuery's
8793 * [outerHeight](http://api.jquery.com/outerHeight/) value for an element.
8794 *
8795 * _Important_ _note_: use of this method _will_ perform CSS calculations that
8796 * can trigger a browser reflow. Therefore, use of this property _during_ an
8797 * animation frame is discouraged. See also:
8798 * [Browser Reflow](https://developers.google.com/speed/articles/reflow)
8799 */
8800 @Experimental()
8801 CssRect get borderEdge => new _BorderCssRect(this);
8802
8803 /**
8804 * Access the dimensions and position of this element's content + padding +
8805 * border + margin box.
8806 *
8807 * This returns a rectangle with the dimenions actually available for content
8808 * in this element, in pixels, regardless of this element's box-sizing
8809 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
8810 * will return the same numerical height if the element is hidden or not. This
8811 * can be used to retrieve jQuery's
8812 * [outerHeight](http://api.jquery.com/outerHeight/) value for an element.
8813 *
8814 * _Important_ _note_: use of this method will perform CSS calculations that
8815 * can trigger a browser reflow. Therefore, use of this property _during_ an
8816 * animation frame is discouraged. See also:
8817 * [Browser Reflow](https://developers.google.com/speed/articles/reflow)
8818 */
8819 @Experimental()
8820 CssRect get marginEdge => new _MarginCssRect(this);
8679 // To suppress missing implicit constructor warnings. 8821 // To suppress missing implicit constructor warnings.
8680 factory Element._() { throw new UnsupportedError("Not supported"); } 8822 factory Element._() { throw new UnsupportedError("Not supported"); }
8681 8823
8682 @DomName('Element.abortEvent') 8824 @DomName('Element.abortEvent')
8683 @DocsEditable() 8825 @DocsEditable()
8684 static const EventStreamProvider<Event> abortEvent = const EventStreamProvider <Event>('abort'); 8826 static const EventStreamProvider<Event> abortEvent = const EventStreamProvider <Event>('abort');
8685 8827
8686 @DomName('Element.beforecopyEvent') 8828 @DomName('Element.beforecopyEvent')
8687 @DocsEditable() 8829 @DocsEditable()
8688 static const EventStreamProvider<Event> beforeCopyEvent = const EventStreamPro vider<Event>('beforecopy'); 8830 static const EventStreamProvider<Event> beforeCopyEvent = const EventStreamPro vider<Event>('beforecopy');
(...skipping 18007 matching lines...) Expand 10 before | Expand all | Expand 10 after
26696 } 26838 }
26697 } 26839 }
26698 return s; 26840 return s;
26699 } 26841 }
26700 26842
26701 void writeClasses(Set<String> s) { 26843 void writeClasses(Set<String> s) {
26702 List list = new List.from(s); 26844 List list = new List.from(s);
26703 _element.className = s.join(' '); 26845 _element.className = s.join(' ');
26704 } 26846 }
26705 } 26847 }
26848 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
26849 // for details. All rights reserved. Use of this source code is governed by a
26850 // BSD-style license that can be found in the LICENSE file.
26851
26852
26853 /**
26854 * A rectangle representing all the content of the element in the
26855 * [box model](http://www.w3.org/TR/CSS2/box.html).
26856 */
26857 class _ContentCssRect extends CssRect {
26858
26859 _ContentCssRect(element) : super(element);
26860
26861 num get height => _element.offsetHeight +
26862 _addOrSubtractToBoxModel(_HEIGHT, _CONTENT);
26863
26864 num get width => _element.offsetWidth +
26865 _addOrSubtractToBoxModel(_WIDTH, _CONTENT);
26866
26867 /**
26868 * Set the height to `newHeight`.
26869 *
26870 * newHeight can be either a [num] representing the height in pixels or a
26871 * [Dimension] object. Values of newHeight that are less than zero are
26872 * converted to effectively setting the height to 0. This is equivalent to the
26873 * `height` function in jQuery and the calculated `height` CSS value,
26874 * converted to a num in pixels.
26875 */
26876 void set height(newHeight) {
26877 if (newHeight is Dimension) {
26878 if (newHeight.value < 0) newHeight = new Dimension.px(0);
26879 _element.style.height = newHeight.toString();
26880 } else {
26881 if (newHeight < 0) newHeight = 0;
26882 _element.style.height = '${newHeight}px';
26883 }
26884 }
26885
26886 /**
26887 * Set the current computed width in pixels of this element.
26888 *
26889 * newWidth can be either a [num] representing the width in pixels or a
26890 * [Dimension] object. This is equivalent to the `width` function in jQuery
26891 * and the calculated
26892 * `width` CSS value, converted to a dimensionless num in pixels.
26893 */
26894 void set width(newWidth) {
26895 if (newWidth is Dimension) {
26896 if (newWidth.value < 0) newWidth = new Dimension.px(0);
26897 _element.style.width = newWidth.toString();
26898 } else {
26899 if (newWidth < 0) newWidth = 0;
26900 _element.style.width = '${newWidth}px';
26901 }
26902 }
26903
26904 num get left => _element.getBoundingClientRect().left -
26905 _addOrSubtractToBoxModel(['left'], _CONTENT);
26906 num get top => _element.getBoundingClientRect().top -
26907 _addOrSubtractToBoxModel(['top'], _CONTENT);
26908 }
26909
26910 /**
26911 * A list of element content rectangles in the
26912 * [box model](http://www.w3.org/TR/CSS2/box.html).
26913 */
26914 class _ContentCssListRect extends _ContentCssRect {
26915 List<Element> _elementList;
26916
26917 _ContentCssListRect(elementList) : super(elementList.first) {
26918 _elementList = elementList;
26919 }
26920
26921 /**
26922 * Set the height to `newHeight`.
26923 *
26924 * Values of newHeight that are less than zero are converted to effectively
26925 * setting the height to 0. This is equivalent to the `height`
26926 * function in jQuery and the calculated `height` CSS value, converted to a
26927 * num in pixels.
26928 */
26929 void set height(newHeight) {
26930 _elementList.forEach((e) => e.contentEdge.height = newHeight);
26931 }
26932
26933 /**
26934 * Set the current computed width in pixels of this element.
26935 *
26936 * This is equivalent to the `width` function in jQuery and the calculated
26937 * `width` CSS value, converted to a dimensionless num in pixels.
26938 */
26939 void set width(newWidth) {
26940 _elementList.forEach((e) => e.contentEdge.width = newWidth);
26941 }
26942 }
26943
26944 /**
26945 * A rectangle representing the dimensions of the space occupied by the
26946 * element's content + padding in the
26947 * [box model](http://www.w3.org/TR/CSS2/box.html).
26948 */
26949 class _PaddingCssRect extends CssRect {
26950 _PaddingCssRect(element) : super(element);
26951 num get height => _element.offsetHeight +
26952 _addOrSubtractToBoxModel(_HEIGHT, _PADDING);
26953 num get width => _element.offsetWidth +
26954 _addOrSubtractToBoxModel(_WIDTH, _PADDING);
26955
26956 num get left => _element.getBoundingClientRect().left -
26957 _addOrSubtractToBoxModel(['left'], _PADDING);
26958 num get top => _element.getBoundingClientRect().top -
26959 _addOrSubtractToBoxModel(['top'], _PADDING);
26960 }
26961
26962 /**
26963 * A rectangle representing the dimensions of the space occupied by the
26964 * element's content + padding + border in the
26965 * [box model](http://www.w3.org/TR/CSS2/box.html).
26966 */
26967 class _BorderCssRect extends CssRect {
26968 _BorderCssRect(element) : super(element);
26969 num get height => _element.offsetHeight;
26970 num get width => _element.offsetWidth;
26971
26972 num get left => _element.getBoundingClientRect().left;
26973 num get top => _element.getBoundingClientRect().top;
26974 }
26975
26976 /**
26977 * A rectangle representing the dimensions of the space occupied by the
26978 * element's content + padding + border + margin in the
26979 * [box model](http://www.w3.org/TR/CSS2/box.html).
26980 */
26981 class _MarginCssRect extends CssRect {
26982 _MarginCssRect(element) : super(element);
26983 num get height => _element.offsetHeight +
26984 _addOrSubtractToBoxModel(_HEIGHT, _MARGIN);
26985 num get width =>
26986 _element.offsetWidth + _addOrSubtractToBoxModel(_WIDTH, _MARGIN);
26987
26988 num get left => _element.getBoundingClientRect().left -
26989 _addOrSubtractToBoxModel(['left'], _MARGIN);
26990 num get top => _element.getBoundingClientRect().top -
26991 _addOrSubtractToBoxModel(['top'], _MARGIN);
26992 }
26993
26994 /**
26995 * A class for representing CSS dimensions.
26996 *
26997 * In contrast to the more general purpose [Rect] class, this class's values are
26998 * mutable, so one can change the height of an element programmatically.
26999 *
27000 * _Important_ _note_: use of these methods will perform CSS calculations that
27001 * can trigger a browser reflow. Therefore, use of these properties _during_ an
27002 * animation frame is discouraged. See also:
27003 * [Browser Reflow](https://developers.google.com/speed/articles/reflow)
27004 */
27005 abstract class CssRect extends RectBase implements Rect {
27006 Element _element;
27007
27008 CssRect(this._element);
27009
27010 num get left;
27011
27012 num get top;
27013
27014 /**
27015 * The height of this rectangle.
27016 *
27017 * This is equivalent to the `height` function in jQuery and the calculated
27018 * `height` CSS value, converted to a dimensionless num in pixels. Unlike
27019 * [getBoundingClientRect], `height` will return the same numerical width if
27020 * the element is hidden or not.
27021 */
27022 num get height;
27023
27024 /**
27025 * The width of this rectangle.
27026 *
27027 * This is equivalent to the `width` function in jQuery and the calculated
27028 * `width` CSS value, converted to a dimensionless num in pixels. Unlike
27029 * [getBoundingClientRect], `width` will return the same numerical width if
27030 * the element is hidden or not.
27031 */
27032 num get width;
27033
27034 /**
27035 * Set the height to `newHeight`.
27036 *
27037 * newHeight can be either a [num] representing the height in pixels or a
27038 * [Dimension] object. Values of newHeight that are less than zero are
27039 * converted to effectively setting the height to 0. This is equivalent to the
27040 * `height` function in jQuery and the calculated `height` CSS value,
27041 * converted to a num in pixels.
27042 *
27043 * Note that only the content height can actually be set via this method.
27044 */
27045 void set height(newHeight) {
27046 throw new UnsupportedError("Can only set height for content rect.");
27047 }
27048
27049 /**
27050 * Set the current computed width in pixels of this element.
27051 *
27052 * newWidth can be either a [num] representing the width in pixels or a
27053 * [Dimension] object. This is equivalent to the `width` function in jQuery
27054 * and the calculated
27055 * `width` CSS value, converted to a dimensionless num in pixels.
27056 *
27057 * Note that only the content width can be set via this method.
27058 */
27059 void set width(newWidth) {
27060 throw new UnsupportedError("Can only set width for content rect.");
27061 }
27062
27063 /**
27064 * Return a value that is used to modify the initial height or width
27065 * measurement of an element. Depending on the value (ideally an enum) passed
27066 * to augmentingMeasurement, we may need to add or subtract margin, padding,
27067 * or border values, depending on the measurement we're trying to obtain.
27068 */
27069 num _addOrSubtractToBoxModel(List<String> dimensions,
27070 String augmentingMeasurement) {
27071 // getComputedStyle always returns pixel values (hence, computed), so we're
27072 // always dealing with pixels in this method.
27073 var styles = _element.getComputedStyle();
27074
27075 var val = 0;
27076
27077 for (String measurement in dimensions) {
27078 // The border-box and default box model both exclude margin in the regular
27079 // height/width calculation, so add it if we want it for this measurement.
27080 if (augmentingMeasurement == _MARGIN) {
27081 val += new Dimension.css(styles.getPropertyValue(
27082 '$augmentingMeasurement-$measurement')).value;
27083 }
27084
27085 // The border-box includes padding and border, so remove it if we want
27086 // just the content itself.
27087 if (augmentingMeasurement == _CONTENT) {
27088 val -= new Dimension.css(
27089 styles.getPropertyValue('${_PADDING}-$measurement')).value;
27090 }
27091
27092 // At this point, we don't wan't to augment with border or margin,
27093 // so remove border.
27094 if (augmentingMeasurement != _MARGIN) {
27095 val -= new Dimension.css(styles.getPropertyValue(
27096 'border-${measurement}-width')).value;
27097 }
27098 }
27099 return val;
27100 }
27101 }
27102
27103 final _HEIGHT = ['top', 'bottom'];
27104 final _WIDTH = ['right', 'left'];
27105 final _CONTENT = 'content';
27106 final _PADDING = 'padding';
27107 final _MARGIN = 'margin';
27108
27109 /**
27110 * Class representing a
27111 * [length measurement](https://developer.mozilla.org/en-US/docs/Web/CSS/length)
27112 * in CSS.
27113 */
27114 @Experimental()
27115 class Dimension {
27116 num _value;
27117 String _unit;
27118
27119 /** Set this CSS Dimension to a percentage `value`. */
27120 Dimension.percent(this._value) : _unit = '%';
27121
27122 /** Set this CSS Dimension to a pixel `value`. */
27123 Dimension.px(this._value) : _unit = 'px';
27124
27125 /** Set this CSS Dimension to a pica `value`. */
27126 Dimension.pc(this._value) : _unit = 'pc';
27127
27128 /** Set this CSS Dimension to a point `value`. */
27129 Dimension.pt(this._value) : _unit = 'pt';
27130
27131 /** Set this CSS Dimension to an inch `value`. */
27132 Dimension.inch(this._value) : _unit = 'in';
27133
27134 /** Set this CSS Dimension to a centimeter `value`. */
27135 Dimension.cm(this._value) : _unit = 'cm';
27136
27137 /** Set this CSS Dimension to a millimeter `value`. */
27138 Dimension.mm(this._value) : _unit = 'mm';
27139
27140 /**
27141 * Set this CSS Dimension to the specified number of ems.
27142 *
27143 * 1em is equal to the current font size. (So 2ems is equal to double the font
27144 * size). This is useful for producing website layouts that scale nicely with
27145 * the user's desired font size.
27146 */
27147 Dimension.em(this._value) : _unit = 'em';
27148
27149 /**
27150 * Set this CSS Dimension to the specified number of x-heights.
27151 *
27152 * One ex is equal to the the x-height of a font's baseline to its mean line,
27153 * generally the height of the letter "x" in the font, which is usually about
27154 * half the font-size.
27155 */
27156 Dimension.ex(this._value) : _unit = 'ex';
27157
27158 /**
27159 * Construct a Dimension object from the valid, simple CSS string `cssValue`
27160 * that represents a distance measurement.
27161 *
27162 * This constructor is intended as a convenience method for working with
27163 * simplistic CSS length measurements. Non-numeric values such as `auto` or
27164 * `inherit` or invalid CSS will cause this constructor to throw a
27165 * FormatError.
27166 */
27167 Dimension.css(String cssValue) {
27168 if (cssValue == '') cssValue = '0px';
27169 if (cssValue.endsWith('%')) {
27170 _unit = '%';
27171 } else {
27172 _unit = cssValue.substring(cssValue.length - 2);
27173 }
27174 if (cssValue.contains('.')) {
27175 _value = double.parse(cssValue.substring(0,
27176 cssValue.length - _unit.length));
27177 } else {
27178 _value = int.parse(cssValue.substring(0, cssValue.length - _unit.length));
27179 }
27180 }
27181
27182 /** Print out the CSS String representation of this value. */
27183 String toString() {
27184 return '${_value}${_unit}';
27185 }
27186
27187 /** Return a unitless, numerical value of this CSS value. */
27188 num get value => this._value;
27189 }
26706 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 27190 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
26707 // for details. All rights reserved. Use of this source code is governed by a 27191 // for details. All rights reserved. Use of this source code is governed by a
26708 // BSD-style license that can be found in the LICENSE file. 27192 // BSD-style license that can be found in the LICENSE file.
26709 27193
26710 27194
26711 typedef EventListener(Event event); 27195 typedef EventListener(Event event);
26712 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 27196 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
26713 // for details. All rights reserved. Use of this source code is governed by a 27197 // for details. All rights reserved. Use of this source code is governed by a
26714 // BSD-style license that can be found in the LICENSE file. 27198 // BSD-style license that can be found in the LICENSE file.
26715 27199
(...skipping 1497 matching lines...) Expand 10 before | Expand all | Expand 10 after
28213 * Indicates the document and all subresources have been loaded. 28697 * Indicates the document and all subresources have been loaded.
28214 */ 28698 */
28215 static const String COMPLETE = "complete"; 28699 static const String COMPLETE = "complete";
28216 } 28700 }
28217 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 28701 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
28218 // for details. All rights reserved. Use of this source code is governed by a 28702 // for details. All rights reserved. Use of this source code is governed by a
28219 // BSD-style license that can be found in the LICENSE file. 28703 // BSD-style license that can be found in the LICENSE file.
28220 28704
28221 28705
28222 /** 28706 /**
28223 * A class for representing two-dimensional rectangles. 28707 * A base class for representing two-dimensional rectangles. This will hopefully
28708 * be moved merged with the dart:math Rect.
28224 */ 28709 */
28225 class Rect { 28710 // TODO(efortuna): Merge with Math rect after finalizing with Florian.
28226 final num left; 28711 abstract class RectBase {
28227 final num top; 28712 // Not used, but keeps the VM from complaining about Rect having a const
28228 final num width; 28713 // constructor and this one not.
28229 final num height; 28714 const RectBase();
28230 28715
28231 const Rect(this.left, this.top, this.width, this.height); 28716 num get left;
28232 28717 num get top;
28233 factory Rect.fromPoints(Point a, Point b) { 28718 num get width;
28234 var left; 28719 num get height;
28235 var width;
28236 if (a.x < b.x) {
28237 left = a.x;
28238 width = b.x - left;
28239 } else {
28240 left = b.x;
28241 width = a.x - left;
28242 }
28243 var top;
28244 var height;
28245 if (a.y < b.y) {
28246 top = a.y;
28247 height = b.y - top;
28248 } else {
28249 top = b.y;
28250 height = a.y - top;
28251 }
28252
28253 return new Rect(left, top, width, height);
28254 }
28255 28720
28256 num get right => left + width; 28721 num get right => left + width;
28257 num get bottom => top + height; 28722 num get bottom => top + height;
28258 28723
28259 // NOTE! All code below should be common with Rect. 28724 // NOTE! All code below should be common with Rect.
28260 // TODO: implement with mixins when available.
28261 28725
28262 String toString() { 28726 String toString() {
28263 return '($left, $top, $width, $height)'; 28727 return '($left, $top, $width, $height)';
28264 } 28728 }
28265 28729
28266 bool operator ==(other) { 28730 bool operator ==(other) {
28267 if (other is !Rect) return false; 28731 if (other is !Rect) return false;
28268 return left == other.left && top == other.top && width == other.width && 28732 return left == other.left && top == other.top && width == other.width &&
28269 height == other.height; 28733 height == other.height;
28270 } 28734 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
28344 * Truncates coordinates to integers and returns the result as a new 28808 * Truncates coordinates to integers and returns the result as a new
28345 * rectangle. 28809 * rectangle.
28346 */ 28810 */
28347 Rect toInt() => new Rect(left.toInt(), top.toInt(), width.toInt(), 28811 Rect toInt() => new Rect(left.toInt(), top.toInt(), width.toInt(),
28348 height.toInt()); 28812 height.toInt());
28349 28813
28350 Point get topLeft => new Point(this.left, this.top); 28814 Point get topLeft => new Point(this.left, this.top);
28351 Point get bottomRight => new Point(this.left + this.width, 28815 Point get bottomRight => new Point(this.left + this.width,
28352 this.top + this.height); 28816 this.top + this.height);
28353 } 28817 }
28818
28819
28820
28821 /**
28822 * A class for representing two-dimensional rectangles.
28823 *
28824 * This class is distinctive from RectBase in that it enforces that its
28825 * properties are immutable.
28826 */
28827 class Rect extends RectBase {
28828 final num left;
28829 final num top;
28830 final num width;
28831 final num height;
28832
28833 const Rect(this.left, this.top, this.width, this.height): super();
28834
28835 factory Rect.fromPoints(Point a, Point b) {
28836 var left;
28837 var width;
28838 if (a.x < b.x) {
28839 left = a.x;
28840 width = b.x - left;
28841 } else {
28842 left = b.x;
28843 width = a.x - left;
28844 }
28845 var top;
28846 var height;
28847 if (a.y < b.y) {
28848 top = a.y;
28849 height = b.y - top;
28850 } else {
28851 top = b.y;
28852 height = a.y - top;
28853 }
28854
28855 return new Rect(left, top, width, height);
28856 }
28857 }
28354 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 28858 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
28355 // for details. All rights reserved. Use of this source code is governed by a 28859 // for details. All rights reserved. Use of this source code is governed by a
28356 // BSD-style license that can be found in the LICENSE file. 28860 // BSD-style license that can be found in the LICENSE file.
28357 28861
28358 28862
28359 class _HttpRequestUtils { 28863 class _HttpRequestUtils {
28360 28864
28361 // Helper for factory HttpRequest.get 28865 // Helper for factory HttpRequest.get
28362 static HttpRequest get(String url, 28866 static HttpRequest get(String url,
28363 onComplete(HttpRequest request), 28867 onComplete(HttpRequest request),
(...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after
29466 _position = nextPosition; 29970 _position = nextPosition;
29467 return true; 29971 return true;
29468 } 29972 }
29469 _current = null; 29973 _current = null;
29470 _position = _array.length; 29974 _position = _array.length;
29471 return false; 29975 return false;
29472 } 29976 }
29473 29977
29474 T get current => _current; 29978 T get current => _current;
29475 } 29979 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/html/dartium/html_dartium.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698