2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-06-24 22:15:00 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2017-11-14 12:41:46 +03:00
|
|
|
#include "mozilla/dom/DOMMatrix.h"
|
|
|
|
|
2014-06-24 22:15:00 +04:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
|
|
|
#include "mozilla/dom/DOMMatrixBinding.h"
|
2017-11-14 12:41:46 +03:00
|
|
|
#include "mozilla/dom/DOMPoint.h"
|
2014-06-24 22:15:00 +04:00
|
|
|
#include "mozilla/dom/DOMPointBinding.h"
|
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
|
|
|
#include "mozilla/dom/ToJSValue.h"
|
2017-12-01 12:35:47 +03:00
|
|
|
#include "mozilla/ServoCSSParser.h"
|
2017-06-14 17:44:17 +03:00
|
|
|
#include "nsGlobalWindowInner.h"
|
2017-11-14 12:41:46 +03:00
|
|
|
#include "nsStyleTransformMatrix.h"
|
2018-03-19 22:18:07 +03:00
|
|
|
#include "nsGlobalWindowInner.h"
|
2014-06-24 22:15:00 +04:00
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
2019-07-11 05:49:51 +03:00
|
|
|
#include "js/Conversions.h" // JS::NumberToString
|
|
|
|
#include "js/Equality.h" // JS::SameValueZero
|
2019-06-30 06:02:13 +03:00
|
|
|
|
2014-06-24 22:15:00 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
template <typename T>
|
|
|
|
static void SetDataInMatrix(DOMMatrixReadOnly* aMatrix, const T* aData,
|
|
|
|
int aLength, ErrorResult& aRv);
|
|
|
|
|
2014-06-24 22:15:00 +04:00
|
|
|
static const double radPerDegree = 2.0 * M_PI / 360.0;
|
|
|
|
|
2014-11-01 16:10:59 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMMatrixReadOnly, mParent)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DOMMatrixReadOnly, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(DOMMatrixReadOnly, Release)
|
|
|
|
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
JSObject* DOMMatrixReadOnly::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return DOMMatrixReadOnly_Binding::Wrap(aCx, this, aGivenProto);
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
}
|
|
|
|
|
2019-06-30 06:02:13 +03:00
|
|
|
// https://drafts.fxtf.org/geometry/#matrix-validate-and-fixup-2d
|
|
|
|
static bool ValidateAndFixupMatrix2DInit(DOMMatrix2DInit& aMatrixInit,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
#define ValidateAliases(field, alias, fieldName, aliasName) \
|
|
|
|
if ((field).WasPassed() && (alias).WasPassed() && \
|
|
|
|
!JS::SameValueZero((field).Value(), (alias).Value())) { \
|
|
|
|
aRv.ThrowTypeError<MSG_MATRIX_INIT_CONFLICTING_VALUE>((fieldName), \
|
|
|
|
(aliasName)); \
|
|
|
|
return false; \
|
|
|
|
}
|
|
|
|
#define SetFromAliasOrDefault(field, alias, defaultValue) \
|
|
|
|
if (!(field).WasPassed()) { \
|
|
|
|
if ((alias).WasPassed()) { \
|
|
|
|
(field).Construct((alias).Value()); \
|
|
|
|
} else { \
|
|
|
|
(field).Construct(defaultValue); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define ValidateAndSet(field, alias, fieldName, aliasName, defaultValue) \
|
|
|
|
ValidateAliases((field), (alias), NS_LITERAL_STRING(fieldName), \
|
|
|
|
NS_LITERAL_STRING(aliasName)); \
|
|
|
|
SetFromAliasOrDefault((field), (alias), (defaultValue));
|
|
|
|
|
|
|
|
ValidateAndSet(aMatrixInit.mM11, aMatrixInit.mA, "m11", "a", 1);
|
|
|
|
ValidateAndSet(aMatrixInit.mM12, aMatrixInit.mB, "m12", "b", 0);
|
|
|
|
ValidateAndSet(aMatrixInit.mM21, aMatrixInit.mC, "m21", "c", 0);
|
|
|
|
ValidateAndSet(aMatrixInit.mM22, aMatrixInit.mD, "m22", "d", 1);
|
|
|
|
ValidateAndSet(aMatrixInit.mM41, aMatrixInit.mE, "m41", "e", 0);
|
|
|
|
ValidateAndSet(aMatrixInit.mM42, aMatrixInit.mF, "m42", "f", 0);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
#undef ValidateAliases
|
|
|
|
#undef SetFromAliasOrDefault
|
|
|
|
#undef ValidateAndSet
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://drafts.fxtf.org/geometry/#matrix-validate-and-fixup
|
|
|
|
static bool ValidateAndFixupMatrixInit(DOMMatrixInit& aMatrixInit,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
#define Check3DField(field, fieldName, defaultValue) \
|
|
|
|
if ((field) != (defaultValue)) { \
|
|
|
|
if (!aMatrixInit.mIs2D.WasPassed()) { \
|
|
|
|
aMatrixInit.mIs2D.Construct(false); \
|
|
|
|
return true; \
|
|
|
|
} \
|
|
|
|
if (aMatrixInit.mIs2D.Value()) { \
|
|
|
|
aRv.ThrowTypeError<MSG_MATRIX_INIT_EXCEEDS_2D>( \
|
|
|
|
NS_LITERAL_STRING(fieldName)); \
|
|
|
|
return false; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ValidateAndFixupMatrix2DInit(aMatrixInit, aRv)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Check3DField(aMatrixInit.mM13, "m13", 0);
|
|
|
|
Check3DField(aMatrixInit.mM14, "m14", 0);
|
|
|
|
Check3DField(aMatrixInit.mM23, "m23", 0);
|
|
|
|
Check3DField(aMatrixInit.mM24, "m24", 0);
|
|
|
|
Check3DField(aMatrixInit.mM31, "m31", 0);
|
|
|
|
Check3DField(aMatrixInit.mM32, "m32", 0);
|
|
|
|
Check3DField(aMatrixInit.mM34, "m34", 0);
|
|
|
|
Check3DField(aMatrixInit.mM43, "m43", 0);
|
|
|
|
Check3DField(aMatrixInit.mM33, "m33", 1);
|
|
|
|
Check3DField(aMatrixInit.mM44, "m44", 1);
|
|
|
|
|
|
|
|
if (!aMatrixInit.mIs2D.WasPassed()) {
|
|
|
|
aMatrixInit.mIs2D.Construct(true);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
#undef Check3DField
|
|
|
|
}
|
|
|
|
|
2019-07-11 09:14:58 +03:00
|
|
|
void DOMMatrixReadOnly::SetDataFromMatrix2DInit(
|
|
|
|
const DOMMatrix2DInit& aMatrixInit) {
|
|
|
|
MOZ_ASSERT(Is2D());
|
|
|
|
mMatrix2D->_11 = aMatrixInit.mM11.Value();
|
|
|
|
mMatrix2D->_12 = aMatrixInit.mM12.Value();
|
|
|
|
mMatrix2D->_21 = aMatrixInit.mM21.Value();
|
|
|
|
mMatrix2D->_22 = aMatrixInit.mM22.Value();
|
|
|
|
mMatrix2D->_31 = aMatrixInit.mM41.Value();
|
|
|
|
mMatrix2D->_32 = aMatrixInit.mM42.Value();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DOMMatrixReadOnly::SetDataFromMatrixInit(
|
|
|
|
const DOMMatrixInit& aMatrixInit) {
|
2019-06-30 06:02:13 +03:00
|
|
|
const bool is2D = aMatrixInit.mIs2D.Value();
|
|
|
|
MOZ_ASSERT(is2D == Is2D());
|
|
|
|
if (is2D) {
|
2019-07-11 09:14:58 +03:00
|
|
|
SetDataFromMatrix2DInit(aMatrixInit);
|
2019-06-30 06:02:13 +03:00
|
|
|
} else {
|
|
|
|
mMatrix3D->_11 = aMatrixInit.mM11.Value();
|
|
|
|
mMatrix3D->_12 = aMatrixInit.mM12.Value();
|
|
|
|
mMatrix3D->_13 = aMatrixInit.mM13;
|
|
|
|
mMatrix3D->_14 = aMatrixInit.mM14;
|
|
|
|
mMatrix3D->_21 = aMatrixInit.mM21.Value();
|
|
|
|
mMatrix3D->_22 = aMatrixInit.mM22.Value();
|
|
|
|
mMatrix3D->_23 = aMatrixInit.mM23;
|
|
|
|
mMatrix3D->_24 = aMatrixInit.mM24;
|
|
|
|
mMatrix3D->_31 = aMatrixInit.mM31;
|
|
|
|
mMatrix3D->_32 = aMatrixInit.mM32;
|
|
|
|
mMatrix3D->_33 = aMatrixInit.mM33;
|
|
|
|
mMatrix3D->_34 = aMatrixInit.mM34;
|
|
|
|
mMatrix3D->_41 = aMatrixInit.mM41.Value();
|
|
|
|
mMatrix3D->_42 = aMatrixInit.mM42.Value();
|
|
|
|
mMatrix3D->_43 = aMatrixInit.mM43;
|
|
|
|
mMatrix3D->_44 = aMatrixInit.mM44;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-11 09:14:58 +03:00
|
|
|
already_AddRefed<DOMMatrixReadOnly> DOMMatrixReadOnly::FromMatrix(
|
|
|
|
nsISupports* aParent, const DOMMatrix2DInit& aMatrixInit,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
DOMMatrix2DInit matrixInit(aMatrixInit);
|
|
|
|
if (!ValidateAndFixupMatrix2DInit(matrixInit, aRv)) {
|
|
|
|
return nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
RefPtr<DOMMatrixReadOnly> matrix =
|
|
|
|
new DOMMatrixReadOnly(aParent, /* is2D */ true);
|
|
|
|
matrix->SetDataFromMatrix2DInit(matrixInit);
|
|
|
|
return matrix.forget();
|
|
|
|
}
|
|
|
|
|
2019-06-30 06:02:13 +03:00
|
|
|
already_AddRefed<DOMMatrixReadOnly> DOMMatrixReadOnly::FromMatrix(
|
2019-07-06 09:55:53 +03:00
|
|
|
nsISupports* aParent, const DOMMatrixInit& aMatrixInit, ErrorResult& aRv) {
|
2019-06-30 06:02:13 +03:00
|
|
|
DOMMatrixInit matrixInit(aMatrixInit);
|
|
|
|
if (!ValidateAndFixupMatrixInit(matrixInit, aRv)) {
|
|
|
|
return nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
RefPtr<DOMMatrixReadOnly> rval =
|
2019-07-06 09:55:53 +03:00
|
|
|
new DOMMatrixReadOnly(aParent, matrixInit.mIs2D.Value());
|
2019-06-30 06:02:13 +03:00
|
|
|
rval->SetDataFromMatrixInit(matrixInit);
|
|
|
|
return rval.forget();
|
|
|
|
}
|
|
|
|
|
2019-07-06 09:55:53 +03:00
|
|
|
already_AddRefed<DOMMatrixReadOnly> DOMMatrixReadOnly::FromMatrix(
|
|
|
|
const GlobalObject& aGlobal, const DOMMatrixInit& aMatrixInit,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
RefPtr<DOMMatrixReadOnly> matrix =
|
|
|
|
FromMatrix(aGlobal.GetAsSupports(), aMatrixInit, aRv);
|
|
|
|
return matrix.forget();
|
|
|
|
}
|
|
|
|
|
2019-07-03 08:51:30 +03:00
|
|
|
already_AddRefed<DOMMatrixReadOnly> DOMMatrixReadOnly::FromFloat32Array(
|
|
|
|
const GlobalObject& aGlobal, const Float32Array& aArray32,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
aArray32.ComputeLengthAndData();
|
|
|
|
|
|
|
|
const int length = aArray32.Length();
|
|
|
|
const bool is2D = length == 6;
|
|
|
|
RefPtr<DOMMatrixReadOnly> obj =
|
|
|
|
new DOMMatrixReadOnly(aGlobal.GetAsSupports(), is2D);
|
|
|
|
SetDataInMatrix(obj, aArray32.Data(), length, aRv);
|
|
|
|
|
|
|
|
return obj.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMMatrixReadOnly> DOMMatrixReadOnly::FromFloat64Array(
|
|
|
|
const GlobalObject& aGlobal, const Float64Array& aArray64,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
aArray64.ComputeLengthAndData();
|
|
|
|
|
|
|
|
const int length = aArray64.Length();
|
|
|
|
const bool is2D = length == 6;
|
|
|
|
RefPtr<DOMMatrixReadOnly> obj =
|
|
|
|
new DOMMatrixReadOnly(aGlobal.GetAsSupports(), is2D);
|
|
|
|
SetDataInMatrix(obj, aArray64.Data(), length, aRv);
|
|
|
|
|
|
|
|
return obj.forget();
|
|
|
|
}
|
|
|
|
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
already_AddRefed<DOMMatrixReadOnly> DOMMatrixReadOnly::Constructor(
|
|
|
|
const GlobalObject& aGlobal,
|
2019-07-17 00:12:38 +03:00
|
|
|
const Optional<StringOrUnrestrictedDoubleSequenceOrDOMMatrixReadOnly>& aArg,
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
ErrorResult& aRv) {
|
|
|
|
if (!aArg.WasPassed()) {
|
2019-06-20 06:59:59 +03:00
|
|
|
RefPtr<DOMMatrixReadOnly> rval =
|
|
|
|
new DOMMatrixReadOnly(aGlobal.GetAsSupports());
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
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;
|
|
|
|
}
|
2019-06-20 06:59:59 +03:00
|
|
|
RefPtr<DOMMatrixReadOnly> rval =
|
|
|
|
new DOMMatrixReadOnly(aGlobal.GetAsSupports());
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
rval->SetMatrixValue(arg.GetAsString(), aRv);
|
2019-06-20 06:59:59 +03:00
|
|
|
return rval.forget();
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
}
|
2019-07-17 00:12:38 +03:00
|
|
|
if (arg.IsDOMMatrixReadOnly()) {
|
|
|
|
RefPtr<DOMMatrixReadOnly> obj = new DOMMatrixReadOnly(
|
|
|
|
aGlobal.GetAsSupports(), arg.GetAsDOMMatrixReadOnly());
|
|
|
|
return obj.forget();
|
|
|
|
}
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
|
2019-06-20 06:59:59 +03:00
|
|
|
const auto& sequence = arg.GetAsUnrestrictedDoubleSequence();
|
|
|
|
const int length = sequence.Length();
|
|
|
|
const bool is2D = length == 6;
|
|
|
|
RefPtr<DOMMatrixReadOnly> rval =
|
|
|
|
new DOMMatrixReadOnly(aGlobal.GetAsSupports(), is2D);
|
|
|
|
SetDataInMatrix(rval, sequence.Elements(), length, aRv);
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
return rval.forget();
|
|
|
|
}
|
|
|
|
|
2019-06-15 20:26:25 +03:00
|
|
|
already_AddRefed<DOMMatrixReadOnly> DOMMatrixReadOnly::ReadStructuredClone(
|
2019-06-25 09:48:29 +03:00
|
|
|
JSContext* aCx, nsIGlobalObject* aGlobal,
|
|
|
|
JSStructuredCloneReader* aReader) {
|
2019-06-15 20:26:25 +03:00
|
|
|
uint8_t is2D;
|
|
|
|
|
|
|
|
if (!JS_ReadBytes(aReader, &is2D, 1)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-06-25 09:48:29 +03:00
|
|
|
RefPtr<DOMMatrixReadOnly> rval = new DOMMatrixReadOnly(aGlobal, is2D);
|
2019-06-15 20:26:25 +03:00
|
|
|
|
|
|
|
if (!ReadStructuredCloneElements(aReader, rval)) {
|
|
|
|
return nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
return rval.forget();
|
|
|
|
}
|
|
|
|
|
2014-06-24 22:15:00 +04:00
|
|
|
already_AddRefed<DOMMatrix> DOMMatrixReadOnly::Translate(double aTx, double aTy,
|
|
|
|
double aTz) const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMMatrix> retval = new DOMMatrix(mParent, *this);
|
2014-06-24 22:15:00 +04:00
|
|
|
retval->TranslateSelf(aTx, aTy, aTz);
|
|
|
|
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
2019-06-28 18:11:00 +03:00
|
|
|
already_AddRefed<DOMMatrix> DOMMatrixReadOnly::Scale(
|
|
|
|
double aScaleX, const Optional<double>& aScaleY, double aScaleZ,
|
|
|
|
double aOriginX, double aOriginY, double aOriginZ) const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMMatrix> retval = new DOMMatrix(mParent, *this);
|
2019-06-28 18:11:00 +03:00
|
|
|
retval->ScaleSelf(aScaleX, aScaleY, aScaleZ, aOriginX, aOriginY, aOriginZ);
|
2014-06-24 22:15:00 +04:00
|
|
|
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMMatrix> DOMMatrixReadOnly::Scale3d(double aScale,
|
|
|
|
double aOriginX,
|
|
|
|
double aOriginY,
|
|
|
|
double aOriginZ) const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMMatrix> retval = new DOMMatrix(mParent, *this);
|
2014-06-24 22:15:00 +04:00
|
|
|
retval->Scale3dSelf(aScale, aOriginX, aOriginY, aOriginZ);
|
|
|
|
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMMatrix> DOMMatrixReadOnly::ScaleNonUniform(
|
2019-06-28 18:11:00 +03:00
|
|
|
double aScaleX, double aScaleY) const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMMatrix> retval = new DOMMatrix(mParent, *this);
|
2019-06-28 18:11:00 +03:00
|
|
|
retval->ScaleSelf(aScaleX, Optional<double>(aScaleY), 1, 0, 0, 0);
|
2014-06-24 22:15:00 +04:00
|
|
|
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
2019-07-02 11:29:46 +03:00
|
|
|
already_AddRefed<DOMMatrix> DOMMatrixReadOnly::Rotate(
|
|
|
|
double aRotX, const Optional<double>& aRotY,
|
|
|
|
const Optional<double>& aRotZ) const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMMatrix> retval = new DOMMatrix(mParent, *this);
|
2019-07-02 11:29:46 +03:00
|
|
|
retval->RotateSelf(aRotX, aRotY, aRotZ);
|
2014-06-24 22:15:00 +04:00
|
|
|
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMMatrix> DOMMatrixReadOnly::RotateFromVector(
|
|
|
|
double x, double y) const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMMatrix> retval = new DOMMatrix(mParent, *this);
|
2014-06-24 22:15:00 +04:00
|
|
|
retval->RotateFromVectorSelf(x, y);
|
|
|
|
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMMatrix> DOMMatrixReadOnly::RotateAxisAngle(
|
|
|
|
double aX, double aY, double aZ, double aAngle) const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMMatrix> retval = new DOMMatrix(mParent, *this);
|
2014-06-24 22:15:00 +04:00
|
|
|
retval->RotateAxisAngleSelf(aX, aY, aZ, aAngle);
|
|
|
|
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMMatrix> DOMMatrixReadOnly::SkewX(double aSx) const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMMatrix> retval = new DOMMatrix(mParent, *this);
|
2014-06-24 22:15:00 +04:00
|
|
|
retval->SkewXSelf(aSx);
|
|
|
|
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMMatrix> DOMMatrixReadOnly::SkewY(double aSy) const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMMatrix> retval = new DOMMatrix(mParent, *this);
|
2014-06-24 22:15:00 +04:00
|
|
|
retval->SkewYSelf(aSy);
|
|
|
|
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMMatrix> DOMMatrixReadOnly::Multiply(
|
2019-06-30 06:02:13 +03:00
|
|
|
const DOMMatrixInit& other, ErrorResult& aRv) const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMMatrix> retval = new DOMMatrix(mParent, *this);
|
2019-06-30 06:02:13 +03:00
|
|
|
retval->MultiplySelf(other, aRv);
|
2014-06-24 22:15:00 +04:00
|
|
|
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMMatrix> DOMMatrixReadOnly::FlipX() const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMMatrix> retval = new DOMMatrix(mParent, *this);
|
2014-06-24 22:15:00 +04:00
|
|
|
if (mMatrix3D) {
|
2019-06-19 18:59:54 +03:00
|
|
|
gfx::Matrix4x4Double m;
|
2014-06-24 22:15:00 +04:00
|
|
|
m._11 = -1;
|
2019-06-19 18:59:54 +03:00
|
|
|
retval->mMatrix3D = new gfx::Matrix4x4Double(m * *mMatrix3D);
|
2014-06-24 22:15:00 +04:00
|
|
|
} else {
|
2019-06-19 18:59:54 +03:00
|
|
|
gfx::MatrixDouble m;
|
2014-06-24 22:15:00 +04:00
|
|
|
m._11 = -1;
|
2019-06-19 18:59:54 +03:00
|
|
|
retval->mMatrix2D = new gfx::MatrixDouble(mMatrix2D ? m * *mMatrix2D : m);
|
2014-06-24 22:15:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMMatrix> DOMMatrixReadOnly::FlipY() const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMMatrix> retval = new DOMMatrix(mParent, *this);
|
2014-06-24 22:15:00 +04:00
|
|
|
if (mMatrix3D) {
|
2019-06-19 18:59:54 +03:00
|
|
|
gfx::Matrix4x4Double m;
|
2014-06-24 22:15:00 +04:00
|
|
|
m._22 = -1;
|
2019-06-19 18:59:54 +03:00
|
|
|
retval->mMatrix3D = new gfx::Matrix4x4Double(m * *mMatrix3D);
|
2014-06-24 22:15:00 +04:00
|
|
|
} else {
|
2019-06-19 18:59:54 +03:00
|
|
|
gfx::MatrixDouble m;
|
2014-06-24 22:15:00 +04:00
|
|
|
m._22 = -1;
|
2019-06-19 18:59:54 +03:00
|
|
|
retval->mMatrix2D = new gfx::MatrixDouble(mMatrix2D ? m * *mMatrix2D : m);
|
2014-06-24 22:15:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMMatrix> DOMMatrixReadOnly::Inverse() const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMMatrix> retval = new DOMMatrix(mParent, *this);
|
2014-06-24 22:15:00 +04:00
|
|
|
retval->InvertSelf();
|
|
|
|
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DOMMatrixReadOnly::Is2D() const { return !mMatrix3D; }
|
|
|
|
|
2017-11-21 11:44:49 +03:00
|
|
|
bool DOMMatrixReadOnly::IsIdentity() const {
|
2014-06-24 22:15:00 +04:00
|
|
|
if (mMatrix3D) {
|
|
|
|
return mMatrix3D->IsIdentity();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mMatrix2D->IsIdentity();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMPoint> DOMMatrixReadOnly::TransformPoint(
|
|
|
|
const DOMPointInit& point) const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMPoint> retval = new DOMPoint(mParent);
|
2014-06-24 22:15:00 +04:00
|
|
|
|
|
|
|
if (mMatrix3D) {
|
|
|
|
gfx::Point4D transformedPoint;
|
|
|
|
transformedPoint.x = point.mX;
|
|
|
|
transformedPoint.y = point.mY;
|
|
|
|
transformedPoint.z = point.mZ;
|
|
|
|
transformedPoint.w = point.mW;
|
|
|
|
|
2016-09-08 19:26:03 +03:00
|
|
|
transformedPoint = mMatrix3D->TransformPoint(transformedPoint);
|
2014-06-24 22:15:00 +04:00
|
|
|
|
|
|
|
retval->SetX(transformedPoint.x);
|
|
|
|
retval->SetY(transformedPoint.y);
|
|
|
|
retval->SetZ(transformedPoint.z);
|
|
|
|
retval->SetW(transformedPoint.w);
|
|
|
|
} else if (point.mZ != 0 || point.mW != 1.0) {
|
2019-06-19 18:59:54 +03:00
|
|
|
gfx::Matrix4x4Double tempMatrix(gfx::Matrix4x4Double::From2D(*mMatrix2D));
|
2014-06-24 22:15:00 +04:00
|
|
|
|
2019-06-19 18:59:54 +03:00
|
|
|
gfx::PointDouble4D transformedPoint;
|
2014-06-24 22:15:00 +04:00
|
|
|
transformedPoint.x = point.mX;
|
|
|
|
transformedPoint.y = point.mY;
|
|
|
|
transformedPoint.z = point.mZ;
|
|
|
|
transformedPoint.w = point.mW;
|
|
|
|
|
2016-09-08 19:26:03 +03:00
|
|
|
transformedPoint = tempMatrix.TransformPoint(transformedPoint);
|
2014-06-24 22:15:00 +04:00
|
|
|
|
|
|
|
retval->SetX(transformedPoint.x);
|
|
|
|
retval->SetY(transformedPoint.y);
|
|
|
|
retval->SetZ(transformedPoint.z);
|
|
|
|
retval->SetW(transformedPoint.w);
|
|
|
|
} else {
|
2019-06-19 18:59:54 +03:00
|
|
|
gfx::PointDouble transformedPoint;
|
2014-06-24 22:15:00 +04:00
|
|
|
transformedPoint.x = point.mX;
|
|
|
|
transformedPoint.y = point.mY;
|
|
|
|
|
2016-09-08 19:26:03 +03:00
|
|
|
transformedPoint = mMatrix2D->TransformPoint(transformedPoint);
|
2014-06-24 22:15:00 +04:00
|
|
|
|
|
|
|
retval->SetX(transformedPoint.x);
|
|
|
|
retval->SetY(transformedPoint.y);
|
|
|
|
retval->SetZ(point.mZ);
|
|
|
|
retval->SetW(point.mW);
|
|
|
|
}
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void GetDataFromMatrix(const DOMMatrixReadOnly* aMatrix, T* aData) {
|
|
|
|
aData[0] = static_cast<T>(aMatrix->M11());
|
|
|
|
aData[1] = static_cast<T>(aMatrix->M12());
|
|
|
|
aData[2] = static_cast<T>(aMatrix->M13());
|
|
|
|
aData[3] = static_cast<T>(aMatrix->M14());
|
|
|
|
aData[4] = static_cast<T>(aMatrix->M21());
|
|
|
|
aData[5] = static_cast<T>(aMatrix->M22());
|
|
|
|
aData[6] = static_cast<T>(aMatrix->M23());
|
|
|
|
aData[7] = static_cast<T>(aMatrix->M24());
|
|
|
|
aData[8] = static_cast<T>(aMatrix->M31());
|
|
|
|
aData[9] = static_cast<T>(aMatrix->M32());
|
|
|
|
aData[10] = static_cast<T>(aMatrix->M33());
|
|
|
|
aData[11] = static_cast<T>(aMatrix->M34());
|
|
|
|
aData[12] = static_cast<T>(aMatrix->M41());
|
|
|
|
aData[13] = static_cast<T>(aMatrix->M42());
|
|
|
|
aData[14] = static_cast<T>(aMatrix->M43());
|
|
|
|
aData[15] = static_cast<T>(aMatrix->M44());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DOMMatrixReadOnly::ToFloat32Array(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JSObject*> aResult,
|
|
|
|
ErrorResult& aRv) const {
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<float, 16> arr;
|
2014-06-24 22:15:00 +04:00
|
|
|
arr.SetLength(16);
|
|
|
|
GetDataFromMatrix(this, arr.Elements());
|
|
|
|
JS::Rooted<JS::Value> value(aCx);
|
|
|
|
if (!ToJSValue(aCx, TypedArrayCreator<Float32Array>(arr), &value)) {
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aResult.set(&value.toObject());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DOMMatrixReadOnly::ToFloat64Array(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JSObject*> aResult,
|
|
|
|
ErrorResult& aRv) const {
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<double, 16> arr;
|
2014-06-24 22:15:00 +04:00
|
|
|
arr.SetLength(16);
|
|
|
|
GetDataFromMatrix(this, arr.Elements());
|
|
|
|
JS::Rooted<JS::Value> value(aCx);
|
|
|
|
if (!ToJSValue(aCx, TypedArrayCreator<Float64Array>(arr), &value)) {
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aResult.set(&value.toObject());
|
|
|
|
}
|
|
|
|
|
2019-07-11 05:49:51 +03:00
|
|
|
void DOMMatrixReadOnly::Stringify(nsAString& aResult, ErrorResult& aRv) {
|
|
|
|
char cbuf[JS::MaximumNumberToStringLength];
|
2014-10-20 13:14:00 +04:00
|
|
|
nsAutoString matrixStr;
|
2019-07-11 05:49:51 +03:00
|
|
|
auto AppendDouble = [&aRv, &cbuf, &matrixStr](double d,
|
|
|
|
bool isLastItem = false) {
|
|
|
|
if (!mozilla::IsFinite(d)) {
|
|
|
|
aRv.ThrowDOMException(
|
|
|
|
NS_ERROR_DOM_INVALID_STATE_ERR,
|
|
|
|
NS_LITERAL_CSTRING(
|
|
|
|
"Matrix with a non-finite element cannot be stringified."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
JS::NumberToString(d, cbuf);
|
|
|
|
matrixStr.AppendASCII(cbuf);
|
|
|
|
if (!isLastItem) {
|
|
|
|
matrixStr.AppendLiteral(", ");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2014-10-20 13:14:00 +04:00
|
|
|
if (mMatrix3D) {
|
2017-03-15 06:16:32 +03:00
|
|
|
// We can't use AppendPrintf here, because it does locale-specific
|
|
|
|
// formatting of floating-point values.
|
|
|
|
matrixStr.AssignLiteral("matrix3d(");
|
2019-07-11 05:49:51 +03:00
|
|
|
if (!AppendDouble(M11()) || !AppendDouble(M12()) || !AppendDouble(M13()) ||
|
|
|
|
!AppendDouble(M14()) || !AppendDouble(M21()) || !AppendDouble(M22()) ||
|
|
|
|
!AppendDouble(M23()) || !AppendDouble(M24()) || !AppendDouble(M31()) ||
|
|
|
|
!AppendDouble(M32()) || !AppendDouble(M33()) || !AppendDouble(M34()) ||
|
|
|
|
!AppendDouble(M41()) || !AppendDouble(M42()) || !AppendDouble(M43()) ||
|
|
|
|
!AppendDouble(M44(), true)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-15 06:16:32 +03:00
|
|
|
matrixStr.AppendLiteral(")");
|
2014-10-20 13:14:00 +04:00
|
|
|
} else {
|
2017-03-15 06:16:32 +03:00
|
|
|
// We can't use AppendPrintf here, because it does locale-specific
|
|
|
|
// formatting of floating-point values.
|
|
|
|
matrixStr.AssignLiteral("matrix(");
|
2019-07-11 05:49:51 +03:00
|
|
|
if (!AppendDouble(A()) || !AppendDouble(B()) || !AppendDouble(C()) ||
|
|
|
|
!AppendDouble(D()) || !AppendDouble(E()) || !AppendDouble(F(), true)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-15 06:16:32 +03:00
|
|
|
matrixStr.AppendLiteral(")");
|
2014-10-20 13:14:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
aResult = matrixStr;
|
|
|
|
}
|
|
|
|
|
2019-06-15 20:26:25 +03:00
|
|
|
// https://drafts.fxtf.org/geometry/#structured-serialization
|
|
|
|
bool DOMMatrixReadOnly::WriteStructuredClone(
|
2019-06-25 09:48:29 +03:00
|
|
|
JSContext* aCx, JSStructuredCloneWriter* aWriter) const {
|
2019-06-19 18:59:54 +03:00
|
|
|
#define WriteDouble(d) \
|
|
|
|
JS_WriteUint32Pair(aWriter, (BitwiseCast<uint64_t>(d) >> 32) & 0xffffffff, \
|
|
|
|
BitwiseCast<uint64_t>(d) & 0xffffffff)
|
2019-06-15 20:26:25 +03:00
|
|
|
|
|
|
|
const uint8_t is2D = Is2D();
|
|
|
|
|
|
|
|
if (!JS_WriteBytes(aWriter, &is2D, 1)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is2D == 1) {
|
2019-06-19 18:59:54 +03:00
|
|
|
return WriteDouble(mMatrix2D->_11) && WriteDouble(mMatrix2D->_12) &&
|
|
|
|
WriteDouble(mMatrix2D->_21) && WriteDouble(mMatrix2D->_22) &&
|
|
|
|
WriteDouble(mMatrix2D->_31) && WriteDouble(mMatrix2D->_32);
|
2019-06-15 20:26:25 +03:00
|
|
|
}
|
|
|
|
|
2019-06-19 18:59:54 +03:00
|
|
|
return WriteDouble(mMatrix3D->_11) && WriteDouble(mMatrix3D->_12) &&
|
|
|
|
WriteDouble(mMatrix3D->_13) && WriteDouble(mMatrix3D->_14) &&
|
|
|
|
WriteDouble(mMatrix3D->_21) && WriteDouble(mMatrix3D->_22) &&
|
|
|
|
WriteDouble(mMatrix3D->_23) && WriteDouble(mMatrix3D->_24) &&
|
|
|
|
WriteDouble(mMatrix3D->_31) && WriteDouble(mMatrix3D->_32) &&
|
|
|
|
WriteDouble(mMatrix3D->_33) && WriteDouble(mMatrix3D->_34) &&
|
|
|
|
WriteDouble(mMatrix3D->_41) && WriteDouble(mMatrix3D->_42) &&
|
|
|
|
WriteDouble(mMatrix3D->_43) && WriteDouble(mMatrix3D->_44);
|
2019-06-15 20:26:25 +03:00
|
|
|
|
2019-06-19 18:59:54 +03:00
|
|
|
#undef WriteDouble
|
2019-06-15 20:26:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DOMMatrixReadOnly::ReadStructuredCloneElements(
|
|
|
|
JSStructuredCloneReader* aReader, DOMMatrixReadOnly* matrix) {
|
|
|
|
uint32_t high;
|
|
|
|
uint32_t low;
|
|
|
|
|
2019-06-19 18:59:54 +03:00
|
|
|
#define ReadDouble(d) \
|
2019-06-15 20:26:25 +03:00
|
|
|
if (!JS_ReadUint32Pair(aReader, &high, &low)) { \
|
|
|
|
return false; \
|
|
|
|
} \
|
2019-06-19 18:59:54 +03:00
|
|
|
(*(d) = BitwiseCast<double>(static_cast<uint64_t>(high) << 32 | low))
|
2019-06-15 20:26:25 +03:00
|
|
|
|
|
|
|
if (matrix->Is2D() == 1) {
|
2019-06-19 18:59:54 +03:00
|
|
|
ReadDouble(&(matrix->mMatrix2D->_11));
|
|
|
|
ReadDouble(&(matrix->mMatrix2D->_12));
|
|
|
|
ReadDouble(&(matrix->mMatrix2D->_21));
|
|
|
|
ReadDouble(&(matrix->mMatrix2D->_22));
|
|
|
|
ReadDouble(&(matrix->mMatrix2D->_31));
|
|
|
|
ReadDouble(&(matrix->mMatrix2D->_32));
|
2019-06-15 20:26:25 +03:00
|
|
|
} else {
|
2019-06-19 18:59:54 +03:00
|
|
|
ReadDouble(&(matrix->mMatrix3D->_11));
|
|
|
|
ReadDouble(&(matrix->mMatrix3D->_12));
|
|
|
|
ReadDouble(&(matrix->mMatrix3D->_13));
|
|
|
|
ReadDouble(&(matrix->mMatrix3D->_14));
|
|
|
|
ReadDouble(&(matrix->mMatrix3D->_21));
|
|
|
|
ReadDouble(&(matrix->mMatrix3D->_22));
|
|
|
|
ReadDouble(&(matrix->mMatrix3D->_23));
|
|
|
|
ReadDouble(&(matrix->mMatrix3D->_24));
|
|
|
|
ReadDouble(&(matrix->mMatrix3D->_31));
|
|
|
|
ReadDouble(&(matrix->mMatrix3D->_32));
|
|
|
|
ReadDouble(&(matrix->mMatrix3D->_33));
|
|
|
|
ReadDouble(&(matrix->mMatrix3D->_34));
|
|
|
|
ReadDouble(&(matrix->mMatrix3D->_41));
|
|
|
|
ReadDouble(&(matrix->mMatrix3D->_42));
|
|
|
|
ReadDouble(&(matrix->mMatrix3D->_43));
|
|
|
|
ReadDouble(&(matrix->mMatrix3D->_44));
|
2019-06-15 20:26:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
2019-06-19 18:59:54 +03:00
|
|
|
#undef ReadDouble
|
2019-06-15 20:26:25 +03:00
|
|
|
}
|
|
|
|
|
2019-06-30 06:02:13 +03:00
|
|
|
already_AddRefed<DOMMatrix> DOMMatrix::FromMatrix(
|
|
|
|
nsISupports* aParent, const DOMMatrixInit& aMatrixInit, ErrorResult& aRv) {
|
|
|
|
DOMMatrixInit matrixInit(aMatrixInit);
|
|
|
|
if (!ValidateAndFixupMatrixInit(matrixInit, aRv)) {
|
|
|
|
return nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
RefPtr<DOMMatrix> matrix = new DOMMatrix(aParent, matrixInit.mIs2D.Value());
|
|
|
|
matrix->SetDataFromMatrixInit(matrixInit);
|
|
|
|
return matrix.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMMatrix> DOMMatrix::FromMatrix(
|
|
|
|
const GlobalObject& aGlobal, const DOMMatrixInit& aMatrixInit,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
RefPtr<DOMMatrix> matrix =
|
|
|
|
FromMatrix(aGlobal.GetAsSupports(), aMatrixInit, aRv);
|
|
|
|
return matrix.forget();
|
|
|
|
}
|
|
|
|
|
2019-07-03 08:51:30 +03:00
|
|
|
already_AddRefed<DOMMatrix> DOMMatrix::FromFloat32Array(
|
|
|
|
const GlobalObject& aGlobal, const Float32Array& aArray32,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
aArray32.ComputeLengthAndData();
|
|
|
|
|
|
|
|
const int length = aArray32.Length();
|
|
|
|
const bool is2D = length == 6;
|
|
|
|
RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports(), is2D);
|
|
|
|
SetDataInMatrix(obj, aArray32.Data(), length, aRv);
|
|
|
|
|
|
|
|
return obj.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMMatrix> DOMMatrix::FromFloat64Array(
|
|
|
|
const GlobalObject& aGlobal, const Float64Array& aArray64,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
aArray64.ComputeLengthAndData();
|
|
|
|
|
|
|
|
const int length = aArray64.Length();
|
|
|
|
const bool is2D = length == 6;
|
|
|
|
RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports(), is2D);
|
|
|
|
SetDataInMatrix(obj, aArray64.Data(), length, aRv);
|
|
|
|
|
|
|
|
return obj.forget();
|
|
|
|
}
|
|
|
|
|
2014-06-24 22:15:00 +04:00
|
|
|
already_AddRefed<DOMMatrix> DOMMatrix::Constructor(
|
2019-07-17 00:12:38 +03:00
|
|
|
const GlobalObject& aGlobal,
|
|
|
|
const Optional<StringOrUnrestrictedDoubleSequenceOrDOMMatrixReadOnly>& aArg,
|
2014-06-24 22:15:00 +04:00
|
|
|
ErrorResult& aRv) {
|
2019-07-17 00:12:38 +03:00
|
|
|
if (!aArg.WasPassed()) {
|
|
|
|
RefPtr<DOMMatrix> rval = new DOMMatrix(aGlobal.GetAsSupports());
|
|
|
|
return rval.forget();
|
2019-06-15 20:26:25 +03:00
|
|
|
}
|
2014-06-24 22:15:00 +04:00
|
|
|
|
2019-07-17 00:12:38 +03:00
|
|
|
const auto& arg = aArg.Value();
|
|
|
|
if (arg.IsString()) {
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> win =
|
|
|
|
do_QueryInterface(aGlobal.GetAsSupports());
|
|
|
|
if (!win) {
|
|
|
|
aRv.ThrowTypeError<MSG_ILLEGAL_CONSTRUCTOR>();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
RefPtr<DOMMatrix> rval = new DOMMatrix(aGlobal.GetAsSupports());
|
|
|
|
rval->SetMatrixValue(arg.GetAsString(), aRv);
|
|
|
|
return rval.forget();
|
|
|
|
}
|
|
|
|
if (arg.IsDOMMatrixReadOnly()) {
|
|
|
|
RefPtr<DOMMatrix> obj =
|
|
|
|
new DOMMatrix(aGlobal.GetAsSupports(), arg.GetAsDOMMatrixReadOnly());
|
|
|
|
return obj.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& sequence = arg.GetAsUnrestrictedDoubleSequence();
|
|
|
|
const int length = sequence.Length();
|
|
|
|
const bool is2D = length == 6;
|
|
|
|
RefPtr<DOMMatrix> rval = new DOMMatrix(aGlobal.GetAsSupports(), is2D);
|
|
|
|
SetDataInMatrix(rval, sequence.Elements(), length, aRv);
|
|
|
|
return rval.forget();
|
2014-06-24 22:15:00 +04:00
|
|
|
}
|
|
|
|
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
template <typename T>
|
|
|
|
static void SetDataInMatrix(DOMMatrixReadOnly* aMatrix, const T* aData,
|
|
|
|
int aLength, ErrorResult& aRv) {
|
2014-06-24 22:15:00 +04:00
|
|
|
if (aLength == 16) {
|
|
|
|
aMatrix->SetM11(aData[0]);
|
|
|
|
aMatrix->SetM12(aData[1]);
|
|
|
|
aMatrix->SetM13(aData[2]);
|
|
|
|
aMatrix->SetM14(aData[3]);
|
|
|
|
aMatrix->SetM21(aData[4]);
|
|
|
|
aMatrix->SetM22(aData[5]);
|
|
|
|
aMatrix->SetM23(aData[6]);
|
|
|
|
aMatrix->SetM24(aData[7]);
|
|
|
|
aMatrix->SetM31(aData[8]);
|
|
|
|
aMatrix->SetM32(aData[9]);
|
|
|
|
aMatrix->SetM33(aData[10]);
|
|
|
|
aMatrix->SetM34(aData[11]);
|
|
|
|
aMatrix->SetM41(aData[12]);
|
|
|
|
aMatrix->SetM42(aData[13]);
|
|
|
|
aMatrix->SetM43(aData[14]);
|
|
|
|
aMatrix->SetM44(aData[15]);
|
|
|
|
} else if (aLength == 6) {
|
|
|
|
aMatrix->SetA(aData[0]);
|
|
|
|
aMatrix->SetB(aData[1]);
|
|
|
|
aMatrix->SetC(aData[2]);
|
|
|
|
aMatrix->SetD(aData[3]);
|
|
|
|
aMatrix->SetE(aData[4]);
|
|
|
|
aMatrix->SetF(aData[5]);
|
|
|
|
} else {
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
nsAutoString lengthStr;
|
|
|
|
lengthStr.AppendInt(aLength);
|
|
|
|
aRv.ThrowTypeError<MSG_MATRIX_INIT_LENGTH_WRONG>(lengthStr);
|
2014-06-24 22:15:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-15 20:26:25 +03:00
|
|
|
already_AddRefed<DOMMatrix> DOMMatrix::ReadStructuredClone(
|
2019-06-25 09:48:29 +03:00
|
|
|
JSContext* aCx, nsIGlobalObject* aGlobal,
|
|
|
|
JSStructuredCloneReader* aReader) {
|
2019-06-15 20:26:25 +03:00
|
|
|
uint8_t is2D;
|
|
|
|
|
|
|
|
if (!JS_ReadBytes(aReader, &is2D, 1)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-06-25 09:48:29 +03:00
|
|
|
RefPtr<DOMMatrix> rval = new DOMMatrix(aGlobal, is2D);
|
2019-06-15 20:26:25 +03:00
|
|
|
|
|
|
|
if (!ReadStructuredCloneElements(aReader, rval)) {
|
|
|
|
return nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
return rval.forget();
|
|
|
|
}
|
|
|
|
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
void DOMMatrixReadOnly::Ensure3DMatrix() {
|
2014-06-24 22:15:00 +04:00
|
|
|
if (!mMatrix3D) {
|
2019-06-19 18:59:54 +03:00
|
|
|
mMatrix3D =
|
|
|
|
new gfx::Matrix4x4Double(gfx::Matrix4x4Double::From2D(*mMatrix2D));
|
2014-06-24 22:15:00 +04:00
|
|
|
mMatrix2D = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-30 06:02:13 +03:00
|
|
|
DOMMatrix* DOMMatrix::MultiplySelf(const DOMMatrixInit& aOtherInit,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
RefPtr<DOMMatrix> other = FromMatrix(mParent, aOtherInit, aRv);
|
|
|
|
if (other->IsIdentity()) {
|
2014-06-24 22:15:00 +04:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-06-30 06:02:13 +03:00
|
|
|
if (other->Is2D()) {
|
2014-06-24 22:15:00 +04:00
|
|
|
if (mMatrix3D) {
|
2019-06-30 06:02:13 +03:00
|
|
|
*mMatrix3D = gfx::Matrix4x4Double::From2D(*other->mMatrix2D) * *mMatrix3D;
|
2014-06-24 22:15:00 +04:00
|
|
|
} else {
|
2019-06-30 06:02:13 +03:00
|
|
|
*mMatrix2D = *other->mMatrix2D * *mMatrix2D;
|
2014-06-24 22:15:00 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Ensure3DMatrix();
|
2019-06-30 06:02:13 +03:00
|
|
|
*mMatrix3D = *other->mMatrix3D * *mMatrix3D;
|
2014-06-24 22:15:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-06-30 06:02:13 +03:00
|
|
|
DOMMatrix* DOMMatrix::PreMultiplySelf(const DOMMatrixInit& aOtherInit,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
RefPtr<DOMMatrix> other = FromMatrix(mParent, aOtherInit, aRv);
|
|
|
|
if (other->IsIdentity()) {
|
2014-06-24 22:15:00 +04:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-06-30 06:02:13 +03:00
|
|
|
if (other->Is2D()) {
|
2014-06-24 22:15:00 +04:00
|
|
|
if (mMatrix3D) {
|
2019-06-30 06:02:13 +03:00
|
|
|
*mMatrix3D = *mMatrix3D * gfx::Matrix4x4Double::From2D(*other->mMatrix2D);
|
2014-06-24 22:15:00 +04:00
|
|
|
} else {
|
2019-06-30 06:02:13 +03:00
|
|
|
*mMatrix2D = *mMatrix2D * *other->mMatrix2D;
|
2014-06-24 22:15:00 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Ensure3DMatrix();
|
2019-06-30 06:02:13 +03:00
|
|
|
*mMatrix3D = *mMatrix3D * *other->mMatrix3D;
|
2014-06-24 22:15:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMMatrix* DOMMatrix::TranslateSelf(double aTx, double aTy, double aTz) {
|
|
|
|
if (aTx == 0 && aTy == 0 && aTz == 0) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mMatrix3D || aTz != 0) {
|
|
|
|
Ensure3DMatrix();
|
2014-10-16 13:51:12 +04:00
|
|
|
mMatrix3D->PreTranslate(aTx, aTy, aTz);
|
2014-06-24 22:15:00 +04:00
|
|
|
} else {
|
2014-09-10 21:29:35 +04:00
|
|
|
mMatrix2D->PreTranslate(aTx, aTy);
|
2014-06-24 22:15:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-06-28 18:11:00 +03:00
|
|
|
DOMMatrix* DOMMatrix::ScaleSelf(double aScaleX, const Optional<double>& aScaleY,
|
|
|
|
double aScaleZ, double aOriginX,
|
|
|
|
double aOriginY, double aOriginZ) {
|
|
|
|
const double scaleY = aScaleY.WasPassed() ? aScaleY.Value() : aScaleX;
|
2014-06-24 22:15:00 +04:00
|
|
|
|
|
|
|
TranslateSelf(aOriginX, aOriginY, aOriginZ);
|
|
|
|
|
2019-06-28 18:11:00 +03:00
|
|
|
if (mMatrix3D || aScaleZ != 1.0) {
|
2014-06-24 22:15:00 +04:00
|
|
|
Ensure3DMatrix();
|
2019-06-19 18:59:54 +03:00
|
|
|
gfx::Matrix4x4Double m;
|
2014-06-24 22:15:00 +04:00
|
|
|
m._11 = aScaleX;
|
2019-06-28 18:11:00 +03:00
|
|
|
m._22 = scaleY;
|
2014-06-24 22:15:00 +04:00
|
|
|
m._33 = aScaleZ;
|
|
|
|
*mMatrix3D = m * *mMatrix3D;
|
|
|
|
} else {
|
2019-06-19 18:59:54 +03:00
|
|
|
gfx::MatrixDouble m;
|
2014-06-24 22:15:00 +04:00
|
|
|
m._11 = aScaleX;
|
2019-06-28 18:11:00 +03:00
|
|
|
m._22 = scaleY;
|
2014-06-24 22:15:00 +04:00
|
|
|
*mMatrix2D = m * *mMatrix2D;
|
|
|
|
}
|
|
|
|
|
|
|
|
TranslateSelf(-aOriginX, -aOriginY, -aOriginZ);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-06-28 18:11:00 +03:00
|
|
|
DOMMatrix* DOMMatrix::Scale3dSelf(double aScale, double aOriginX,
|
|
|
|
double aOriginY, double aOriginZ) {
|
|
|
|
ScaleSelf(aScale, Optional<double>(aScale), aScale, aOriginX, aOriginY,
|
|
|
|
aOriginZ);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2014-06-24 22:15:00 +04:00
|
|
|
DOMMatrix* DOMMatrix::RotateFromVectorSelf(double aX, double aY) {
|
2019-07-04 10:39:45 +03:00
|
|
|
const double angle = (aX == 0.0 && aY == 0.0) ? 0 : atan2(aY, aX);
|
2019-07-02 11:29:46 +03:00
|
|
|
|
|
|
|
if (fmod(angle, 2 * M_PI) == 0) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mMatrix3D) {
|
|
|
|
RotateAxisAngleSelf(0, 0, 1, angle / radPerDegree);
|
|
|
|
} else {
|
|
|
|
*mMatrix2D = mMatrix2D->PreRotate(angle);
|
|
|
|
}
|
2014-06-24 22:15:00 +04:00
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-07-02 11:29:46 +03:00
|
|
|
DOMMatrix* DOMMatrix::RotateSelf(double aRotX, const Optional<double>& aRotY,
|
|
|
|
const Optional<double>& aRotZ) {
|
|
|
|
double rotY;
|
|
|
|
double rotZ;
|
|
|
|
if (!aRotY.WasPassed() && !aRotZ.WasPassed()) {
|
|
|
|
rotZ = aRotX;
|
|
|
|
aRotX = 0;
|
|
|
|
rotY = 0;
|
|
|
|
} else {
|
|
|
|
rotY = aRotY.WasPassed() ? aRotY.Value() : 0;
|
|
|
|
rotZ = aRotZ.WasPassed() ? aRotZ.Value() : 0;
|
2014-06-24 22:15:00 +04:00
|
|
|
}
|
|
|
|
|
2019-07-02 11:29:46 +03:00
|
|
|
if (aRotX != 0 || rotY != 0) {
|
|
|
|
Ensure3DMatrix();
|
|
|
|
}
|
2014-06-24 22:15:00 +04:00
|
|
|
|
|
|
|
if (mMatrix3D) {
|
2019-07-02 11:29:46 +03:00
|
|
|
if (fmod(rotZ, 360) != 0) {
|
|
|
|
mMatrix3D->RotateZ(rotZ * radPerDegree);
|
|
|
|
}
|
|
|
|
if (fmod(rotY, 360) != 0) {
|
|
|
|
mMatrix3D->RotateY(rotY * radPerDegree);
|
|
|
|
}
|
|
|
|
if (fmod(aRotX, 360) != 0) {
|
|
|
|
mMatrix3D->RotateX(aRotX * radPerDegree);
|
|
|
|
}
|
|
|
|
} else if (fmod(rotZ, 360) != 0) {
|
|
|
|
*mMatrix2D = mMatrix2D->PreRotate(rotZ * radPerDegree);
|
2014-06-24 22:15:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMMatrix* DOMMatrix::RotateAxisAngleSelf(double aX, double aY, double aZ,
|
|
|
|
double aAngle) {
|
|
|
|
if (fmod(aAngle, 360) == 0) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
aAngle *= radPerDegree;
|
|
|
|
|
|
|
|
Ensure3DMatrix();
|
2019-06-19 18:59:54 +03:00
|
|
|
gfx::Matrix4x4Double m;
|
2016-02-04 11:30:00 +03:00
|
|
|
m.SetRotateAxisAngle(aX, aY, aZ, aAngle);
|
2014-06-24 22:15:00 +04:00
|
|
|
|
|
|
|
*mMatrix3D = m * *mMatrix3D;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMMatrix* DOMMatrix::SkewXSelf(double aSx) {
|
|
|
|
if (fmod(aSx, 360) == 0) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mMatrix3D) {
|
2019-06-19 18:59:54 +03:00
|
|
|
gfx::Matrix4x4Double m;
|
2014-06-24 22:15:00 +04:00
|
|
|
m._21 = tan(aSx * radPerDegree);
|
|
|
|
*mMatrix3D = m * *mMatrix3D;
|
|
|
|
} else {
|
2019-06-19 18:59:54 +03:00
|
|
|
gfx::MatrixDouble m;
|
2014-06-24 22:15:00 +04:00
|
|
|
m._21 = tan(aSx * radPerDegree);
|
|
|
|
*mMatrix2D = m * *mMatrix2D;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMMatrix* DOMMatrix::SkewYSelf(double aSy) {
|
|
|
|
if (fmod(aSy, 360) == 0) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mMatrix3D) {
|
2019-06-19 18:59:54 +03:00
|
|
|
gfx::Matrix4x4Double m;
|
2014-06-24 22:15:00 +04:00
|
|
|
m._12 = tan(aSy * radPerDegree);
|
|
|
|
*mMatrix3D = m * *mMatrix3D;
|
|
|
|
} else {
|
2019-06-19 18:59:54 +03:00
|
|
|
gfx::MatrixDouble m;
|
2014-06-24 22:15:00 +04:00
|
|
|
m._12 = tan(aSy * radPerDegree);
|
|
|
|
*mMatrix2D = m * *mMatrix2D;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMMatrix* DOMMatrix::InvertSelf() {
|
|
|
|
if (mMatrix3D) {
|
|
|
|
if (!mMatrix3D->Invert()) {
|
|
|
|
mMatrix3D->SetNAN();
|
|
|
|
}
|
|
|
|
} else if (!mMatrix2D->Invert()) {
|
|
|
|
mMatrix2D = nullptr;
|
|
|
|
|
2019-06-19 18:59:54 +03:00
|
|
|
mMatrix3D = new gfx::Matrix4x4Double();
|
2014-06-24 22:15:00 +04:00
|
|
|
mMatrix3D->SetNAN();
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
DOMMatrixReadOnly* DOMMatrixReadOnly::SetMatrixValue(
|
|
|
|
const nsAString& aTransformList, ErrorResult& aRv) {
|
2017-11-14 12:41:46 +03:00
|
|
|
// An empty string is a no-op.
|
|
|
|
if (aTransformList.IsEmpty()) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-11-27 09:27:56 +03:00
|
|
|
gfx::Matrix4x4 transform;
|
|
|
|
bool contains3dTransform = false;
|
2018-03-25 20:42:10 +03:00
|
|
|
if (!ServoCSSParser::ParseTransformIntoMatrix(
|
2019-03-21 20:00:27 +03:00
|
|
|
aTransformList, contains3dTransform, transform)) {
|
2018-03-25 20:42:10 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
|
|
|
return nullptr;
|
2017-11-27 09:27:56 +03:00
|
|
|
}
|
2017-11-14 12:41:46 +03:00
|
|
|
|
|
|
|
if (!contains3dTransform) {
|
|
|
|
mMatrix3D = nullptr;
|
2019-06-20 06:59:59 +03:00
|
|
|
if (!mMatrix2D) {
|
|
|
|
mMatrix2D = new gfx::MatrixDouble();
|
|
|
|
}
|
2017-11-14 12:41:46 +03:00
|
|
|
|
|
|
|
SetA(transform._11);
|
|
|
|
SetB(transform._12);
|
|
|
|
SetC(transform._21);
|
|
|
|
SetD(transform._22);
|
|
|
|
SetE(transform._41);
|
|
|
|
SetF(transform._42);
|
|
|
|
} else {
|
2019-06-19 18:59:54 +03:00
|
|
|
mMatrix3D = new gfx::Matrix4x4Double(transform);
|
2017-11-14 12:41:46 +03:00
|
|
|
mMatrix2D = nullptr;
|
2014-06-24 22:15:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
DOMMatrix* DOMMatrix::SetMatrixValue(const nsAString& aTransformList,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
DOMMatrixReadOnly::SetMatrixValue(aTransformList, aRv);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
JSObject* DOMMatrix::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return DOMMatrix_Binding::Wrap(aCx, this, aGivenProto);
|
2014-06-24 22:15:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|