Bug 865735 - Add a units template parameter to the gfx Point, Size, and Rect classes. r=bas,roc
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 29 May 2013 09:32:30 -0400
changeset 133288 58bf49390ed428c5078a9cbb307ed15fe1b4d248
parent 133287 dbccec261411ca30aa7d6a9aab6e256181b794a5
child 133289 233122ebffd29995e23f71e02f9c4c6b3f4cfeb3
push id24751
push userryanvm@gmail.com
push dateThu, 30 May 2013 15:43:11 +0000
treeherdermozilla-central@75407626ba46 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas, roc
bugs865735
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 865735 - Add a units template parameter to the gfx Point, Size, and Rect classes. r=bas,roc
content/canvas/src/CanvasRenderingContext2D.h
content/html/content/public/HTMLCanvasElement.h
dom/browser-element/BrowserElementParent.h
gfx/2d/Point.h
gfx/2d/Rect.cpp
gfx/2d/Rect.h
gfx/2d/moz.build
--- a/content/canvas/src/CanvasRenderingContext2D.h
+++ b/content/canvas/src/CanvasRenderingContext2D.h
@@ -15,22 +15,22 @@
 #include "CanvasUtils.h"
 #include "gfxFont.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/dom/ImageData.h"
 #include "mozilla/dom/UnionTypes.h"
 #include "mozilla/dom/CanvasGradient.h"
 #include "mozilla/dom/CanvasRenderingContext2DBinding.h"
 #include "mozilla/dom/CanvasPattern.h"
+#include "mozilla/gfx/Rect.h"
 
 class nsXULElement;
 
 namespace mozilla {
 namespace gfx {
-struct Rect;
 class SourceSurface;
 }
 
 namespace dom {
 class TextMetrics;
 
 extern const mozilla::gfx::Float SIGMA_MAX;
 
--- a/content/html/content/public/HTMLCanvasElement.h
+++ b/content/html/content/public/HTMLCanvasElement.h
@@ -10,33 +10,30 @@
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsSize.h"
 #include "nsError.h"
 #include "nsNodeInfoManager.h"
 
 #include "nsICanvasElementExternal.h"
 #include "nsLayoutUtils.h"
+#include "mozilla/gfx/Rect.h"
 
 class nsICanvasRenderingContextInternal;
 class nsIDOMFile;
 class nsITimerCallback;
 class nsIPropertyBag;
 
 namespace mozilla {
 
 namespace layers {
 class CanvasLayer;
 class LayerManager;
 }
 
-namespace gfx {
-struct Rect;
-}
-
 namespace dom {
 
 class HTMLCanvasPrintState;
 
 class HTMLCanvasElement MOZ_FINAL : public nsGenericHTMLElement,
                                     public nsICanvasElementExternal,
                                     public nsIDOMHTMLCanvasElement
 {
--- a/dom/browser-element/BrowserElementParent.h
+++ b/dom/browser-element/BrowserElementParent.h
@@ -1,31 +1,28 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_BrowserElementHelpers_h
 #define mozilla_BrowserElementHelpers_h
 
 #include "nsAString.h"
+#include "mozilla/gfx/Point.h"
+#include "mozilla/gfx/Rect.h"
 
 class nsIDOMWindow;
 class nsIURI;
 
 namespace mozilla {
 
 namespace dom {
 class TabParent;
 }
 
-namespace gfx{
-struct Rect;
-struct Size;
-}
-
 /**
  * BrowserElementParent implements a portion of the parent-process side of
  * <iframe mozbrowser>.
  *
  * Most of the parent-process side of <iframe mozbrowser> is implemented in
  * BrowserElementParent.js.  This file implements the few parts of this
  * functionality which must be written in C++.
  *
--- a/gfx/2d/Point.h
+++ b/gfx/2d/Point.h
@@ -8,47 +8,62 @@
 
 #include "Types.h"
 #include "BasePoint.h"
 #include "BaseSize.h"
 
 namespace mozilla {
 namespace gfx {
 
-struct IntPoint :
-  public BasePoint<int32_t, IntPoint> {
-  typedef BasePoint<int32_t, IntPoint> Super;
-
-  IntPoint() : Super() {}
-  IntPoint(int32_t aX, int32_t aY) : Super(aX, aY) {}
-};
+// This should only be used by the typedefs below.
+struct UnknownUnits {};
 
-struct Point :
-  public BasePoint<Float, Point> {
-  typedef BasePoint<Float, Point> Super;
+template<class units>
+struct IntPointTyped :
+  public BasePoint< int32_t, IntPointTyped<units> >,
+  public units {
+  typedef BasePoint< int32_t, IntPointTyped<units> > Super;
 
-  Point() : Super() {}
-  Point(Float aX, Float aY) : Super(aX, aY) {}
-  Point(const IntPoint& point) : Super(float(point.x), float(point.y)) {}
+  IntPointTyped() : Super() {}
+  IntPointTyped(int32_t aX, int32_t aY) : Super(aX, aY) {}
 };
+typedef IntPointTyped<UnknownUnits> IntPoint;
 
-struct IntSize :
-  public BaseSize<int32_t, IntSize> {
-  typedef BaseSize<int32_t, IntSize> Super;
+template<class units>
+struct PointTyped :
+  public BasePoint< Float, PointTyped<units> >,
+  public units {
+  typedef BasePoint< Float, PointTyped<units> > Super;
 
-  IntSize() : Super() {}
-  IntSize(int32_t aWidth, int32_t aHeight) : Super(aWidth, aHeight) {}
+  PointTyped() : Super() {}
+  PointTyped(Float aX, Float aY) : Super(aX, aY) {}
+  PointTyped(const IntPointTyped<units>& point) : Super(float(point.x), float(point.y)) {}
 };
+typedef PointTyped<UnknownUnits> Point;
 
-struct Size :
-  public BaseSize<Float, Size> {
-  typedef BaseSize<Float, Size> Super;
+template<class units>
+struct IntSizeTyped :
+  public BaseSize< int32_t, IntSizeTyped<units> >,
+  public units {
+  typedef BaseSize< int32_t, IntSizeTyped<units> > Super;
 
-  Size() : Super() {}
-  Size(Float aWidth, Float aHeight) : Super(aWidth, aHeight) {}
-  explicit Size(const IntSize& size) :
+  IntSizeTyped() : Super() {}
+  IntSizeTyped(int32_t aWidth, int32_t aHeight) : Super(aWidth, aHeight) {}
+};
+typedef IntSizeTyped<UnknownUnits> IntSize;
+
+template<class units>
+struct SizeTyped :
+  public BaseSize< Float, SizeTyped<units> >,
+  public units {
+  typedef BaseSize< Float, SizeTyped<units> > Super;
+
+  SizeTyped() : Super() {}
+  SizeTyped(Float aWidth, Float aHeight) : Super(aWidth, aHeight) {}
+  explicit SizeTyped(const IntSizeTyped<units>& size) :
     Super(float(size.width), float(size.height)) {}
 };
+typedef SizeTyped<UnknownUnits> Size;
 
 }
 }
 
 #endif /* MOZILLA_GFX_POINT_H_ */
deleted file mode 100644
--- a/gfx/2d/Rect.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "Rect.h"
-#include "Tools.h"
-
-namespace mozilla {
-namespace gfx {
-
-void Rect::NudgeToIntegers()
-{
-  NudgeToInteger(&x);
-  NudgeToInteger(&y);
-  NudgeToInteger(&width);
-  NudgeToInteger(&height);
-}
-
-}
-}
--- a/gfx/2d/Rect.h
+++ b/gfx/2d/Rect.h
@@ -4,67 +4,81 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_GFX_RECT_H_
 #define MOZILLA_GFX_RECT_H_
 
 #include "BaseRect.h"
 #include "BaseMargin.h"
 #include "Point.h"
+#include "Tools.h"
 
 namespace mozilla {
 namespace gfx {
 
 struct Margin :
   public BaseMargin<Float, Margin> {
   typedef BaseMargin<Float, Margin> Super;
 
   // Constructors
   Margin() : Super(0, 0, 0, 0) {}
   Margin(const Margin& aMargin) : Super(aMargin) {}
   Margin(Float aTop, Float aRight, Float aBottom, Float aLeft)
     : Super(aTop, aRight, aBottom, aLeft) {}
 };
 
-struct IntRect :
-    public BaseRect<int32_t, IntRect, IntPoint, IntSize, Margin> {
-    typedef BaseRect<int32_t, IntRect, IntPoint, mozilla::gfx::IntSize, Margin> Super;
+template<class units>
+struct IntRectTyped :
+    public BaseRect<int32_t, IntRectTyped<units>, IntPointTyped<units>, IntSizeTyped<units>, Margin>,
+    public units {
+    typedef BaseRect<int32_t, IntRectTyped<units>, IntPointTyped<units>, IntSizeTyped<units>, Margin> Super;
 
-    IntRect() : Super() {}
-    IntRect(IntPoint aPos, mozilla::gfx::IntSize aSize) :
+    IntRectTyped() : Super() {}
+    IntRectTyped(IntPointTyped<units> aPos, IntSizeTyped<units> aSize) :
         Super(aPos, aSize) {}
-    IntRect(int32_t _x, int32_t _y, int32_t _width, int32_t _height) :
+    IntRectTyped(int32_t _x, int32_t _y, int32_t _width, int32_t _height) :
         Super(_x, _y, _width, _height) {}
 
     // Rounding isn't meaningful on an integer rectangle.
     void Round() {}
     void RoundIn() {}
     void RoundOut() {}
 };
-
-struct Rect :
-    public BaseRect<Float, Rect, Point, Size, Margin> {
-    typedef BaseRect<Float, Rect, Point, mozilla::gfx::Size, Margin> Super;
+typedef IntRectTyped<UnknownUnits> IntRect;
 
-    Rect() : Super() {}
-    Rect(Point aPos, mozilla::gfx::Size aSize) :
+template<class units>
+struct RectTyped :
+    public BaseRect<Float, RectTyped<units>, PointTyped<units>, SizeTyped<units>, Margin>,
+    public units {
+    typedef BaseRect<Float, RectTyped<units>, PointTyped<units>, SizeTyped<units>, Margin> Super;
+
+    RectTyped() : Super() {}
+    RectTyped(PointTyped<units> aPos, SizeTyped<units> aSize) :
         Super(aPos, aSize) {}
-    Rect(Float _x, Float _y, Float _width, Float _height) :
+    RectTyped(Float _x, Float _y, Float _width, Float _height) :
         Super(_x, _y, _width, _height) {}
-    explicit Rect(const IntRect& rect) :
+    explicit RectTyped(const IntRectTyped<units>& rect) :
         Super(float(rect.x), float(rect.y),
               float(rect.width), float(rect.height)) {}
 
-    GFX2D_API void NudgeToIntegers();
-
-    bool ToIntRect(IntRect *aOut) const
+    GFX2D_API void NudgeToIntegers()
     {
-      *aOut = IntRect(int32_t(X()), int32_t(Y()),
-                    int32_t(Width()), int32_t(Height()));
-      return Rect(Float(aOut->x), Float(aOut->y), 
-                  Float(aOut->width), Float(aOut->height)).IsEqualEdges(*this);
+      NudgeToInteger(&(this->x));
+      NudgeToInteger(&(this->y));
+      NudgeToInteger(&(this->width));
+      NudgeToInteger(&(this->height));
+    }
+
+    bool ToIntRect(IntRectTyped<units> *aOut) const
+    {
+      *aOut = IntRectTyped<units>(int32_t(this->X()), int32_t(this->Y()),
+                                  int32_t(this->Width()), int32_t(this->Height()));
+      return RectTyped<units>(Float(aOut->x), Float(aOut->y), 
+                              Float(aOut->width), Float(aOut->height))
+             .IsEqualEdges(*this);
     }
 };
+typedef RectTyped<UnknownUnits> Rect;
 
 }
 }
 
 #endif /* MOZILLA_GFX_RECT_H_ */
--- a/gfx/2d/moz.build
+++ b/gfx/2d/moz.build
@@ -79,15 +79,14 @@ CPP_SOURCES += [
     'DrawTargetDual.cpp',
     'DrawTargetRecording.cpp',
     'Factory.cpp',
     'ImageScaling.cpp',
     'Matrix.cpp',
     'PathCairo.cpp',
     'PathRecording.cpp',
     'RecordedEvent.cpp',
-    'Rect.cpp',
     'Scale.cpp',
     'ScaledFontBase.cpp',
     'SourceSurfaceCairo.cpp',
     'SourceSurfaceRawData.cpp',
 ]