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

Unified Diff: tools/dom/src/Rectangle.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 side-by-side diff with in-line comments
Download patch
Index: tools/dom/src/Rectangle.dart
diff --git a/tools/dom/src/Rectangle.dart b/tools/dom/src/Rectangle.dart
index e6a80b2f0edc67caa2607040ede9ad3f7d5653c8..a2f52864fbb1747687da30bbbfb5030667118e77 100644
--- a/tools/dom/src/Rectangle.dart
+++ b/tools/dom/src/Rectangle.dart
@@ -5,44 +5,20 @@
part of html;
/**
- * A class for representing two-dimensional rectangles.
+ * A base class for representing two-dimensional rectangles. This will hopefully
+ * be moved merged with the dart:math Rect.
*/
-class Rect {
- final num left;
- final num top;
- final num width;
- final num height;
-
- const Rect(this.left, this.top, this.width, this.height);
-
- 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);
- }
+// TODO(efortuna): Merge with Math rect after finalizing with Florian.
+abstract class 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.
- // TODO: implement with mixins when available.
String toString() {
return '($left, $top, $width, $height)';
@@ -136,3 +112,40 @@ class Rect {
Point get bottomRight => new Point(this.left + this.width,
this.top + this.height);
}
+
+
+
+/**
+ * A class for representing two-dimensional rectangles.
+ */
+class Rect extends RectBase {
Jennifer Messerly 2013/07/16 22:03:16 Would be good to add a comment on why we have Rect
Emily Fortuna 2013/07/18 22:45:02 Done.
+ final num left;
+ final num top;
+ final num width;
+ final num height;
+
+ const Rect(this.left, this.top, this.width, this.height);
+
+ 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);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698