mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +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
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue