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

Side by Side Diff: sdk/lib/html/dartium/html_dartium.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, 7 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 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 7445 matching lines...) Expand 10 before | Expand all | Expand 10 after
7456 } 7456 }
7457 7457
7458 Element get single { 7458 Element get single {
7459 if (length > 1) throw new StateError("More than one element"); 7459 if (length > 1) throw new StateError("More than one element");
7460 return first; 7460 return first;
7461 } 7461 }
7462 } 7462 }
7463 7463
7464 /** 7464 /**
7465 * An immutable list containing HTML elements. This list contains some 7465 * An immutable list containing HTML elements. This list contains some
7466 * additional methods for ease of CSS manipulation on a group of elements. 7466 * additional methods when compared to regular lists for ease of CSS
7467 * manipulation on a group of elements.
7467 */ 7468 */
7468 abstract class ElementList<T extends Element> extends ListBase<T> { 7469 abstract class ElementList<T extends Element> extends ListBase<T> {
7469 /** 7470 /**
7470 * The union of all CSS classes applied to the elements in this list. 7471 * The union of all CSS classes applied to the elements in this list.
7471 * 7472 *
7472 * This set makes it easy to add, remove or toggle (add if not present, remove 7473 * This set makes it easy to add, remove or toggle (add if not present, remove
7473 * if present) the classes applied to a collection of elements. 7474 * if present) the classes applied to a collection of elements.
7474 * 7475 *
7475 * htmlList.classes.add('selected'); 7476 * htmlList.classes.add('selected');
7476 * htmlList.classes.toggle('isOnline'); 7477 * htmlList.classes.toggle('isOnline');
7477 * htmlList.classes.remove('selected'); 7478 * htmlList.classes.remove('selected');
7478 */ 7479 */
7479 CssClassSet get classes; 7480 CssClassSet get classes;
7480 7481
7481 /** Replace the classes with `value` for every element in this list. */ 7482 /** Replace the classes with `value` for every element in this list. */
7482 set classes(Iterable<String> value); 7483 set classes(Iterable<String> value);
7484
7485 /**
7486 * Access dimensions and position of the first Element's content in this list.
7487 *
7488 * Setting the height or width properties will set the height or width
7489 * property for all elements in the list. This returns a rectangle with the
7490 * dimenions actually available for content
7491 * in this element, in pixels, regardless of this element's box-sizing
7492 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
7493 * will return the same numerical height if the element is hidden or not.
7494 */
7495 CssRect get contentEdge;
7496
7497 /**
7498 * Access dimensions and position of the first Element's content + padding box
7499 * in this list.
7500 *
7501 * This returns a rectangle with the dimenions actually available for content
7502 * in this element, in pixels, regardless of this element's box-sizing
7503 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
7504 * will return the same numerical height if the element is hidden or not. This
7505 * can be used to retrieve jQuery's `innerHeight` value for an element. This
7506 * is also a rectangle equalling the dimensions of clientHeight and
7507 * clientWidth.
7508 */
7509 CssRect get paddingEdge;
7510
7511 /**
7512 * Access dimensions and position of the first Element's content + padding +
7513 * border box in this list.
7514 *
7515 * This returns a rectangle with the dimenions actually available for content
7516 * in this element, in pixels, regardless of this element's box-sizing
7517 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
7518 * will return the same numerical height if the element is hidden or not. This
7519 * can be used to retrieve jQuery's `outerHeight` value for an element.
7520 */
7521 CssRect get borderEdge;
7522
7523 /**
7524 * Access dimensions and position of the first Element's content + padding +
7525 * border + margin box in this list.
7526 *
7527 * This returns a rectangle with the dimenions actually available for content
7528 * in this element, in pixels, regardless of this element's box-sizing
7529 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
7530 * will return the same numerical height if the element is hidden or not. This
7531 * can be used to retrieve jQuery's `outerHeight` value for an element.
7532 */
7533 CssRect get marginEdge;
7483 } 7534 }
7484 7535
7485 // TODO(jacobr): this is an inefficient implementation but it is hard to see 7536 // TODO(jacobr): this is an inefficient implementation but it is hard to see
7486 // a better option given that we cannot quite force NodeList to be an 7537 // a better option given that we cannot quite force NodeList to be an
7487 // ElementList as there are valid cases where a NodeList JavaScript object 7538 // ElementList as there are valid cases where a NodeList JavaScript object
7488 // contains Node objects that are not Elements. 7539 // contains Node objects that are not Elements.
7489 class _FrozenElementList<T extends Element> extends ListBase<T> implements Eleme ntList { 7540 class _FrozenElementList<T extends Element> extends ListBase<T> implements Eleme ntList {
7490 final List<Node> _nodeList; 7541 final List<Node> _nodeList;
7542 // The subset of _nodeList that are Elements.
7543 List<Element> _elementList;
7491 7544
7492 _FrozenElementList._wrap(this._nodeList); 7545 _FrozenElementList._wrap(this._nodeList) {
7546 _elementList = _nodeList.where((e) => e is Element);
7547 }
7493 7548
7494 int get length => _nodeList.length; 7549 int get length => _nodeList.length;
7495 7550
7496 Element operator [](int index) => _nodeList[index]; 7551 Element operator [](int index) => _nodeList[index];
7497 7552
7498 void operator []=(int index, Element value) { 7553 void operator []=(int index, Element value) {
7499 throw new UnsupportedError('Cannot modify list'); 7554 throw new UnsupportedError('Cannot modify list');
7500 } 7555 }
7501 7556
7502 void set length(int newLength) { 7557 void set length(int newLength) {
7503 throw new UnsupportedError('Cannot modify list'); 7558 throw new UnsupportedError('Cannot modify list');
7504 } 7559 }
7505 7560
7506 void sort([Comparator<Element> compare]) { 7561 void sort([Comparator<Element> compare]) {
7507 throw new UnsupportedError('Cannot sort list'); 7562 throw new UnsupportedError('Cannot sort list');
7508 } 7563 }
7509 7564
7510 Element get first => _nodeList.first; 7565 Element get first => _nodeList.first;
7511 7566
7512 Element get last => _nodeList.last; 7567 Element get last => _nodeList.last;
7513 7568
7514 Element get single => _nodeList.single; 7569 Element get single => _nodeList.single;
7515 7570
7516 CssClassSet get classes => new _MultiElementCssClassSet( 7571 CssClassSet get classes => new _MultiElementCssClassSet(_elementList);
7517 _nodeList.where((e) => e is Element));
7518 7572
7519 void set classes(Iterable<String> value) { 7573 void set classes(Iterable<String> value) {
7520 _nodeList.where((e) => e is Element).forEach((e) => e.classes = value); 7574 _elementList.forEach((e) => e.classes = value);
7521 } 7575 }
7576
7577 /**
7578 * Access this element's content position.
7579 *
7580 * This returns a rectangle with the dimenions actually available for content
7581 * in this element, in pixels, regardless of this element's box-sizing
7582 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
7583 * will return the same numerical height if the element is hidden or not.
7584 */
7585 CssRect get contentEdge => new _ContentCssListRect(_elementList);
7586
7587 /**
7588 * Access the dimensions and position of this element's content + padding box.
7589 *
7590 * This returns a rectangle with the dimenions actually available for content
7591 * in this element, in pixels, regardless of this element's box-sizing
7592 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
7593 * will return the same numerical height if the element is hidden or not. This
7594 * can be used to retrieve jQuery's `innerHeight` value for an element. This
7595 * is also a rectangle equalling the dimensions of clientHeight and
7596 * clientWidth.
7597 */
7598 CssRect get paddingEdge => _elementList.first.paddingEdge;
7599
7600 /**
7601 * Access the dimensions and position of this element's content + padding +
7602 * border box.
7603 *
7604 * This returns a rectangle with the dimenions actually available for content
7605 * in this element, in pixels, regardless of this element's box-sizing
7606 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
7607 * will return the same numerical height if the element is hidden or not. This
7608 * can be used to retrieve jQuery's `outerHeight` value for an element.
7609 */
7610 CssRect get borderEdge => _elementList.first.borderEdge;
7611
7612 /**
7613 * Access the dimensions and position of this element's content + padding +
7614 * border + margin box.
7615 *
7616 * This returns a rectangle with the dimenions actually available for content
7617 * in this element, in pixels, regardless of this element's box-sizing
7618 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
7619 * will return the same numerical height if the element is hidden or not. This
7620 * can be used to retrieve jQuery's `outerHeight` value for an element.
7621 */
7622 CssRect get marginEdge => _elementList.first.marginEdge;
7522 } 7623 }
7523 7624
7524 /** 7625 /**
7525 * An abstract class, which all HTML elements extend. 7626 * An abstract class, which all HTML elements extend.
7526 */ 7627 */
7527 @DomName('Element') 7628 @DomName('Element')
7528 abstract class Element extends Node implements ElementTraversal { 7629 abstract class Element extends Node implements ElementTraversal {
7529 7630
7530 /** 7631 /**
7531 * Creates an HTML element from a valid fragment of HTML. 7632 * Creates an HTML element from a valid fragment of HTML.
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
7789 this.$dom_scrollIntoViewIfNeeded(true); 7890 this.$dom_scrollIntoViewIfNeeded(true);
7790 } else { 7891 } else {
7791 this.$dom_scrollIntoViewIfNeeded(); 7892 this.$dom_scrollIntoViewIfNeeded();
7792 } 7893 }
7793 } else { 7894 } else {
7794 this.$dom_scrollIntoView(); 7895 this.$dom_scrollIntoView();
7795 } 7896 }
7796 } 7897 }
7797 7898
7798 7899
7900 /**
7901 * Access this element's content position.
7902 *
7903 * This returns a rectangle with the dimenions actually available for content
7904 * in this element, in pixels, regardless of this element's box-sizing
7905 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
7906 * will return the same numerical height if the element is hidden or not.
7907 */
7908 CssRect get contentEdge => new _ContentCssRect(this);
7909
7910 /**
7911 * Access the dimensions and position of this element's content + padding box.
7912 *
7913 * This returns a rectangle with the dimenions actually available for content
7914 * in this element, in pixels, regardless of this element's box-sizing
7915 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
7916 * will return the same numerical height if the element is hidden or not. This
7917 * can be used to retrieve jQuery's `innerHeight` value for an element. This
7918 * is also a rectangle equalling the dimensions of clientHeight and
7919 * clientWidth.
7920 */
7921 CssRect get paddingEdge => new _PaddingCssRect(this);
7922
7923 /**
7924 * Access the dimensions and position of this element's content + padding +
7925 * border box.
7926 *
7927 * This returns a rectangle with the dimenions actually available for content
7928 * in this element, in pixels, regardless of this element's box-sizing
7929 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
7930 * will return the same numerical height if the element is hidden or not. This
7931 * can be used to retrieve jQuery's `outerHeight` value for an element.
7932 */
7933 CssRect get borderEdge => new _BorderCssRect(this);
7934
7935 /**
7936 * Access the dimensions and position of this element's content + padding +
7937 * border + margin box.
7938 *
7939 * This returns a rectangle with the dimenions actually available for content
7940 * in this element, in pixels, regardless of this element's box-sizing
7941 * property. Unlike [getBoundingClientRect], the dimensions of this rectangle
7942 * will return the same numerical height if the element is hidden or not. This
7943 * can be used to retrieve jQuery's `outerHeight` value for an element.
7944 */
7945 CssRect get marginEdge => new _MarginCssRect(this);
7799 Element.internal() : super.internal(); 7946 Element.internal() : super.internal();
7800 7947
7801 @DomName('Element.abortEvent') 7948 @DomName('Element.abortEvent')
7802 @DocsEditable 7949 @DocsEditable
7803 static const EventStreamProvider<Event> abortEvent = const EventStreamProvider <Event>('abort'); 7950 static const EventStreamProvider<Event> abortEvent = const EventStreamProvider <Event>('abort');
7804 7951
7805 @DomName('Element.beforecopyEvent') 7952 @DomName('Element.beforecopyEvent')
7806 @DocsEditable 7953 @DocsEditable
7807 static const EventStreamProvider<Event> beforeCopyEvent = const EventStreamPro vider<Event>('beforecopy'); 7954 static const EventStreamProvider<Event> beforeCopyEvent = const EventStreamPro vider<Event>('beforecopy');
7808 7955
(...skipping 16506 matching lines...) Expand 10 before | Expand all | Expand 10 after
24315 } 24462 }
24316 } 24463 }
24317 return s; 24464 return s;
24318 } 24465 }
24319 24466
24320 void writeClasses(Set<String> s) { 24467 void writeClasses(Set<String> s) {
24321 List list = new List.from(s); 24468 List list = new List.from(s);
24322 _element.$dom_className = s.join(' '); 24469 _element.$dom_className = s.join(' ');
24323 } 24470 }
24324 } 24471 }
24472 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
24473 // for details. All rights reserved. Use of this source code is governed by a
24474 // BSD-style license that can be found in the LICENSE file.
24475
24476
24477 class _ContentCssRect extends CssRect {
24478
24479 _ContentCssRect(element) : super(element);
24480 int get height => _element.offsetHeight +
24481 _addOrSubtractToBoxModel(CssRect._HEIGHT, 'content');
24482
24483 int get width => _element.offsetWidth +
24484 _addOrSubtractToBoxModel(CssRect._WIDTH, 'content');
24485
24486 /**
24487 * Set the height to `newHeight`.
24488 *
24489 * Values of newHeight that are less than zero are converted to effectively
24490 * setting the height to 0. This is equivalent to the `height`
24491 * function in jQuery and the calculated `height` css value, converted to an
24492 * int in pixels.
24493 */
24494 void set height(Dimension newHeight) {
24495 if (newHeight.value < 0) newHeight = new Dimension.px(0);
24496 _element.style.height = newHeight.toString();
24497 }
24498
24499 /**
24500 * Set the current computed width in pixels of this element.
24501 *
24502 * This is equivalent to the `width` function in jQuery and the calculated
24503 * `width` css value, converted to a dimensionless int in pixels.
24504 */
24505 void set width(Dimension newWidth) {
24506 if (newWidth.value < 0) newWidth = new Dimension.px(0);
24507 _element.style.width = newWidth.toString();
24508 }
24509
24510 int get left() => _element.getBoundingClientRect().left -
24511 _addOrSubtractToBoxModel(['left'], 'content');
24512 int get top() => _element.getBoundingClientRect().top -
24513 _addOrSubtractToBoxModel(['top'], 'content');
24514 }
24515
24516 class _ContentCssListRect extends _ContentCssRect {
24517 List<Element> _elementList;
24518
24519 _ContentCssListRect(elementList) : super(elementList.first) {
24520 _elementList = elementList;
24521 }
24522
24523 /**
24524 * Set the height to `newHeight`.
24525 *
24526 * Values of newHeight that are less than zero are converted to effectively
24527 * setting the height to 0. This is equivalent to the `height`
24528 * function in jQuery and the calculated `height` css value, converted to an
24529 * int in pixels.
24530 */
24531 void set height(Dimension newHeight) {
24532 _elementList.forEach((e) => e.contentEdge.height = newHeight);
24533 }
24534
24535 /**
24536 * Set the current computed width in pixels of this element.
24537 *
24538 * This is equivalent to the `width` function in jQuery and the calculated
24539 * `width` css value, converted to a dimensionless int in pixels.
24540 */
24541 void set width(Dimension newWidth) {
24542 _elementList.forEach((e) => e.contentEdge.width = newWidth);
24543 }
24544 }
24545
24546 class _PaddingCssRect extends CssRect {
24547 _PaddingCssRect(element) : super(element);
24548 int get height => _element.offsetHeight +
24549 _addOrSubtractToBoxModel(CssRect._HEIGHT, 'padding');
24550 int get width => _element.offsetWidth +
24551 _addOrSubtractToBoxModel(CssRect._WIDTH, 'padding');
24552
24553 int get left() => _element.getBoundingClientRect().left -
24554 _addOrSubtractToBoxModel(['left'], 'padding');
24555 int get top() => _element.getBoundingClientRect().top -
24556 _addOrSubtractToBoxModel(['top'], 'padding');
24557 }
24558
24559 class _BorderCssRect extends CssRect {
24560 _BorderCssRect(element) : super(element);
24561 int get height() => _element.offsetHeight;
24562 int get width() => _element.offsetWidth;
24563
24564 int get left() => _element.getBoundingClientRect().left;
24565 int get top() => _element.getBoundingClientRect().top;
24566 }
24567
24568 class _MarginCssRect extends CssRect {
24569 _MarginCssRect(element) : super(element);
24570 int get height() => _element.offsetHeight +
24571 _addOrSubtractToBoxModel(CssRect._HEIGHT, 'margin');
24572 int get width() =>
24573 _element.offsetWidth + _addOrSubtractToBoxModel(CssRect._WIDTH, 'margin');
24574
24575 int get left() => _element.getBoundingClientRect().left -
24576 _addOrSubtractToBoxModel(['left'], 'margin');
24577 int get top() => _element.getBoundingClientRect().top -
24578 _addOrSubtractToBoxModel(['top'], 'margin');
24579 }
24580
24581 /**
24582 * A class for representing CSS dimensions.
24583 *
24584 * In contrast to the more general purpose [Rect] class, this class's values are
24585 * mutable, so one can change the height of an element programmatically.
24586 *
24587 * SPECIAL NOTE: Do _not_ use these methods of setting height for animations, as
24588 * they will trigger a redraw of the layout. For deferred layout options, see
24589 * the LayoutManager.
24590 */
24591 abstract class CssRect extends RectBase implements Rect {
24592 Element _element;
24593
24594 CssRect(this._element);
24595
24596 int get left();
24597
24598 int get top();
24599
24600 /**
24601 * The height of this rectangle.
24602 *
24603 * This is equivalent to the `height` function in jQuery and the calculated
24604 * `height` css value, converted to a dimensionless int in pixels. Unlike
24605 * [getBoundingClientRect], `height` will return the same numerical width if
24606 * the element is hidden or not.
24607 */
24608 int get height();
24609
24610 /**
24611 * The width of this rectangle.
24612 *
24613 * This is equivalent to the `width` function in jQuery and the calculated
24614 * `width` css value, converted to a dimensionless int in pixels. Unlike
24615 * [getBoundingClientRect], `width` will return the same numerical width if
24616 * the element is hidden or not.
24617 */
24618 int get width();
24619
24620 /**
24621 * Set the height to `newHeight`.
24622 *
24623 * Values of newHeight that are less than zero are converted to effectively
24624 * setting the height to 0. Note that only the content height can be set via
24625 * this method.
24626 */
24627 void set height(Dimension newHeight) {
24628 throw new UnsupportedError("Can only set height for content rect.");
24629 }
24630
24631 /**
24632 * Set the current computed width in pixels of this element.
24633 *
24634 * Note that only the content width can be set via this method.
24635 */
24636 void set width(Dimension newWidth) {
24637 throw new UnsupportedError("Can only set width for content rect.");
24638 }
24639
24640 /**
24641 * Return a value that is used to modify the initial height or width
24642 * measurement of an element. Depending on the value (ideally an enum) passed
24643 * to augmentingMeasurement, we may need to add or subtract margin, padding,
24644 * or border values, depending on the measurement we're trying to obtain.
24645 */
24646 int _addOrSubtractToBoxModel(List<String> dimensions,
24647 String augmentingMeasurement) {
24648 // getComputedStyle always returns pixel values (hence, computed), so we're
24649 // always dealing with pixels in this method.
24650 var styles = _element.getComputedStyle();
24651
24652 var val = 0;
24653
24654 for (String measurement in dimensions) {
24655 // The border-box and default box model both exclude margin in the regular
24656 // height/width calculation, so add it if we want it for this measurement.
24657 if (augmentingMeasurement == "margin") {
24658 val += new Dimension.css(styles.getPropertyValue(
24659 '$augmentingMeasurement-$measurement')).value;
24660 }
24661
24662 // The border-box includes padding and border, so remove it if we want
24663 // just the content itself.
24664 if (augmentingMeasurement == 'content') {
24665 val -= new Dimension.css(
24666 styles.getPropertyValue('padding-$measurement')).value;
24667 }
24668
24669 // At this point, we don't wan't to augment with border or margin,
24670 // so remove border.
24671 if (augmentingMeasurement != 'margin') {
24672 val -= new Dimension.css(styles.getPropertyValue(
24673 'border-${measurement}-width')).value;
24674 }
24675 }
24676 return val;
24677 }
24678
24679 final static _HEIGHT = ['top', 'bottom'];
24680 final static _WIDTH = ['right', 'left'];
24681 }
24682
24683 /** Class representing a distance measurement in CSS. */
24684 class Dimension {
24685 num _value;
24686 String _unit;
24687
24688 /** Set this CSS Dimension to a percentage `value`. */
24689 Dimension.percent(this._value) : _unit = '%';
24690
24691 /** Set this CSS Dimension to a pixel `value`. */
24692 Dimension.px(this._value) : _unit = 'px';
24693
24694 /** Set this CSS Dimension to a pica `value`. */
24695 Dimension.pc(this._value) : _unit = 'pc';
24696
24697 /** Set this CSS Dimension to a point `value`. */
24698 Dimension.pt(this._value) : _unit = 'pt';
24699
24700 /** Set this CSS Dimension to an inch `value`. */
24701 Dimension.inch(this._value) : _unit = 'in';
24702
24703 /** Set this CSS Dimension to a centimeter `value`. */
24704 Dimension.cm(this._value) : _unit = 'cm';
24705
24706 /** Set this CSS Dimension to a millimeter `value`. */
24707 Dimension.mm(this._value) : _unit = 'mm';
24708
24709 /**
24710 * Set this CSS Dimension to the specified number of ems.
24711 *
24712 * 1em is equal to the current font size. (So 2ems is equal to double the font
24713 * size). This is useful for producing website layouts that scale nicely with
24714 * the user's desired font size.
24715 */
24716 Dimension.em(this._value) : _unit = 'em';
24717
24718 /**
24719 * Set this CSS Dimension to the specified number of x-heights.
24720 *
24721 * One ex is equal to the the x-height of a font's baseline to its mean line,
24722 * generally the height of the letter "x" in the font, which is usually about
24723 * half the font-size.
24724 */
24725 Dimension.ex(this._value) : _unit = 'ex';
24726
24727 /** Construct a Dimension object from the valid CSS string `cssValue`. */
24728 Dimension.css(String cssValue) {
24729 if (cssValue == '') cssValue = '0px';
24730 if (cssValue.endsWith('%')) {
24731 _unit = '%';
24732 _value = int.parse(cssValue.substring(0, cssValue.length-1));
24733 } else {
24734 _value = int.parse(cssValue.substring(0, cssValue.length - 2));
24735 _unit = cssValue.substring(cssValue.length - 2);
24736 }
24737 }
24738
24739 /** Print out the CSS String representation of this value. */
24740 String toString() {
24741 return '${_value}${_unit}';
24742 }
24743
24744 /** Return a unitless, numerical value of this CSS value. */
24745 num get value => this._value;
24746 }
24325 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 24747 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
24326 // for details. All rights reserved. Use of this source code is governed by a 24748 // for details. All rights reserved. Use of this source code is governed by a
24327 // BSD-style license that can be found in the LICENSE file. 24749 // BSD-style license that can be found in the LICENSE file.
24328 24750
24329 24751
24330 typedef EventListener(Event event); 24752 typedef EventListener(Event event);
24331 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 24753 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
24332 // for details. All rights reserved. Use of this source code is governed by a 24754 // for details. All rights reserved. Use of this source code is governed by a
24333 // BSD-style license that can be found in the LICENSE file. 24755 // BSD-style license that can be found in the LICENSE file.
24334 24756
(...skipping 1589 matching lines...) Expand 10 before | Expand all | Expand 10 after
25924 * Indicates the document and all subresources have been loaded. 26346 * Indicates the document and all subresources have been loaded.
25925 */ 26347 */
25926 static const String COMPLETE = "complete"; 26348 static const String COMPLETE = "complete";
25927 } 26349 }
25928 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 26350 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
25929 // for details. All rights reserved. Use of this source code is governed by a 26351 // for details. All rights reserved. Use of this source code is governed by a
25930 // BSD-style license that can be found in the LICENSE file. 26352 // BSD-style license that can be found in the LICENSE file.
25931 26353
25932 26354
25933 /** 26355 /**
25934 * A class for representing two-dimensional rectangles. 26356 * A base class for representing two-dimensional rectangles. This will hopefully
26357 * be moved merged with the dart:math Rect.
25935 */ 26358 */
25936 class Rect { 26359 // TODO(efortuna): Merge with Math rect after finalizing with Florian.
25937 final num left; 26360 abstract class RectBase {
25938 final num top; 26361 num get left;
25939 final num width; 26362 num get top;
25940 final num height; 26363 num get width;
25941 26364 num get height;
25942 const Rect(this.left, this.top, this.width, this.height);
25943
25944 factory Rect.fromPoints(Point a, Point b) {
25945 var left;
25946 var width;
25947 if (a.x < b.x) {
25948 left = a.x;
25949 width = b.x - left;
25950 } else {
25951 left = b.x;
25952 width = a.x - left;
25953 }
25954 var top;
25955 var height;
25956 if (a.y < b.y) {
25957 top = a.y;
25958 height = b.y - top;
25959 } else {
25960 top = b.y;
25961 height = a.y - top;
25962 }
25963
25964 return new Rect(left, top, width, height);
25965 }
25966 26365
25967 num get right => left + width; 26366 num get right => left + width;
25968 num get bottom => top + height; 26367 num get bottom => top + height;
25969 26368
25970 // NOTE! All code below should be common with Rect. 26369 // NOTE! All code below should be common with Rect.
25971 // TODO: implement with mixins when available.
25972 26370
25973 String toString() { 26371 String toString() {
25974 return '($left, $top, $width, $height)'; 26372 return '($left, $top, $width, $height)';
25975 } 26373 }
25976 26374
25977 bool operator ==(other) { 26375 bool operator ==(other) {
25978 if (other is !Rect) return false; 26376 if (other is !Rect) return false;
25979 return left == other.left && top == other.top && width == other.width && 26377 return left == other.left && top == other.top && width == other.width &&
25980 height == other.height; 26378 height == other.height;
25981 } 26379 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
26052 * Truncates coordinates to integers and returns the result as a new 26450 * Truncates coordinates to integers and returns the result as a new
26053 * rectangle. 26451 * rectangle.
26054 */ 26452 */
26055 Rect toInt() => new Rect(left.toInt(), top.toInt(), width.toInt(), 26453 Rect toInt() => new Rect(left.toInt(), top.toInt(), width.toInt(),
26056 height.toInt()); 26454 height.toInt());
26057 26455
26058 Point get topLeft => new Point(this.left, this.top); 26456 Point get topLeft => new Point(this.left, this.top);
26059 Point get bottomRight => new Point(this.left + this.width, 26457 Point get bottomRight => new Point(this.left + this.width,
26060 this.top + this.height); 26458 this.top + this.height);
26061 } 26459 }
26460
26461
26462
26463 /**
26464 * A class for representing two-dimensional rectangles.
26465 */
26466 class Rect extends RectBase {
26467 final num left;
26468 final num top;
26469 final num width;
26470 final num height;
26471
26472 const Rect(this.left, this.top, this.width, this.height);
26473
26474 factory Rect.fromPoints(Point a, Point b) {
26475 var left;
26476 var width;
26477 if (a.x < b.x) {
26478 left = a.x;
26479 width = b.x - left;
26480 } else {
26481 left = b.x;
26482 width = a.x - left;
26483 }
26484 var top;
26485 var height;
26486 if (a.y < b.y) {
26487 top = a.y;
26488 height = b.y - top;
26489 } else {
26490 top = b.y;
26491 height = a.y - top;
26492 }
26493
26494 return new Rect(left, top, width, height);
26495 }
26496 }
26062 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 26497 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
26063 // for details. All rights reserved. Use of this source code is governed by a 26498 // for details. All rights reserved. Use of this source code is governed by a
26064 // BSD-style license that can be found in the LICENSE file. 26499 // BSD-style license that can be found in the LICENSE file.
26065 26500
26066 26501
26067 /** 26502 /**
26068 * Helper class to implement custom events which wrap DOM events. 26503 * Helper class to implement custom events which wrap DOM events.
26069 */ 26504 */
26070 class _WrappedEvent implements Event { 26505 class _WrappedEvent implements Event {
26071 final Event wrapped; 26506 final Event wrapped;
(...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after
27302 } 27737 }
27303 27738
27304 _send(msg) { 27739 _send(msg) {
27305 _sendToHelperIsolate(msg, _sendPort); 27740 _sendToHelperIsolate(msg, _sendPort);
27306 } 27741 }
27307 } 27742 }
27308 27743
27309 get _pureIsolateTimerFactoryClosure => 27744 get _pureIsolateTimerFactoryClosure =>
27310 ((int milliSeconds, void callback(Timer time), bool repeating) => 27745 ((int milliSeconds, void callback(Timer time), bool repeating) =>
27311 new _PureIsolateTimer(milliSeconds, callback, repeating)); 27746 new _PureIsolateTimer(milliSeconds, callback, repeating));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698