script: implement setMatrixValue for DOMMatrix (#39148)

Even more progress on the geometry suite. Almost there!

Testing: Covered by WPT (css/geometry).

Signed-off-by: lumiscosity <averyrudelphe@gmail.com>
This commit is contained in:
lumiscosity 2025-09-04 21:02:54 +02:00 committed by GitHub
parent f3a8ad30f1
commit c7ca281f44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 44 additions and 10 deletions

View file

@ -10,6 +10,7 @@ use dom_struct::dom_struct;
use euclid::default::Transform3D;
use js::rust::{CustomAutoRooterGuard, HandleObject};
use js::typedarray::{Float32Array, Float64Array};
use script_bindings::str::DOMString;
use crate::dom::bindings::codegen::Bindings::DOMMatrixBinding::{DOMMatrixInit, DOMMatrixMethods};
use crate::dom::bindings::codegen::Bindings::DOMMatrixReadOnlyBinding::DOMMatrixReadOnlyMethods;
@ -477,6 +478,25 @@ impl DOMMatrixMethods<crate::DomTypeHolder> for DOMMatrix {
// Step 3.
DomRoot::from_ref(self)
}
/// <https://drafts.fxtf.org/geometry-1/#dom-dommatrix-setmatrixvalue>
fn SetMatrixValue(&self, transformList: DOMString) -> Fallible<DomRoot<DOMMatrix>> {
// 1. Parse transformList into an abstract matrix, and let
// matrix and 2dTransform be the result. If the result is failure,
// then throw a "SyntaxError" DOMException.
match transform_to_matrix(transformList.to_string()) {
Ok(tuple) => {
// 2. Set is 2D to the value of 2dTransform.
self.parent.set_is2D(tuple.0);
// 3. Set m11 element through m44 element to the element values of matrix in column-major order.
self.parent.set_matrix(tuple.1);
},
Err(error) => return Err(error),
}
// 4. Return the current matrix.
Ok(DomRoot::from_ref(self))
}
}
impl Serializable for DOMMatrix {

View file

@ -86,10 +86,33 @@ impl DOMMatrixReadOnly {
self.matrix.borrow()
}
pub(crate) fn set_matrix(&self, value: Transform3D<f64>) {
self.set_m11(value.m11);
self.set_m12(value.m12);
self.set_m13(value.m13);
self.set_m14(value.m14);
self.set_m21(value.m21);
self.set_m22(value.m22);
self.set_m23(value.m23);
self.set_m24(value.m24);
self.set_m31(value.m31);
self.set_m32(value.m32);
self.set_m33(value.m33);
self.set_m34(value.m34);
self.set_m41(value.m41);
self.set_m42(value.m42);
self.set_m43(value.m43);
self.set_m44(value.m44);
}
pub(crate) fn is2D(&self) -> bool {
self.is2D.get()
}
pub(crate) fn set_is2D(&self, value: bool) {
self.is2D.set(value);
}
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m11
pub(crate) fn set_m11(&self, value: f64) {
self.matrix.borrow_mut().m11 = value;

View file

@ -68,7 +68,7 @@ interface DOMMatrix : DOMMatrixReadOnly {
DOMMatrix skewYSelf(optional unrestricted double sy = 0);
DOMMatrix invertSelf();
// DOMMatrix setMatrixValue(DOMString transformList);
[Exposed=Window, Throws] DOMMatrix setMatrixValue(DOMString transformList);
};
dictionary DOMMatrix2DInit {

View file

@ -7,18 +7,9 @@
[DOMRectList interface: [object DOMRect\] must inherit property "item(unsigned long)" with the proper type]
expected: FAIL
[DOMMatrix interface: operation setMatrixValue(DOMString)]
expected: FAIL
[DOMMatrix interface: calling setMatrixValue(DOMString) on new DOMMatrix() with too few arguments must throw TypeError]
expected: FAIL
[DOMRectList interface: calling item(unsigned long) on [object DOMRect\] with too few arguments must throw TypeError]
expected: FAIL
[DOMMatrix interface: new DOMMatrix() must inherit property "setMatrixValue(DOMString)" with the proper type]
expected: FAIL
[DOMRectList must be primary interface of [object DOMRect\]]
expected: FAIL