summaryrefslogtreecommitdiff
path: root/dom/base
diff options
context:
space:
mode:
authorJob Bautista <jobbautista9@aol.com>2023-05-12 11:35:18 +0800
committerJob Bautista <jobbautista9@aol.com>2023-05-12 16:26:05 +0800
commit4c2a1920b821645f1766dec320d83f1ffb97ce35 (patch)
tree2e3ad720b5cac156c8cf55558d737b1ca61d2d6a /dom/base
parent29bdffbb54691ce31245c921dd07850fb6478d4c (diff)
downloaduxp-4c2a1920b821645f1766dec320d83f1ffb97ce35.tar.gz
Issue #2241 - Part 4.1: Get DOMPoint, DOMQuad, DOMRect, DOMMatrix a bit closer to spec.
Backported from Mozilla bug 1186265's part 1.
Diffstat (limited to 'dom/base')
-rw-r--r--dom/base/DOMMatrix.cpp59
-rw-r--r--dom/base/DOMMatrix.h102
-rw-r--r--dom/base/DOMPoint.cpp27
-rw-r--r--dom/base/DOMPoint.h13
-rw-r--r--dom/base/DOMQuad.cpp119
-rw-r--r--dom/base/DOMQuad.h8
-rw-r--r--dom/base/DOMRect.cpp19
-rw-r--r--dom/base/DOMRect.h66
8 files changed, 227 insertions, 186 deletions
diff --git a/dom/base/DOMMatrix.cpp b/dom/base/DOMMatrix.cpp
index 72c8d9b76b..1631f2cdcf 100644
--- a/dom/base/DOMMatrix.cpp
+++ b/dom/base/DOMMatrix.cpp
@@ -20,6 +20,10 @@
namespace mozilla {
namespace dom {
+template <typename T>
+static void
+SetDataInMatrix(DOMMatrixReadOnly* aMatrix, const T* aData, int aLength, ErrorResult& aRv);
+
static const double radPerDegree = 2.0 * M_PI / 360.0;
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMMatrixReadOnly, mParent)
@@ -27,6 +31,39 @@ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMMatrixReadOnly, mParent)
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DOMMatrixReadOnly, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(DOMMatrixReadOnly, Release)
+JSObject*
+DOMMatrixReadOnly::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
+{
+ return DOMMatrixReadOnlyBinding::Wrap(aCx, this, aGivenProto);
+}
+
+already_AddRefed<DOMMatrixReadOnly>
+DOMMatrixReadOnly::Constructor(
+ const GlobalObject& aGlobal,
+ const Optional<StringOrUnrestrictedDoubleSequence>& aArg,
+ ErrorResult& aRv)
+{
+ RefPtr<DOMMatrixReadOnly> rval = new DOMMatrixReadOnly(aGlobal.GetAsSupports());
+ if (!aArg.WasPassed()) {
+ return rval.forget();
+ }
+
+ const auto& arg = aArg.Value();
+ if (arg.IsString()) {
+ nsCOMPtr<nsPIDOMWindowInner> win = do_QueryInterface(aGlobal.GetAsSupports());
+ if (!win) {
+ aRv.ThrowTypeError<MSG_ILLEGAL_CONSTRUCTOR>();
+ return nullptr;
+ }
+ rval->SetMatrixValue(arg.GetAsString(), aRv);
+ } else {
+ const auto& sequence = arg.GetAsUnrestrictedDoubleSequence();
+ SetDataInMatrix(rval, sequence.Elements(), sequence.Length(), aRv);
+ }
+
+ return rval.forget();
+}
+
already_AddRefed<DOMMatrix>
DOMMatrixReadOnly::Translate(double aTx,
double aTy,
@@ -330,7 +367,9 @@ DOMMatrix::Constructor(const GlobalObject& aGlobal, const DOMMatrixReadOnly& aOt
return obj.forget();
}
-template <typename T> void SetDataInMatrix(DOMMatrix* aMatrix, const T* aData, int aLength, ErrorResult& aRv)
+template <typename T>
+static void
+SetDataInMatrix(DOMMatrixReadOnly* aMatrix, const T* aData, int aLength, ErrorResult& aRv)
{
if (aLength == 16) {
aMatrix->SetM11(aData[0]);
@@ -357,7 +396,9 @@ template <typename T> void SetDataInMatrix(DOMMatrix* aMatrix, const T* aData, i
aMatrix->SetE(aData[4]);
aMatrix->SetF(aData[5]);
} else {
- aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
+ nsAutoString lengthStr;
+ lengthStr.AppendInt(aLength);
+ aRv.ThrowTypeError<MSG_MATRIX_INIT_LENGTH_WRONG>(lengthStr);
}
}
@@ -390,7 +431,8 @@ DOMMatrix::Constructor(const GlobalObject& aGlobal, const Sequence<double>& aNum
return obj.forget();
}
-void DOMMatrix::Ensure3DMatrix()
+void
+DOMMatrixReadOnly::Ensure3DMatrix()
{
if (!mMatrix3D) {
mMatrix3D = new gfx::Matrix4x4(gfx::Matrix4x4::From2D(*mMatrix2D));
@@ -617,8 +659,8 @@ DOMMatrix::InvertSelf()
return this;
}
-DOMMatrix*
-DOMMatrix::SetMatrixValue(const nsAString& aTransformList, ErrorResult& aRv)
+DOMMatrixReadOnly*
+DOMMatrixReadOnly::SetMatrixValue(const nsAString& aTransformList, ErrorResult& aRv)
{
SVGTransformListParser parser(aTransformList);
if (!parser.Parse()) {
@@ -644,6 +686,13 @@ DOMMatrix::SetMatrixValue(const nsAString& aTransformList, ErrorResult& aRv)
return this;
}
+DOMMatrix*
+DOMMatrix::SetMatrixValue(const nsAString& aTransformList, ErrorResult& aRv)
+{
+ DOMMatrixReadOnly::SetMatrixValue(aTransformList, aRv);
+ return this;
+}
+
JSObject*
DOMMatrix::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
diff --git a/dom/base/DOMMatrix.h b/dom/base/DOMMatrix.h
index 9b83548efa..e956878c20 100644
--- a/dom/base/DOMMatrix.h
+++ b/dom/base/DOMMatrix.h
@@ -22,6 +22,7 @@ namespace dom {
class GlobalObject;
class DOMMatrix;
class DOMPoint;
+class StringOrUnrestrictedDoubleSequence;
struct DOMPointInit;
class DOMMatrixReadOnly : public nsWrapperCache
@@ -51,6 +52,12 @@ public:
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DOMMatrixReadOnly)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DOMMatrixReadOnly)
+ nsISupports* GetParentObject() const { return mParent; }
+ virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
+
+ static already_AddRefed<DOMMatrixReadOnly>
+ Constructor(const GlobalObject& aGlobal, const Optional<StringOrUnrestrictedDoubleSequence>& aArg, ErrorResult& aRv);
+
#define GetMatrixMember(entry2D, entry3D, default) \
{ \
if (mMatrix3D) { \
@@ -94,6 +101,51 @@ public:
#undef GetMatrixMember
#undef Get3DMatrixMember
+ // Defined here so we can construct DOMMatrixReadOnly objects.
+#define Set2DMatrixMember(entry2D, entry3D) \
+{ \
+ if (mMatrix3D) { \
+ mMatrix3D->entry3D = v; \
+ } else { \
+ mMatrix2D->entry2D = v; \
+ } \
+}
+
+#define Set3DMatrixMember(entry3D, default) \
+{ \
+ if (mMatrix3D || (v != default)) { \
+ Ensure3DMatrix(); \
+ mMatrix3D->entry3D = v; \
+ } \
+}
+
+ void SetA(double v) Set2DMatrixMember(_11, _11)
+ void SetB(double v) Set2DMatrixMember(_12, _12)
+ void SetC(double v) Set2DMatrixMember(_21, _21)
+ void SetD(double v) Set2DMatrixMember(_22, _22)
+ void SetE(double v) Set2DMatrixMember(_31, _41)
+ void SetF(double v) Set2DMatrixMember(_32, _42)
+
+ void SetM11(double v) Set2DMatrixMember(_11, _11)
+ void SetM12(double v) Set2DMatrixMember(_12, _12)
+ void SetM13(double v) Set3DMatrixMember(_13, 0)
+ void SetM14(double v) Set3DMatrixMember(_14, 0)
+ void SetM21(double v) Set2DMatrixMember(_21, _21)
+ void SetM22(double v) Set2DMatrixMember(_22, _22)
+ void SetM23(double v) Set3DMatrixMember(_23, 0)
+ void SetM24(double v) Set3DMatrixMember(_24, 0)
+ void SetM31(double v) Set3DMatrixMember(_31, 0)
+ void SetM32(double v) Set3DMatrixMember(_32, 0)
+ void SetM33(double v) Set3DMatrixMember(_33, 1.0)
+ void SetM34(double v) Set3DMatrixMember(_34, 0)
+ void SetM41(double v) Set2DMatrixMember(_31, _41)
+ void SetM42(double v) Set2DMatrixMember(_32, _42)
+ void SetM43(double v) Set3DMatrixMember(_43, 0)
+ void SetM44(double v) Set3DMatrixMember(_44, 1.0)
+
+#undef Set2DMatrixMember
+#undef Set3DMatrixMember
+
already_AddRefed<DOMMatrix> Translate(double aTx,
double aTy,
double aTz = 0) const;
@@ -143,6 +195,9 @@ protected:
virtual ~DOMMatrixReadOnly() {}
+ DOMMatrixReadOnly* SetMatrixValue(const nsAString& aTransformList, ErrorResult& aRv);
+ void Ensure3DMatrix();
+
private:
DOMMatrixReadOnly() = delete;
DOMMatrixReadOnly(const DOMMatrixReadOnly&) = delete;
@@ -177,53 +232,8 @@ public:
static already_AddRefed<DOMMatrix>
Constructor(const GlobalObject& aGlobal, const Sequence<double>& aNumberSequence, ErrorResult& aRv);
- nsISupports* GetParentObject() const { return mParent; }
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
-#define Set2DMatrixMember(entry2D, entry3D) \
-{ \
- if (mMatrix3D) { \
- mMatrix3D->entry3D = v; \
- } else { \
- mMatrix2D->entry2D = v; \
- } \
-}
-
-#define Set3DMatrixMember(entry3D, default) \
-{ \
- if (mMatrix3D || (v != default)) { \
- Ensure3DMatrix(); \
- mMatrix3D->entry3D = v; \
- } \
-}
-
- void SetA(double v) Set2DMatrixMember(_11, _11)
- void SetB(double v) Set2DMatrixMember(_12, _12)
- void SetC(double v) Set2DMatrixMember(_21, _21)
- void SetD(double v) Set2DMatrixMember(_22, _22)
- void SetE(double v) Set2DMatrixMember(_31, _41)
- void SetF(double v) Set2DMatrixMember(_32, _42)
-
- void SetM11(double v) Set2DMatrixMember(_11, _11)
- void SetM12(double v) Set2DMatrixMember(_12, _12)
- void SetM13(double v) Set3DMatrixMember(_13, 0)
- void SetM14(double v) Set3DMatrixMember(_14, 0)
- void SetM21(double v) Set2DMatrixMember(_21, _21)
- void SetM22(double v) Set2DMatrixMember(_22, _22)
- void SetM23(double v) Set3DMatrixMember(_23, 0)
- void SetM24(double v) Set3DMatrixMember(_24, 0)
- void SetM31(double v) Set3DMatrixMember(_31, 0)
- void SetM32(double v) Set3DMatrixMember(_32, 0)
- void SetM33(double v) Set3DMatrixMember(_33, 1.0)
- void SetM34(double v) Set3DMatrixMember(_34, 0)
- void SetM41(double v) Set2DMatrixMember(_31, _41)
- void SetM42(double v) Set2DMatrixMember(_32, _42)
- void SetM43(double v) Set3DMatrixMember(_43, 0)
- void SetM44(double v) Set3DMatrixMember(_44, 1.0)
-
-#undef Set2DMatrixMember
-#undef Set3DMatrixMember
-
DOMMatrix* MultiplySelf(const DOMMatrix& aOther);
DOMMatrix* PreMultiplySelf(const DOMMatrix& aOther);
DOMMatrix* TranslateSelf(double aTx,
@@ -255,8 +265,6 @@ public:
DOMMatrix* SkewYSelf(double aSy);
DOMMatrix* InvertSelf();
DOMMatrix* SetMatrixValue(const nsAString& aTransformList, ErrorResult& aRv);
-protected:
- void Ensure3DMatrix();
virtual ~DOMMatrix() {}
};
diff --git a/dom/base/DOMPoint.cpp b/dom/base/DOMPoint.cpp
index 97eec9e766..508bfab1e2 100644
--- a/dom/base/DOMPoint.cpp
+++ b/dom/base/DOMPoint.cpp
@@ -16,9 +16,32 @@ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMPointReadOnly, mParent)
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DOMPointReadOnly, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(DOMPointReadOnly, Release)
+already_AddRefed<DOMPointReadOnly>
+DOMPointReadOnly::FromPoint(const GlobalObject& aGlobal, const DOMPointInit& aParams)
+{
+ RefPtr<DOMPointReadOnly> obj =
+ new DOMPointReadOnly(aGlobal.GetAsSupports(), aParams.mX, aParams.mY,
+ aParams.mZ, aParams.mW);
+ return obj.forget();
+}
+
+already_AddRefed<DOMPointReadOnly>
+DOMPointReadOnly::Constructor(const GlobalObject& aGlobal, double aX, double aY,
+ double aZ, double aW, ErrorResult& aRV)
+{
+ RefPtr<DOMPointReadOnly> obj =
+ new DOMPointReadOnly(aGlobal.GetAsSupports(), aX, aY, aZ, aW);
+ return obj.forget();
+}
+
+JSObject*
+DOMPointReadOnly::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
+{
+ return DOMPointReadOnlyBinding::Wrap(aCx, this, aGivenProto);
+}
+
already_AddRefed<DOMPoint>
-DOMPoint::Constructor(const GlobalObject& aGlobal, const DOMPointInit& aParams,
- ErrorResult& aRV)
+DOMPoint::FromPoint(const GlobalObject& aGlobal, const DOMPointInit& aParams)
{
RefPtr<DOMPoint> obj =
new DOMPoint(aGlobal.GetAsSupports(), aParams.mX, aParams.mY,
diff --git a/dom/base/DOMPoint.h b/dom/base/DOMPoint.h
index 1a85982cc7..79937f83a3 100644
--- a/dom/base/DOMPoint.h
+++ b/dom/base/DOMPoint.h
@@ -33,6 +33,12 @@ public:
{
}
+ static already_AddRefed<DOMPointReadOnly>
+ FromPoint(const GlobalObject& aGlobal, const DOMPointInit& aParams);
+ static already_AddRefed<DOMPointReadOnly>
+ Constructor(const GlobalObject& aGlobal, double aX, double aY,
+ double aZ, double aW, ErrorResult& aRV);
+
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DOMPointReadOnly)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DOMPointReadOnly)
@@ -41,6 +47,9 @@ public:
double Z() const { return mZ; }
double W() const { return mW; }
+ nsISupports* GetParentObject() const { return mParent; }
+ virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
+
protected:
virtual ~DOMPointReadOnly() {}
@@ -57,13 +66,11 @@ public:
{}
static already_AddRefed<DOMPoint>
- Constructor(const GlobalObject& aGlobal, const DOMPointInit& aParams,
- ErrorResult& aRV);
+ FromPoint(const GlobalObject& aGlobal, const DOMPointInit& aParams);
static already_AddRefed<DOMPoint>
Constructor(const GlobalObject& aGlobal, double aX, double aY,
double aZ, double aW, ErrorResult& aRV);
- nsISupports* GetParentObject() const { return mParent; }
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
void SetX(double aX) { mX = aX; }
diff --git a/dom/base/DOMQuad.cpp b/dom/base/DOMQuad.cpp
index 9da70c043d..2cf55e1b8b 100644
--- a/dom/base/DOMQuad.cpp
+++ b/dom/base/DOMQuad.cpp
@@ -14,7 +14,7 @@ using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::gfx;
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMQuad, mParent, mBounds, mPoints[0],
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMQuad, mParent, mPoints[0],
mPoints[1], mPoints[2], mPoints[3])
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DOMQuad, AddRef)
@@ -52,10 +52,10 @@ DOMQuad::Constructor(const GlobalObject& aGlobal,
ErrorResult& aRV)
{
RefPtr<DOMQuad> obj = new DOMQuad(aGlobal.GetAsSupports());
- obj->mPoints[0] = DOMPoint::Constructor(aGlobal, aP1, aRV);
- obj->mPoints[1] = DOMPoint::Constructor(aGlobal, aP2, aRV);
- obj->mPoints[2] = DOMPoint::Constructor(aGlobal, aP3, aRV);
- obj->mPoints[3] = DOMPoint::Constructor(aGlobal, aP4, aRV);
+ obj->mPoints[0] = DOMPoint::FromPoint(aGlobal, aP1);
+ obj->mPoints[1] = DOMPoint::FromPoint(aGlobal, aP2);
+ obj->mPoints[2] = DOMPoint::FromPoint(aGlobal, aP3);
+ obj->mPoints[3] = DOMPoint::FromPoint(aGlobal, aP4);
return obj.forget();
}
@@ -73,87 +73,44 @@ DOMQuad::Constructor(const GlobalObject& aGlobal, const DOMRectReadOnly& aRect,
return obj.forget();
}
-class DOMQuad::QuadBounds final : public DOMRectReadOnly
+void
+DOMQuad::GetHorizontalMinMax(double* aX1, double* aX2) const
{
-public:
- explicit QuadBounds(DOMQuad* aQuad)
- : DOMRectReadOnly(aQuad->GetParentObject())
- , mQuad(aQuad)
- {}
-
- NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(QuadBounds, DOMRectReadOnly)
- NS_DECL_ISUPPORTS_INHERITED
-
- virtual double X() const override
- {
- double x1, x2;
- GetHorizontalMinMax(&x1, &x2);
- return x1;
- }
- virtual double Y() const override
- {
- double y1, y2;
- GetVerticalMinMax(&y1, &y2);
- return y1;
- }
- virtual double Width() const override
- {
- double x1, x2;
- GetHorizontalMinMax(&x1, &x2);
- return x2 - x1;
- }
- virtual double Height() const override
- {
- double y1, y2;
- GetVerticalMinMax(&y1, &y2);
- return y2 - y1;
- }
-
- void GetHorizontalMinMax(double* aX1, double* aX2) const
- {
- double x1, x2;
- x1 = x2 = mQuad->Point(0)->X();
- for (uint32_t i = 1; i < 4; ++i) {
- double x = mQuad->Point(i)->X();
- x1 = std::min(x1, x);
- x2 = std::max(x2, x);
- }
- *aX1 = x1;
- *aX2 = x2;
+ double x1, x2;
+ x1 = x2 = Point(0)->X();
+ for (uint32_t i = 1; i < 4; ++i) {
+ double x = Point(i)->X();
+ x1 = std::min(x1, x);
+ x2 = std::max(x2, x);
}
+ *aX1 = x1;
+ *aX2 = x2;
+}
- void GetVerticalMinMax(double* aY1, double* aY2) const
- {
- double y1, y2;
- y1 = y2 = mQuad->Point(0)->Y();
- for (uint32_t i = 1; i < 4; ++i) {
- double y = mQuad->Point(i)->Y();
- y1 = std::min(y1, y);
- y2 = std::max(y2, y);
- }
- *aY1 = y1;
- *aY2 = y2;
+void
+DOMQuad::GetVerticalMinMax(double* aY1, double* aY2) const
+{
+ double y1, y2;
+ y1 = y2 = Point(0)->Y();
+ for (uint32_t i = 1; i < 4; ++i) {
+ double y = Point(i)->Y();
+ y1 = std::min(y1, y);
+ y2 = std::max(y2, y);
}
+ *aY1 = y1;
+ *aY2 = y2;
+}
-protected:
- virtual ~QuadBounds() {}
-
- RefPtr<DOMQuad> mQuad;
-};
-
-NS_IMPL_CYCLE_COLLECTION_INHERITED(DOMQuad::QuadBounds, DOMRectReadOnly, mQuad)
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DOMQuad::QuadBounds)
-NS_INTERFACE_MAP_END_INHERITING(DOMRectReadOnly)
+already_AddRefed<DOMRectReadOnly>
+DOMQuad::GetBounds() const
+{
+ double x1, x2;
+ double y1, y2;
-NS_IMPL_ADDREF_INHERITED(DOMQuad::QuadBounds, DOMRectReadOnly)
-NS_IMPL_RELEASE_INHERITED(DOMQuad::QuadBounds, DOMRectReadOnly)
+ GetHorizontalMinMax(&x1, &x2);
+ GetVerticalMinMax(&y1, &y2);
-DOMRectReadOnly*
-DOMQuad::Bounds() const
-{
- if (!mBounds) {
- mBounds = new QuadBounds(const_cast<DOMQuad*>(this));
- }
- return mBounds;
+ RefPtr<DOMRectReadOnly> rval = new DOMRectReadOnly(GetParentObject(),
+ x1, y1, x2 - x1, y2 - y1);
+ return rval.forget();
}
diff --git a/dom/base/DOMQuad.h b/dom/base/DOMQuad.h
index 89d258a106..25cf7dbd06 100644
--- a/dom/base/DOMQuad.h
+++ b/dom/base/DOMQuad.h
@@ -47,20 +47,20 @@ public:
Constructor(const GlobalObject& aGlobal, const DOMRectReadOnly& aRect,
ErrorResult& aRV);
- DOMRectReadOnly* Bounds() const;
+ already_AddRefed<DOMRectReadOnly> GetBounds() const;
DOMPoint* P1() const { return mPoints[0]; }
DOMPoint* P2() const { return mPoints[1]; }
DOMPoint* P3() const { return mPoints[2]; }
DOMPoint* P4() const { return mPoints[3]; }
- DOMPoint* Point(uint32_t aIndex) { return mPoints[aIndex]; }
+ DOMPoint* Point(uint32_t aIndex) const { return mPoints[aIndex]; }
protected:
- class QuadBounds;
+ void GetHorizontalMinMax(double* aX1, double* aX2) const;
+ void GetVerticalMinMax(double* aY1, double* aY2) const;
nsCOMPtr<nsISupports> mParent;
RefPtr<DOMPoint> mPoints[4];
- mutable RefPtr<QuadBounds> mBounds; // allocated lazily
};
} // namespace dom
diff --git a/dom/base/DOMRect.cpp b/dom/base/DOMRect.cpp
index 3728ea7a7c..ecd56f10a7 100644
--- a/dom/base/DOMRect.cpp
+++ b/dom/base/DOMRect.cpp
@@ -27,6 +27,15 @@ DOMRectReadOnly::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
return DOMRectReadOnlyBinding::Wrap(aCx, this, aGivenProto);
}
+already_AddRefed<DOMRectReadOnly>
+DOMRectReadOnly::Constructor(const GlobalObject& aGlobal, double aX, double aY,
+ double aWidth, double aHeight, ErrorResult& aRv)
+{
+ RefPtr<DOMRectReadOnly> obj =
+ new DOMRectReadOnly(aGlobal.GetAsSupports(), aX, aY, aWidth, aHeight);
+ return obj.forget();
+}
+
// -----------------------------------------------------------------------------
NS_IMPL_ISUPPORTS_INHERITED(DOMRect, DOMRectReadOnly, nsIDOMClientRect)
@@ -54,16 +63,8 @@ DOMRect::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
}
already_AddRefed<DOMRect>
-DOMRect::Constructor(const GlobalObject& aGlobal, ErrorResult& aRV)
-{
- RefPtr<DOMRect> obj =
- new DOMRect(aGlobal.GetAsSupports(), 0.0, 0.0, 0.0, 0.0);
- return obj.forget();
-}
-
-already_AddRefed<DOMRect>
DOMRect::Constructor(const GlobalObject& aGlobal, double aX, double aY,
- double aWidth, double aHeight, ErrorResult& aRV)
+ double aWidth, double aHeight, ErrorResult& aRv)
{
RefPtr<DOMRect> obj =
new DOMRect(aGlobal.GetAsSupports(), aX, aY, aWidth, aHeight);
diff --git a/dom/base/DOMRect.h b/dom/base/DOMRect.h
index da3162be0c..baf3268b20 100644
--- a/dom/base/DOMRect.h
+++ b/dom/base/DOMRect.h
@@ -32,8 +32,13 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMRectReadOnly)
- explicit DOMRectReadOnly(nsISupports* aParent)
+ explicit DOMRectReadOnly(nsISupports* aParent, double aX = 0, double aY = 0,
+ double aWidth = 0, double aHeight = 0)
: mParent(aParent)
+ , mX(aX)
+ , mY(aY)
+ , mWidth(aWidth)
+ , mHeight(aHeight)
{
}
@@ -44,10 +49,26 @@ public:
}
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
- virtual double X() const = 0;
- virtual double Y() const = 0;
- virtual double Width() const = 0;
- virtual double Height() const = 0;
+ static already_AddRefed<DOMRectReadOnly>
+ Constructor(const GlobalObject& aGlobal, double aX, double aY,
+ double aWidth, double aHeight, ErrorResult& aRv);
+
+ double X() const
+ {
+ return mX;
+ }
+ double Y() const
+ {
+ return mY;
+ }
+ double Width() const
+ {
+ return mWidth;
+ }
+ double Height() const
+ {
+ return mHeight;
+ }
double Left() const
{
@@ -72,6 +93,7 @@ public:
protected:
nsCOMPtr<nsISupports> mParent;
+ double mX, mY, mWidth, mHeight;
};
class DOMRect final : public DOMRectReadOnly
@@ -80,22 +102,16 @@ class DOMRect final : public DOMRectReadOnly
public:
explicit DOMRect(nsISupports* aParent, double aX = 0, double aY = 0,
double aWidth = 0, double aHeight = 0)
- : DOMRectReadOnly(aParent)
- , mX(aX)
- , mY(aY)
- , mWidth(aWidth)
- , mHeight(aHeight)
+ : DOMRectReadOnly(aParent, aX, aY, aWidth, aHeight)
{
}
-
+
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMCLIENTRECT
static already_AddRefed<DOMRect>
- Constructor(const GlobalObject& aGlobal, ErrorResult& aRV);
- static already_AddRefed<DOMRect>
Constructor(const GlobalObject& aGlobal, double aX, double aY,
- double aWidth, double aHeight, ErrorResult& aRV);
+ double aWidth, double aHeight, ErrorResult& aRv);
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
@@ -104,23 +120,6 @@ public:
}
void SetLayoutRect(const nsRect& aLayoutRect);
- virtual double X() const override
- {
- return mX;
- }
- virtual double Y() const override
- {
- return mY;
- }
- virtual double Width() const override
- {
- return mWidth;
- }
- virtual double Height() const override
- {
- return mHeight;
- }
-
void SetX(double aX)
{
mX = aX;
@@ -138,11 +137,8 @@ public:
mHeight = aHeight;
}
-protected:
- double mX, mY, mWidth, mHeight;
-
private:
- ~DOMRect() {};
+ ~DOMRect() {}
};
class DOMRectList final : public nsIDOMClientRectList,