Bug 1002289 - Allow adding/subtracting of BaseSize on BaseRect. r=botond, Bas
authorDoug Sherk <bugzilla@sherk.me>
Fri, 02 May 2014 11:22:54 -0400
changeset 181763 db686f9cc96fdb60d3bec2431ef18c710548b24e
parent 181762 43b2f692bb54a644f0b5b32387c89b19ffd0cfdc
child 181764 8f4e9cf85af807633add95d9495ba1238a09bc59
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersbotond, Bas
bugs1002289
milestone32.0a1
Bug 1002289 - Allow adding/subtracting of BaseSize on BaseRect. r=botond, Bas
gfx/2d/BaseRect.h
--- a/gfx/2d/BaseRect.h
+++ b/gfx/2d/BaseRect.h
@@ -230,35 +230,58 @@ struct BaseRect {
   }
   // Return true if the rectangles contain the same area of the plane.
   // Use when we do not care about differences in empty rectangles.
   bool IsEqualInterior(const Sub& aRect) const
   {
     return IsEqualEdges(aRect) || (IsEmpty() && aRect.IsEmpty());
   }
 
-  Sub operator+(const Point& aPoint) const
+  friend Sub operator+(Sub aSub, const Point& aPoint)
   {
-    return Sub(x + aPoint.x, y + aPoint.y, width, height);
+    aSub += aPoint;
+    return aSub;
+  }
+  friend Sub operator-(Sub aSub, const Point& aPoint)
+  {
+    aSub -= aPoint;
+    return aSub;
   }
-  Sub operator-(const Point& aPoint) const
+  friend Sub operator+(Sub aSub, const SizeT& aSize)
   {
-    return Sub(x - aPoint.x, y - aPoint.y, width, height);
+    aSub += aSize;
+    return aSub;
+  }
+  friend Sub operator-(Sub aSub, const SizeT& aSize)
+  {
+    aSub -= aSize;
+    return aSub;
   }
   Sub& operator+=(const Point& aPoint)
   {
     MoveBy(aPoint);
     return *static_cast<Sub*>(this);
   }
   Sub& operator-=(const Point& aPoint)
   {
     MoveBy(-aPoint);
     return *static_cast<Sub*>(this);
   }
-
+  Sub& operator+=(const SizeT& aSize)
+  {
+    width += aSize.width;
+    height += aSize.height;
+    return *static_cast<Sub*>(this);
+  }
+  Sub& operator-=(const SizeT& aSize)
+  {
+    width -= aSize.width;
+    height -= aSize.height;
+    return *static_cast<Sub*>(this);
+  }
   // Find difference as a Margin
   MarginT operator-(const Sub& aRect) const
   {
     return MarginT(aRect.y - y,
                    XMost() - aRect.XMost(),
                    YMost() - aRect.YMost(),
                    aRect.x - x);
   }