mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue