diff options
author | Job Bautista <jobbautista9@aol.com> | 2023-05-12 11:35:18 +0800 |
---|---|---|
committer | Job Bautista <jobbautista9@aol.com> | 2023-05-12 16:26:05 +0800 |
commit | 4c2a1920b821645f1766dec320d83f1ffb97ce35 (patch) | |
tree | 2e3ad720b5cac156c8cf55558d737b1ca61d2d6a /dom | |
parent | 29bdffbb54691ce31245c921dd07850fb6478d4c (diff) | |
download | uxp-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')
-rw-r--r-- | dom/base/DOMMatrix.cpp | 59 | ||||
-rw-r--r-- | dom/base/DOMMatrix.h | 102 | ||||
-rw-r--r-- | dom/base/DOMPoint.cpp | 27 | ||||
-rw-r--r-- | dom/base/DOMPoint.h | 13 | ||||
-rw-r--r-- | dom/base/DOMQuad.cpp | 119 | ||||
-rw-r--r-- | dom/base/DOMQuad.h | 8 | ||||
-rw-r--r-- | dom/base/DOMRect.cpp | 19 | ||||
-rw-r--r-- | dom/base/DOMRect.h | 66 | ||||
-rw-r--r-- | dom/bindings/Bindings.conf | 2 | ||||
-rw-r--r-- | dom/bindings/Errors.msg | 1 | ||||
-rw-r--r-- | dom/webidl/DOMMatrix.webidl | 4 | ||||
-rw-r--r-- | dom/webidl/DOMPoint.webidl | 15 | ||||
-rw-r--r-- | dom/webidl/DOMQuad.webidl | 6 | ||||
-rw-r--r-- | dom/webidl/DOMRect.webidl | 9 |
14 files changed, 252 insertions, 198 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, diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 8b13babdbb..a12a294766 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -236,12 +236,10 @@ DOMInterfaces = { 'DOMMatrixReadOnly': { 'headerFile': 'mozilla/dom/DOMMatrix.h', - 'concrete': False, }, 'DOMPointReadOnly': { 'headerFile': 'mozilla/dom/DOMPoint.h', - 'concrete': False, }, 'DOMRectList': { diff --git a/dom/bindings/Errors.msg b/dom/bindings/Errors.msg index c894c6c7b4..b40dc239d5 100644 --- a/dom/bindings/Errors.msg +++ b/dom/bindings/Errors.msg @@ -100,6 +100,7 @@ MSG_DEF(MSG_TIME_VALUE_OUT_OF_RANGE, 1, JSEXN_TYPEERR, "{0} is outside the suppo MSG_DEF(MSG_ONLY_IF_CACHED_WITHOUT_SAME_ORIGIN, 1, JSEXN_TYPEERR, "Request mode '{0}' was used, but request cache mode 'only-if-cached' can only be used with request mode 'same-origin'.") MSG_DEF(MSG_THRESHOLD_RANGE_ERROR, 0, JSEXN_RANGEERR, "Threshold values must all be in the range [0, 1].") MSG_DEF(MSG_CACHE_OPEN_FAILED, 0, JSEXN_TYPEERR, "CacheStorage.open() failed to access the storage system.") +MSG_DEF(MSG_MATRIX_INIT_LENGTH_WRONG, 1, JSEXN_TYPEERR, "Matrix init sequence must have a length of 6 or 16 (actual value: {0})") MSG_DEF(MSG_NO_NEGATIVE_ATTR, 1, JSEXN_TYPEERR, "Given attribute {0} cannot be negative.") MSG_DEF(MSG_PMO_NO_SEPARATE_ENDMARK, 0, JSEXN_TYPEERR, "Cannot provide separate endMark argument if PerformanceMeasureOptions argument is given.") MSG_DEF(MSG_PMO_MISSING_STARTENDMARK, 0, JSEXN_TYPEERR, "PerformanceMeasureOptions must have start and/or end member.") diff --git a/dom/webidl/DOMMatrix.webidl b/dom/webidl/DOMMatrix.webidl index 6b236ae666..97dc16616c 100644 --- a/dom/webidl/DOMMatrix.webidl +++ b/dom/webidl/DOMMatrix.webidl @@ -10,7 +10,8 @@ * liability, trademark and document use rules apply. */ -[Pref="layout.css.DOMMatrix.enabled"] +[Pref="layout.css.DOMMatrix.enabled", + Constructor(optional (DOMString or sequence<unrestricted double>) init)] interface DOMMatrixReadOnly { // These attributes are simple aliases for certain elements of the 4x4 matrix readonly attribute unrestricted double a; @@ -77,6 +78,7 @@ interface DOMMatrixReadOnly { [Throws] Float32Array toFloat32Array(); [Throws] Float64Array toFloat64Array(); stringifier; + [Default] object toJSON(); }; [Pref="layout.css.DOMMatrix.enabled", diff --git a/dom/webidl/DOMPoint.webidl b/dom/webidl/DOMPoint.webidl index d092d900f5..2ebba958e4 100644 --- a/dom/webidl/DOMPoint.webidl +++ b/dom/webidl/DOMPoint.webidl @@ -10,19 +10,26 @@ * liability, trademark and document use rules apply. */ -[Pref="layout.css.DOMPoint.enabled"] +[Pref="layout.css.DOMPoint.enabled", + Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0, + optional unrestricted double z = 0, optional unrestricted double w = 1)] interface DOMPointReadOnly { + [NewObject] static DOMPointReadOnly fromPoint(optional DOMPointInit other); + readonly attribute unrestricted double x; readonly attribute unrestricted double y; readonly attribute unrestricted double z; readonly attribute unrestricted double w; + + [Default] object toJSON(); }; [Pref="layout.css.DOMPoint.enabled", - Constructor(optional DOMPointInit point), - Constructor(unrestricted double x, unrestricted double y, + Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0, optional unrestricted double z = 0, optional unrestricted double w = 1)] interface DOMPoint : DOMPointReadOnly { + [NewObject] static DOMPoint fromPoint(optional DOMPointInit other); + inherit attribute unrestricted double x; inherit attribute unrestricted double y; inherit attribute unrestricted double z; @@ -34,4 +41,4 @@ dictionary DOMPointInit { unrestricted double y = 0; unrestricted double z = 0; unrestricted double w = 1; -};
\ No newline at end of file +}; diff --git a/dom/webidl/DOMQuad.webidl b/dom/webidl/DOMQuad.webidl index b933987d59..f3674e9ad7 100644 --- a/dom/webidl/DOMQuad.webidl +++ b/dom/webidl/DOMQuad.webidl @@ -19,5 +19,7 @@ interface DOMQuad { [SameObject] readonly attribute DOMPoint p2; [SameObject] readonly attribute DOMPoint p3; [SameObject] readonly attribute DOMPoint p4; - [SameObject] readonly attribute DOMRectReadOnly bounds; -};
\ No newline at end of file + [NewObject] DOMRectReadOnly getBounds(); + + [Default] object toJSON(); +}; diff --git a/dom/webidl/DOMRect.webidl b/dom/webidl/DOMRect.webidl index 24a07900c5..4a4f3e4eda 100644 --- a/dom/webidl/DOMRect.webidl +++ b/dom/webidl/DOMRect.webidl @@ -10,9 +10,8 @@ * liability, trademark and document use rules apply. */ -[Constructor, - Constructor(unrestricted double x, unrestricted double y, - unrestricted double width, unrestricted double height)] +[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0, + optional unrestricted double width = 0, optional unrestricted double height = 0)] interface DOMRect : DOMRectReadOnly { inherit attribute unrestricted double x; inherit attribute unrestricted double y; @@ -20,6 +19,8 @@ interface DOMRect : DOMRectReadOnly { inherit attribute unrestricted double height; }; +[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0, + optional unrestricted double width = 0, optional unrestricted double height = 0)] interface DOMRectReadOnly { readonly attribute unrestricted double x; readonly attribute unrestricted double y; @@ -29,6 +30,8 @@ interface DOMRectReadOnly { readonly attribute unrestricted double right; readonly attribute unrestricted double bottom; readonly attribute unrestricted double left; + + [Default] object toJSON(); }; dictionary DOMRectInit { |