Skip to content

Truly independent web browser

LibWeb: Remove discarded fragment links from the overflow index

Timothy Flynn54ba79ab9e66
diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs b/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs
index 2c0a687b32b..73871f34568 100644
--- a/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs
@@ -666,7 +666,7 @@ impl LinksHeldApartFromTheirContainingBlocks {
.push(node);
}
- fn remove(&mut self, node: NodeSlotId) {
+ pub(super) fn remove(&mut self, node: NodeSlotId) {
if let Some(containing_block) = self.containing_block_of.remove(&node) {
self.remove_from(containing_block, node);
}
@@ -904,6 +904,44 @@ mod tests {
use crate::css::css_enums::overflow;
use crate::css::style::layout_style::LayoutScratchStyle;
+ #[test]
+ fn discarded_fragment_links_leave_the_containing_block_index() {
+ let mut arena = LayoutNodeArena::new();
+ let container = arena.allocate_for_test().slot;
+ let cleared = arena.allocate_for_test().slot;
+ let freed = arena.allocate_for_test().slot;
+ for child in [cleared, freed] {
+ arena.set_committed_fragment_link(child, FragmentLink::for_test(child), None);
+ arena.note_whether_link_is_held_apart_from_its_containing_block(child, container, true);
+ }
+ assert_eq!(
+ arena
+ .links_held_apart_from_their_containing_blocks
+ .held_apart_from(container),
+ &[cleared, freed]
+ );
+
+ arena.clear_committed_fragment_link(cleared);
+ assert_eq!(
+ arena
+ .links_held_apart_from_their_containing_blocks
+ .held_apart_from(container),
+ &[freed]
+ );
+
+ let main_thread = crate::stage::MainThread::for_test();
+ arena
+ .free_subtree(freed)
+ .destroy_shells_and_invoke_callbacks(&main_thread);
+ assert!(arena.links_held_apart_from_their_containing_blocks.is_empty());
+
+ for row in [cleared, container] {
+ arena
+ .free_subtree(row)
+ .destroy_shells_and_invoke_callbacks(&main_thread);
+ }
+ }
+
#[test]
fn overflow_percentage_margins_use_the_containing_blocks_inline_size() {
for (mode, expected_bottom) in [
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
index 86fd226b7d6..f280db81847 100644
--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
@@ -1830,6 +1830,7 @@ impl LayoutNodeArena {
if let Some(slot) = self.default_scroll_shift_anchors.get_mut(index as usize) {
*slot = DefaultScrollShiftAnchorSlot::default();
}
+ self.links_held_apart_from_their_containing_blocks.remove(id);
self.paintable_rows.reset_committed_fragment_link_slot(index);
self.text_slots.reset(index as usize);
self.text_nodes_enrolled_for_content_sync.remove(&id);
@@ -5666,6 +5667,7 @@ impl LayoutNodeArena {
// Cached runs may reuse the committed paintable subtree without replaying its fragments.
// Once that subtree is cleared, a later layout must rebuild it instead.
self.memo_invalidations.note_run_cache_entries_dropped(id.slot_index());
+ self.links_held_apart_from_their_containing_blocks.remove(id);
drop(self.take_committed_fragment_link(id));
}
diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs
index 5fe39da29b5..2cd0929a151 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs
@@ -1062,8 +1062,6 @@ impl LayoutNodeArena {
}
pub(crate) fn paintable_row_cleared(&mut self, reset: PaintableRowReset) {
- // NB: The overflow index may keep listing this box. Overflow measurement passes over boxes without a row, and
- // populating the row again notes the box anew.
self.reset_paintable_row(true, reset);
}