Replace CanGc::note() calls with arguments in components/script/dom (#33692)

* Replace CanGc::note() calls with arguments in components/script/dom

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>

* Add methods to Bindings.conf

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>

* Modify existing interface sections

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>

* Resolve conflicts

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>

---------

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
This commit is contained in:
tanishka 2024-10-08 18:28:09 +05:30 committed by GitHub
parent 38c5ebbf8e
commit 39133a5478
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 53 additions and 31 deletions

View file

@ -40,6 +40,7 @@ use crate::dom::node::{stylesheets_owner_from_node, window_from_node, Node, Shad
use crate::dom::types::HTMLElement; use crate::dom::types::HTMLElement;
use crate::realms::enter_realm; use crate::realms::enter_realm;
use crate::script_module::ScriptFetchOptions; use crate::script_module::ScriptFetchOptions;
use crate::script_runtime::CanGc;
use crate::script_thread::Documents; use crate::script_thread::Documents;
#[allow(unsafe_code)] #[allow(unsafe_code)]
@ -336,7 +337,7 @@ pub fn handle_get_layout(
let elem = node let elem = node
.downcast::<Element>() .downcast::<Element>()
.expect("should be getting layout of element"); .expect("should be getting layout of element");
let rect = elem.GetBoundingClientRect(); let rect = elem.GetBoundingClientRect(CanGc::note());
let width = rect.Width() as f32; let width = rect.Width() as f32;
let height = rect.Height() as f32; let height = rect.Height() as f32;

View file

@ -23,7 +23,7 @@ DOMInterfaces = {
}, },
'BaseAudioContext': { 'BaseAudioContext': {
'inRealms': ['DecodeAudioData', 'Resume'], 'inRealms': ['DecodeAudioData', 'Resume', 'ParseFromString', 'GetBounds', 'GetClientRects'],
}, },
'Blob': { 'Blob': {
@ -71,7 +71,7 @@ DOMInterfaces = {
}, },
'Element': { 'Element': {
'canGc': ['InsertAdjacentHTML', 'SetInnerHTML', 'SetOuterHTML'], 'canGc': ['SetInnerHTML', 'SetOuterHTML', 'InsertAdjacentHTML', 'GetClientRects', 'GetBoundingClientRect'],
}, },
'EventSource': { 'EventSource': {
@ -118,7 +118,7 @@ DOMInterfaces = {
}, },
'MediaDevices': { 'MediaDevices': {
'inRealms': ['GetUserMedia'], 'inRealms': ['GetUserMedia', 'GetClientRects', 'GetBoundingClientRect'],
}, },
'MediaQueryList': { 'MediaQueryList': {

View file

@ -90,7 +90,7 @@ impl DOMParserMethods for DOMParser {
Default::default(), Default::default(),
can_gc, can_gc,
); );
ServoParser::parse_html_document(&document, Some(s), url, CanGc::note()); ServoParser::parse_html_document(&document, Some(s), url, can_gc);
document.set_ready_state(DocumentReadyState::Complete); document.set_ready_state(DocumentReadyState::Complete);
Ok(document) Ok(document)
}, },
@ -112,7 +112,7 @@ impl DOMParserMethods for DOMParser {
Default::default(), Default::default(),
can_gc, can_gc,
); );
ServoParser::parse_xml_document(&document, Some(s), url, CanGc::note()); ServoParser::parse_xml_document(&document, Some(s), url, can_gc);
document.set_ready_state(DocumentReadyState::Complete); document.set_ready_state(DocumentReadyState::Complete);
Ok(document) Ok(document)
}, },

View file

@ -162,6 +162,13 @@ impl DOMQuadMethods for DOMQuad {
.max(self.p3.Y()) .max(self.p3.Y())
.max(self.p4.Y()); .max(self.p4.Y());
DOMRect::new(&self.global(), left, top, right - left, bottom - top) DOMRect::new(
&self.global(),
left,
top,
right - left,
bottom - top,
CanGc::note(),
)
} }
} }

View file

@ -26,8 +26,15 @@ impl DOMRect {
} }
} }
pub fn new(global: &GlobalScope, x: f64, y: f64, width: f64, height: f64) -> DomRoot<DOMRect> { pub fn new(
Self::new_with_proto(global, None, x, y, width, height, CanGc::note()) global: &GlobalScope,
x: f64,
y: f64,
width: f64,
height: f64,
can_gc: CanGc,
) -> DomRoot<DOMRect> {
Self::new_with_proto(global, None, x, y, width, height, can_gc)
} }
fn new_with_proto( fn new_with_proto(

View file

@ -2341,7 +2341,7 @@ impl ElementMethods for Element {
} }
// https://drafts.csswg.org/cssom-view/#dom-element-getclientrects // https://drafts.csswg.org/cssom-view/#dom-element-getclientrects
fn GetClientRects(&self) -> Vec<DomRoot<DOMRect>> { fn GetClientRects(&self, can_gc: CanGc) -> Vec<DomRoot<DOMRect>> {
let win = window_from_node(self); let win = window_from_node(self);
let raw_rects = self.upcast::<Node>().content_boxes(); let raw_rects = self.upcast::<Node>().content_boxes();
raw_rects raw_rects
@ -2353,13 +2353,14 @@ impl ElementMethods for Element {
rect.origin.y.to_f64_px(), rect.origin.y.to_f64_px(),
rect.size.width.to_f64_px(), rect.size.width.to_f64_px(),
rect.size.height.to_f64_px(), rect.size.height.to_f64_px(),
can_gc,
) )
}) })
.collect() .collect()
} }
// https://drafts.csswg.org/cssom-view/#dom-element-getboundingclientrect // https://drafts.csswg.org/cssom-view/#dom-element-getboundingclientrect
fn GetBoundingClientRect(&self) -> DomRoot<DOMRect> { fn GetBoundingClientRect(&self, can_gc: CanGc) -> DomRoot<DOMRect> {
let win = window_from_node(self); let win = window_from_node(self);
let rect = self.upcast::<Node>().bounding_content_box_or_zero(); let rect = self.upcast::<Node>().bounding_content_box_or_zero();
DOMRect::new( DOMRect::new(
@ -2368,6 +2369,7 @@ impl ElementMethods for Element {
rect.origin.y.to_f64_px(), rect.origin.y.to_f64_px(),
rect.size.width.to_f64_px(), rect.size.width.to_f64_px(),
rect.size.height.to_f64_px(), rect.size.height.to_f64_px(),
can_gc,
) )
} }

View file

@ -1823,7 +1823,9 @@ impl VirtualMethods for HTMLImageElement {
mouse_event.ClientX().to_f32().unwrap(), mouse_event.ClientX().to_f32().unwrap(),
mouse_event.ClientY().to_f32().unwrap(), mouse_event.ClientY().to_f32().unwrap(),
); );
let bcr = self.upcast::<Element>().GetBoundingClientRect(); let bcr = self
.upcast::<Element>()
.GetBoundingClientRect(CanGc::note());
let bcr_p = Point2D::new(bcr.X() as f32, bcr.Y() as f32); let bcr_p = Point2D::new(bcr.X() as f32, bcr.Y() as f32);
// Walk HTMLAreaElements // Walk HTMLAreaElements

View file

@ -382,28 +382,31 @@ fn get_element_in_view_center_point(element: &Element) -> Option<Point2D<i64>> {
.and_then(|body| { .and_then(|body| {
// Step 1: Let rectangle be the first element of the DOMRect sequence // Step 1: Let rectangle be the first element of the DOMRect sequence
// returned by calling getClientRects() on element. // returned by calling getClientRects() on element.
element.GetClientRects().first().map(|rectangle| { element
let x = rectangle.X().round() as i64; .GetClientRects(CanGc::note())
let y = rectangle.Y().round() as i64; .first()
let width = rectangle.Width().round() as i64; .map(|rectangle| {
let height = rectangle.Height().round() as i64; let x = rectangle.X().round() as i64;
let y = rectangle.Y().round() as i64;
let width = rectangle.Width().round() as i64;
let height = rectangle.Height().round() as i64;
let client_width = body.ClientWidth() as i64; let client_width = body.ClientWidth() as i64;
let client_height = body.ClientHeight() as i64; let client_height = body.ClientHeight() as i64;
// Steps 2 - 5 // Steps 2 - 5
let left = cmp::max(0, cmp::min(x, x + width)); let left = cmp::max(0, cmp::min(x, x + width));
let right = cmp::min(client_width, cmp::max(x, x + width)); let right = cmp::min(client_width, cmp::max(x, x + width));
let top = cmp::max(0, cmp::min(y, y + height)); let top = cmp::max(0, cmp::min(y, y + height));
let bottom = cmp::min(client_height, cmp::max(y, y + height)); let bottom = cmp::min(client_height, cmp::max(y, y + height));
// Steps 6 - 7 // Steps 6 - 7
let x = (left + right) / 2; let x = (left + right) / 2;
let y = (top + bottom) / 2; let y = (top + bottom) / 2;
// Step 8 // Step 8
Point2D::new(x, y) Point2D::new(x, y)
}) })
}) })
} }
@ -930,7 +933,7 @@ pub fn handle_get_bounding_client_rect(
.downcast::<Element>( .downcast::<Element>(
) { ) {
Some(element) => { Some(element) => {
let rect = element.GetBoundingClientRect(); let rect = element.GetBoundingClientRect(CanGc::note());
Ok(Rect::new( Ok(Rect::new(
Point2D::new(rect.X() as f32, rect.Y() as f32), Point2D::new(rect.X() as f32, rect.Y() as f32),
Size2D::new(rect.Width() as f32, rect.Height() as f32), Size2D::new(rect.Width() as f32, rect.Height() as f32),