From 8e2f65bd16be8e8c98a43a1ff9bd3f81a0557a9e Mon Sep 17 00:00:00 2001 From: lumiscosity Date: Wed, 20 Aug 2025 18:36:59 +0200 Subject: [PATCH] Add `matrixTransform` for `DOMPointReadOnly` (#38801) Adds the `matrixTransform` function for `DOMPointReadOnly`. Testing: Covered by WPT tests (`css/geometry`) --------- Signed-off-by: lumiscosity --- components/script/dom/dompointreadonly.rs | 55 ++++++++++++++++--- .../script_bindings/codegen/Bindings.conf | 2 +- .../webidls/DOMPointReadOnly.webidl | 2 + .../meta/css/geometry/DOMPoint-002.html.ini | 6 -- .../wpt/meta/css/geometry/historical.html.ini | 3 - .../meta/css/geometry/idlharness.any.js.ini | 30 ---------- .../meta/css/geometry/spec-examples.html.ini | 3 - 7 files changed, 50 insertions(+), 51 deletions(-) delete mode 100644 tests/wpt/meta/css/geometry/DOMPoint-002.html.ini delete mode 100644 tests/wpt/meta/css/geometry/historical.html.ini delete mode 100644 tests/wpt/meta/css/geometry/spec-examples.html.ini diff --git a/components/script/dom/dompointreadonly.rs b/components/script/dom/dompointreadonly.rs index eb6bc9b93a9..4d1faec3ccd 100644 --- a/components/script/dom/dompointreadonly.rs +++ b/components/script/dom/dompointreadonly.rs @@ -10,17 +10,20 @@ use constellation_traits::DomPoint; use dom_struct::dom_struct; use js::rust::HandleObject; +use crate::dom::bindings::codegen::Bindings::DOMMatrixBinding::DOMMatrixInit; use crate::dom::bindings::codegen::Bindings::DOMPointBinding::DOMPointInit; use crate::dom::bindings::codegen::Bindings::DOMPointReadOnlyBinding::DOMPointReadOnlyMethods; use crate::dom::bindings::error::Fallible; -use crate::dom::bindings::reflector::{Reflector, reflect_dom_object_with_proto}; +use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto}; use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::serializable::Serializable; use crate::dom::bindings::structuredclone::StructuredData; +use crate::dom::dommatrixreadonly::dommatrixinit_to_matrix; use crate::dom::globalscope::GlobalScope; +use crate::dom::types::DOMPoint; use crate::script_runtime::CanGc; -// http://dev.w3.org/fxtf/geometry/Overview.html#dompointreadonly +/// #[dom_struct] pub(crate) struct DOMPointReadOnly { reflector_: Reflector, @@ -73,7 +76,7 @@ impl DOMPointReadOnly { #[allow(non_snake_case)] impl DOMPointReadOnlyMethods for DOMPointReadOnly { - // https://drafts.fxtf.org/geometry/#dom-dompoint-dompoint + /// fn Constructor( global: &GlobalScope, proto: Option, @@ -88,30 +91,66 @@ impl DOMPointReadOnlyMethods for DOMPointReadOnly { )) } - // https://drafts.fxtf.org/geometry/#dom-dompointreadonly-frompoint + /// fn FromPoint(global: &GlobalScope, init: &DOMPointInit, can_gc: CanGc) -> DomRoot { Self::new(global, init.x, init.y, init.z, init.w, can_gc) } - // https://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-x + /// fn X(&self) -> f64 { self.x.get() } - // https://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-y + /// fn Y(&self) -> f64 { self.y.get() } - // https://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-z + /// fn Z(&self) -> f64 { self.z.get() } - // https://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-w + /// fn W(&self) -> f64 { self.w.get() } + + /// + /// + fn MatrixTransform( + &self, + matrix: &DOMMatrixInit, + can_gc: CanGc, + ) -> Fallible> { + // Let matrixObject be the result of invoking create a DOMMatrix from the dictionary matrix. + let matrix_object = match dommatrixinit_to_matrix(matrix) { + Ok(converted) => converted, + Err(exception) => { + return Err(exception); + }, + }; + // Steps 1-4 of transforming a point with a matrix + let x = self.X(); + let y = self.Y(); + let z = self.Z(); + let w = self.W(); + // Steps 5-12 of transforming a point with a matrix + let m = &matrix_object.1; + let transformed_point = DOMPointInit { + x: m.m11 * x + m.m21 * y + m.m31 * z + m.m41 * w, + y: m.m12 * x + m.m22 * y + m.m32 * z + m.m42 * w, + z: m.m13 * x + m.m23 * y + m.m33 * z + m.m43 * w, + w: m.m14 * x + m.m24 * y + m.m34 * z + m.m44 * w, + }; + // Return the result of invoking transform a point with a matrix, given the current point + // and matrixObject. The current point does not get modified. + Ok(DOMPoint::new_from_init( + &self.global(), + &transformed_point, + can_gc, + )) + } } #[allow(non_snake_case)] diff --git a/components/script_bindings/codegen/Bindings.conf b/components/script_bindings/codegen/Bindings.conf index b9f9bee5251..f33d0e8a629 100644 --- a/components/script_bindings/codegen/Bindings.conf +++ b/components/script_bindings/codegen/Bindings.conf @@ -208,7 +208,7 @@ DOMInterfaces = { }, 'DOMPointReadOnly': { - 'canGc': ['FromPoint'], + 'canGc': ['FromPoint', 'MatrixTransform'], }, 'DOMQuad': { diff --git a/components/script_bindings/webidls/DOMPointReadOnly.webidl b/components/script_bindings/webidls/DOMPointReadOnly.webidl index 3ce4bf773fc..412dabf8df1 100644 --- a/components/script_bindings/webidls/DOMPointReadOnly.webidl +++ b/components/script_bindings/webidls/DOMPointReadOnly.webidl @@ -22,5 +22,7 @@ interface DOMPointReadOnly { readonly attribute unrestricted double z; readonly attribute unrestricted double w; + [Throws, NewObject] DOMPoint matrixTransform(optional DOMMatrixInit matrix = {}); + [Default] object toJSON(); }; diff --git a/tests/wpt/meta/css/geometry/DOMPoint-002.html.ini b/tests/wpt/meta/css/geometry/DOMPoint-002.html.ini deleted file mode 100644 index 1d6e42bc5d4..00000000000 --- a/tests/wpt/meta/css/geometry/DOMPoint-002.html.ini +++ /dev/null @@ -1,6 +0,0 @@ -[DOMPoint-002.html] - [test DOMPoint matrixTransform] - expected: FAIL - - [test DOMPointReadOnly matrixTransform] - expected: FAIL diff --git a/tests/wpt/meta/css/geometry/historical.html.ini b/tests/wpt/meta/css/geometry/historical.html.ini deleted file mode 100644 index 3db6d9bc760..00000000000 --- a/tests/wpt/meta/css/geometry/historical.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[historical.html] - [DOMPointReadOnly matrixTransform number of required arguments] - expected: FAIL diff --git a/tests/wpt/meta/css/geometry/idlharness.any.js.ini b/tests/wpt/meta/css/geometry/idlharness.any.js.ini index 9a7d375f577..24ca51dc0b5 100644 --- a/tests/wpt/meta/css/geometry/idlharness.any.js.ini +++ b/tests/wpt/meta/css/geometry/idlharness.any.js.ini @@ -1,36 +1,12 @@ [idlharness.any.worker.html] - [DOMPointReadOnly interface: calling matrixTransform(optional DOMMatrixInit) on new DOMPoint() with too few arguments must throw TypeError] - expected: FAIL - - [DOMPointReadOnly interface: operation matrixTransform(optional DOMMatrixInit)] - expected: FAIL - - [DOMPointReadOnly interface: new DOMPoint() must inherit property "matrixTransform(optional DOMMatrixInit)" with the proper type] - expected: FAIL - - [DOMPointReadOnly interface: new DOMPointReadOnly() must inherit property "matrixTransform(optional DOMMatrixInit)" with the proper type] - expected: FAIL - - [DOMPointReadOnly interface: calling matrixTransform(optional DOMMatrixInit) on new DOMPointReadOnly() with too few arguments must throw TypeError] - expected: FAIL - [idlharness.any.html] - [DOMPointReadOnly interface: calling matrixTransform(optional DOMMatrixInit) on new DOMPoint() with too few arguments must throw TypeError] - expected: FAIL - - [DOMPointReadOnly interface: operation matrixTransform(optional DOMMatrixInit)] - expected: FAIL - [DOMRectList interface: [object DOMRect\] must inherit property "length" with the proper type] expected: FAIL [DOMRectList interface: [object DOMRect\] must inherit property "item(unsigned long)" with the proper type] expected: FAIL - [DOMPointReadOnly interface: new DOMPoint() must inherit property "matrixTransform(optional DOMMatrixInit)" with the proper type] - expected: FAIL - [DOMMatrix interface: operation setMatrixValue(DOMString)] expected: FAIL @@ -40,9 +16,6 @@ [DOMMatrix interface: calling setMatrixValue(DOMString) on new DOMMatrix() with too few arguments must throw TypeError] expected: FAIL - [DOMPointReadOnly interface: new DOMPointReadOnly() must inherit property "matrixTransform(optional DOMMatrixInit)" with the proper type] - expected: FAIL - [DOMRectList interface: calling item(unsigned long) on [object DOMRect\] with too few arguments must throw TypeError] expected: FAIL @@ -52,9 +25,6 @@ [DOMRectList must be primary interface of [object DOMRect\]] expected: FAIL - [DOMPointReadOnly interface: calling matrixTransform(optional DOMMatrixInit) on new DOMPointReadOnly() with too few arguments must throw TypeError] - expected: FAIL - [DOMMatrix interface: legacy window alias] expected: FAIL diff --git a/tests/wpt/meta/css/geometry/spec-examples.html.ini b/tests/wpt/meta/css/geometry/spec-examples.html.ini deleted file mode 100644 index 3e18f3b85ea..00000000000 --- a/tests/wpt/meta/css/geometry/spec-examples.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[spec-examples.html] - [matrixTransform] - expected: FAIL \ No newline at end of file