Auto merge of #25734 - pylbrecht:get.transform, r=jdm

Implement CanvasRenderingContext2D.getTransform()

<!-- Please describe your changes on the following line: -->
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix part of #25331

<!-- Either: -->
- [x] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2020-02-13 12:03:42 -05:00 committed by GitHub
commit 2c70db5f5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 42 additions and 22 deletions

View file

@ -16,6 +16,7 @@ use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString;
use crate::dom::canvasgradient::{CanvasGradient, CanvasGradientStyle, ToFillOrStrokeStyle};
use crate::dom::canvaspattern::CanvasPattern;
use crate::dom::dommatrix::DOMMatrix;
use crate::dom::element::cors_setting_for_element;
use crate::dom::element::Element;
use crate::dom::globalscope::GlobalScope;
@ -1415,6 +1416,15 @@ impl CanvasState {
self.update_transform()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform
pub fn get_transform(&self, global: &GlobalScope) -> DomRoot<DOMMatrix> {
let (sender, receiver) = ipc::channel::<Transform2D<f32>>().unwrap();
self.send_canvas_2d_msg(Canvas2dMsg::GetTransform(sender));
let transform = receiver.recv().unwrap();
DOMMatrix::new(global, true, transform.cast::<f64>().to_3d())
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform
pub fn set_transform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) {
if !(a.is_finite() &&

View file

@ -18,6 +18,7 @@ use crate::dom::bindings::root::{Dom, DomRoot, LayoutDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::canvasgradient::CanvasGradient;
use crate::dom::canvaspattern::CanvasPattern;
use crate::dom::dommatrix::DOMMatrix;
use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlcanvaselement::HTMLCanvasElement;
use crate::dom::imagedata::ImageData;
@ -224,6 +225,11 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
self.canvas_state.borrow().transform(a, b, c, d, e, f)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform
fn GetTransform(&self) -> DomRoot<DOMMatrix> {
self.canvas_state.borrow().get_transform(&self.global())
}
// 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) {
self.canvas_state.borrow().set_transform(a, b, c, d, e, f)

View file

@ -19,6 +19,7 @@ use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString;
use crate::dom::canvasgradient::CanvasGradient;
use crate::dom::canvaspattern::CanvasPattern;
use crate::dom::dommatrix::DOMMatrix;
use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlcanvaselement::HTMLCanvasElement;
use crate::dom::imagedata::ImageData;
@ -470,6 +471,11 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
self.canvas_state.borrow().transform(a, b, c, d, e, f)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform
fn GetTransform(&self) -> DomRoot<DOMMatrix> {
self.canvas_state.borrow().get_transform(&self.global())
}
// 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) {
self.canvas_state.borrow().set_transform(a, b, c, d, e, f)

View file

@ -20,6 +20,7 @@ use crate::dom::bindings::str::DOMString;
use crate::dom::canvasgradient::CanvasGradient;
use crate::dom::canvaspattern::CanvasPattern;
use crate::dom::canvasrenderingcontext2d::CanvasRenderingContext2D;
use crate::dom::dommatrix::DOMMatrix;
use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope;
use crate::euclidext::Size2DExt;
use canvas_traits::canvas::CanvasImageData;
@ -119,6 +120,11 @@ impl PaintRenderingContext2DMethods for PaintRenderingContext2D {
self.context.Transform(a, b, c, d, e, f)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform
fn GetTransform(&self) -> DomRoot<DOMMatrix> {
self.context.GetTransform()
}
// 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) {
self.context.SetTransform(a, b, c, d, e, f);

View file

@ -59,7 +59,7 @@ interface mixin CanvasTransform {
unrestricted double e,
unrestricted double f);
// [NewObject] DOMMatrix getTransform();
[NewObject] DOMMatrix getTransform();
void setTransform(unrestricted double a,
unrestricted double b,
unrestricted double c,

View file

@ -10,7 +10,7 @@
* related or neighboring rights to this work.
*/
[Exposed=(Window,Worker),
[Exposed=(Window,Worker,PaintWorklet),
LegacyWindowAlias=WebKitCSSMatrix]
interface DOMMatrix : DOMMatrixReadOnly {
[Throws] constructor(optional (DOMString or sequence<unrestricted double>) init);

View file

@ -10,7 +10,7 @@
* related or neighboring rights to this work.
*/
[Exposed=(Window,Worker)]
[Exposed=(Window,Worker,PaintWorklet)]
interface DOMMatrixReadOnly {
[Throws] constructor(optional (DOMString or sequence<unrestricted double>) init);

View file

@ -10,7 +10,7 @@
*/
// http://dev.w3.org/fxtf/geometry/Overview.html#dompoint
[Exposed=(Window,Worker)]
[Exposed=(Window,Worker,PaintWorklet)]
interface DOMPoint : DOMPointReadOnly {
[Throws] constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
optional unrestricted double z = 0, optional unrestricted double w = 1);

View file

@ -10,7 +10,7 @@
*/
// http://dev.w3.org/fxtf/geometry/Overview.html#dompointreadonly
[Exposed=(Window,Worker)]
[Exposed=(Window,Worker,PaintWorklet)]
interface DOMPointReadOnly {
[Throws] constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
optional unrestricted double z = 0, optional unrestricted double w = 1);