mirror of
https://github.com/servo/servo.git
synced 2025-08-28 08:38:20 +01:00
Add matrixTransform
for DOMPointReadOnly
(#38801)
Adds the `matrixTransform` function for `DOMPointReadOnly`. Testing: Covered by WPT tests (`css/geometry`) --------- Signed-off-by: lumiscosity <averyrudelphe@gmail.com>
This commit is contained in:
parent
d8ff9c7a08
commit
8e2f65bd16
7 changed files with 50 additions and 51 deletions
|
@ -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
|
||||
/// <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<crate::DomTypeHolder> for DOMPointReadOnly {
|
||||
// https://drafts.fxtf.org/geometry/#dom-dompoint-dompoint
|
||||
/// <https://drafts.fxtf.org/geometry/#dom-dompoint-dompoint>
|
||||
fn Constructor(
|
||||
global: &GlobalScope,
|
||||
proto: Option<HandleObject>,
|
||||
|
@ -88,30 +91,66 @@ impl DOMPointReadOnlyMethods<crate::DomTypeHolder> for DOMPointReadOnly {
|
|||
))
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-dompointreadonly-frompoint
|
||||
/// <https://drafts.fxtf.org/geometry/#dom-dompointreadonly-frompoint>
|
||||
fn FromPoint(global: &GlobalScope, init: &DOMPointInit, can_gc: CanGc) -> DomRoot<Self> {
|
||||
Self::new(global, init.x, init.y, init.z, init.w, can_gc)
|
||||
}
|
||||
|
||||
// https://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-x
|
||||
/// <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
|
||||
/// <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
|
||||
/// <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
|
||||
/// <https://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-w>
|
||||
fn W(&self) -> f64 {
|
||||
self.w.get()
|
||||
}
|
||||
|
||||
/// <https://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-matrixtransform>
|
||||
/// <https://drafts.fxtf.org/geometry/Overview.html#transform-a-point-with-a-matrix>
|
||||
fn MatrixTransform(
|
||||
&self,
|
||||
matrix: &DOMMatrixInit,
|
||||
can_gc: CanGc,
|
||||
) -> Fallible<DomRoot<DOMPoint>> {
|
||||
// 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)]
|
||||
|
|
|
@ -208,7 +208,7 @@ DOMInterfaces = {
|
|||
},
|
||||
|
||||
'DOMPointReadOnly': {
|
||||
'canGc': ['FromPoint'],
|
||||
'canGc': ['FromPoint', 'MatrixTransform'],
|
||||
},
|
||||
|
||||
'DOMQuad': {
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
[DOMPoint-002.html]
|
||||
[test DOMPoint matrixTransform]
|
||||
expected: FAIL
|
||||
|
||||
[test DOMPointReadOnly matrixTransform]
|
||||
expected: FAIL
|
|
@ -1,3 +0,0 @@
|
|||
[historical.html]
|
||||
[DOMPointReadOnly matrixTransform number of required arguments]
|
||||
expected: FAIL
|
|
@ -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
|
||||
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
[spec-examples.html]
|
||||
[matrixTransform]
|
||||
expected: FAIL
|
Loading…
Add table
Add a link
Reference in a new issue