content/base/src/DOMQuad.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "mozilla/dom/DOMQuad.h"
michael@0 7
michael@0 8 #include "mozilla/dom/DOMQuadBinding.h"
michael@0 9 #include "mozilla/dom/DOMPoint.h"
michael@0 10 #include "mozilla/dom/DOMRect.h"
michael@0 11 #include <algorithm>
michael@0 12
michael@0 13 using namespace mozilla;
michael@0 14 using namespace mozilla::dom;
michael@0 15 using namespace mozilla::gfx;
michael@0 16
michael@0 17 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_6(DOMQuad, mParent, mBounds, mPoints[0],
michael@0 18 mPoints[1], mPoints[2], mPoints[3])
michael@0 19
michael@0 20 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DOMQuad, AddRef)
michael@0 21 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(DOMQuad, Release)
michael@0 22
michael@0 23 DOMQuad::DOMQuad(nsISupports* aParent, CSSPoint aPoints[4])
michael@0 24 : mParent(aParent)
michael@0 25 {
michael@0 26 SetIsDOMBinding();
michael@0 27 for (uint32_t i = 0; i < 4; ++i) {
michael@0 28 mPoints[i] = new DOMPoint(aParent, aPoints[i].x, aPoints[i].y);
michael@0 29 }
michael@0 30 }
michael@0 31
michael@0 32 DOMQuad::DOMQuad(nsISupports* aParent)
michael@0 33 : mParent(aParent)
michael@0 34 {
michael@0 35 SetIsDOMBinding();
michael@0 36 }
michael@0 37
michael@0 38 DOMQuad::~DOMQuad()
michael@0 39 {
michael@0 40 }
michael@0 41
michael@0 42 JSObject*
michael@0 43 DOMQuad::WrapObject(JSContext* aCx)
michael@0 44 {
michael@0 45 return DOMQuadBinding::Wrap(aCx, this);
michael@0 46 }
michael@0 47
michael@0 48 already_AddRefed<DOMQuad>
michael@0 49 DOMQuad::Constructor(const GlobalObject& aGlobal,
michael@0 50 const DOMPointInit& aP1,
michael@0 51 const DOMPointInit& aP2,
michael@0 52 const DOMPointInit& aP3,
michael@0 53 const DOMPointInit& aP4,
michael@0 54 ErrorResult& aRV)
michael@0 55 {
michael@0 56 nsRefPtr<DOMQuad> obj = new DOMQuad(aGlobal.GetAsSupports());
michael@0 57 obj->mPoints[0] = DOMPoint::Constructor(aGlobal, aP1, aRV);
michael@0 58 obj->mPoints[1] = DOMPoint::Constructor(aGlobal, aP2, aRV);
michael@0 59 obj->mPoints[2] = DOMPoint::Constructor(aGlobal, aP3, aRV);
michael@0 60 obj->mPoints[3] = DOMPoint::Constructor(aGlobal, aP4, aRV);
michael@0 61 return obj.forget();
michael@0 62 }
michael@0 63
michael@0 64 already_AddRefed<DOMQuad>
michael@0 65 DOMQuad::Constructor(const GlobalObject& aGlobal, const DOMRectReadOnly& aRect,
michael@0 66 ErrorResult& aRV)
michael@0 67 {
michael@0 68 CSSPoint points[4];
michael@0 69 Float x = aRect.X(), y = aRect.Y(), w = aRect.Width(), h = aRect.Height();
michael@0 70 points[0] = CSSPoint(x, y);
michael@0 71 points[1] = CSSPoint(x + w, y);
michael@0 72 points[2] = CSSPoint(x + w, y + h);
michael@0 73 points[3] = CSSPoint(x, y + h);
michael@0 74 nsRefPtr<DOMQuad> obj = new DOMQuad(aGlobal.GetAsSupports(), points);
michael@0 75 return obj.forget();
michael@0 76 }
michael@0 77
michael@0 78 class DOMQuad::QuadBounds MOZ_FINAL : public DOMRectReadOnly
michael@0 79 {
michael@0 80 public:
michael@0 81 QuadBounds(DOMQuad* aQuad)
michael@0 82 : DOMRectReadOnly(aQuad->GetParentObject())
michael@0 83 , mQuad(aQuad)
michael@0 84 {}
michael@0 85
michael@0 86 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(QuadBounds, DOMRectReadOnly)
michael@0 87 NS_DECL_ISUPPORTS_INHERITED
michael@0 88
michael@0 89 virtual double X() const
michael@0 90 {
michael@0 91 double x1, x2;
michael@0 92 GetHorizontalMinMax(&x1, &x2);
michael@0 93 return x1;
michael@0 94 }
michael@0 95 virtual double Y() const
michael@0 96 {
michael@0 97 double y1, y2;
michael@0 98 GetVerticalMinMax(&y1, &y2);
michael@0 99 return y1;
michael@0 100 }
michael@0 101 virtual double Width() const
michael@0 102 {
michael@0 103 double x1, x2;
michael@0 104 GetHorizontalMinMax(&x1, &x2);
michael@0 105 return x2 - x1;
michael@0 106 }
michael@0 107 virtual double Height() const
michael@0 108 {
michael@0 109 double y1, y2;
michael@0 110 GetVerticalMinMax(&y1, &y2);
michael@0 111 return y2 - y1;
michael@0 112 }
michael@0 113
michael@0 114 void GetHorizontalMinMax(double* aX1, double* aX2) const
michael@0 115 {
michael@0 116 double x1, x2;
michael@0 117 x1 = x2 = mQuad->Point(0)->X();
michael@0 118 for (uint32_t i = 1; i < 4; ++i) {
michael@0 119 double x = mQuad->Point(i)->X();
michael@0 120 x1 = std::min(x1, x);
michael@0 121 x2 = std::max(x2, x);
michael@0 122 }
michael@0 123 *aX1 = x1;
michael@0 124 *aX2 = x2;
michael@0 125 }
michael@0 126
michael@0 127 void GetVerticalMinMax(double* aY1, double* aY2) const
michael@0 128 {
michael@0 129 double y1, y2;
michael@0 130 y1 = y2 = mQuad->Point(0)->Y();
michael@0 131 for (uint32_t i = 1; i < 4; ++i) {
michael@0 132 double y = mQuad->Point(i)->Y();
michael@0 133 y1 = std::min(y1, y);
michael@0 134 y2 = std::max(y2, y);
michael@0 135 }
michael@0 136 *aY1 = y1;
michael@0 137 *aY2 = y2;
michael@0 138 }
michael@0 139
michael@0 140 protected:
michael@0 141 nsRefPtr<DOMQuad> mQuad;
michael@0 142 };
michael@0 143
michael@0 144 NS_IMPL_CYCLE_COLLECTION_INHERITED(DOMQuad::QuadBounds, DOMRectReadOnly, mQuad)
michael@0 145
michael@0 146 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DOMQuad::QuadBounds)
michael@0 147 NS_INTERFACE_MAP_END_INHERITING(DOMRectReadOnly)
michael@0 148
michael@0 149 NS_IMPL_ADDREF_INHERITED(DOMQuad::QuadBounds, DOMRectReadOnly)
michael@0 150 NS_IMPL_RELEASE_INHERITED(DOMQuad::QuadBounds, DOMRectReadOnly)
michael@0 151
michael@0 152 DOMRectReadOnly*
michael@0 153 DOMQuad::Bounds() const
michael@0 154 {
michael@0 155 if (!mBounds) {
michael@0 156 mBounds = new QuadBounds(const_cast<DOMQuad*>(this));
michael@0 157 }
michael@0 158 return mBounds;
michael@0 159 }

mercurial