diff --git a/dom/base/DOMMatrix.cpp b/dom/base/DOMMatrix.cpp index f2dbe2a2a7..307fb27e92 100644 --- a/dom/base/DOMMatrix.cpp +++ b/dom/base/DOMMatrix.cpp @@ -320,12 +320,11 @@ DOMMatrixReadOnly::ScaleNonUniform(double aScaleX, } already_AddRefed -DOMMatrixReadOnly::Rotate(double aAngle, - double aOriginX , - double aOriginY) const -{ +DOMMatrixReadOnly::Rotate(double aRotX, + const Optional& aRotY, + const Optional& aRotZ) const { RefPtr retval = new DOMMatrix(mParent, *this); - retval->RotateSelf(aAngle, aOriginX, aOriginY); + retval->RotateSelf(aRotX, aRotY, aRotZ); return retval.forget(); } @@ -893,28 +892,52 @@ DOMMatrix::RotateFromVectorSelf(double aX, double aY) return this; } - RotateSelf(atan2(aY, aX) / radPerDegree); + const double angle = atan2(aY, aX); + + if (fmod(angle, 2 * M_PI) == 0) { + return this; + } + + if (mMatrix3D) { + RotateAxisAngleSelf(0, 0, 1, angle / radPerDegree); + } else { + *mMatrix2D = mMatrix2D->PreRotate(angle); + } return this; } -DOMMatrix* -DOMMatrix::RotateSelf(double aAngle, double aOriginX, double aOriginY) -{ - if (fmod(aAngle, 360) == 0) { - return this; +DOMMatrix* DOMMatrix::RotateSelf(double aRotX, const Optional& aRotY, + const Optional& 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; } - TranslateSelf(aOriginX, aOriginY); + if (aRotX != 0 || rotY != 0) { + Ensure3DMatrix(); + } if (mMatrix3D) { - RotateAxisAngleSelf(0, 0, 1, aAngle); - } else { - *mMatrix2D = mMatrix2D->PreRotate(aAngle * radPerDegree); + 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); } - TranslateSelf(-aOriginX, -aOriginY); - return this; } diff --git a/dom/base/DOMMatrix.h b/dom/base/DOMMatrix.h index 9e961de7b4..237767a5dc 100644 --- a/dom/base/DOMMatrix.h +++ b/dom/base/DOMMatrix.h @@ -191,9 +191,9 @@ public: double aOriginX = 0, double aOriginY = 0, double aOriginZ = 0) const; - already_AddRefed Rotate(double aAngle, - double aOriginX = 0, - double aOriginY = 0) const; + already_AddRefed Rotate(double aRotX, + const Optional& aRotY, + const Optional& aRotZ) const; already_AddRefed RotateFromVector(double aX, double aY) const; already_AddRefed RotateAxisAngle(double aX, @@ -324,9 +324,9 @@ public: double aOriginX = 0, double aOriginY = 0, double aOriginZ = 0); - DOMMatrix* RotateSelf(double aAngle, - double aOriginX = 0, - double aOriginY = 0); + DOMMatrix* RotateSelf(double aRotX, + const Optional& aRotY, + const Optional& aRotZ); DOMMatrix* RotateFromVectorSelf(double aX, double aY); DOMMatrix* RotateAxisAngleSelf(double aX, diff --git a/dom/webidl/DOMMatrix.webidl b/dom/webidl/DOMMatrix.webidl index 5a7c8aac7f..f1f3ead43f 100644 --- a/dom/webidl/DOMMatrix.webidl +++ b/dom/webidl/DOMMatrix.webidl @@ -59,15 +59,15 @@ interface DOMMatrixReadOnly { 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); - DOMMatrix rotateFromVector(unrestricted double x, - unrestricted double y); - DOMMatrix rotateAxisAngle(unrestricted double x, - unrestricted double y, - unrestricted double z, - unrestricted double angle); + [NewObject] DOMMatrix rotate(optional unrestricted double rotX = 0, + optional unrestricted double rotY, + optional unrestricted double rotZ); + [NewObject] DOMMatrix rotateFromVector(optional unrestricted double x = 0, + optional unrestricted double y = 0); + [NewObject] DOMMatrix rotateAxisAngle(optional unrestricted double x = 0, + optional unrestricted double y = 0, + optional unrestricted double z = 0, + optional unrestricted double angle = 0); DOMMatrix skewX(unrestricted double sx); DOMMatrix skewY(unrestricted double sy); [NewObject, Throws] DOMMatrix multiply(optional DOMMatrixInit other); @@ -141,15 +141,15 @@ interface DOMMatrix : DOMMatrixReadOnly { optional unrestricted double originX = 0, optional unrestricted double originY = 0, optional unrestricted double originZ = 0); - DOMMatrix rotateSelf(unrestricted double angle, - optional unrestricted double originX = 0, - optional unrestricted double originY = 0); - DOMMatrix rotateFromVectorSelf(unrestricted double x, - unrestricted double y); - DOMMatrix rotateAxisAngleSelf(unrestricted double x, - unrestricted double y, - unrestricted double z, - unrestricted double angle); + DOMMatrix rotateSelf(optional unrestricted double rotX = 0, + optional unrestricted double rotY, + optional unrestricted double rotZ); + DOMMatrix rotateFromVectorSelf(optional unrestricted double x = 0, + optional unrestricted double y = 0); + DOMMatrix rotateAxisAngleSelf(optional unrestricted double x = 0, + optional unrestricted double y = 0, + optional unrestricted double z = 0, + optional unrestricted double angle = 0); DOMMatrix skewXSelf(unrestricted double sx); DOMMatrix skewYSelf(unrestricted double sy); DOMMatrix invertSelf();