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

Unified Diff: sdk/lib/html/dartium/html_dartium.dart

Issue 25785003: "Reverting 28184" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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:
Download patch
« no previous file with comments | « sdk/lib/html/dart2js/html_dart2js.dart ('k') | sdk/lib/html/html_common/html_common.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/html/dartium/html_dartium.dart
diff --git a/sdk/lib/html/dartium/html_dartium.dart b/sdk/lib/html/dartium/html_dartium.dart
index 4c6b7ecc4f8278403d51fe0aabe95fd01d1b877a..c9879ea63b422888fb7d1ebf09c5a637906aa4c6 100644
--- a/sdk/lib/html/dartium/html_dartium.dart
+++ b/sdk/lib/html/dartium/html_dartium.dart
@@ -51,8 +51,6 @@ import 'dart:web_audio' as web_audio;
// native code for custom elements.
// Not actually used, but imported since dart:html can generate these objects.
-export 'dart:math' show Rectangle, RectangleBase, Point;
-
@@ -1924,19 +1922,19 @@ class CanvasRenderingContext2D extends CanvasRenderingContext {
* img.height = 100;
*
* // Scale the image to 20x20.
- * ctx.drawImageToRect(img, new Rectangle(50, 50, 20, 20));
+ * ctx.drawImageToRect(img, new Rect(50, 50, 20, 20));
*
* VideoElement video = document.query('video');
* video.width = 100;
* video.height = 100;
* // Take the middle 20x20 pixels from the video and stretch them.
- * ctx.drawImageToRect(video, new Rectangle(50, 50, 100, 100),
- * sourceRect: new Rectangle(40, 40, 20, 20));
+ * ctx.drawImageToRect(video, new Rect(50, 50, 100, 100),
+ * sourceRect: new Rect(40, 40, 20, 20));
*
* // Draw the top 100x20 pixels from the otherCanvas.
* CanvasElement otherCanvas = document.query('canvas');
- * ctx.drawImageToRect(otherCanvas, new Rectangle(0, 0, 100, 20),
- * sourceRect: new Rectangle(0, 0, 100, 20));
+ * ctx.drawImageToRect(otherCanvas, new Rect(0, 0, 100, 20),
+ * sourceRect: new Rect(0, 0, 100, 20));
*
* See also:
*
@@ -1946,8 +1944,8 @@ class CanvasRenderingContext2D extends CanvasRenderingContext {
* from the WHATWG.
*/
@DomName('CanvasRenderingContext2D.drawImage')
- void drawImageToRect(CanvasImageSource source, Rectangle destRect,
- {Rectangle sourceRect}) {
+ void drawImageToRect(CanvasImageSource source, Rect destRect,
+ {Rect sourceRect}) {
if (sourceRect == null) {
_drawImage(source,
destRect.left,
@@ -9790,14 +9788,12 @@ abstract class Element extends Node implements ParentNode, ChildNode {
/**
* Gets the position of this element relative to the client area of the page.
*/
- Rectangle get client => new Rectangle(clientLeft, clientTop, clientWidth,
- clientHeight);
+ Rect get client => new Rect(clientLeft, clientTop, clientWidth, clientHeight);
/**
* Gets the offset of this element relative to its offsetParent.
*/
- Rectangle get offset => new Rectangle(offsetLeft, offsetTop, offsetWidth,
- offsetHeight);
+ Rect get offset => new Rect(offsetLeft, offsetTop, offsetWidth, offsetHeight);
/**
* Adds the specified text after the last child of this element.
@@ -10731,11 +10727,11 @@ abstract class Element extends Node implements ParentNode, ChildNode {
@DomName('Element.getBoundingClientRect')
@DocsEditable()
- Rectangle getBoundingClientRect() native "Element_getBoundingClientRect_Callback";
+ Rect getBoundingClientRect() native "Element_getBoundingClientRect_Callback";
@DomName('Element.getClientRects')
@DocsEditable()
- List<Rectangle> getClientRects() native "Element_getClientRects_Callback";
+ List<Rect> getClientRects() native "Element_getClientRects_Callback";
@DomName('Element.getDestinationInsertionPoints')
@DocsEditable()
@@ -21559,11 +21555,11 @@ class Range extends NativeFieldWrapperClass1 {
@DomName('Range.getBoundingClientRect')
@DocsEditable()
- Rectangle getBoundingClientRect() native "Range_getBoundingClientRect_Callback";
+ Rect getBoundingClientRect() native "Range_getBoundingClientRect_Callback";
@DomName('Range.getClientRects')
@DocsEditable()
- List<Rectangle> getClientRects() native "Range_getClientRects_Callback";
+ List<Rect> getClientRects() native "Range_getClientRects_Callback";
@DomName('Range.insertNode')
@DocsEditable()
@@ -22364,7 +22360,7 @@ class Screen extends NativeFieldWrapperClass1 {
@DomName('Screen.availLeft')
@DomName('Screen.availTop')
@DomName('Screen.availWidth')
- Rectangle get available => new Rectangle(_availLeft, _availTop, _availWidth,
+ Rect get available => new Rect(_availLeft, _availTop, _availWidth,
_availHeight);
@DomName('Screen.availHeight')
@@ -26539,13 +26535,13 @@ class Url extends NativeFieldWrapperClass1 {
if ((blob_OR_source_OR_stream is Blob || blob_OR_source_OR_stream == null)) {
return _createObjectURL_1(blob_OR_source_OR_stream);
}
- if ((blob_OR_source_OR_stream is MediaSource || blob_OR_source_OR_stream == null)) {
+ if ((blob_OR_source_OR_stream is MediaStream || blob_OR_source_OR_stream == null)) {
return _createObjectURL_2(blob_OR_source_OR_stream);
}
- if ((blob_OR_source_OR_stream is _WebKitMediaSource || blob_OR_source_OR_stream == null)) {
+ if ((blob_OR_source_OR_stream is MediaSource || blob_OR_source_OR_stream == null)) {
return _createObjectURL_3(blob_OR_source_OR_stream);
}
- if ((blob_OR_source_OR_stream is MediaStream || blob_OR_source_OR_stream == null)) {
+ if ((blob_OR_source_OR_stream is _WebKitMediaSource || blob_OR_source_OR_stream == null)) {
return _createObjectURL_4(blob_OR_source_OR_stream);
}
throw new ArgumentError("Incorrect number or type of arguments");
@@ -28911,9 +28907,11 @@ abstract class _CSSValue extends NativeFieldWrapperClass1 {
@DocsEditable()
@DomName('ClientRect')
-class _ClientRect extends NativeFieldWrapperClass1 implements Rectangle {
+class _ClientRect extends NativeFieldWrapperClass1 implements Rect {
+
+ // NOTE! All code below should be common with Rect.
+ // TODO(blois): implement with mixins when available.
- // NOTE! All code below should be common with RectangleBase.
String toString() {
return '($left, $top, $width, $height)';
}
@@ -29039,38 +29037,38 @@ class _ClientRect extends NativeFieldWrapperClass1 implements Rectangle {
@DocsEditable()
@DomName('ClientRectList')
-class _ClientRectList extends NativeFieldWrapperClass1 with ListMixin<Rectangle>, ImmutableListMixin<Rectangle> implements List<Rectangle> {
+class _ClientRectList extends NativeFieldWrapperClass1 with ListMixin<Rect>, ImmutableListMixin<Rect> implements List<Rect> {
@DomName('ClientRectList.length')
@DocsEditable()
int get length native "ClientRectList_length_Getter";
- Rectangle operator[](int index) {
+ Rect operator[](int index) {
if (index < 0 || index >= length)
throw new RangeError.range(index, 0, length);
return _nativeIndexedGetter(index);
}
- Rectangle _nativeIndexedGetter(int index) native "ClientRectList_item_Callback";
+ Rect _nativeIndexedGetter(int index) native "ClientRectList_item_Callback";
- void operator[]=(int index, Rectangle value) {
+ void operator[]=(int index, Rect value) {
throw new UnsupportedError("Cannot assign element of immutable List.");
}
- // -- start List<Rectangle> mixins.
- // Rectangle is the element type.
+ // -- start List<Rect> mixins.
+ // Rect is the element type.
void set length(int value) {
throw new UnsupportedError("Cannot resize immutable List.");
}
- Rectangle get first {
+ Rect get first {
if (this.length > 0) {
return _nativeIndexedGetter(0);
}
throw new StateError("No elements");
}
- Rectangle get last {
+ Rect get last {
int len = this.length;
if (len > 0) {
return _nativeIndexedGetter(len - 1);
@@ -29078,7 +29076,7 @@ class _ClientRectList extends NativeFieldWrapperClass1 with ListMixin<Rectangle>
throw new StateError("No elements");
}
- Rectangle get single {
+ Rect get single {
int len = this.length;
if (len == 1) {
return _nativeIndexedGetter(0);
@@ -29087,12 +29085,12 @@ class _ClientRectList extends NativeFieldWrapperClass1 with ListMixin<Rectangle>
throw new StateError("More than one element");
}
- Rectangle elementAt(int index) => this[index];
- // -- end List<Rectangle> mixins.
+ Rect elementAt(int index) => this[index];
+ // -- end List<Rect> mixins.
@DomName('ClientRectList.item')
@DocsEditable()
- Rectangle item(int index) native "ClientRectList_item_Callback";
+ Rect item(int index) native "ClientRectList_item_Callback";
}
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
@@ -30851,16 +30849,15 @@ class _MarginCssRect extends CssRect {
/**
* A class for representing CSS dimensions.
*
- * In contrast to the more general purpose [Rectangle] class, this class's
- * values are mutable, so one can change the height of an element
- * programmatically.
+ * In contrast to the more general purpose [Rect] class, this class's values are
+ * mutable, so one can change the height of an element programmatically.
*
* _Important_ _note_: use of these methods will perform CSS calculations that
* can trigger a browser reflow. Therefore, use of these properties _during_ an
* animation frame is discouraged. See also:
* [Browser Reflow](https://developers.google.com/speed/articles/reflow)
*/
-abstract class CssRect extends RectangleBase<num> implements Rectangle<num> {
+abstract class CssRect extends RectBase implements Rect {
Element _element;
CssRect(this._element);
@@ -33924,6 +33921,77 @@ class _SvgNodeValidator implements NodeValidator {
return allowsElement(element);
}
}
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+
+/**
+ * A utility class for representing two-dimensional positions.
+ */
+class Point {
+ final num x;
+ final num y;
+
+ const Point([num x = 0, num y = 0]): x = x, y = y;
+
+ String toString() => '($x, $y)';
+
+ bool operator ==(other) {
+ if (other is !Point) return false;
+ return x == other.x && y == other.y;
+ }
+
+ int get hashCode => JenkinsSmiHash.hash2(x.hashCode, y.hashCode);
+
+ Point operator +(Point other) {
+ return new Point(x + other.x, y + other.y);
+ }
+
+ Point operator -(Point other) {
+ return new Point(x - other.x, y - other.y);
+ }
+
+ Point operator *(num factor) {
+ return new Point(x * factor, y * factor);
+ }
+
+ /**
+ * Get the straight line (Euclidean) distance between the origin (0, 0) and
+ * this point.
+ */
+ num get magnitude => sqrt(x * x + y * y);
+
+ /**
+ * Returns the distance between two points.
+ */
+ double distanceTo(Point other) {
+ var dx = x - other.x;
+ var dy = y - other.y;
+ return sqrt(dx * dx + dy * dy);
+ }
+
+ /**
+ * Returns the squared distance between two points.
+ *
+ * Squared distances can be used for comparisons when the actual value is not
+ * required.
+ */
+ num squaredDistanceTo(Point other) {
+ var dx = x - other.x;
+ var dy = y - other.y;
+ return dx * dx + dy * dy;
+ }
+
+ Point ceil() => new Point(x.ceil(), y.ceil());
+ Point floor() => new Point(x.floor(), y.floor());
+ Point round() => new Point(x.round(), y.round());
+
+ /**
+ * Truncates x and y to integers and returns the result as a new point.
+ */
+ Point toInt() => new Point(x.toInt(), y.toInt());
+}
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@@ -33949,6 +34017,163 @@ abstract class ReadyState {
*/
static const String COMPLETE = "complete";
}
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+
+/**
+ * A base class for representing two-dimensional rectangles. This will hopefully
+ * be moved merged with the dart:math Rect.
+ */
+// TODO(efortuna): Merge with Math rect after finalizing with Florian.
+abstract class RectBase {
+ // Not used, but keeps the VM from complaining about Rect having a const
+ // constructor and this one not.
+ const RectBase();
+
+ num get left;
+ num get top;
+ num get width;
+ num get height;
+
+ num get right => left + width;
+ num get bottom => top + height;
+
+ // NOTE! All code below should be common with Rect.
+
+ String toString() {
+ return '($left, $top, $width, $height)';
+ }
+
+ bool operator ==(other) {
+ if (other is !Rect) return false;
+ return left == other.left && top == other.top && width == other.width &&
+ height == other.height;
+ }
+
+ int get hashCode => JenkinsSmiHash.hash4(left.hashCode, top.hashCode,
+ width.hashCode, height.hashCode);
+
+ /**
+ * Computes the intersection of this rectangle and the rectangle parameter.
+ * Returns null if there is no intersection.
+ */
+ Rect intersection(Rect rect) {
+ var x0 = max(left, rect.left);
+ var x1 = min(left + width, rect.left + rect.width);
+
+ if (x0 <= x1) {
+ var y0 = max(top, rect.top);
+ var y1 = min(top + height, rect.top + rect.height);
+
+ if (y0 <= y1) {
+ return new Rect(x0, y0, x1 - x0, y1 - y0);
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ * Returns whether a rectangle intersects this rectangle.
+ */
+ bool intersects(Rect other) {
+ return (left <= other.left + other.width && other.left <= left + width &&
+ top <= other.top + other.height && other.top <= top + height);
+ }
+
+ /**
+ * Returns a new rectangle which completely contains this rectangle and the
+ * input rectangle.
+ */
+ Rect union(Rect rect) {
+ var right = max(this.left + this.width, rect.left + rect.width);
+ var bottom = max(this.top + this.height, rect.top + rect.height);
+
+ var left = min(this.left, rect.left);
+ var top = min(this.top, rect.top);
+
+ return new Rect(left, top, right - left, bottom - top);
+ }
+
+ /**
+ * Tests whether this rectangle entirely contains another rectangle.
+ */
+ bool containsRect(Rect another) {
+ return left <= another.left &&
+ left + width >= another.left + another.width &&
+ top <= another.top &&
+ top + height >= another.top + another.height;
+ }
+
+ /**
+ * Tests whether this rectangle entirely contains a point.
+ */
+ bool containsPoint(Point another) {
+ return another.x >= left &&
+ another.x <= left + width &&
+ another.y >= top &&
+ another.y <= top + height;
+ }
+
+ Rect ceil() => new Rect(left.ceil(), top.ceil(), width.ceil(), height.ceil());
+ Rect floor() => new Rect(left.floor(), top.floor(), width.floor(),
+ height.floor());
+ Rect round() => new Rect(left.round(), top.round(), width.round(),
+ height.round());
+
+ /**
+ * Truncates coordinates to integers and returns the result as a new
+ * rectangle.
+ */
+ Rect toInt() => new Rect(left.toInt(), top.toInt(), width.toInt(),
+ height.toInt());
+
+ Point get topLeft => new Point(this.left, this.top);
+ Point get bottomRight => new Point(this.left + this.width,
+ this.top + this.height);
+}
+
+
+
+/**
+ * A class for representing two-dimensional rectangles.
+ *
+ * This class is distinctive from RectBase in that it enforces that its
+ * properties are immutable.
+ */
+class Rect extends RectBase {
+ final num left;
+ final num top;
+ final num width;
+ final num height;
+
+ const Rect(this.left, this.top, this.width, this.height): super();
+
+ factory Rect.fromPoints(Point a, Point b) {
+ var left;
+ var width;
+ if (a.x < b.x) {
+ left = a.x;
+ width = b.x - left;
+ } else {
+ left = b.x;
+ width = a.x - left;
+ }
+ var top;
+ var height;
+ if (a.y < b.y) {
+ top = a.y;
+ height = b.y - top;
+ } else {
+ top = b.y;
+ height = a.y - top;
+ }
+
+ return new Rect(left, top, width, height);
+ }
+}
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
« no previous file with comments | « sdk/lib/html/dart2js/html_dart2js.dart ('k') | sdk/lib/html/html_common/html_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698