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/base/DOMMatrix.cpp | |
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/base/DOMMatrix.cpp')
-rw-r--r-- | dom/base/DOMMatrix.cpp | 59 |
1 files changed, 54 insertions, 5 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) { |