Bug 1397945: Align DOMMatrix scale* operations to the spec r=bzbarsky

Adjusted scale() to receive six arguments, scale3d() to allow zero argument, and scaleNonUniform to support only two arguments.  Try: https://treeherder.mozilla.org/#/jobs?repo=try&revision=e6484802f1961c7fe881b4d1d7f4309ec19110a7

Differential Revision: https://phabricator.services.mozilla.com/D36147

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kagami Sascha Rosylight 2019-06-28 15:11:00 +00:00
Родитель 167403a1d1
Коммит 5e70c0e2ab
13 изменённых файлов: 70 добавлений и 150 удалений

Просмотреть файл

@ -219,11 +219,11 @@ already_AddRefed<DOMMatrix> DOMMatrixReadOnly::Translate(double aTx, double aTy,
return retval.forget();
}
already_AddRefed<DOMMatrix> DOMMatrixReadOnly::Scale(double aScale,
double aOriginX,
double aOriginY) const {
already_AddRefed<DOMMatrix> DOMMatrixReadOnly::Scale(
double aScaleX, const Optional<double>& aScaleY, double aScaleZ,
double aOriginX, double aOriginY, double aOriginZ) const {
RefPtr<DOMMatrix> retval = new DOMMatrix(mParent, *this);
retval->ScaleSelf(aScale, aOriginX, aOriginY);
retval->ScaleSelf(aScaleX, aScaleY, aScaleZ, aOriginX, aOriginY, aOriginZ);
return retval.forget();
}
@ -239,11 +239,9 @@ already_AddRefed<DOMMatrix> DOMMatrixReadOnly::Scale3d(double aScale,
}
already_AddRefed<DOMMatrix> DOMMatrixReadOnly::ScaleNonUniform(
double aScaleX, double aScaleY, double aScaleZ, double aOriginX,
double aOriginY, double aOriginZ) const {
double aScaleX, double aScaleY) const {
RefPtr<DOMMatrix> retval = new DOMMatrix(mParent, *this);
retval->ScaleNonUniformSelf(aScaleX, aScaleY, aScaleZ, aOriginX, aOriginY,
aOriginZ);
retval->ScaleSelf(aScaleX, Optional<double>(aScaleY), 1, 0, 0, 0);
return retval.forget();
}
@ -775,16 +773,36 @@ DOMMatrix* DOMMatrix::TranslateSelf(double aTx, double aTy, double aTz) {
return this;
}
DOMMatrix* DOMMatrix::ScaleSelf(double aScale, double aOriginX,
double aOriginY) {
ScaleNonUniformSelf(aScale, aScale, 1.0, aOriginX, aOriginY, 0);
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;
TranslateSelf(aOriginX, aOriginY, aOriginZ);
if (mMatrix3D || aScaleZ != 1.0) {
Ensure3DMatrix();
gfx::Matrix4x4Double m;
m._11 = aScaleX;
m._22 = scaleY;
m._33 = aScaleZ;
*mMatrix3D = m * *mMatrix3D;
} else {
gfx::MatrixDouble m;
m._11 = aScaleX;
m._22 = scaleY;
*mMatrix2D = m * *mMatrix2D;
}
TranslateSelf(-aOriginX, -aOriginY, -aOriginZ);
return this;
}
DOMMatrix* DOMMatrix::Scale3dSelf(double aScale, double aOriginX,
double aOriginY, double aOriginZ) {
ScaleNonUniformSelf(aScale, aScale, aScale, aOriginX, aOriginY, aOriginZ);
ScaleSelf(aScale, Optional<double>(aScale), aScale, aOriginX, aOriginY,
aOriginZ);
return this;
}
@ -792,27 +810,8 @@ DOMMatrix* DOMMatrix::Scale3dSelf(double aScale, double aOriginX,
DOMMatrix* DOMMatrix::ScaleNonUniformSelf(double aScaleX, double aScaleY,
double aScaleZ, double aOriginX,
double aOriginY, double aOriginZ) {
if (aScaleX == 1.0 && aScaleY == 1.0 && aScaleZ == 1.0) {
return this;
}
TranslateSelf(aOriginX, aOriginY, aOriginZ);
if (mMatrix3D || aScaleZ != 1.0 || aOriginZ != 0) {
Ensure3DMatrix();
gfx::Matrix4x4Double m;
m._11 = aScaleX;
m._22 = aScaleY;
m._33 = aScaleZ;
*mMatrix3D = m * *mMatrix3D;
} else {
gfx::MatrixDouble m;
m._11 = aScaleX;
m._22 = aScaleY;
*mMatrix2D = m * *mMatrix2D;
}
TranslateSelf(-aOriginX, -aOriginY, -aOriginZ);
ScaleSelf(aScaleX, Optional<double>(aScaleY), aScaleZ, aOriginX, aOriginY,
aOriginZ);
return this;
}

Просмотреть файл

@ -162,14 +162,15 @@ class DOMMatrixReadOnly : public nsWrapperCache {
already_AddRefed<DOMMatrix> Translate(double aTx, double aTy,
double aTz = 0) const;
already_AddRefed<DOMMatrix> Scale(double aScale, double aOriginX = 0,
double aOriginY = 0) const;
already_AddRefed<DOMMatrix> Scale(double aScaleX,
const Optional<double>& aScaleY,
double aScaleZ, double aOriginX,
double aOriginY, double aOriginZ) const;
already_AddRefed<DOMMatrix> Scale3d(double aScale, double aOriginX = 0,
double aOriginY = 0,
double aOriginZ = 0) const;
already_AddRefed<DOMMatrix> ScaleNonUniform(
double aScaleX, double aScaleY = 1.0, double aScaleZ = 1.0,
double aOriginX = 0, double aOriginY = 0, double aOriginZ = 0) const;
already_AddRefed<DOMMatrix> ScaleNonUniform(double aScaleX,
double aScaleY) const;
already_AddRefed<DOMMatrix> Rotate(double aAngle, double aOriginX = 0,
double aOriginY = 0) const;
already_AddRefed<DOMMatrix> RotateFromVector(double aX, double aY) const;
@ -275,7 +276,9 @@ class DOMMatrix : public DOMMatrixReadOnly {
DOMMatrix* MultiplySelf(const DOMMatrixInit& aOther, ErrorResult& aRv);
DOMMatrix* PreMultiplySelf(const DOMMatrixInit& aOther, ErrorResult& aRv);
DOMMatrix* TranslateSelf(double aTx, double aTy, double aTz = 0);
DOMMatrix* ScaleSelf(double aScale, double aOriginX = 0, double aOriginY = 0);
DOMMatrix* ScaleSelf(double aScaleX, const Optional<double>& aScaleY,
double aScaleZ, double aOriginX, double aOriginY,
double aOriginZ);
DOMMatrix* Scale3dSelf(double aScale, double aOriginX = 0,
double aOriginY = 0, double aOriginZ = 0);
DOMMatrix* ScaleNonUniformSelf(double aScaleX, double aScaleY = 1,

Просмотреть файл

@ -96,18 +96,6 @@ already_AddRefed<WebKitCSSMatrix> WebKitCSSMatrix::Translate(double aTx,
return retval.forget();
}
already_AddRefed<WebKitCSSMatrix> WebKitCSSMatrix::Scale(
double aScaleX, const Optional<double>& aScaleY, double aScaleZ) const {
double scaleX = aScaleX;
double scaleY = aScaleY.WasPassed() ? aScaleY.Value() : scaleX;
double scaleZ = aScaleZ;
RefPtr<WebKitCSSMatrix> retval = new WebKitCSSMatrix(mParent, *this);
retval->ScaleNonUniformSelf(scaleX, scaleY, scaleZ);
return retval.forget();
}
already_AddRefed<WebKitCSSMatrix> WebKitCSSMatrix::Rotate(
double aRotX, const Optional<double>& aRotY,
const Optional<double>& aRotZ) const {

Просмотреть файл

@ -42,9 +42,6 @@ class WebKitCSSMatrix final : public DOMMatrix {
already_AddRefed<WebKitCSSMatrix> Inverse(ErrorResult& aRv) const;
already_AddRefed<WebKitCSSMatrix> Translate(double aTx, double aTy,
double aTz) const;
already_AddRefed<WebKitCSSMatrix> Scale(double aScaleX,
const Optional<double>& aScaleY,
double aScaleZ) const;
already_AddRefed<WebKitCSSMatrix> Rotate(double aRotX,
const Optional<double>& aRotY,
const Optional<double>& aRotZ) const;

Просмотреть файл

@ -138,7 +138,7 @@ test(function() {
var m3 = new WebKitCSSMatrix("matrix(1,2,3,4,5,6)");
var m1r = m1.scale(2);
var m2r = m2.scaleNonUniform(2, 2, 1);
var m2r = m2.scale(2, 2, 1);
assert_true(RoughCompareMatrix(m1r, m2r), "scale should return the same result as DOMMatrixReadOnly.");
assert_true(CompareMatrix(m1, m3), "scale should not mutate original matrix.");
@ -150,7 +150,7 @@ test(function() {
var m3 = new WebKitCSSMatrix("matrix(1,2,3,4,5,6)");
var m1r = m1.scale(2, 3);
var m2r = m2.scaleNonUniform(2, 3, 1);
var m2r = m2.scale(2, 3, 1);
assert_true(RoughCompareMatrix(m1r, m2r), "scale should return the same result as DOMMatrixReadOnly.");
assert_true(CompareMatrix(m1, m3), "scale should not mutate original matrix.");
@ -162,7 +162,7 @@ test(function() {
var m3 = new WebKitCSSMatrix("matrix(1,2,3,4,5,6)");
var m1r = m1.scale(2, 3, 4);
var m2r = m2.scaleNonUniform(2, 3, 4);
var m2r = m2.scale(2, 3, 4);
assert_true(RoughCompareMatrix(m1r, m2r), "scale should return the same result as DOMMatrixReadOnly.");
assert_true(CompareMatrix(m1, m3), "scale should not mutate original matrix.");
@ -174,7 +174,7 @@ test(function() {
var m3 = new WebKitCSSMatrix("matrix(1,2,3,4,5,6)");
var m1r = m1.scale(undefined, 3, 4);
var m2r = m2.scaleNonUniform(1, 3, 4);
var m2r = m2.scale(1, 3, 4);
assert_true(RoughCompareMatrix(m1r, m2r), "scale should return the same result as DOMMatrixReadOnly.");
assert_true(CompareMatrix(m1, m3), "scale should not mutate original matrix.");
@ -186,7 +186,7 @@ test(function() {
var m3 = new WebKitCSSMatrix("matrix(1,2,3,4,5,6)");
var m1r = m1.scale(2, undefined, 4);
var m2r = m2.scaleNonUniform(2, 2, 4);
var m2r = m2.scale(2, 2, 4);
assert_true(RoughCompareMatrix(m1r, m2r), "scale should return the same result as DOMMatrixReadOnly.");
assert_true(CompareMatrix(m1, m3), "scale should not mutate original matrix.");
@ -198,7 +198,7 @@ test(function() {
var m3 = new WebKitCSSMatrix("matrix(1,2,3,4,5,6)");
var m1r = m1.scale(2, 3, undefined);
var m2r = m2.scaleNonUniform(2, 3, 1);
var m2r = m2.scale(2, 3, 1);
assert_true(RoughCompareMatrix(m1r, m2r), "scale should return the same result as DOMMatrixReadOnly.");
assert_true(CompareMatrix(m1, m3), "scale should not mutate original matrix.");

Просмотреть файл

@ -46,19 +46,18 @@ interface DOMMatrixReadOnly {
DOMMatrix translate(optional unrestricted double tx = 0,
optional unrestricted double ty = 0,
optional unrestricted double tz = 0);
DOMMatrix scale(unrestricted double scale,
optional unrestricted double originX = 0,
optional unrestricted double originY = 0);
DOMMatrix scale3d(unrestricted double scale,
[NewObject] DOMMatrix scale(optional unrestricted double scaleX = 1,
optional unrestricted double scaleY,
optional unrestricted double scaleZ = 1,
optional unrestricted double originX = 0,
optional unrestricted double originY = 0,
optional unrestricted double originZ = 0);
[NewObject] DOMMatrix scaleNonUniform(optional unrestricted double scaleX = 1,
optional unrestricted double scaleY = 1);
DOMMatrix scale3d(optional unrestricted double scale = 1,
optional unrestricted double originX = 0,
optional unrestricted double originY = 0,
optional unrestricted double originZ = 0);
DOMMatrix scaleNonUniform(unrestricted double scaleX,
optional unrestricted double scaleY = 1,
optional unrestricted double scaleZ = 1,
optional unrestricted double originX = 0,
optional unrestricted double originY = 0,
optional unrestricted double originZ = 0);
DOMMatrix rotate(unrestricted double angle,
optional unrestricted double originX = 0,
optional unrestricted double originY = 0);
@ -128,10 +127,13 @@ interface DOMMatrix : DOMMatrixReadOnly {
DOMMatrix translateSelf(optional unrestricted double tx = 0,
optional unrestricted double ty = 0,
optional unrestricted double tz = 0);
DOMMatrix scaleSelf(unrestricted double scale,
DOMMatrix scaleSelf(optional unrestricted double scaleX = 1,
optional unrestricted double scaleY,
optional unrestricted double scaleZ = 1,
optional unrestricted double originX = 0,
optional unrestricted double originY = 0);
DOMMatrix scale3dSelf(unrestricted double scale,
optional unrestricted double originY = 0,
optional unrestricted double originZ = 0);
DOMMatrix scale3dSelf(optional unrestricted double scale = 1,
optional unrestricted double originX = 0,
optional unrestricted double originY = 0,
optional unrestricted double originZ = 0);

Просмотреть файл

@ -25,9 +25,6 @@ interface WebKitCSSMatrix : DOMMatrix {
WebKitCSSMatrix translate(optional unrestricted double tx = 0,
optional unrestricted double ty = 0,
optional unrestricted double tz = 0);
WebKitCSSMatrix scale(optional unrestricted double scaleX = 1,
optional unrestricted double scaleY,
optional unrestricted double scaleZ = 1);
WebKitCSSMatrix rotate(optional unrestricted double rotX = 0,
optional unrestricted double rotY,
optional unrestricted double rotZ);

Просмотреть файл

@ -1,22 +1,3 @@
[DOMMatrix-003.html]
[test scale() without offsets]
expected: FAIL
[test scale() with offsets]
expected: FAIL
[test scale3d()]
expected: FAIL
[test rotate()]
expected: FAIL
[test scaleNonUniform()]
expected: FAIL
[test scaleNonUniform() with sx]
expected: FAIL
[test scaleNonUniform() with sx, sy]
expected: FAIL
expected: FAIL

Просмотреть файл

@ -1,10 +1,4 @@
[DOMMatrix-newobject.html]
[DOMMatrix scale]
expected: FAIL
[DOMMatrix scale3d]
expected: FAIL
[DOMMatrix rotate]
expected: FAIL
@ -14,12 +8,6 @@
[DOMMatrix rotateAxisAngle]
expected: FAIL
[DOMMatrixReadOnly scale]
expected: FAIL
[DOMMatrixReadOnly scale3d]
expected: FAIL
[DOMMatrixReadOnly rotate]
expected: FAIL

Просмотреть файл

@ -2,24 +2,12 @@
[DOMMatrix scaleNonUniformSelf must be nuked]
expected: FAIL
[DOMMatrixReadOnly scale number of required arguments]
expected: FAIL
[DOMMatrix scaleSelf number of required arguments]
expected: FAIL
[DOMMatrixReadOnly scale3d number of required arguments]
expected: FAIL
[DOMMatrixReadOnly rotateFromVector number of required arguments]
expected: FAIL
[DOMMatrixReadOnly rotateAxisAngle number of required arguments]
expected: FAIL
[DOMMatrix scale3dSelf number of required arguments]
expected: FAIL
[DOMMatrix rotateFromVectorSelf number of required arguments]
expected: FAIL

Просмотреть файл

@ -53,15 +53,6 @@
[DOMMatrixReadOnly interface: operation fromFloat64Array(Float64Array)]
expected: FAIL
[DOMMatrixReadOnly interface: operation scale(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double)]
expected: FAIL
[DOMMatrixReadOnly interface: operation scaleNonUniform(unrestricted double, unrestricted double)]
expected: FAIL
[DOMMatrixReadOnly interface: operation scale3d(unrestricted double, unrestricted double, unrestricted double, unrestricted double)]
expected: FAIL
[DOMMatrixReadOnly interface: operation rotate(unrestricted double, unrestricted double, unrestricted double)]
expected: FAIL
@ -86,12 +77,6 @@
[DOMMatrix interface: operation fromFloat64Array(Float64Array)]
expected: FAIL
[DOMMatrix interface: operation scaleSelf(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double)]
expected: FAIL
[DOMMatrix interface: operation scale3dSelf(unrestricted double, unrestricted double, unrestricted double, unrestricted double)]
expected: FAIL
[DOMMatrix interface: operation rotateSelf(unrestricted double, unrestricted double, unrestricted double)]
expected: FAIL

Просмотреть файл

@ -47,15 +47,6 @@
[DOMMatrixReadOnly interface: operation fromFloat64Array(Float64Array)]
expected: FAIL
[DOMMatrixReadOnly interface: operation scale(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double)]
expected: FAIL
[DOMMatrixReadOnly interface: operation scaleNonUniform(unrestricted double, unrestricted double)]
expected: FAIL
[DOMMatrixReadOnly interface: operation scale3d(unrestricted double, unrestricted double, unrestricted double, unrestricted double)]
expected: FAIL
[DOMMatrixReadOnly interface: operation rotate(unrestricted double, unrestricted double, unrestricted double)]
expected: FAIL
@ -77,12 +68,6 @@
[DOMMatrix interface: operation fromFloat64Array(Float64Array)]
expected: FAIL
[DOMMatrix interface: operation scaleSelf(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double)]
expected: FAIL
[DOMMatrix interface: operation scale3dSelf(unrestricted double, unrestricted double, unrestricted double, unrestricted double)]
expected: FAIL
[DOMMatrix interface: operation rotateSelf(unrestricted double, unrestricted double, unrestricted double)]
expected: FAIL

Просмотреть файл

@ -139,6 +139,13 @@
checkDOMMatrix(result, expected);
},"test scale() with offsets");
test(function() {
var result = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6])
.scale(1, 1, 1, 1, 1, 1);
var expected = new DOMMatrixReadOnly([1, 2, 0, 0, 3, 4, 0, 0, 0, 0, 1, 0, 5, 6, 0, 1]);
checkDOMMatrix(result, expected);
},"test scale() with identity scale and nonzero originZ");
test(function() {
var result = initialDOMMatrix().scaleNonUniform();
var expected = initialDOMMatrix()