Truly independent web browser
LibWeb: Return a new matrix from CSSMatrixComponent.toMatrix()
Andreas Kling7ebbdef3dcb0
diff --git a/Libraries/LibWeb/CSS/CSSMatrixComponent.cpp b/Libraries/LibWeb/CSS/CSSMatrixComponent.cppindex 3193c6829a1..6bd652cdf28 100644--- a/Libraries/LibWeb/CSS/CSSMatrixComponent.cpp+++ b/Libraries/LibWeb/CSS/CSSMatrixComponent.cpp@@ -71,9 +71,23 @@ WebIDL::ExceptionOr<Utf16String> CSSMatrixComponent::to_string() constWebIDL::ExceptionOr<GC::Ref<Geometry::DOMMatrix>> CSSMatrixComponent::to_matrix() const{- // AD-HOC: Not specced, but we already have a matrix so use that.- // https://github.com/w3c/css-houdini-drafts/issues/1153- return matrix();+ // https://drafts.css-houdini.org/css-typed-om-1/#dom-csstransformcomponent-tomatrix+ // 1. Let matrix be a new DOMMatrix object, initialized to this’s equivalent 4x4 transform matrix, as defined in+ // CSS Transforms 1 § 12. Mathematical Description of Transform Functions, and with its is2D internal slot set to+ // the same value as this’s is2D internal slot.+ // NB: The elements are m11, m12, m13, m14, m21, ..., m44. A 2D component only uses m11, m12, m21, m22, m41 and m42.+ auto elements = m_matrix->elements();+ if (is_2d()) {+ elements = { elements[0], elements[1], 0, 0,+ elements[4], elements[5], 0, 0,+ 0, 0, 1, 0,+ elements[12], elements[13], 0, 1 };+ }+ auto matrix = Geometry::DOMMatrix::create();+ matrix->set_elements(elements, is_2d());++ // 2. Return matrix.+ return matrix;}WebIDL::ExceptionOr<void> CSSMatrixComponent::set_matrix(GC::Ref<Geometry::DOMMatrix> matrix)diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/stylevalue-subclasses/cssMatrixComponent-toMatrix-returns-new-matrix.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/stylevalue-subclasses/cssMatrixComponent-toMatrix-returns-new-matrix.txtindex b269c814275..9f4cb897997 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/stylevalue-subclasses/cssMatrixComponent-toMatrix-returns-new-matrix.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/stylevalue-subclasses/cssMatrixComponent-toMatrix-returns-new-matrix.txt@@ -2,8 +2,8 @@ Harness status: OKFound 4 tests-4 Fail-Fail Mutating the result of toMatrix() on a 2D CSSMatrixComponent does not change the component-Fail Mutating the result of toMatrix() on a 3D CSSMatrixComponent does not change the component-Fail Calling a self-mutating method on the result of toMatrix() on a 3D CSSMatrixComponent does not change the component-Fail Mutating the result of toMatrix() on a 3D CSSMatrixComponent does not change an enclosing CSSTransformValue\ No newline at end of file+4 Pass+Pass Mutating the result of toMatrix() on a 2D CSSMatrixComponent does not change the component+Pass Mutating the result of toMatrix() on a 3D CSSMatrixComponent does not change the component+Pass Calling a self-mutating method on the result of toMatrix() on a 3D CSSMatrixComponent does not change the component+Pass Mutating the result of toMatrix() on a 3D CSSMatrixComponent does not change an enclosing CSSTransformValue\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/stylevalue-subclasses/cssTransformComponent-2d-flattening.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/stylevalue-subclasses/cssTransformComponent-2d-flattening.txtindex d445373e7aa..5cdac7cf595 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/stylevalue-subclasses/cssTransformComponent-2d-flattening.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/stylevalue-subclasses/cssTransformComponent-2d-flattening.txt@@ -2,9 +2,8 @@ Harness status: OKFound 4 tests-3 Pass-1 Fail+4 PassPass CSSTranslate.toMatrix() flattens when told it is 2dPass CSSRotate.toMatrix() flattens when told it is 2dPass CSSScale.toMatrix() flattens when told it is 2d-Fail CSSMatrixComponent.toMatrix() flattens when told it is 2d\ No newline at end of file+Pass CSSMatrixComponent.toMatrix() flattens when told it is 2d\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/stylevalue-subclasses/cssTransformValue-toMatrix.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/stylevalue-subclasses/cssTransformValue-toMatrix.txtindex 7db8711da00..6cfa3c25892 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/stylevalue-subclasses/cssTransformValue-toMatrix.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/stylevalue-subclasses/cssTransformValue-toMatrix.txt@@ -2,7 +2,6 @@ Harness status: OKFound 2 tests-1 Pass-1 Fail+2 PassPass CSSTransformValue.toMatrix() multiplies its component matrices-Fail CSSTransformValue.toMatrix() respects is2D changes in its components\ No newline at end of file+Pass CSSTransformValue.toMatrix() respects is2D changes in its components\ No newline at end of file