mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Implement DOMRect::FromRect (#33798)
* Implement DOMRect::FromRect Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Silence crown errors The rect type does not contain any gc'd members, so not rooting it is perfectly fineSilence crown errors Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Update WPT expectations Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Add SVGRect to the list of exposed interface globals Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Update WPT manifest Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> --------- Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
parent
8843a0e400
commit
c5899e596d
8 changed files with 63 additions and 48 deletions
|
@ -6,11 +6,13 @@ use dom_struct::dom_struct;
|
|||
use js::rust::HandleObject;
|
||||
|
||||
use crate::dom::bindings::codegen::Bindings::DOMRectBinding::DOMRectMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::DOMRectReadOnlyBinding::DOMRectReadOnlyMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::DOMRectReadOnlyBinding::{
|
||||
DOMRectInit, DOMRectReadOnlyMethods,
|
||||
};
|
||||
use crate::dom::bindings::error::Fallible;
|
||||
use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, reflect_dom_object_with_proto};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::domrectreadonly::DOMRectReadOnly;
|
||||
use crate::dom::domrectreadonly::{create_a_domrectreadonly_from_the_dictionary, DOMRectReadOnly};
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::script_runtime::CanGc;
|
||||
|
||||
|
@ -71,6 +73,14 @@ impl DOMRectMethods for DOMRect {
|
|||
))
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-domrect-fromrect
|
||||
#[allow(crown::unrooted_must_root)]
|
||||
fn FromRect(global: &GlobalScope, other: &DOMRectInit) -> DomRoot<DOMRect> {
|
||||
let rect = create_a_domrectreadonly_from_the_dictionary(other);
|
||||
|
||||
reflect_dom_object(Box::new(Self { rect }), global)
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-domrect-x
|
||||
fn X(&self) -> f64 {
|
||||
self.rect.X()
|
||||
|
|
|
@ -7,9 +7,13 @@ use std::cell::Cell;
|
|||
use dom_struct::dom_struct;
|
||||
use js::rust::HandleObject;
|
||||
|
||||
use crate::dom::bindings::codegen::Bindings::DOMRectReadOnlyBinding::DOMRectReadOnlyMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::DOMRectReadOnlyBinding::{
|
||||
DOMRectInit, DOMRectReadOnlyMethods,
|
||||
};
|
||||
use crate::dom::bindings::error::Fallible;
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, Reflector};
|
||||
use crate::dom::bindings::reflector::{
|
||||
reflect_dom_object, reflect_dom_object_with_proto, Reflector,
|
||||
};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::script_runtime::CanGc;
|
||||
|
@ -84,6 +88,14 @@ impl DOMRectReadOnlyMethods for DOMRectReadOnly {
|
|||
))
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-domrectreadonly-fromrect
|
||||
#[allow(crown::unrooted_must_root)]
|
||||
fn FromRect(global: &GlobalScope, other: &DOMRectInit) -> DomRoot<DOMRectReadOnly> {
|
||||
let dom_rect = create_a_domrectreadonly_from_the_dictionary(other);
|
||||
|
||||
reflect_dom_object(Box::new(dom_rect), global)
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-domrectreadonly-x
|
||||
fn X(&self) -> f64 {
|
||||
self.x.get()
|
||||
|
@ -144,3 +156,25 @@ impl DOMRectReadOnlyMethods for DOMRectReadOnly {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://drafts.fxtf.org/geometry/#ref-for-create-a-domrectreadonly-from-the-dictionary>
|
||||
#[allow(crown::unrooted_must_root)]
|
||||
pub(super) fn create_a_domrectreadonly_from_the_dictionary(other: &DOMRectInit) -> DOMRectReadOnly {
|
||||
// NOTE: We trivially combine all three steps into one
|
||||
|
||||
// Step 1. Let rect be a new DOMRectReadOnly or DOMRect as appropriate.
|
||||
|
||||
// Step 2. Set rect’s variables x coordinate to other’s x dictionary member, y coordinate to other’s y
|
||||
// dictionary member, width dimension to other’s width dictionary member and height dimension to
|
||||
// other’s height dictionary member.
|
||||
|
||||
// Step 3. Return rect.
|
||||
|
||||
DOMRectReadOnly {
|
||||
reflector_: Reflector::new(),
|
||||
x: Cell::new(other.x),
|
||||
y: Cell::new(other.y),
|
||||
width: Cell::new(other.width),
|
||||
height: Cell::new(other.height),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,17 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
[Exposed=(Window,Worker)]
|
||||
// https://drafts.fxtf.org/geometry/#domrect
|
||||
|
||||
[Exposed=(Window,Worker),
|
||||
Serializable,
|
||||
LegacyWindowAlias=SVGRect]
|
||||
interface DOMRect : DOMRectReadOnly {
|
||||
[Throws] constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
|
||||
optional unrestricted double width = 0, optional unrestricted double height = 0);
|
||||
|
||||
[NewObject] static DOMRect fromRect(optional DOMRectInit other = {});
|
||||
|
||||
inherit attribute unrestricted double x;
|
||||
inherit attribute unrestricted double y;
|
||||
inherit attribute unrestricted double width;
|
||||
|
|
|
@ -2,12 +2,15 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
[Exposed=(Window,Worker)]
|
||||
// https://drafts.fxtf.org/geometry/#domrect
|
||||
|
||||
[Exposed=(Window,Worker),
|
||||
Serializable]
|
||||
interface DOMRectReadOnly {
|
||||
[Throws] constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
|
||||
optional unrestricted double width = 0, optional unrestricted double height = 0);
|
||||
// [NewObject] static DOMRectReadOnly fromRect(optional DOMRectInit other);
|
||||
|
||||
[NewObject] static DOMRectReadOnly fromRect(optional DOMRectInit other = {});
|
||||
|
||||
readonly attribute unrestricted double x;
|
||||
readonly attribute unrestricted double y;
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
[DOMRect-002.html]
|
||||
[DOMRect.fromRect]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRectReadOnly.fromRect]
|
||||
expected: FAIL
|
|
@ -1,28 +1,13 @@
|
|||
[idlharness.any.worker.html]
|
||||
[DOMRectReadOnly interface: operation fromRect(optional DOMRectInit)]
|
||||
expected: FAIL
|
||||
|
||||
[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
|
||||
|
||||
[DOMRect interface: operation fromRect(optional DOMRectInit)]
|
||||
expected: FAIL
|
||||
|
||||
[DOMPointReadOnly interface: new DOMPoint() must inherit property "matrixTransform(optional DOMMatrixInit)" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRectReadOnly interface: calling fromRect(optional DOMRectInit) on new DOMRect() with too few arguments must throw TypeError]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRect interface: calling fromRect(optional DOMRectInit) on new DOMRect() with too few arguments must throw TypeError]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRectReadOnly interface: calling fromRect(optional DOMRectInit) on new DOMRectReadOnly() 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
|
||||
|
||||
|
@ -31,9 +16,6 @@
|
|||
|
||||
|
||||
[idlharness.any.html]
|
||||
[DOMRectReadOnly interface: operation fromRect(optional DOMRectInit)]
|
||||
expected: FAIL
|
||||
|
||||
[DOMPointReadOnly interface: calling matrixTransform(optional DOMMatrixInit) on new DOMPoint() with too few arguments must throw TypeError]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -49,9 +31,6 @@
|
|||
[DOMRectList interface: [object DOMRect\] must inherit property "length" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRect interface: operation fromRect(optional DOMRectInit)]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRectList interface: operation item(unsigned long)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -70,18 +49,9 @@
|
|||
[DOMMatrix interface: operation setMatrixValue(DOMString)]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRectReadOnly interface: calling fromRect(optional DOMRectInit) on new DOMRect() with too few arguments must throw TypeError]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRect interface: calling fromRect(optional DOMRectInit) on new DOMRect() with too few arguments must throw TypeError]
|
||||
expected: FAIL
|
||||
|
||||
[DOMPoint interface: legacy window alias]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRectReadOnly interface: calling fromRect(optional DOMRectInit) on new DOMRectReadOnly() with too few arguments must throw TypeError]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRectList interface object length]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -91,9 +61,6 @@
|
|||
[DOMPointReadOnly interface: new DOMPointReadOnly() must inherit property "matrixTransform(optional DOMMatrixInit)" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRect interface: legacy window alias]
|
||||
expected: FAIL
|
||||
|
||||
[DOMRectList interface: calling item(unsigned long) on [object DOMRect\] with too few arguments must throw TypeError]
|
||||
expected: FAIL
|
||||
|
||||
|
|
2
tests/wpt/mozilla/meta/MANIFEST.json
vendored
2
tests/wpt/mozilla/meta/MANIFEST.json
vendored
|
@ -13495,7 +13495,7 @@
|
|||
]
|
||||
],
|
||||
"interfaces.https.html": [
|
||||
"94f1102da478919d2948ebb96f81450f5d545635",
|
||||
"bfe16e7de02b6c95f3aaf274510633f029ad682a",
|
||||
[
|
||||
null,
|
||||
{}
|
||||
|
|
|
@ -240,6 +240,7 @@ test_interfaces([
|
|||
"StyleSheet",
|
||||
"StyleSheetList",
|
||||
"SubmitEvent",
|
||||
"SVGRect",
|
||||
"Text",
|
||||
"TextTrack",
|
||||
"TextTrackCue",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue