CanGc changes from fontfaceset.rs (#33920)

* CanGc changes from fontfaceset.rs

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

* Update components/script/dom/bindings/codegen/Bindings.conf

Co-authored-by: Josh Matthews <josh@joshmatthews.net>
Signed-off-by: chickenleaf <lashwinib@gmail.com>

---------

Signed-off-by: L Ashwin B <lashwinib@gmail.com>
Signed-off-by: chickenleaf <lashwinib@gmail.com>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
chickenleaf 2024-10-21 17:58:56 +05:30 committed by GitHub
parent 66695d2f7e
commit 9acb25521e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 425 additions and 274 deletions

View file

@ -694,7 +694,7 @@ impl Document {
self.activity.get() != DocumentActivity::Inactive
}
pub fn set_activity(&self, activity: DocumentActivity) {
pub fn set_activity(&self, activity: DocumentActivity, can_gc: CanGc) {
// This function should only be called on documents with a browsing context
assert!(self.has_browsing_context);
if activity == self.activity.get() {
@ -716,8 +716,11 @@ impl Document {
self.title_changed();
self.dirty_all_nodes();
self.window()
.reflow(ReflowGoal::Full, ReflowReason::CachedPageNeededReflow);
self.window().reflow(
ReflowGoal::Full,
ReflowReason::CachedPageNeededReflow,
can_gc,
);
self.window().resume();
media.resume(&client_context_id);
@ -906,7 +909,7 @@ impl Document {
}
/// Reflows and disarms the timer if the reflow timer has expired.
pub fn reflow_if_reflow_timer_expired(&self) {
pub fn reflow_if_reflow_timer_expired(&self, can_gc: CanGc) {
let Some(reflow_timeout) = self.reflow_timeout.get() else {
return;
};
@ -917,7 +920,7 @@ impl Document {
self.reflow_timeout.set(None);
self.window
.reflow(ReflowGoal::Full, ReflowReason::RefreshTick);
.reflow(ReflowGoal::Full, ReflowReason::RefreshTick, can_gc);
}
/// Schedules a reflow to be kicked off at the given [`Duration`] in the future. This reflow
@ -1019,11 +1022,11 @@ impl Document {
/// Scroll to the target element, and when we do not find a target
/// and the fragment is empty or "top", scroll to the top.
/// <https://html.spec.whatwg.org/multipage/#scroll-to-the-fragment-identifier>
pub fn check_and_scroll_fragment(&self, fragment: &str) {
pub fn check_and_scroll_fragment(&self, fragment: &str, can_gc: CanGc) {
let target = self.find_fragment_node(fragment);
// Step 1
self.set_target_element(target.as_deref());
self.set_target_element(target.as_deref(), can_gc);
let point = target
.as_ref()
@ -1032,7 +1035,9 @@ impl Document {
// inside other scrollable containers. Ideally this should use an implementation of
// `scrollIntoView` when that is available:
// See https://github.com/servo/servo/issues/24059.
let rect = element.upcast::<Node>().bounding_content_box_or_zero();
let rect = element
.upcast::<Node>()
.bounding_content_box_or_zero(can_gc);
// In order to align with element edges, we snap to unscaled pixel boundaries, since
// the paint thread currently does the same for drawing elements. This is important
@ -1056,7 +1061,7 @@ impl Document {
if let Some((x, y)) = point {
self.window
.scroll(x as f64, y as f64, ScrollBehavior::Instant)
.scroll(x as f64, y as f64, ScrollBehavior::Instant, can_gc)
}
}
@ -1188,7 +1193,7 @@ impl Document {
// Notify the embedder to display an input method.
if let Some(kind) = elem.input_method_type() {
let rect = elem.upcast::<Node>().bounding_content_box_or_zero();
let rect = elem.upcast::<Node>().bounding_content_box_or_zero(can_gc);
let rect = Rect::new(
Point2D::new(rect.origin.x.to_px(), rect.origin.y.to_px()),
Size2D::new(rect.size.width.to_px(), rect.size.height.to_px()),
@ -2088,7 +2093,7 @@ impl Document {
}
/// <https://html.spec.whatwg.org/multipage/#run-the-animation-frame-callbacks>
pub fn run_the_animation_frame_callbacks(&self) {
pub fn run_the_animation_frame_callbacks(&self, can_gc: CanGc) {
rooted_vec!(let mut animation_frame_list);
mem::swap(
&mut *animation_frame_list,
@ -2107,9 +2112,11 @@ impl Document {
self.running_animation_callbacks.set(false);
let spurious = !self
.window
.reflow(ReflowGoal::Full, ReflowReason::RequestAnimationFrame);
let spurious = !self.window.reflow(
ReflowGoal::Full,
ReflowReason::RequestAnimationFrame,
can_gc,
);
if spurious && !was_faking_animation_frames {
// If the rAF callbacks did not mutate the DOM, then the
@ -2239,7 +2246,7 @@ impl Document {
self.reflow_timeout.set(None);
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
self.window
.reflow(ReflowGoal::Full, ReflowReason::FirstLoad);
.reflow(ReflowGoal::Full, ReflowReason::FirstLoad, can_gc);
}
// Deferred scripts have to wait for page to finish loading,
@ -2471,7 +2478,7 @@ impl Document {
update_with_current_instant(&document.load_event_end);
if let Some(fragment) = document.url().fragment() {
document.check_and_scroll_fragment(fragment);
document.check_and_scroll_fragment(fragment, CanGc::note());
}
}),
self.window.upcast(),
@ -3048,12 +3055,14 @@ impl Document {
pub(crate) fn gather_active_resize_observations_at_depth(
&self,
depth: &ResizeObservationDepth,
can_gc: CanGc,
) -> bool {
let mut has_active_resize_observations = false;
for observer in self.resize_observers.borrow_mut().iter_mut() {
observer.gather_active_resize_observations_at_depth(
depth,
&mut has_active_resize_observations,
can_gc,
);
}
has_active_resize_observations
@ -3444,10 +3453,10 @@ impl Document {
}
/// As part of a `update_the_rendering` task, tick all pending animations.
pub fn tick_all_animations(&self, should_run_rafs: bool) {
pub fn tick_all_animations(&self, should_run_rafs: bool, can_gc: CanGc) {
let tick_type = mem::take(&mut *self.pending_animation_ticks.borrow_mut());
if should_run_rafs {
self.run_the_animation_frame_callbacks();
self.run_the_animation_frame_callbacks(can_gc);
}
if tick_type.contains(AnimationTickType::CSS_ANIMATIONS_AND_TRANSITIONS) {
self.maybe_mark_animating_nodes_as_dirty();
@ -3839,7 +3848,7 @@ impl Document {
self.referrer_policy.get()
}
pub fn set_target_element(&self, node: Option<&Element>) {
pub fn set_target_element(&self, node: Option<&Element>, can_gc: CanGc) {
if let Some(ref element) = self.target_element.get() {
element.set_target_state(false);
}
@ -3851,7 +3860,7 @@ impl Document {
}
self.window
.reflow(ReflowGoal::Full, ReflowReason::ElementStateChanged);
.reflow(ReflowGoal::Full, ReflowReason::ElementStateChanged, can_gc);
}
pub fn incr_ignore_destructive_writes_counter(&self) {
@ -5280,22 +5289,34 @@ impl DocumentMethods for Document {
);
// https://drafts.csswg.org/cssom-view/#dom-document-elementfrompoint
fn ElementFromPoint(&self, x: Finite<f64>, y: Finite<f64>) -> Option<DomRoot<Element>> {
fn ElementFromPoint(
&self,
x: Finite<f64>,
y: Finite<f64>,
can_gc: CanGc,
) -> Option<DomRoot<Element>> {
self.document_or_shadow_root.element_from_point(
x,
y,
self.GetDocumentElement(),
self.has_browsing_context,
can_gc,
)
}
// https://drafts.csswg.org/cssom-view/#dom-document-elementsfrompoint
fn ElementsFromPoint(&self, x: Finite<f64>, y: Finite<f64>) -> Vec<DomRoot<Element>> {
fn ElementsFromPoint(
&self,
x: Finite<f64>,
y: Finite<f64>,
can_gc: CanGc,
) -> Vec<DomRoot<Element>> {
self.document_or_shadow_root.elements_from_point(
x,
y,
self.GetDocumentElement(),
self.has_browsing_context,
can_gc,
)
}
@ -5560,9 +5581,9 @@ impl DocumentMethods for Document {
}
// https://drafts.csswg.org/css-font-loading/#font-face-source
fn Fonts(&self) -> DomRoot<FontFaceSet> {
fn Fonts(&self, can_gc: CanGc) -> DomRoot<FontFaceSet> {
self.fonts
.or_init(|| FontFaceSet::new(&self.global(), None))
.or_init(|| FontFaceSet::new(&self.global(), None, can_gc))
}
/// <https://html.spec.whatwg.org/multipage/#dom-document-hidden>
@ -5625,9 +5646,9 @@ pub struct FakeRequestAnimationFrameCallback {
}
impl FakeRequestAnimationFrameCallback {
pub fn invoke(self) {
pub fn invoke(self, can_gc: CanGc) {
let document = self.document.root();
document.run_the_animation_frame_callbacks();
document.run_the_animation_frame_callbacks(can_gc);
}
}