Skip to content

Truly independent web browser

LibWeb: Keep the overflow index across tree edits that leave it valid

Andreas Kling535429cc4a28
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
index df09f7d09f5..46929f9f153 100644
--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
@@ -1611,9 +1611,8 @@ impl LayoutNodeArena {
self.pending_rebuilt_subtree_roots.get_mut().clear();
self.pending_layout_tree_update_escaped_rebuild_roots.set(false);
}
- if !self.scrollable_overflow.non_child_boxes.borrow().is_empty() {
- self.scrollable_overflow.contained_boxes_dirty.set(true);
- }
+ // NB: The root was unlinked through remove_child(), which already noted what its subtree takes out of the
+ // overflow index.
if self.scrollable_overflow.viewport.get() == Some(root) {
self.scrollable_overflow.viewport.set(None);
self.scrollable_overflow.non_child_boxes.borrow_mut().clear();
@@ -5218,9 +5217,6 @@ impl LayoutNodeArena {
}
pub(crate) fn note_structural_change_at_and_above(&self, node: NodeSlotId) {
- if !self.scrollable_overflow.non_child_boxes.borrow().is_empty() {
- self.scrollable_overflow.contained_boxes_dirty.set(true);
- }
self.invalidate_at_and_above(node, AncestorInvalidation::StructuralChange);
}
@@ -5293,6 +5289,7 @@ impl LayoutNodeArena {
self.assign_pre_order_labels_to_inserted_subtree(parent, child);
self.note_layout_subtree_attached(child);
self.pending_attached_subtree_roots.borrow_mut().push(child);
+ self.note_overflow_contained_boxes_may_move_with_subtree(child);
self.note_structural_change_at_and_above(parent);
}
@@ -5300,6 +5297,7 @@ impl LayoutNodeArena {
if self.paintable_row_count() > 0 {
self.push_enclosing_paint_order_damage(child);
}
+ self.note_overflow_contained_boxes_may_move_with_subtree(child);
self.unlink_child(parent, child);
self.note_structural_change_at_and_above(parent);
}
diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs
index 43ee928c47e..4bcd2e20345 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs
@@ -1164,9 +1164,8 @@ impl LayoutNodeArena {
}
pub(crate) fn paintable_row_cleared(&mut self, reset: PaintableRowReset) {
- if !self.scrollable_overflow.non_child_boxes.borrow().is_empty() {
- self.scrollable_overflow.contained_boxes_dirty.set(true);
- }
+ // 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);
}
diff --git a/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs b/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs
index d8f94ceab27..0d447dd0205 100644
--- a/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs
+++ b/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs
@@ -664,6 +664,28 @@ impl LayoutNodeArena {
}
}
+ /// Notes that `root` is being linked into or out of the tree. The tree above a box decides its
+ /// containing block, so only boxes in this subtree can enter or leave the index, and only those
+ /// whose containing block differs from their parent are listed in it.
+ pub(crate) fn note_overflow_contained_boxes_may_move_with_subtree(&self, root: NodeSlotId) {
+ if self.scrollable_overflow.contained_boxes_dirty.get()
+ || self.scrollable_overflow.non_child_boxes.borrow().is_empty()
+ {
+ return;
+ }
+ let mut found = false;
+ self.for_each_node_in_layout_subtree_in_pre_order_with_pruning(root, |node| {
+ let data = self.data(node);
+ found = found
+ || (node_facts::kind_is_box(data.kind.get())
+ && self.node_containing_block_if_live(node) != Some(data.parent.get()));
+ !found
+ });
+ if found {
+ self.scrollable_overflow.contained_boxes_dirty.set(true);
+ }
+ }
+
pub(crate) fn ensure_overflow_contained_boxes(&self) {
if !self.scrollable_overflow.contained_boxes_dirty.replace(false) {
return;
diff --git a/Tests/LibWeb/Text/expected/scrollable-overflow-contained-box-index-edits.txt b/Tests/LibWeb/Text/expected/scrollable-overflow-contained-box-index-edits.txt
index ed8555a0129..cdeb5a76d4c 100644
--- a/Tests/LibWeb/Text/expected/scrollable-overflow-contained-box-index-edits.txt
+++ b/Tests/LibWeb/Text/expected/scrollable-overflow-contained-box-index-edits.txt
@@ -1,6 +1,6 @@
-text edit: refills=1 scrollHeight=300
-plain block inserted: refills=1 scrollHeight=300
-plain block removed: refills=1 scrollHeight=300
+text edit: refills=0 scrollHeight=300
+plain block inserted: refills=0 scrollHeight=300
+plain block removed: refills=0 scrollHeight=300
nested absolutely positioned box inserted: refills=1 scrollHeight=500
nested absolutely positioned box removed: refills=1 scrollHeight=300
inline-block moved out of its inline parent: refills=1 scrollHeight=300