From b2889d844f8c2f826100588b23b741f73e96cbbc Mon Sep 17 00:00:00 2001 From: Job Bautista Date: Fri, 12 May 2023 15:42:46 +0800 Subject: Issue #2241 - Part 6: Implement DOMMatrix.fromMatrix. Also fixes .multiply() to use DOMMatrixInit. Backported from Mozilla bug 1560462. --- dom/base/DOMMatrix.h | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'dom/base/DOMMatrix.h') diff --git a/dom/base/DOMMatrix.h b/dom/base/DOMMatrix.h index fe1325c594..9bbdef688f 100644 --- a/dom/base/DOMMatrix.h +++ b/dom/base/DOMMatrix.h @@ -25,6 +25,7 @@ class DOMMatrix; class DOMPoint; class StringOrUnrestrictedDoubleSequence; struct DOMPointInit; +struct DOMMatrixInit; class DOMMatrixReadOnly : public nsWrapperCache { @@ -56,6 +57,9 @@ public: nsISupports* GetParentObject() const { return mParent; } virtual JSObject* WrapObject(JSContext* cx, JS::Handle aGivenProto) override; + static already_AddRefed + FromMatrix(const GlobalObject& aGlobal, const DOMMatrixInit& aMatrixInit, ErrorResult& aRv); + static already_AddRefed Constructor(const GlobalObject& aGlobal, const Optional& aArg, ErrorResult& aRv); @@ -180,7 +184,8 @@ public: double aAngle) const; already_AddRefed SkewX(double aSx) const; already_AddRefed SkewY(double aSy) const; - already_AddRefed Multiply(const DOMMatrix& aOther) const; + already_AddRefed Multiply(const DOMMatrixInit& aOther, + ErrorResult& aRv) const; already_AddRefed FlipX() const; already_AddRefed FlipY() const; already_AddRefed Inverse() const; @@ -204,6 +209,13 @@ protected: virtual ~DOMMatrixReadOnly() {} + /** + * Sets data from a fully validated and fixed-up matrix init, + * where all of its members are properly defined. + * The init dictionary's dimension must match the matrix one. + */ + void SetDataFromMatrixInit(DOMMatrixInit& aMatrixInit); + DOMMatrixReadOnly* SetMatrixValue(const nsAString& aTransformList, ErrorResult& aRv); void Ensure3DMatrix(); @@ -236,6 +248,11 @@ public: : DOMMatrixReadOnly(aParent, aMatrix) {} + static already_AddRefed + FromMatrix(nsISupports* aParent, const DOMMatrixInit& aMatrixInit, ErrorResult& aRv); + static already_AddRefed + FromMatrix(const GlobalObject& aGlobal, const DOMMatrixInit& aMatrixInit, ErrorResult& aRv); + static already_AddRefed Constructor(const GlobalObject& aGlobal, ErrorResult& aRv); static already_AddRefed @@ -254,8 +271,8 @@ public: virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; - DOMMatrix* MultiplySelf(const DOMMatrix& aOther); - DOMMatrix* PreMultiplySelf(const DOMMatrix& aOther); + DOMMatrix* MultiplySelf(const DOMMatrixInit& aOther, ErrorResult& aRv); + DOMMatrix* PreMultiplySelf(const DOMMatrixInit& aOther, ErrorResult& aRv); DOMMatrix* TranslateSelf(double aTx, double aTy, double aTz = 0); -- cgit v1.2.3