canvas: Add CanvasTransform 'setTransform(transform)' method (#37692)

Follow the HTML canvas specification and add missing
'setTransform(transform)' method to CanvasTransform interface.

https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform-matrix

The third-party WebIDL doesn't support different extended attributes
on different overloads of methods, so 'Throws' attribute was added
to another 'setTransform(...)' method.
https://bugzilla.mozilla.org/show_bug.cgi?id=1020975

Testing: Improvements in the tests
- css/geometry/DOMMatrix*
-
html/canvas/element/transformations/2d.transformation.setTransform.multiple.html
-
html/canvas/offscreen/transformations/2d.transformation.setTransform.multiple

New failing tests due to disabled 'paint worklet' feature
- css/css-paint-api/setTransform-00*.https.html

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
This commit is contained in:
Andrei Volykhin 2025-06-25 19:11:54 +03:00 committed by GitHub
parent 64259de1f7
commit 59b99de90a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 226 additions and 362 deletions

View file

@ -17,6 +17,7 @@ use crate::canvas_state::CanvasState;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::{
CanvasFillRule, CanvasImageSource, CanvasLineCap, CanvasLineJoin,
};
use crate::dom::bindings::codegen::Bindings::DOMMatrixBinding::DOMMatrix2DInit;
use crate::dom::bindings::codegen::Bindings::PaintRenderingContext2DBinding::PaintRenderingContext2DMethods;
use crate::dom::bindings::codegen::UnionTypes::StringOrCanvasGradientOrCanvasPattern;
use crate::dom::bindings::error::{ErrorResult, Fallible};
@ -131,10 +132,18 @@ impl PaintRenderingContext2DMethods<crate::DomTypeHolder> for PaintRenderingCont
self.canvas_state.get_transform(&self.global(), can_gc)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform
fn SetTransform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) {
/// <https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform>
fn SetTransform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) -> ErrorResult {
self.canvas_state.set_transform(a, b, c, d, e, f);
self.scale_by_device_pixel_ratio();
Ok(())
}
/// <https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform-matrix>
fn SetTransform_(&self, transform: &DOMMatrix2DInit) -> ErrorResult {
self.canvas_state.set_transform_(transform)?;
self.scale_by_device_pixel_ratio();
Ok(())
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-resettransform