diff --git a/Tests/LibWeb/Text/expected/geometry/dommatrix.txt b/Tests/LibWeb/Text/expected/geometry/dommatrix.txt index 146a39da144..d928e142cc9 100644 --- a/Tests/LibWeb/Text/expected/geometry/dommatrix.txt +++ b/Tests/LibWeb/Text/expected/geometry/dommatrix.txt @@ -10,3 +10,5 @@ 10. {"a":10,"b":20,"c":31.76326980708465,"d":43.5265396141693,"e":50,"f":60,"m11":10,"m12":20,"m13":0,"m14":0,"m21":31.76326980708465,"m22":43.5265396141693,"m23":0,"m24":0,"m31":0,"m32":0,"m33":1,"m34":0,"m41":50,"m42":60,"m43":0,"m44":1,"is2D":true,"isIdentity":false} 11. {"a":15.289809421253949,"b":27.0530792283386,"c":30,"d":40,"e":50,"f":60,"m11":15.289809421253949,"m12":27.0530792283386,"m13":0,"m14":0,"m21":30,"m22":40,"m23":0,"m24":0,"m31":0,"m32":0,"m33":1,"m34":0,"m41":50,"m42":60,"m43":0,"m44":1,"is2D":true,"isIdentity":false} 12. {"a":15.289809421253949,"b":27.0530792283386,"c":30,"d":40,"e":50,"f":60,"m11":15.289809421253949,"m12":27.0530792283386,"m13":0,"m14":0,"m21":30,"m22":40,"m23":0,"m24":0,"m31":0,"m32":0,"m33":1,"m34":0,"m41":50,"m42":60,"m43":0,"m44":1,"is2D":true,"isIdentity":false} +13. {"a":-10,"b":-20,"c":30,"d":40,"e":50,"f":60,"m11":-10,"m12":-20,"m13":0,"m14":0,"m21":30,"m22":40,"m23":0,"m24":0,"m31":0,"m32":0,"m33":1,"m34":0,"m41":50,"m42":60,"m43":0,"m44":1,"is2D":true,"isIdentity":false} +14. {"a":10,"b":20,"c":-30,"d":-40,"e":50,"f":60,"m11":10,"m12":20,"m13":0,"m14":0,"m21":-30,"m22":-40,"m23":0,"m24":0,"m31":0,"m32":0,"m33":1,"m34":0,"m41":50,"m42":60,"m43":0,"m44":1,"is2D":true,"isIdentity":false} diff --git a/Tests/LibWeb/Text/input/geometry/dommatrix.html b/Tests/LibWeb/Text/input/geometry/dommatrix.html index 981bc2d2620..9e39d68771b 100644 --- a/Tests/LibWeb/Text/input/geometry/dommatrix.html +++ b/Tests/LibWeb/Text/input/geometry/dommatrix.html @@ -41,5 +41,11 @@ // 12. Skew Y DOMMatrix with multiply testPart(() => new DOMMatrix([10, 20, 30, 40, 50, 60]).multiply(new DOMMatrix().skewY(10))); + + // 13. Flip X DOMMatrix + testPart(() => new DOMMatrix([10, 20, 30, 40, 50, 60]).flipX()); + + // 14. Flip Y DOMMatrix + testPart(() => new DOMMatrix([10, 20, 30, 40, 50, 60]).flipY()); }); diff --git a/Userland/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.cpp b/Userland/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.cpp index 948f3229c36..45f8d08b0b7 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.cpp +++ b/Userland/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.cpp @@ -284,6 +284,44 @@ WebIDL::ExceptionOr> DOMMatrixReadOnly::multiply(DOM return result->multiply_self(other); } +// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-flipx +JS::NonnullGCPtr DOMMatrixReadOnly::flip_x() +{ + // 1. Let result be the resulting matrix initialized to the values of the current matrix. + auto result = DOMMatrix::create_from_dom_matrix_read_only(realm(), *this); + + // 2. Post-multiply result with new DOMMatrix([-1, 0, 0, 1, 0, 0]). + // clang-format off + Gfx::DoubleMatrix4x4 flip_matrix = { -1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 }; + // clang-format on + result->m_matrix = result->m_matrix * flip_matrix; + + // 3. Return result. + return result; +} + +// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-flipy +JS::NonnullGCPtr DOMMatrixReadOnly::flip_y() +{ + // 1. Let result be the resulting matrix initialized to the values of the current matrix. + auto result = DOMMatrix::create_from_dom_matrix_read_only(realm(), *this); + + // 2. Post-multiply result with new DOMMatrix([1, 0, 0, -1, 0, 0]). + // clang-format off + Gfx::DoubleMatrix4x4 flip_matrix = { 1, 0, 0, 0, + 0, -1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 }; + // clang-format on + result->m_matrix = result->m_matrix * flip_matrix; + + // 3. Return result. + return result; +} + // https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-inverse JS::NonnullGCPtr DOMMatrixReadOnly::inverse() const { diff --git a/Userland/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.h b/Userland/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.h index 6b7d2e5769b..41025d20d70 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.h +++ b/Userland/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.h @@ -88,6 +88,8 @@ public: JS::NonnullGCPtr skew_x(double sx = 0) const; JS::NonnullGCPtr skew_y(double sy = 0) const; WebIDL::ExceptionOr> multiply(DOMMatrixInit other = {}); + JS::NonnullGCPtr flip_x(); + JS::NonnullGCPtr flip_y(); JS::NonnullGCPtr inverse() const; JS::NonnullGCPtr transform_point(DOMPointInit const&) const; diff --git a/Userland/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.idl b/Userland/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.idl index 2b25fad8de9..6a5651bbb10 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.idl +++ b/Userland/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.idl @@ -49,8 +49,8 @@ interface DOMMatrixReadOnly { [NewObject] DOMMatrix skewX(optional unrestricted double sx = 0); [NewObject] DOMMatrix skewY(optional unrestricted double sy = 0); [NewObject] DOMMatrix multiply(optional DOMMatrixInit other = {}); - // FIXME: [NewObject] DOMMatrix flipX(); - // FIXME: [NewObject] DOMMatrix flipY(); + [NewObject] DOMMatrix flipX(); + [NewObject] DOMMatrix flipY(); [NewObject] DOMMatrix inverse(); [NewObject] DOMPoint transformPoint(optional DOMPointInit point = {});