Truly independent web browser
LibWeb: Read scrollable overflow from fragments
Aliaksandr Kalenik4ca7f3fb342c
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex ce6aae9ee27..ead82656e12 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -871,7 +871,6 @@ void Document::reset_style_invalidation_counters(Layout::BegunRead const& read)(void)CSS::StyleEngineFFI::style_engine_size_query_container_scan_visits(style_computer().style_engine().host(), &read, true);if (m_layout_node_arena) {Layout::RustFFI::render_state_scrollable_overflow_recalculation_count(m_layout_node_arena->host(), true);- Layout::RustFFI::render_state_overflow_contained_box_index_refill_count(m_layout_node_arena->host(), true);}CSS::reset_longhand_wrappers_minted();}diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cppindex 7758699d4a5..25d27dccff7 100644--- a/Libraries/LibWeb/Internals/Internals.cpp+++ b/Libraries/LibWeb/Internals/Internals.cpp@@ -3381,7 +3381,6 @@ GC::Ref<JS::Object> Internals::style_invalidation_counters_object() constobject->define_direct_property("styleCascadeMicroseconds"_utf16_fly_string, JS::Value(counters.style_cascade_microseconds), JS::default_attributes);object->define_direct_property("styleValuesMicroseconds"_utf16_fly_string, JS::Value(counters.style_values_microseconds), JS::default_attributes);object->define_direct_property("scrollableOverflowRecalculations"_utf16_fly_string, JS::Value(Layout::RustFFI::render_state_scrollable_overflow_recalculation_count(document.layout_node_arena().host(), false)), JS::default_attributes);- object->define_direct_property("overflowContainedBoxIndexRefills"_utf16_fly_string, JS::Value(Layout::RustFFI::render_state_overflow_contained_box_index_refill_count(document.layout_node_arena().host(), false)), JS::default_attributes);return object;}diff --git a/Libraries/LibWeb/Rust/src/layout/commit.rs b/Libraries/LibWeb/Rust/src/layout/commit.rsindex f076d6b60ab..3718e07cf42 100644--- a/Libraries/LibWeb/Rust/src/layout/commit.rs+++ b/Libraries/LibWeb/Rust/src/layout/commit.rs@@ -211,6 +211,20 @@ impl<'tree> Commit<'_, 'tree> {let number = self.number;self.arena_mut().note_committed_link_holder(node, recorded_holder, number);+ let containing_block = link.containing_block;+ if !containing_block.is_invalid() {+ let held_by_containing_block = recorded_holder == containing_block+ || self+ .arena()+ .committed_link_holder(recorded_holder)+ .is_some_and(|(holder_of_holder, _)| holder_of_holder == containing_block);+ self.arena_mut()+ .note_whether_link_is_held_apart_from_its_containing_block(+ node,+ containing_block,+ !held_by_containing_block,+ );+ }if holder.node.is_invalid() && !keeps_its_holder && (self.is_full_commit || !was_at_pass_level) {self.pass_level_links.push(node);}@@ -544,7 +558,6 @@ impl<'tree> Commit<'_, 'tree> {if prepared.has_paintable_row {self.paintables.set_box_fragments(inline_box, &[]);self.paintables.clear_line_data(inline_box);- self.paintables.schedule_scrollable_overflow_recalculation(inline_box);}self.arena_mut().gather_layout_style_snapshot_geometry(inline_box);self.arena_mut().refresh_paint_order_inputs(inline_box);@@ -711,7 +724,7 @@ pub(crate) fn commit_replacing(arena.note_layout_commit();let number = arena.layout_commit_count() as u32;let is_full_commit = arena.data(root).kind.get() == NodeKind::Viewport;- let mut paintables = crate::painting::paintable_build::PaintableCommit::new(arena, root);+ let mut paintables = crate::painting::paintable_build::PaintableCommit::new(arena);paintables.begin_commit();Commit {paintables,diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex a0d75a31729..5598e9b082d 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -3493,13 +3493,14 @@ impl LayoutStageJob {arena.reset_layout_update_flags_in_subtree(root);arena.leave_active_layout_pass();match kind {- LayoutStageKind::Root { .. } => arena.did_commit_full_layout(root),+ // NB: The full pass covered every subtree the last build rebuilt.+ LayoutStageKind::Root { .. } => arena.clear_pending_rebuilt_subtree_roots(),LayoutStageKind::Boundary { .. } => {- // Commit reset the subtree's rows, and its new size may affect ancestor scrollable- // overflow. Partial relayout roots are SVG viewports or abspos boxes, never SVG- // content boxes that would require a new layout instead of an overflow update.+ // The root's new size may affect the scrollable overflow of the boxes it is placed in. Partial relayout+ // roots are SVG viewports or abspos boxes, never SVG content boxes that would require a new layout+ // instead of an overflow update.debug_assert!(!node_facts::kind_is_svg_box(arena.data(root).kind.get()));- arena.schedule_scrollable_overflow_recalculation(root);+ arena.request_fragment_overflow_recalculation_of_containing_block(root);}}notificationsdiff --git a/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs b/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rsindex 063198565d4..20c7be65585 100644--- a/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs+++ b/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs@@ -672,6 +672,188 @@ pub(crate) fn scrollable_overflow_of<'link>(}}+impl LayoutNodeArena {+ pub(crate) fn request_fragment_overflow_recalculation(&mut self, node: NodeSlotId) {+ if !node.is_invalid() {+ self.scrollable_overflow.recalculation_requests.push(node);+ }+ }++ pub(crate) fn note_whether_link_is_held_apart_from_its_containing_block(+ &mut self,+ node: NodeSlotId,+ containing_block: NodeSlotId,+ is_held_apart: bool,+ ) {+ if is_held_apart {+ self.links_held_apart_from_their_containing_blocks.insert(node);+ self.request_fragment_overflow_recalculation(containing_block);+ } else if !self.links_held_apart_from_their_containing_blocks.is_empty() {+ self.links_held_apart_from_their_containing_blocks.remove(&node);+ }+ }++ pub(crate) fn request_fragment_overflow_recalculation_of_containing_block(&mut self, node: NodeSlotId) {+ if self.slot_is_live(node) && self.paintable_row_is_populated(node) {+ let containing_block = self.paintable_data(node).containing_block;+ self.request_fragment_overflow_recalculation(containing_block);+ }+ }++ fn committed_links_in_containing_block_fragment(+ &self,+ node: NodeSlotId,+ containing_block_fragment: u32,+ links: &mut Vec<FragmentLink>,+ ) {+ let side_data = self.committed_side_data(node);+ if side_data.containing_block_fragment == containing_block_fragment+ && let Some(link) = self+ .paintable_rows+ .committed_fragment_link_cloned(node.slot_index(), node.generation())+ {+ links.push(link);+ }+ links.extend(+ side_data+ .box_fragments()+ .iter()+ .filter(|fragment| fragment.containing_block_fragment == containing_block_fragment)+ .map(|fragment| fragment.link.clone()),+ );+ }++ fn recalculated_fragment_overflow(+ &self,+ node: NodeSlotId,+ link: &FragmentLink,+ fragment_index: u32,+ ) -> FragmentScrollableOverflow {+ let mut met = crate::fast_hash::FastSet::default();+ let mut contained = Vec::new();+ let holder_fragment = self+ .committed_link_holder(node)+ .map(|(holder, _)| holder)+ .filter(|&holder| self.slot_is_live(holder))+ .and_then(|holder| {+ self.paintable_rows+ .committed_fragment_link_cloned(holder.slot_index(), holder.generation())+ })+ .map(|holder_link| holder_link.fragment)+ .filter(|holder_fragment| holder_fragment.holds_links_of_outer_containing_blocks);+ let links_held_beside = holder_fragment+ .iter()+ .flat_map(|holder_fragment| holder_fragment.children.iter())+ .filter(|held| held.containing_block == node)+ .map(|held| held.fragment.node);+ let candidates = contained_links(&link.fragment)+ .map(|contained_link| contained_link.fragment.node)+ .chain(links_held_beside)+ .chain(self.links_held_apart_from_their_containing_blocks.iter().copied());+ for candidate in candidates {+ if met.insert(candidate)+ && self.slot_is_live(candidate)+ && self.paintable_row_is_populated(candidate)+ && self.paintable_data(candidate).containing_block == node+ {+ self.committed_links_in_containing_block_fragment(candidate, fragment_index, &mut contained);+ }+ }+ scrollable_overflow_of(self, &link.fragment, link.frame, contained.iter())+ }++ fn has_scrollable_overflow_in_any_fragment(&self, node: NodeSlotId) -> bool {+ self.with_committed_fragment_link(node, |link| {+ link.is_some_and(|link| link.fragment.scrollable_overflow.has_scrollable_overflow)+ }) || self+ .committed_side_data(node)+ .box_fragments()+ .iter()+ .any(|fragment| fragment.link.fragment.scrollable_overflow.has_scrollable_overflow)+ }++ fn recalculate_fragment_overflow_of(&mut self, node: NodeSlotId) -> bool {+ if !self.node_kind_if_live(node).is_some_and(node_facts::kind_is_box) {+ return false;+ }+ let Some(link) = self+ .paintable_rows+ .committed_fragment_link_cloned(node.slot_index(), node.generation())+ else {+ return false;+ };+ let had_scrollable_overflow = self.has_scrollable_overflow_in_any_fragment(node);+ let mut changed = false;+ let overflow = self.recalculated_fragment_overflow(node, &link, 0);+ if overflow != link.fragment.scrollable_overflow {+ let fragment = std::sync::Arc::new(link.fragment.with_scrollable_overflow(overflow));+ self.paintable_rows+ .replace_committed_fragment_link_keeping_its_geometry_epoch(+ node.slot_index(),+ node.generation(),+ FragmentLink { fragment, ..link },+ );+ changed = true;+ }+ let box_fragments = self.committed_side_data(node).box_fragments.clone();+ if let Some(box_fragments) = box_fragments {+ let mut recalculated = (*box_fragments).clone();+ let mut any_changed = false;+ for (index, box_fragment) in recalculated.iter_mut().enumerate() {+ let overflow = self.recalculated_fragment_overflow(node, &box_fragment.link, index as u32 + 1);+ if overflow != box_fragment.link.fragment.scrollable_overflow {+ box_fragment.link.fragment =+ std::sync::Arc::new(box_fragment.link.fragment.with_scrollable_overflow(overflow));+ any_changed = true;+ }+ }+ if any_changed {+ self.committed_side_data_mut(node).box_fragments = Some(std::sync::Arc::new(recalculated));+ changed = true;+ }+ }+ if changed {+ let has_scrollable_overflow = self.has_scrollable_overflow_in_any_fragment(node);+ self.note_scrollable_overflow_change(node, had_scrollable_overflow, has_scrollable_overflow, true);+ self.note_scroll_offset_may_leave_range(node);+ }+ changed+ }++ fn tree_depth(&self, node: NodeSlotId) -> u32 {+ std::iter::successors(Some(node), |&ancestor| self.node_parent_if_live(ancestor)).count() as u32+ }++ pub(crate) fn recalculate_requested_fragment_overflow(&mut self) {+ if self.scrollable_overflow.recalculation_requests.is_empty() {+ return;+ }+ self.scrollable_overflow.recalculations += 1;+ let requests = std::mem::take(&mut self.scrollable_overflow.recalculation_requests);+ let mut queued = crate::fast_hash::FastSet::default();+ let mut queue = std::collections::BinaryHeap::new();+ for node in requests {+ if self.slot_is_live(node) && queued.insert(node) {+ queue.push((self.tree_depth(node), node.index));+ }+ }+ while let Some((_, index)) = queue.pop() {+ let node = NodeSlotId { index };+ if !self.slot_is_live(node) || !self.paintable_row_is_populated(node) {+ continue;+ }+ if !self.recalculate_fragment_overflow_of(node) {+ continue;+ }+ let containing_block = self.paintable_data(node).containing_block;+ if !containing_block.is_invalid() && self.slot_is_live(containing_block) && queued.insert(containing_block)+ {+ queue.push((self.tree_depth(containing_block), containing_block.index));+ }+ }+ }+}+#[cfg(test)]mod tests {use super::*;diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rsindex 27caed8ad54..c1ca51f02b0 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs@@ -1113,6 +1113,7 @@ pub(crate) struct LayoutNodeArena {committed_link_holders: Vec<CommittedLinkHolder>,/// The boxes whose committed links a full commit met at the top of its pass, which no fragment holds.pass_level_committed_links: Vec<NodeSlotId>,+ pub(crate) links_held_apart_from_their_containing_blocks: crate::fast_hash::FastSet<NodeSlotId>,layout_tree_build_stats: FfiLayoutTreeBuildStats,pre_order_labels: Vec<u64>,pre_order_relabel_count: u64,@@ -1167,8 +1168,6 @@ pub(crate) struct LayoutNodeArena {/// this escape bit is set. Partial relayout may only run while the bit is clear; a full/// layout pass re-derives every fact boundary qualification depends on, so it clears the bit.pub(crate) pending_updates_escape_partial_relayout: bool,- pub(crate) boxes_needing_scrollable_overflow_recalculation: Vec<NodeSlotId>,- pub(crate) needs_full_scrollable_overflow_recalculation: bool,text_nodes_enrolled_for_content_sync: HashSet<NodeSlotId>,/// The scroll containers a running tree build gave a style, which may be where scroll/// snapping happens once the build is over.@@ -1239,6 +1238,7 @@ impl LayoutNodeArena {layout_commit_count: 0,committed_link_holders: Vec::new(),pass_level_committed_links: Vec::new(),+ links_held_apart_from_their_containing_blocks: Default::default(),layout_tree_build_stats: (FfiLayoutTreeBuildStats::default()),pre_order_labels: Vec::new(),pre_order_relabel_count: 0,@@ -1273,8 +1273,6 @@ impl LayoutNodeArena {inline_boxes_lifted_out_of: HashMap::default(),out_of_flow_positioning_contained: HashMap::default(),pending_updates_escape_partial_relayout: false,- boxes_needing_scrollable_overflow_recalculation: Vec::new(),- needs_full_scrollable_overflow_recalculation: false,text_nodes_enrolled_for_content_sync: HashSet::default(),built_scroll_containers: Default::default(),image_resources_owed_to_host: Default::default(),@@ -1515,17 +1513,12 @@ impl LayoutNodeArena {self.layout_root = NodeSlotId::INVALID;self.pending_rebuilt_subtree_roots.clear();self.pending_layout_tree_update_escaped_rebuild_roots = false;- }- // 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 == Some(root) {- self.scrollable_overflow.viewport = None;- self.scrollable_overflow.non_child_boxes.clear();- self.scrollable_overflow.full_layout_commit = false;- self.scrollable_overflow.geometry_changed = false;- self.scrollable_overflow.scrollability_changed = false;- self.boxes_needing_scrollable_overflow_recalculation.clear();- self.needs_full_scrollable_overflow_recalculation = false;+ let overflow = &mut self.scrollable_overflow;+ overflow.recalculation_requests.clear();+ overflow.scroll_offset_clamp_candidates.clear();+ overflow.geometry_changed = false;+ overflow.scrollability_changed = false;+ self.links_held_apart_from_their_containing_blocks.clear();}let mut rows = Vec::new();self.for_each_node_in_layout_subtree_in_pre_order(root, |slot| rows.push(slot));@@ -2170,10 +2163,23 @@ impl LayoutNodeArena {/// Record whether the node sits in the user agent shadow tree of the focused text control.pub(crate) fn set_identity_in_focused_text_control(&mut self, node: StyleNodeID, value: bool) {let identities = &mut self.style_node_tables.identities_in_focused_text_control;- if value {- identities.insert(node);+ let changed = if value {+ identities.insert(node)} else {- identities.remove(&node);+ identities.remove(&node)+ };+ if !changed {+ return;+ }+ let mut row = self.first_rows_by_style_node.head(node);+ while !row.is_invalid() {+ if let Some(line_root) = self.node_containing_block_if_live(row)+ && self.paintable_row_is_populated(line_root)+ {+ self.invalidate_fragments_of_self_and_ancestors_for_change_that_sizes_no_box(line_root);+ self.request_fragment_overflow_recalculation(line_root);+ }+ row = self.next_rows_with_same_style_node[row.slot_index() as usize];}}@@ -3879,7 +3885,6 @@ impl LayoutNodeArena {return;}self.set_needs_layout_update(node, true);- self.scrollable_overflow.contained_boxes_dirty = true;if releases_contained_boxes {self.record_partial_relayout_escape();}@@ -4573,16 +4578,6 @@ impl LayoutNodeArena {if flag == NodeFlag::HasAnimatedOpacityOrTransform && updated != previous {self.push_paint_damage(id, crate::painting::record::damage::PaintDamage::ELIGIBILITY);}- // A commit leaves an ordinary inline's overflow unmeasured, since nothing reads it. Once the- // inline stores a scroll offset, its overflow clamps that offset, so the pass measures it.- if flag == NodeFlag::HasScrollOffset- && value- && updated != previous- && self.paintable_row_is_populated(id)- && !self.paintable_side_data(id).overflow_measured_this_commit- {- self.note_row_overflow_unmeasured(id);- }}pub(crate) fn set_node_needs_compositor_animation_frame(@@ -5762,9 +5757,6 @@ impl LayoutNodeArena {self.memo_invalidations.note_structural_inline_change(node);}self.bump_fragment_cache_epoch(node);- if super::node_facts::kind_is_box(self.data(node).kind.get()) {- self.paintable_rows_mut().clear_cached_overflow_data(node);- }}pub(super) fn bump_fragment_cache_epoch(&mut self, node: NodeSlotId) {@@ -5864,7 +5856,6 @@ impl LayoutNodeArena {self.assign_pre_order_labels_to_inserted_subtree(parent, child);self.note_layout_subtree_attached(child);self.pending_attached_subtree_roots.push(child);- self.note_overflow_contained_boxes_may_move_with_subtree(child);// NB: Resolving the deferred insertion marks the parent for layout, which resets its intrinsic sizes.self.invalidate_self_and_ancestors(parent,@@ -5877,7 +5868,6 @@ 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.invalidate_self_and_ancestors(parent,diff --git a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rsindex d69b6015130..b98634fccd5 100644--- a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs+++ b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs@@ -236,7 +236,6 @@ impl LayoutNodeArena {pub(crate) fn record_partial_relayout_escape(&mut self) {self.pending_updates_escape_partial_relayout = true;- self.set_needs_full_scrollable_overflow_recalculation();}pub(crate) fn clear_partial_relayout_escape(&mut self) {@@ -294,9 +293,6 @@ impl LayoutNodeArena {) -> Option<Vec<PlannedBoundary>> {let pending_updates_escaped = std::mem::replace(&mut self.pending_updates_escape_partial_relayout, false)|| layout_tree_update_escaped_rebuild_roots;- if pending_updates_escaped {- self.set_needs_full_scrollable_overflow_recalculation();- }if self.node_needs_layout_update(root) || pending_updates_escaped {return None;}@@ -673,7 +669,7 @@ impl LayoutNodeArena {return;}self.note_contained_child_list_change(parent);- self.schedule_scrollable_overflow_recalculation(parent);+ self.request_fragment_overflow_recalculation(parent);}/// What a box that is not laid out again still owes a child list change that stays inside itsdiff --git a/Libraries/LibWeb/Rust/src/layout/row_reads.rs b/Libraries/LibWeb/Rust/src/layout/row_reads.rsindex c83aed5b1ed..596ee94f285 100644--- a/Libraries/LibWeb/Rust/src/layout/row_reads.rs+++ b/Libraries/LibWeb/Rust/src/layout/row_reads.rs@@ -38,7 +38,7 @@ pub(crate) struct RowSnapshot {/// How far the arena's rows had been written when they were published.version: RowsVersion,/// Whether every row's scrollable overflow was measured when the rows were published.- overflow_is_measured: bool,+ overflow_is_settled: bool,/// The text rows that waited for their text to be rendered again when the rows were published, by slot index:/// every other text row carries the text it renders.text_awaiting_render: Box<[NodeSlotId]>,@@ -85,8 +85,8 @@ impl RowSnapshot {/// Whether every row's scrollable overflow was measured when the rows were published, which a read of overflow/// needs.- pub(crate) fn overflow_is_measured(&self) -> bool {- self.overflow_is_measured+ pub(crate) fn overflow_is_settled(&self) -> bool {+ self.overflow_is_settled}/// The row in slot `id`, if the slot held it when the rows were published.@@ -247,11 +247,11 @@ impl RowIdentities {}impl LayoutNodeArena {- /// The rows as they are now, for the host to read, once every row's scrollable overflow is measured where- /// `measure_overflow` says so.- pub(crate) fn publish_row_snapshot(&mut self, measure_overflow: bool) -> RowSnapshot {- if measure_overflow {- self.measure_scrollable_overflow();+ /// The rows as they are now, for the host to read, once every row's scrollable overflow is settled where+ /// `settle_overflow` says so.+ pub(crate) fn publish_row_snapshot(&mut self, settle_overflow: bool) -> RowSnapshot {+ if settle_overflow {+ self.settle_scrollable_overflow();}let paintable = self.publish_rows();let bound = self.bound_rows_mut().publish();@@ -261,7 +261,7 @@ impl LayoutNodeArena {image_maps: self.image_map_areas().snapshot(),visual_context_tree: self.paint_state().visual_context.tree.clone(),version: self.rows_version(),- overflow_is_measured: self.scrollable_overflow_is_measured(),+ overflow_is_settled: self.scrollable_overflow_is_settled(),text_awaiting_render: self.text_rows_awaiting_sync(),}}diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rsindex 1138d4469ea..6651bf78840 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs@@ -1676,7 +1676,6 @@ impl TreeBuildJob {&state.additional_table_fixup_roots,);} else {- host.arena_mut().set_needs_full_scrollable_overflow_recalculation();fixup_tables(host, document_layout_node);}diff --git a/Libraries/LibWeb/Rust/src/layout/tree_mutation.rs b/Libraries/LibWeb/Rust/src/layout/tree_mutation.rsindex 777570cf219..f8adf5b116e 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_mutation.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_mutation.rs@@ -350,7 +350,7 @@ mod tests {use super::UnplacedLayoutNode;use crate::layout::LayoutNodeArena;use crate::layout::layout_node_arena::NodeAllocation;- use crate::layout::node_data::{NodeKind, NodeSlotId};+ use crate::layout::node_data::NodeSlotId;struct Links {parent: NodeSlotId,@@ -522,32 +522,6 @@ mod tests {free(&mut arena, grandparent);}- #[test]- fn a_structural_change_clears_the_overflow_validity_of_box_ancestors_only() {- let mut arena = LayoutNodeArena::new();- let grandparent = arena.allocate_for_test();- let parent = arena.allocate_for_test();- let child = arena.allocate_for_test();- arena.write_shape(grandparent.slot).set_kind(NodeKind::BlockContainer);- arena.write_shape(parent.slot).set_kind(NodeKind::InlineNode);- arena.attach_child(grandparent.slot, owned(parent.slot), NodeSlotId::INVALID);- for node in [grandparent.slot, parent.slot] {- arena.populate_paintable_row(node);- arena.committed_side_data_mut(node).overflow_valid_across_recommits = true;- }-- arena.attach_child(parent.slot, owned(child.slot), NodeSlotId::INVALID);-- assert!(- !arena- .committed_side_data(grandparent.slot)- .overflow_valid_across_recommits- );- assert!(arena.committed_side_data(parent.slot).overflow_valid_across_recommits);-- free(&mut arena, grandparent);- }-#[cfg(debug_assertions)]#[test]#[should_panic(expected = "leaked without being attached or freed")]diff --git a/Libraries/LibWeb/Rust/src/painting/ffi.rs b/Libraries/LibWeb/Rust/src/painting/ffi.rsindex 58de9bc1eba..67244546edb 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi.rs@@ -162,7 +162,7 @@ pub extern "C" fn render_state_paintable_scrollable_overflow() {// The host reads the overflow from the rows it holds, where they were measured and still read as the arena.let known = host.read_known_rows(|rows, source| {- rows.overflow_is_measured()+ rows.overflow_is_settled().then(|| FfiOptionalOverflowData::of(source, slot))});if let Some(Some(overflow)) = known {@@ -171,7 +171,7 @@ pub extern "C" fn render_state_paintable_scrollable_overflow(}*out = {read_arena(host, node_read(), slot, |arena, slot| {- arena.measure_scrollable_overflow();+ arena.settle_scrollable_overflow();FfiOptionalOverflowData::of(&arena.paintable_rows(), slot)})};@@ -190,9 +190,13 @@ impl FfiOptionalOverflowData {let Some(rect) = crate::painting::paintable_geometry::scrollable_overflow_rect(rows, slot) else {return Self::default();};- let mut value = rows.committed_side_data(slot).overflow_relative_to_padding_box;- value.rect = rect.into();- Self { has_value: true, value }+ Self {+ has_value: true,+ value: crate::painting::paintable_data::FfiOverflowData {+ rect: rect.into(),+ has_scrollable_overflow: crate::painting::paintable_geometry::has_scrollable_overflow(rows, slot),+ },+ }}}@@ -1410,136 +1414,3 @@ pub extern "C" fn render_state_note_svg_paint_resources_changed(host: &DocumentH}enrolled}--#[cfg(test)]-mod tests {- use super::*;- use crate::css::css_pixels::CssPixelRect;- use crate::layout::LayoutNodeArena;- use crate::layout::node_data::NodeKind;- use crate::painting::host::RootBackgroundSource;- use crate::painting::paintable_data::FfiOverflowData;- use crate::painting::record::damage::PaintDamage;- use crate::painting::visual_context::dirty::VisualContextBoxDirtyKind;- use crate::painting::visual_context::{TransformData, TransformDataRole, VisualContextTree};-- #[test]- fn publishing_measured_rows_can_remeasure_viewport_overflow_and_invalidate_painting() {- {- let mut arena = LayoutNodeArena::new();- let viewport = arena.allocate_for_test().slot;- arena.write_shape(viewport).set_kind(NodeKind::Viewport);- arena.populate_paintable_row(viewport);- arena.scrollable_overflow.viewport = Some(viewport);- let root = arena.allocate_for_test().slot;- arena.populate_paintable_row(root);- {- let state = arena.paint_state_mut();- state.root_background_source = Some(RootBackgroundSource {- root_layout_node: root,- ..Default::default()- });- state.visual_context.tree = Some(std::sync::Arc::new(VisualContextTree::create(TransformData {- matrix: libgfx_rust::FloatMatrix4x4::identity(),- origin: Default::default(),- sorting_context_root_index: None,- flattens_inherited_transform: false,- role: TransformDataRole::CssTransform,- synthetic_plane: false,- establishes_sorting_context: false,- })));- state.visual_context.dirty_boxes.clear();- }- // Leave stale overflow for the hit-test geometry query to remeasure. Losing- // scrollability must invalidate both the root background and visual context.- arena.committed_side_data_mut(viewport).overflow_relative_to_padding_box = FfiOverflowData {- rect: CssPixelRect::new(- CssPixels::from_integer(0),- CssPixels::from_integer(0),- CssPixels::from_integer(100),- CssPixels::from_integer(2000),- )- .into(),- has_scrollable_overflow: true,- };- arena.paintable_side_data_mut(viewport).overflow_measured_this_commit = true;- arena.note_publishing_paint_recording_started();- arena.clear_paint_damage_consumed_by_published_recording();-- // Hit testing reads rows published with every row's overflow measured.- let rows = arena.publish_row_snapshot(true);- let absolute_rects = std::cell::RefCell::default();- let source = crate::painting::paint_read::PaintSource::over_rows(&rows.paintable, &absolute_rects);- let rect = crate::painting::paintable_geometry::scrollable_overflow_rect(&source, viewport);- assert_eq!(rect, Some(CssPixelRect::default()));- assert!(arena.scrollable_overflow.geometry_changed);- assert!(arena.scrollable_overflow.scrollability_changed);- assert!(arena.paint_damage_of_row(root).contains(PaintDamage::DRAW_BACKGROUND));- assert!(- arena- .paint_damage_of_row(viewport)- .contains(PaintDamage::SCROLL_METADATA)- );- assert!(- arena.paint_state().visual_context.dirty_boxes.boxes[&viewport]- .contains(VisualContextBoxDirtyKind::ScrollableOverflowFlipped)- );- }- }-- #[test]- fn preparing_for_rendering_measures_root_overflow_before_recording_reads_it() {- let mut arena = LayoutNodeArena::new();- let viewport = arena.allocate_for_test().slot;- arena.write_shape(viewport).set_kind(NodeKind::Viewport);- arena.populate_paintable_row(viewport);- arena.scrollable_overflow.viewport = Some(viewport);- let root = arena.allocate_for_test().slot;- arena.write_shape(root).set_kind(NodeKind::BlockContainer);- arena.populate_paintable_row(root);- // A structural change invalidated the root's overflow, measured earlier in this commit,- // without queueing a recalculation, so nothing but a query measures it again. Measuring- // it drops its scrollable overflow.- arena.committed_side_data_mut(root).overflow_relative_to_padding_box = FfiOverflowData {- rect: CssPixelRect::new(- CssPixels::from_integer(0),- CssPixels::from_integer(0),- CssPixels::from_integer(100),- CssPixels::from_integer(2000),- )- .into(),- has_scrollable_overflow: true,- };- arena.paintable_side_data_mut(root).overflow_measured_this_commit = true;- arena.paint_state_mut().visual_context.dirty_boxes.clear();-- let outcome = crate::painting::paint_passes::prepare_for_rendering(- &mut arena,- RootBackgroundSource {- root_layout_node: root,- ..Default::default()- },- Some(&crate::painting::host::FfiVisualContextTreeInputs {- device_pixels_per_css_pixel: 1.0,- visual_viewport_offset_x: 0.0,- visual_viewport_offset_y: 0.0,- visual_viewport_scale: 1.0,- }),- )- .outcome;- assert!(outcome.requires_visual_context_update);- assert!(- arena.paint_state().visual_context.dirty_boxes.boxes[&root]- .contains(VisualContextBoxDirtyKind::ScrollableOverflowFlipped)- );-- // Recording reads the root's overflow while it holds the paint state.- let _paint_state = arena.paint_state();- let canvas_rect = crate::painting::record::paint::background_resolution::root_background_canvas_rect(- &arena.paintable_rows(),- root,- CssPixelRect::default(),- );- assert_eq!(canvas_rect, CssPixelRect::default());- }-}diff --git a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rsindex 509c576e614..10b27efa7f4 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs@@ -139,7 +139,7 @@ pub extern "C" fn render_state_scroll_target_for_text_position(super::node_read(),(text, offset, affinity_is_downstream, scroll_block_axis),|arena, (text, offset, affinity_is_downstream, scroll_block_axis)| {- arena.measure_scrollable_overflow();+ arena.settle_scrollable_overflow();crate::painting::scroll_chain::scroll_target_for_text_position(&arena.paintable_rows(),text,@@ -169,7 +169,7 @@ pub extern "C" fn render_state_scrolling_box_for_scroll_step(super::node_read(),(target, viewport, delta),|arena, (target, viewport, delta)| {- arena.measure_scrollable_overflow();+ arena.settle_scrollable_overflow();crate::painting::scroll_chain::scrolling_box_for_scroll_step(&arena.paintable_rows(),target,@@ -198,7 +198,7 @@ pub unsafe extern "C" fn render_state_for_each_wheel_scrollable_box_in_containinsuper::node_read(),(start, wheel_delta_x, wheel_delta_y),|arena, (start, wheel_delta_x, wheel_delta_y)| {- arena.measure_scrollable_overflow();+ arena.settle_scrollable_overflow();let mut boxes = Vec::new();crate::painting::scroll_chain::for_each_wheel_scrollable_box_in_containing_block_chain(&arena.paintable_rows(),@@ -240,7 +240,7 @@ pub extern "C" fn render_state_first_wheel_scrollable_box_in_containing_block_chstart: NodeSlotId,) -> NodeSlotId {read_arena(host, node_read(), start, |arena, start| {- arena.measure_scrollable_overflow();+ arena.settle_scrollable_overflow();crate::painting::scroll_chain::first_wheel_scrollable_box_in_containing_block_chain(&arena.paintable_rows(),start,diff --git a/Libraries/LibWeb/Rust/src/painting/layout_tree_dump.rs b/Libraries/LibWeb/Rust/src/painting/layout_tree_dump.rsindex a8a2cb66468..f75b55e38f9 100644--- a/Libraries/LibWeb/Rust/src/painting/layout_tree_dump.rs+++ b/Libraries/LibWeb/Rust/src/painting/layout_tree_dump.rs@@ -145,7 +145,7 @@ pub unsafe extern "C" fn render_state_dump_layout_tree(node_read(),(root, initial_indent, interactive),|arena, (root, initial_indent, interactive)| {- arena.measure_scrollable_overflow();+ arena.settle_scrollable_overflow();let mut plan = DumpPlan::default();plan_layout_node(&mut plan,diff --git a/Libraries/LibWeb/Rust/src/painting/paint_passes.rs b/Libraries/LibWeb/Rust/src/painting/paint_passes.rsindex 03a5c102278..d370bb8dbb2 100644--- a/Libraries/LibWeb/Rust/src/painting/paint_passes.rs+++ b/Libraries/LibWeb/Rust/src/painting/paint_passes.rs@@ -77,8 +77,8 @@ pub(crate) fn prepare_for_clock_tick(arena: &mut LayoutNodeArena,viewport: NodeSlotId,) -> Result<Option<ClockTickVisualContexts>, VisualContextsNeedHost> {- // Recording reads overflow, and measuring it notes a flip in scrollability for the check below.- arena.measure_scrollable_overflow();+ // Recording reads overflow, and settling it notes a flip in scrollability for the check below.+ arena.settle_scrollable_overflow();if arena.svg_paint_resources().needs_sync()|| arena.paint_state().root_background_source!= Some(crate::layout::viewport_propagation::root_background_source(arena))@@ -281,16 +281,16 @@ impl PendingPreparation {}}-/// Whether preparing `arena` for rendering would change anything: its root background source moved, or scrollable-/// overflow is left to settle or to measure, or a measurement changed what the preparation answers.+/// Whether preparing `arena` for rendering would change anything: its root background source moved, scrollable+/// overflow is left to settle, a stored scroll offset may have to be clamped, or an overflow change since the last+/// preparation changed what it answers.pub(crate) fn rendering_preparation_pending(arena: &LayoutNodeArena) -> Option<PendingPreparation> {let root_background_source = crate::layout::viewport_propagation::root_background_source(arena);let overflow = &arena.scrollable_overflow;let pending = arena.paint_state().root_background_source != Some(root_background_source)- || overflow.full_layout_commit- || overflow.measurement_awaits_preparation()- || arena.scrollable_overflow_recalculation_is_scheduled()- || !arena.scrollable_overflow_is_measured();+ || overflow.change_awaits_preparation()+ || !overflow.scroll_offset_clamp_candidates.is_empty()+ || !arena.scrollable_overflow_is_settled();pending.then_some(PendingPreparation { root_background_source })}@@ -314,7 +314,7 @@ pub(crate) fn prepare_for_rendering(sticky_inputs: Option<&FfiVisualContextTreeInputs>,) -> RenderingPreparation {let background_source_changed = arena.update_root_background_source(root_background_source);- // This measures all overflow left unmeasured, including the root's: the root background covers+ // This settles all overflow left to recalculate, including the root's: the root background covers// the viewport united with it, so a flip in its scrollability is seen here rather than while// recording holds the paint state.let clamped_scroll_offsets = crate::painting::scrollable_overflow::update_scrollable_overflow(arena);@@ -350,7 +350,7 @@ pub(crate) fn refresh_scroll_state(arena: &mut LayoutNodeArena,device_pixels_per_css_pixel: f64,) -> Option<Vec<FloatPoint>> {- arena.measure_scrollable_overflow();+ arena.settle_scrollable_overflow();arena.with_visual_context_state_lent(|arena, state| {if !state.needs_to_refresh_scroll_state {return None;@@ -392,7 +392,7 @@ pub(crate) fn update_accumulated_visual_contexts(viewport: NodeSlotId,inputs: FfiVisualContextTreeInputs,) -> FfiVisualContextUpdateOutcome {- arena.measure_scrollable_overflow();+ arena.settle_scrollable_overflow();if !arena.paintable_row_is_populated(viewport) {return FfiVisualContextUpdateOutcome::default();}diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs b/Libraries/LibWeb/Rust/src/painting/paintable_build.rsindex a3dad4a1b75..df7e9471754 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs@@ -93,21 +93,16 @@ fn has_descendant_dependent_paint(arena: &LayoutNodeArena, node: NodeSlotId) ->pub(crate) struct PaintableCommit<'a> {arena: &'a mut LayoutNodeArena,- is_full_layout: bool,committed_navigable_container_viewports: Vec<NodeSlotId>,row_reset_notifications: Vec<crate::painting::paintable_rows::PaintableRowReset>,- overflow_invalidated_boxes: crate::fast_hash::FastSet<NodeSlotId>,}impl<'a> PaintableCommit<'a> {- pub(crate) fn new(arena: &'a mut LayoutNodeArena, root: NodeSlotId) -> Self {- let is_full_layout = arena.data(root).kind.get() == NodeKind::Viewport;+ pub(crate) fn new(arena: &'a mut LayoutNodeArena) -> Self {Self {arena,- is_full_layout,committed_navigable_container_viewports: Vec::new(),row_reset_notifications: Vec::new(),- overflow_invalidated_boxes: Default::default(),}}@@ -266,9 +261,11 @@ impl<'a> PaintableCommit<'a> {let mut inline_item_order_unchanged = false;let mut child_sequence_unchanged = false;let mut link_shows_box_the_same = true;+ let mut old_scrollable_overflow = crate::layout::fragment_overflow::FragmentScrollableOverflow::default();let (old_identity, old_content_size) = self.arena().with_committed_fragment_link(node, |old_link| {old_link.map_or((0, used_values::FfiCssPixelSize::default()), |old_link| {let previous = &old_link.fragment;+ old_scrollable_overflow = previous.scrollable_overflow;if previous.identity == fragment.identity {own_paint_unchanged = true;child_placements_unchanged = true;@@ -300,9 +297,6 @@ impl<'a> PaintableCommit<'a> {})});if old_content_size != new_content_size {- if self.arena().data(node).kind.get() == NodeKind::Viewport {- self.arena_mut().set_needs_full_scrollable_overflow_recalculation();- }content_size_change = Some((old_content_size, new_content_size));}let committed_fragment_identity_changed = old_identity != fragment.identity;@@ -363,14 +357,15 @@ impl<'a> PaintableCommit<'a> {self.arena_mut().note_visual_context_box_dirty(node, VisualContextBoxDirtyKind::RecommittedInPlace);}- if !fragment_content_unchanged || !self.arena().committed_side_data(node).overflow_valid_across_recommits {- self.schedule_scrollable_overflow_recalculation(node);- } else if !offset_unchanged {- // NB: Moving an unchanged subtree preserves its overflow relative to its padding- // box. Only its contribution to containing blocks needs to be measured again.- let containing_block = self.committed_containing_block(node, Some(link));- self.schedule_scrollable_overflow_recalculation(containing_block);+ if old_scrollable_overflow != fragment.scrollable_overflow {+ self.arena_mut().note_scrollable_overflow_change(+ node,+ old_scrollable_overflow.has_scrollable_overflow,+ fragment.scrollable_overflow.has_scrollable_overflow,+ false,+ );}+ self.arena_mut().note_scroll_offset_may_leave_range(node);{let arena = self.arena_mut();let mut paintable_rows = arena.paintable_rows_mut();@@ -446,6 +441,29 @@ impl<'a> PaintableCommit<'a> {if identical {return;}+ let (later_overflow_changed, later_fragments_had_scrollable_overflow) = {+ let committed = self.arena().committed_side_data(slot).box_fragments();+ (+ committed.len() != later_fragments.len()+ || committed.iter().zip(later_fragments).any(|(committed, fragment)| {+ committed.link.fragment.scrollable_overflow != fragment.link.fragment.scrollable_overflow+ }),+ committed+ .iter()+ .any(|committed| committed.link.fragment.scrollable_overflow.has_scrollable_overflow),+ )+ };+ if later_overflow_changed {+ let later_fragments_have_scrollable_overflow = later_fragments+ .iter()+ .any(|fragment| fragment.link.fragment.scrollable_overflow.has_scrollable_overflow);+ self.arena_mut().note_scrollable_overflow_change(+ slot,+ later_fragments_had_scrollable_overflow,+ later_fragments_have_scrollable_overflow,+ false,+ );+ }{let mut side = self.arena_mut().committed_side_data_mut(slot);side.containing_block_fragment = containing_block_fragment;@@ -474,7 +492,6 @@ impl<'a> PaintableCommit<'a> {VisualContextBoxDirtyKind::RecommittedInPlace},);- self.schedule_scrollable_overflow_recalculation(slot);}pub(crate) fn set_line_data(@@ -523,26 +540,6 @@ impl<'a> PaintableCommit<'a> {}}- pub(crate) fn schedule_scrollable_overflow_recalculation(&mut self, mut node: NodeSlotId) {- // NB: Commit visits changed boxes before their descendants. Invalidate each containing- // block once, including blocks outside the committed layout subtree.- while !node.is_invalid() && self.arena().slot_is_live(node) {- if !self.overflow_invalidated_boxes.insert(node) {- break;- }- let is_full_layout = self.is_full_layout;- let arena = self.arena_mut();- if arena.paintable_row_is_populated(node) {- arena.paintable_rows_mut().clear_cached_overflow_data(node);- // Commit queues are consumed immediately and are bounded by the committed tree.- if is_full_layout && !arena.needs_full_scrollable_overflow_recalculation {- arena.boxes_needing_scrollable_overflow_recalculation.push(node);- }- }- node = arena.containing_block_by_walking_ancestors(node);- }- }-fn committed_containing_block(&self,node: formatting_context::Node,diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_data.rs b/Libraries/LibWeb/Rust/src/painting/paintable_data.rsindex 32abc86a655..067215492b2 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_data.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_data.rs@@ -189,7 +189,6 @@ pub struct PaintableSideData {// Invalidation also runs while paint geometry is borrowed. Keep this// mutable cache state out of the plain-data row shared with C++.pub(crate) overflow_style: Option<crate::painting::scrollable_overflow::OverflowStyle>,- pub(crate) overflow_measured_this_commit: bool,// The filter a recommit cleared, kept so the next assignment can tell whether the box// paints a different selection of fragments than before.pub(crate) fragment_ownership_before_recommit:@@ -202,14 +201,12 @@ pub(crate) struct CommittedBoxFragment {pub(crate) containing_block_fragment: u32,}-/// What a row committed beside its geometry that painting reads with it: its inline content, its-/// measured scrollable overflow, and what paint preparation adds for the recording. Shared records are held by `Arc`, so copying a row+/// What a row committed beside its geometry that painting reads with it: its inline content and what paint+/// preparation adds for the recording. Shared records are held by `Arc`, so copying a row/// copies reference counts.#[derive(Clone, Default)]pub(crate) struct CommittedSideData {pub(crate) inline_content: Option<std::sync::Arc<crate::layout::inline_content::InlineContent>>,- pub(crate) overflow_valid_across_recommits: bool,- pub(crate) overflow_relative_to_padding_box: FfiOverflowData,/// The bounds of the SVG filter the box references, as the visual context update resolved/// them.pub(crate) svg_filter_bounds: Option<used_values::FfiCssPixelRect>,@@ -227,9 +224,7 @@ pub(crate) struct CommittedSideData {impl PartialEq for CommittedSideData {fn eq(&self, other: &Self) -> bool {use crate::cow_column::same_payload;- self.overflow_valid_across_recommits == other.overflow_valid_across_recommits- && self.overflow_relative_to_padding_box == other.overflow_relative_to_padding_box- && self.svg_filter_bounds == other.svg_filter_bounds+ self.svg_filter_bounds == other.svg_filter_bounds&& self.order_inputs == other.order_inputs&& same_payload(self.fragment_ownership.as_ref(),@@ -262,16 +257,6 @@ impl CommittedSideData {pub(crate) fn lines(&self) -> &[crate::layout::inline_content::LineRecord] {self.inline_content.as_ref().map_or(&[], |content| &content.lines)}- pub(crate) fn elided_content_rects(&self) -> &[(u32, used_values::FfiCssPixelRect)] {- self.inline_content- .as_ref()- .map_or(&[], |content| &content.elided_content_rects)- }- pub(crate) fn lines_after_clamp_point_rect(&self) -> Option<used_values::FfiCssPixelRect> {- self.inline_content- .as_ref()- .and_then(|content| content.lines_after_clamp_point_rect.as_deref().copied())- }pub(crate) fn fragments(&self) -> &[FragmentRecord] {self.inline_content.as_ref().map_or(&[], |content| &content.fragments)}diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs b/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rsindex 541b754504f..b84c00fb68c 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs@@ -717,25 +717,50 @@ pub(crate) fn first_fragment_border_box_rect(arena: &impl GeometryRead, slot: No)}-/// The overflow the pass measured. Reading it never measures it.+/// The scrollable overflow of the box in `slot`, united over its fragments, where its committed fragments hold one. An+/// inline box has none until it stores a scroll offset, which its padding box then bounds.pub(crate) fn scrollable_overflow_rect(arena: &impl GeometryRead, slot: NodeSlotId) -> Option<CssPixelRect> {if !arena.paintable_row_is_populated(slot) {return None;}- let cache = arena.committed_side_data(slot);- if !cache.overflow_valid_across_recommits {- return None;- }- Some(- CssPixelRect::from(cache.overflow_relative_to_padding_box.rect)- .translated_by(first_fragment_padding_box_rect(arena, slot).location()),- )+ if !arena+ .node_kind_if_live(slot)+ .is_some_and(crate::layout::node_facts::kind_is_box)+ {+ let stores_scroll_offset =+ arena.node_flags_if_live(slot) & crate::layout::node_data::NodeFlag::HasScrollOffset as u32 != 0;+ return stores_scroll_offset.then(|| first_fragment_padding_box_rect(arena, slot));+ }+ let first = arena.with_committed_fragment_link(slot, |link| {+ link.map(|link| link.fragment.scrollable_overflow.rect_relative_to_padding_box)+ })?;+ let mut rect = first.translated_by(first_fragment_padding_box_rect(arena, slot).location());+ for (index, fragment) in arena.committed_side_data(slot).box_fragments().iter().enumerate() {+ rect.unite(+ fragment+ .link+ .fragment+ .scrollable_overflow+ .rect_relative_to_padding_box+ .translated_by(absolute_fragment_padding_box_rect(arena, slot, index + 1).location()),+ );+ }+ Some(rect)}pub(crate) fn has_scrollable_overflow(arena: &impl GeometryRead, slot: NodeSlotId) -> bool {- if !arena.paintable_row_is_populated(slot) {+ if !arena.paintable_row_is_populated(slot)+ || !arena+ .node_kind_if_live(slot)+ .is_some_and(crate::layout::node_facts::kind_is_box)+ {return false;}- let cache = arena.committed_side_data(slot);- cache.overflow_valid_across_recommits && cache.overflow_relative_to_padding_box.has_scrollable_overflow+ arena.with_committed_fragment_link(slot, |link| {+ link.is_some_and(|link| link.fragment.scrollable_overflow.has_scrollable_overflow)+ }) || arena+ .committed_side_data(slot)+ .box_fragments()+ .iter()+ .any(|fragment| fragment.link.fragment.scrollable_overflow.has_scrollable_overflow)}diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rsindex 1376ba145ee..85bc978bfb1 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs@@ -85,12 +85,6 @@ mod tests {..side_data.clone()};assert!(side_data != without_content);-- let measured = CommittedSideData {- overflow_valid_across_recommits: true,- ..side_data.clone()- };- assert!(side_data != measured);}/// Places the single piece of the inline box `node` on a line of a new line root, at the padding box `rect`.@@ -119,7 +113,7 @@ mod tests {}#[test]- fn overflow_queries_do_not_measure_ordinary_inline_fragments() {+ fn an_inline_box_shows_scrollable_overflow_once_it_stores_a_scroll_offset() {use crate::css::css_pixels::{CssPixelRect, CssPixels};use crate::layout::node_data::NodeKind;use crate::painting::paintable_geometry;@@ -128,7 +122,6 @@ mod tests {let node = arena.allocate_for_test().slot;arena.write_shape(node).set_kind(NodeKind::InlineNode);arena.populate_paintable_row(node);- arena.scrollable_overflow.viewport = Some(node);let rect = CssPixelRect::new(CssPixels::from_integer(0),CssPixels::from_integer(0),@@ -136,107 +129,15 @@ mod tests {CssPixels::from_integer(80),);give_inline_box_a_piece(&mut arena, node, rect);-- arena.measure_scrollable_overflow();- let rows = arena.paintable_rows();- assert_eq!(paintable_geometry::scrollable_overflow_rect(&rows, node), None);- assert!(!paintable_geometry::has_scrollable_overflow(&rows, node));- assert!(!arena.paintable_side_data(node).overflow_measured_this_commit);- }-- #[test]- fn inline_that_starts_storing_a_scroll_offset_is_measured_before_recording() {- use crate::css::css_pixels::{CssPixelRect, CssPixels};- use crate::layout::node_data::NodeKind;- use crate::painting::paintable_geometry;-- let mut arena = LayoutNodeArena::new();- let node = arena.allocate_for_test().slot;- arena.write_shape(node).set_kind(NodeKind::InlineNode);- arena.populate_paintable_row(node);- arena.scrollable_overflow.viewport = Some(node);- let rect = CssPixelRect::new(- CssPixels::from_integer(0),- CssPixels::from_integer(0),- CssPixels::from_integer(100),- CssPixels::from_integer(80),- );- give_inline_box_a_piece(&mut arena, node, rect);- arena.measure_scrollable_overflow();assert_eq!(paintable_geometry::scrollable_overflow_rect(&arena.paintable_rows(), node),None);arena.set_node_flag(node, NodeFlag::HasScrollOffset, true);- arena.measure_scrollable_overflow();- assert_eq!(- paintable_geometry::scrollable_overflow_rect(&arena.paintable_rows(), node),- Some(rect)- );- }-- #[test]- fn overflow_is_measured_before_recording_while_geometry_is_borrowed() {- use crate::css::css_pixels::{CssPixelRect, CssPixels};- use crate::layout::node_data::NodeKind;- use crate::painting::paintable_geometry;-- let mut arena = LayoutNodeArena::new();- let node = arena.allocate_for_test().slot;- arena.write_shape(node).set_kind(NodeKind::InlineNode);- arena.set_node_flag(node, NodeFlag::HasScrollOffset, true);- arena.populate_paintable_row(node);- arena.scrollable_overflow.viewport = Some(node);- let rect = CssPixelRect::new(- CssPixels::from_integer(0),- CssPixels::from_integer(0),- CssPixels::from_integer(100),- CssPixels::from_integer(80),- );- give_inline_box_a_piece(&mut arena, node, rect);- {- let mut committed = arena.committed_side_data_mut(node);- committed.overflow_relative_to_padding_box = FfiOverflowData {- rect: CssPixelRect::new(rect.x, rect.y, CssPixels::from_integer(500), rect.height).into(),- has_scrollable_overflow: true,- };- committed.overflow_valid_across_recommits = true;- }- arena.paintable_side_data_mut(node).overflow_measured_this_commit = true;-- let previous_geometry = *arena.paintable_rows().paintable_data(node);- arena.paintable_rows_mut().clear_cached_overflow_data(node);- // Reading overflow never measures it.- assert_eq!(- paintable_geometry::scrollable_overflow_rect(&arena.paintable_rows(), node),- None- );- assert!(!arena.scrollable_overflow.geometry_changed);- arena.measure_scrollable_overflow();let rows = arena.paintable_rows();assert_eq!(paintable_geometry::scrollable_overflow_rect(&rows, node), Some(rect));assert!(!paintable_geometry::has_scrollable_overflow(&rows, node));- assert_eq!(*rows.paintable_data(node), previous_geometry);- assert!(arena.scrollable_overflow.geometry_changed);- assert!(arena.scrollable_overflow.scrollability_changed);- }-- #[test]- fn overflow_cache_invalidation_leaves_the_geometry_alone() {- let mut arena = LayoutNodeArena::new();- let node = arena.allocate_for_test().slot;- arena.populate_paintable_row(node);- arena.committed_side_data_mut(node).overflow_valid_across_recommits = true;- arena.paintable_side_data_mut(node).overflow_measured_this_commit = true;- arena.paintable_rows_mut().begin_paintable_row_recommit(node);- assert!(arena.committed_side_data(node).overflow_valid_across_recommits);-- let previous_geometry = *arena.paintable_rows().paintable_data(node);- arena.paintable_rows_mut().clear_cached_overflow_data(node);- assert_eq!(*arena.paintable_rows().paintable_data(node), previous_geometry);- assert!(!arena.committed_side_data(node).overflow_valid_across_recommits);- assert!(!arena.paintable_side_data(node).overflow_measured_this_commit);}}@@ -369,12 +270,6 @@ pub(crate) struct PaintableRows<Arena> {absolute_rects: RefCell<crate::painting::record::recorder_state::AbsoluteRectMemo>,}-impl<Arena> PaintableRows<Arena> {- pub(crate) fn into_absolute_rect_memo(self) -> crate::painting::record::recorder_state::AbsoluteRectMemo {- self.absolute_rects.into_inner()- }-}-pub(crate) type PaintableRowsRef<'a> = PaintableRows<&'a LayoutNodeArena>;pub(crate) type PaintableRowsMut<'a> = PaintableRows<&'a mut LayoutNodeArena>;@@ -486,15 +381,6 @@ impl<Arena> PaintableRows<Arena>whereArena: DerefMut<Target = LayoutNodeArena>,{- pub(crate) fn clear_cached_overflow_data(&mut self, id: NodeSlotId) {- if !self.paintable_row_is_populated(id) {- return;- }- if std::mem::take(&mut self.arena.committed_side_data_mut(id).overflow_valid_across_recommits) {- self.arena.note_row_overflow_unmeasured(id);- }- }-/// A text-decoration change on a box repaints the text of every line root and inline/// below it that inherits the decoration.pub(crate) fn push_propagated_text_decoration_damage(&mut self, root: NodeSlotId) {@@ -544,10 +430,10 @@ wherepub(crate) fn begin_paintable_row_recommit(&mut self, id: NodeSlotId) {// The row's damage is deliberately kept; the commit diff pushes what actually changed.let filter = self.arena.committed_side_data_mut(id).fragment_ownership.take();- let side = self.arena.paintable_side_data_mut(id);- side.overflow_measured_this_commit = false;if filter.is_some() {- side.fragment_ownership_before_recommit = filter;+ self.arena+ .paintable_side_data_mut(id)+ .fragment_ownership_before_recommit = filter;}}}@@ -684,6 +570,19 @@ impl PaintableRowStore {slot.geometry_is_current = geometry_epoch.is_some();}+ pub(crate) fn replace_committed_fragment_link_keeping_its_geometry_epoch(+ &mut self,+ layout_slot_index: u32,+ layout_slot_generation: u8,+ link: fragment_tree::FragmentLink,+ ) {+ if let Some(mut slot) = RowMut::new(&mut self.committed_fragment_links, layout_slot_index as usize)+ && slot.layout_slot_generation == layout_slot_generation+ {+ slot.link = Some(link);+ }+ }+pub(crate) fn take_committed_fragment_link(&mut self,layout_slot_index: u32,@@ -731,71 +630,6 @@ impl LayoutNodeArena {}}- pub(crate) fn paintable_rows_with_absolute_rect_memo(- &self,- memo: crate::painting::record::recorder_state::AbsoluteRectMemo,- ) -> PaintableRowsRef<'_> {- PaintableRows {- arena: self,- absolute_rects: RefCell::new(memo),- }- }-- pub(crate) fn schedule_scrollable_overflow_recalculation(&mut self, node: NodeSlotId) {- // SAFETY: The caller supplies a live slot; data() generation-checks every slot the- // containing-block walk visits.- let node_kind = self.data(node).kind.get();- if crate::layout::node_facts::kind_is_box(node_kind) {- let mut containing_box = node;- loop {- if self.paintable_row_is_populated(containing_box) {- self.paintable_rows_mut().clear_cached_overflow_data(containing_box);- }- // SAFETY: As above.- let Some(next) = self.node_containing_block_if_live(containing_box) else {- break;- };- containing_box = next;- }- }-- if self.needs_full_scrollable_overflow_recalculation {- return;- }-- // NB: Cap the queue in case it's never consumed (e.g. forced style updates in a document- // that never updates layout).- const MAX_PENDING_SCROLLABLE_OVERFLOW_RECALCULATIONS: usize = 1024;- let row_is_populated = self.paintable_rows().paintable_row_is_populated(node);- let boxes = &mut self.boxes_needing_scrollable_overflow_recalculation;- if boxes.len() >= MAX_PENDING_SCROLLABLE_OVERFLOW_RECALCULATIONS {- boxes.clear();- self.needs_full_scrollable_overflow_recalculation = true;- return;- }-- if row_is_populated {- boxes.push(node);- }- }-- pub(crate) fn set_needs_full_scrollable_overflow_recalculation(&mut self) {- self.needs_full_scrollable_overflow_recalculation = true;- }-- /// Whether a scrollable overflow recalculation is scheduled, which the next rendering preparation settles.- pub(crate) fn scrollable_overflow_recalculation_is_scheduled(&self) -> bool {- self.needs_full_scrollable_overflow_recalculation- || !self.boxes_needing_scrollable_overflow_recalculation.is_empty()- }-- pub(crate) fn take_scrollable_overflow_recalculation_state(&mut self) -> (Vec<NodeSlotId>, bool) {- (- std::mem::take(&mut self.boxes_needing_scrollable_overflow_recalculation),- std::mem::replace(&mut self.needs_full_scrollable_overflow_recalculation, false),- )- }-/// The layout tree's shape and paint facts, the paintable rows and the columns read beside them/// as they are now. The live columns go on being written, copying only the/// chunks the publication shares.@@ -870,7 +704,6 @@ impl LayoutNodeArena {}pub(crate) fn populate_paintable_row(&mut self, layout_node: NodeSlotId) {- self.note_overflow_contained_box_added(layout_node);let overflow_style = self.node_style_if_live(layout_node).map(crate::painting::scrollable_overflow::OverflowStyle::new);@@ -903,7 +736,6 @@ impl LayoutNodeArena {store.visual_context_records.set(index, None);set_visual_context_node_handles(&mut store.visual_context_node_handles, index, None);drop_table(&mut store.stacking_context_entries, index);- self.scrollable_overflow.rows_to_measure.push(layout_node);self.notify_committed_box_changed(layout_node);}diff --git a/Libraries/LibWeb/Rust/src/painting/published_frame.rs b/Libraries/LibWeb/Rust/src/painting/published_frame.rsindex 0ca25cd33d1..3f2f52fbce1 100644--- a/Libraries/LibWeb/Rust/src/painting/published_frame.rs+++ b/Libraries/LibWeb/Rust/src/painting/published_frame.rs@@ -337,7 +337,6 @@ mod tests {let mut link = fragment_tree::FragmentLink::for_test(node);link.inset_top = CssPixels::from_integer(index as i64);arena.set_committed_fragment_link(node, link, None);- arena.committed_side_data_mut(node).overflow_valid_across_recommits = true;}}diff --git a/Libraries/LibWeb/Rust/src/painting/recording_slot.rs b/Libraries/LibWeb/Rust/src/painting/recording_slot.rsindex 0858815b09a..aa7157eb17b 100644--- a/Libraries/LibWeb/Rust/src/painting/recording_slot.rs+++ b/Libraries/LibWeb/Rust/src/painting/recording_slot.rs@@ -495,7 +495,7 @@ pub(crate) struct FrozenFrame {/// viewport has no box to paint.pub(crate) fn freeze_recording_frame(arena: &mut LayoutNodeArena, inputs: FrameInputs) -> Option<FrozenFrame> {// Recording reads overflow, and reading overflow never measures it.- arena.measure_scrollable_overflow();+ arena.settle_scrollable_overflow();if !arena.paintable_row_is_populated(inputs.viewport) || arena.stacking_context_entries(inputs.viewport).is_none() {return None;}diff --git a/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs b/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rsindex 5c5ae70b9a7..efda7644456 100644--- a/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs+++ b/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs@@ -4,46 +4,13 @@* SPDX-License-Identifier: BSD-2-Clause*/-use crate::css::css_enums::{flex_direction, flex_wrap, overflow, positioning, writing_mode};-use crate::css::css_pixels::{CssPixelPoint, CssPixelRect, CssPixels};-use crate::css::display::FfiDisplay;-use crate::fast_hash::FastMap as HashMap;+use crate::css::css_enums::{flex_direction, flex_wrap, writing_mode};+use crate::css::css_pixels::CssPixelPoint;use crate::layout::LayoutNodeArena;use crate::layout::node_data::{NodeFlag, NodeKind, NodeSlotId};-use crate::layout::node_facts::{self, NodeShape};-use crate::painting::paint_read::{GeometryRead, PaintRead, PaintRow};-use crate::painting::paintable_data::FfiOverflowData;-use crate::painting::paintable_rows::{PaintableRowsRead, PaintableRowsWrite};+use crate::layout::node_facts;+use crate::painting::paint_read::{GeometryRead, PaintRead};use crate::painting::visual_context::dirty::VisualContextBoxDirtyKind;-use crate::painting::visual_context::node_values;-use crate::painting::{paintable_geometry, style_queries, text_fragment};--/// Index boxes whose containing block differs from their layout parent. Direct children are-/// enumerated from the layout tree when measuring overflow.-pub(crate) fn refill_contained_boxes_index(- layout_arena: &impl PaintableRowsRead,- root: NodeSlotId,- non_child_boxes_by_containing_block: &mut HashMap<NodeSlotId, Vec<NodeSlotId>>,-) {- for contained_boxes in non_child_boxes_by_containing_block.values_mut() {- contained_boxes.clear();- }- layout_arena.for_each_node_in_layout_subtree_in_pre_order_with_pruning(root, |node| {- if let Some(row) = layout_arena.node(node)- && node_facts::kind_is_box(row.kind())- && layout_arena.paintable_row_is_populated(node)- && let Some(containing_block) = layout_arena.node_containing_block_if_live(node)- && row.parent() != containing_block- {- non_child_boxes_by_containing_block- .entry(containing_block)- .or_default()- .push(node);- }- true- });- non_child_boxes_by_containing_block.retain(|_, contained_boxes| !contained_boxes.is_empty());-}pub(crate) struct PhysicalOverflowDirections {pub(crate) horizontal_axis_is_positive: bool,@@ -126,791 +93,87 @@ pub(crate) fn physical_overflow_directions_of_style(}}-fn apply_css_transform_to_scrollable_overflow_rect(- layout_arena: &impl PaintableRowsRead,- box_paintable: NodeSlotId,- rect: CssPixelRect,- box_has_css_transform: bool,-) -> CssPixelRect {- if !box_has_css_transform {- return rect;- }- let Some((transform, _is_invertible)) = node_values::compute_transform(layout_arena, box_paintable, 1.0) else {- return rect;- };- super::scroll_snap::map_rect_through_css_transform(transform.matrix, transform.origin, rect)-}--fn padding_inflated_scrollable_overflow(- layout_arena: &impl PaintableRowsRead,- box_paintable: NodeSlotId,- in_flow_and_floated_content_bounds: CssPixelRect,-) -> CssPixelRect {- // NB: The box's own padding surrounds its in-flow and floated content. Whatever of it falls inside the padding box,- // or in the unreachable scrollable overflow region, adds nothing. This matches Blink.- let padding = paintable_geometry::committed_padding(layout_arena, box_paintable);- in_flow_and_floated_content_bounds.inflated(padding.top, padding.right, padding.bottom, padding.left)-}--#[derive(Clone, Copy)]-pub(crate) struct OverflowAssignment {- box_paintable: NodeSlotId,- /// None re-validates the row's still-current stored rect without rewriting it.- overflow_relative_to_padding_box: Option<FfiOverflowData>,-}--impl OverflowAssignment {- pub(crate) fn apply(self, layout_arena: &mut impl PaintableRowsWrite) {- let previously_measured = layout_arena- .paintable_side_data(self.box_paintable)- .overflow_measured_this_commit;- let (scroll_metadata_changed, scrollability_flipped) = {- let mut data = layout_arena.committed_side_data_mut(self.box_paintable);- let scroll_metadata_changed = self- .overflow_relative_to_padding_box- .is_some_and(|overflow| overflow != data.overflow_relative_to_padding_box);- let scrollability_flipped = self.overflow_relative_to_padding_box.is_some_and(|overflow| {- overflow.has_scrollable_overflow != data.overflow_relative_to_padding_box.has_scrollable_overflow- });- if let Some(overflow) = self.overflow_relative_to_padding_box {- data.overflow_relative_to_padding_box = overflow;- data.overflow_valid_across_recommits = true;- }- (scroll_metadata_changed, scrollability_flipped)- };- layout_arena- .paintable_side_data_mut(self.box_paintable)- .overflow_measured_this_commit = true;- use crate::painting::record::damage::PaintDamage;- if scroll_metadata_changed {- if previously_measured {- layout_arena.scrollable_overflow.geometry_changed = true;- }- layout_arena.push_paint_damage(- self.box_paintable,- PaintDamage::SCROLL_METADATA | PaintDamage::DRAW_OVERLAY | PaintDamage::HIT_OVERLAY,- );- // The root background covers the viewport united with the root's overflow.- if layout_arena.node_kind_if_live(self.box_paintable) == Some(NodeKind::Viewport) {- let root_background_source = layout_arena.paint_state().root_background_source;- if let Some(source) = root_background_source {- layout_arena.push_paint_damage(source.root_layout_node, PaintDamage::DRAW_BACKGROUND);- }- }- }- // A flip changes what rendering preparation answers even where it is the box's first measurement since it- // was laid out: the visual context of the box goes stale either way.- if scrollability_flipped {- layout_arena.scrollable_overflow.scrollability_changed = true;- layout_arena.push_paint_damage(self.box_paintable, PaintDamage::ALL_PRODUCERS);- layout_arena.push_paint_damage_to_paint_subtree(self.box_paintable, PaintDamage::SCROLL_METADATA);- layout_arena.note_visual_context_box_dirty(- self.box_paintable,- VisualContextBoxDirtyKind::ScrollableOverflowFlipped,- );- }- }-}--fn store_overflow_data(- assignments: &mut Vec<OverflowAssignment>,- box_paintable: NodeSlotId,- paintable_absolute_padding_box: CssPixelRect,- scrollable_overflow_rect: CssPixelRect,- has_scrollable_overflow: bool,-) {- let rect_relative_to_padding_box =- scrollable_overflow_rect.translated(-paintable_absolute_padding_box.x, -paintable_absolute_padding_box.y);- assignments.push(OverflowAssignment {- box_paintable,- overflow_relative_to_padding_box: Some(FfiOverflowData {- rect: rect_relative_to_padding_box.into(),- has_scrollable_overflow,- }),- });-}--// https://drafts.csswg.org/css-overflow-3/#scrollable-overflow-calculation-pub(crate) fn measure_box_scrollable_overflow(- layout_arena: &impl PaintableRowsRead,- non_child_boxes_by_containing_block: &HashMap<NodeSlotId, Vec<NodeSlotId>>,- box_paintable: NodeSlotId,-) -> Vec<OverflowAssignment> {- // Each box occurs under only one containing block, so this traversal visits each box at most once and can stage- // assignments append-only.- let mut assignments = Vec::new();- measure_scrollable_overflow_impl(- layout_arena,- non_child_boxes_by_containing_block,- box_paintable,- &mut assignments,- );- assignments-}--fn measure_scrollable_overflow_impl(- layout_arena: &impl PaintableRowsRead,- non_child_boxes_by_containing_block: &HashMap<NodeSlotId, Vec<NodeSlotId>>,- box_paintable: NodeSlotId,- assignments: &mut Vec<OverflowAssignment>,-) -> CssPixelRect {- let still_valid_overflow = {- let data = layout_arena.committed_side_data(box_paintable);- let measured_this_commit = layout_arena- .paintable_side_data(box_paintable)- .overflow_measured_this_commit;- if measured_this_commit && data.overflow_valid_across_recommits {- return CssPixelRect::from(data.overflow_relative_to_padding_box.rect).translated_by(- paintable_geometry::first_fragment_padding_box_rect(layout_arena, box_paintable).location(),- );- }- data.overflow_valid_across_recommits- .then_some(data.overflow_relative_to_padding_box)- };-- let box_node = box_paintable;- let paintable_absolute_padding_box =- paintable_geometry::first_fragment_padding_box_rect(layout_arena, box_paintable);- let paintable_absolute_content_box = paintable_geometry::absolute_rect(layout_arena, box_paintable);-- if let Some(still_valid_overflow) = still_valid_overflow {- let scrollable_overflow_rect =- CssPixelRect::from(still_valid_overflow.rect).translated_by(paintable_absolute_padding_box.location());- assignments.push(OverflowAssignment {- box_paintable,- overflow_relative_to_padding_box: None,- });- return scrollable_overflow_rect;- }-- let line_clamp_clip = (style_queries::has_line_clamp_point(layout_arena, box_node)- && !style_queries::clamped_content_is_scrollable_overflow(layout_arena, box_node))- .then(|| style_queries::line_clamp_clip_rect(layout_arena, box_node));- let clip_in_flow = |rect: CssPixelRect| line_clamp_clip.map_or(rect, |clip| rect.intersected(clip));-- // The scrollable overflow area of a box is the union of:-- // - Its own padding box.- let mut scrollable_overflow_rect = paintable_absolute_padding_box;- let mut in_flow_and_floated_content_bounds = paintable_absolute_content_box;-- // Replaced SVG viewports clip their content- if layout_arena.node_kind_if_live(box_node) == Some(NodeKind::SVGSVGBox) {- store_overflow_data(- assignments,- box_paintable,- paintable_absolute_padding_box,- scrollable_overflow_rect,- false,- );- return scrollable_overflow_rect;- }-- let overflow_directions = physical_overflow_directions(layout_arena, box_node);-- // - All line boxes it directly contains.- if crate::painting::node_painting::has_lines(layout_arena, box_paintable) {- let side_data = layout_arena.committed_side_data(box_paintable);- let positions = paintable_geometry::LineRootPositions::new(layout_arena, box_paintable);- let lines = side_data.lines();- let line_rects = lines- .iter()- .map(|line| CssPixelRect::from(line.rect).translated_by(positions.of_fragment(line.box_fragment)));- let elided_content_rects = side_data.elided_content_rects().iter().map(|&(line_index, rect)| {- CssPixelRect::from(rect).translated_by(positions.of_fragment(lines[line_index as usize].box_fragment))- });- let lines_after_clamp_point = side_data- .lines_after_clamp_point_rect()- .map(|rect| CssPixelRect::from(rect).translated_by(positions.of_fragment(0)));- for line_rect in line_rects.chain(elided_content_rects).chain(lines_after_clamp_point) {- scrollable_overflow_rect.unite(line_rect);- in_flow_and_floated_content_bounds.unite_horizontally(line_rect);- in_flow_and_floated_content_bounds.unite_vertically(line_rect);- }- for fragment in side_data.fragments() {- // NB: The box holding the line boxes is the containing block of each of their fragments, and their- // offsets are relative to it, also for a fragment whose node left the tree since it was laid out.- debug_assert!(- text_fragment::containing_block_paintable(layout_arena, fragment)- .is_none_or(|block| block == box_paintable)- );- let mut fragment_rect = text_fragment::rect_in_containing_block(fragment)- .translated_by(positions.of_line(side_data.lines(), fragment.line_index as usize));- if layout_arena.node_is_in_focused_text_control(fragment.layout_node)- && let Some(style_source_style) =- layout_arena.node_style_if_live(text_fragment::style_source(layout_arena, fragment))- {- // NB: Reserve one pixel of reachable inline-axis overflow for an end-of-line caret. This keeps the- // caret at its insertion position while allowing a text control to scroll the painted bar fully- // into view, matching the caret overflow accounted for by other engines.- let one = CssPixels::from_integer(1);- if style_source_style.writing_mode() == writing_mode::HORIZONTAL_TB {- if style_source_style.inline_axis_is_reverse() {- fragment_rect.set_left(fragment_rect.left() - one);- } else {- fragment_rect.set_right(fragment_rect.right() + one);- }- } else if style_source_style.inline_axis_is_reverse() {- fragment_rect.set_top(fragment_rect.top() - one);- } else {- fragment_rect.set_bottom(fragment_rect.bottom() + one);- }- }- fragment_rect = clip_in_flow(fragment_rect);- scrollable_overflow_rect.unite(fragment_rect);- in_flow_and_floated_content_bounds.unite(fragment_rect);- }- }-- // https://drafts.csswg.org/css-grid-2/#overflow- // The grid is also included in a grid container's scrollable overflow region.- // INTEROP: Blink only does this when the grid container is a scroll container, so the grid does not reach the- // scrollable overflow of its ancestors.- if style_queries::is_scroll_container(layout_arena, box_node)- && let Some(tracks) = paintable_geometry::committed_used_grid_tracks(layout_arena, box_paintable)- {- let grid_area = tracks- .grid_area- .translated_by(paintable_absolute_content_box.location());- // NB: A grid with tracks in one axis only, e.g. columns but no rows, still reaches the overflow in that axis.- if grid_area.width > CssPixels::default() {- scrollable_overflow_rect.unite_horizontally(grid_area);- in_flow_and_floated_content_bounds.unite_horizontally(grid_area);- }- if grid_area.height > CssPixels::default() {- scrollable_overflow_rect.unite_vertically(grid_area);- in_flow_and_floated_content_bounds.unite_vertically(grid_area);- }- }-- // - The border boxes of all boxes for which it is the containing block and whose border boxes are positioned not- // wholly in the negative scrollable overflow region,- // FIXME: accounting for 3D transforms by projecting each box onto the plane of the element that establishes- // its 3D rendering context. [CSS3-TRANSFORMS]- // OPTIMIZATION: The layout tree already indexes direct children. Retain only boxes whose- // containing block differs from their parent in the supplemental index.- let box_has_line_clamp_point = style_queries::has_line_clamp_point(layout_arena, box_node);- let container_inline_axis_is_horizontal = layout_arena- .node_style_if_live(box_node)- .is_none_or(|style| style.writing_mode() == writing_mode::HORIZONTAL_TB);- let direct_children = layout_arena.children(box_node);- let other_contained_boxes = non_child_boxes_by_containing_block- .get(&box_node)- .into_iter()- .flatten()- .copied();- for child_node in direct_children.chain(other_contained_boxes) {- let Some(child_row) = layout_arena.node(child_node) else {- continue;- };- if !node_facts::kind_is_box(child_row.kind())- || !layout_arena.paintable_row_is_populated(child_node)- || layout_arena.node_containing_block_if_live(child_node) != Some(box_node)- {- continue;- }-- let child_style = child_row.style();- let child_position = child_style.map_or(positioning::STATIC, |style| style.position());- let child_is_absolutely_positioned = matches!(child_position, positioning::ABSOLUTE | positioning::FIXED);-- // https://drafts.csswg.org/css-position/#fixed-positioning-containing-block- // [..] As a result, parts of fixed-positioned boxes that extend outside the layout viewport/page area- // cannot be scrolled to and will not print.- // FIXME: Properly establish the fixed positioning containing block for `position: fixed`- if child_position == positioning::FIXED {- continue;- }-- let child_has_css_transform =- child_style.is_some_and(|style| style_queries::has_css_transform(layout_arena, child_node, style));- let child_flags = child_row.flags();- let child_is_flex_or_grid_item = child_flags & (NodeFlag::IsFlexItem as u32 | NodeFlag::IsGridItem as u32) != 0;- let child_is_floating = !child_is_flex_or_grid_item && child_style.is_some_and(|style| style.is_floating());- let child_display = child_style.map_or_else(FfiDisplay::block, |style| style.display());-- {- let child_data = layout_arena.committed_side_data(child_node);- // NB: A line before a line clamp point can be cut short of the atomic inlines on it, so it does not- // contribute their boxes.- if child_position == positioning::STATIC- && child_display.is_inline_outside()- && !child_is_floating- && !child_has_css_transform- && !box_has_line_clamp_point- && child_data.overflow_valid_across_recommits- {- let border = crate::painting::paintable_geometry::committed_border(layout_arena, child_node);- let zero = CssPixels::from_raw(0);- let has_border =- border.top != zero || border.right != zero || border.bottom != zero || border.left != zero;- if !has_border {- let padding = crate::painting::paintable_geometry::committed_padding(layout_arena, child_node);- let content_size =- crate::painting::paintable_geometry::committed_content_size(layout_arena, child_node);- let content_box_relative_to_padding_box =- CssPixelRect::new(padding.left, padding.top, content_size.width, content_size.height);- // The committed line fragment already contributes this content box. A box with no border whose- // cached overflow fits inside the content box cannot expand its containing block's overflow.- if content_box_relative_to_padding_box- .contains_rect(child_data.overflow_relative_to_padding_box.rect.into())- {- continue;- }- }- }- }- if style_queries::is_excluded_from_scrollable_overflow_by_line_clamp(layout_arena, child_node) {- continue;- }-- let untransformed_child_border_box = paintable_geometry::absolute_border_box_rect(layout_arena, child_node);- // NB: Collect normal-flow bounds before filtering visible overflow, which relative positioning can move- // wholly before the scroll origin.- let child_is_in_flow = !(child_is_floating || child_is_absolutely_positioned);- if child_is_in_flow || child_is_floating {- let mut normal_flow_border_box = untransformed_child_border_box;- if child_position == positioning::RELATIVE {- let inset = paintable_geometry::committed_inset(layout_arena, child_node);- normal_flow_border_box = normal_flow_border_box.translated(-inset.left, -inset.top);- }- // INTEROP: The edges of in-flow and floated content, after which the container's end padding comes,- // are those of the margin boxes of block-level boxes, flex items and grid items, as in Blink:- // with their computed margins, auto counting as zero, and where they are laid out before- // relative positioning. Toward the end of the scrollable overflow a negative margin counts,- // but no further than the size of the box; toward its start, it does not.- let child_is_block_level = child_is_flex_or_grid_item || !child_display.is_inline_outside();- let content_box = match child_style {- Some(style) if child_is_block_level || child_row.is_atomic_inline() => {- let border_box = normal_flow_border_box;- let margin = &style.surround().margin;- let basis = if container_inline_axis_is_horizontal {- paintable_absolute_content_box.width- } else {- paintable_absolute_content_box.height- };- let zero = CssPixels::from_raw(0);- // NB: An atomic inline's inline margins contribute even when its line box has zero area.- // Its block-axis margins are already accounted for by the line box.- let (left, right) = if child_is_block_level || container_inline_axis_is_horizontal {- (margin.left.to_px(basis), margin.right.to_px(basis))- } else {- (zero, zero)- };- let (top, bottom) = if child_is_block_level || !container_inline_axis_is_horizontal {- (margin.top.to_px(basis), margin.bottom.to_px(basis))- } else {- (zero, zero)- };- let (left, right) = if overflow_directions.horizontal_axis_is_positive {- (left.max(zero), right.max(-border_box.width))- } else {- (left.max(-border_box.width), right.max(zero))- };- let (top, bottom) = if overflow_directions.vertical_axis_is_positive {- (top.max(zero), bottom.max(-border_box.height))- } else {- (top.max(-border_box.height), bottom.max(zero))- };- border_box.inflated(top, right, bottom, left)- }- _ => normal_flow_border_box,- };- // NB: Empty boxes still contribute their extents to the padding alignment bounds.- in_flow_and_floated_content_bounds.unite_horizontally(content_box);- in_flow_and_floated_content_bounds.unite_vertically(content_box);- }- let mut child_border_box = apply_css_transform_to_scrollable_overflow_rect(- layout_arena,- child_node,- untransformed_child_border_box,- child_has_css_transform,- );- if !child_is_absolutely_positioned {- child_border_box = clip_in_flow(child_border_box);- }- // INTEROP: Chrome and Firefox retain reachable overflow in each axis independently, even when- // the border box lies wholly in the other axis's unreachable region.- let wholly_in_unreachable_horizontal_axis = if overflow_directions.horizontal_axis_is_positive {- child_border_box.right() < paintable_absolute_padding_box.x- } else {- child_border_box.x > paintable_absolute_padding_box.right()- };- let wholly_in_unreachable_vertical_axis = if overflow_directions.vertical_axis_is_positive {- child_border_box.bottom() < paintable_absolute_padding_box.y- } else {- child_border_box.y > paintable_absolute_padding_box.bottom()- };- if wholly_in_unreachable_horizontal_axis && wholly_in_unreachable_vertical_axis {- continue;- }-- // Border boxes with zero area do not affect the scrollable overflow area.- if !child_border_box.is_empty() {- if !wholly_in_unreachable_horizontal_axis {- scrollable_overflow_rect.unite_horizontally(child_border_box);- }- if !wholly_in_unreachable_vertical_axis {- scrollable_overflow_rect.unite_vertically(child_border_box);- }- }-- // - The scrollable overflow areas of all of the above boxes (including zero-area boxes and accounting for- // transforms as described above), provided they themselves have overflow: visible (i.e. do not themselves- // trap the overflow) and that scrollable overflow is not already clipped (e.g. by the clip property or the- // contain property).- // Scrollable overflow is already clipped by the contain property.- if child_style.is_some_and(|style| {- style_queries::has_layout_containment(layout_arena, child_node, style)- || style_queries::has_paint_containment(layout_arena, child_node, style)- }) {- continue;- }-- let child_overflow_x = child_style.map_or(overflow::VISIBLE, |style| style.overflow_x());- let child_overflow_y = child_style.map_or(overflow::VISIBLE, |style| style.overflow_y());- if child_overflow_x == overflow::VISIBLE || child_overflow_y == overflow::VISIBLE {- let untransformed_child_scrollable_overflow = measure_scrollable_overflow_impl(- layout_arena,- non_child_boxes_by_containing_block,- child_node,- assignments,- );- let mut child_scrollable_overflow = apply_css_transform_to_scrollable_overflow_rect(- layout_arena,- child_node,- untransformed_child_scrollable_overflow,- child_has_css_transform,- );- if !child_is_absolutely_positioned {- child_scrollable_overflow = clip_in_flow(child_scrollable_overflow);- }- if !child_scrollable_overflow.is_empty() {- if child_overflow_x == overflow::VISIBLE && !wholly_in_unreachable_horizontal_axis {- scrollable_overflow_rect.unite_horizontally(child_scrollable_overflow);- }- if child_overflow_y == overflow::VISIBLE && !wholly_in_unreachable_vertical_axis {- scrollable_overflow_rect.unite_vertically(child_scrollable_overflow);- }- }- }- }-- // FIXME: - The margin areas of grid item and flex item boxes for which the box establishes a containing block.-- // - Additional padding added to the scrollable overflow rectangle as necessary to enable scroll positions that- // satisfy the requirements of both place-content: start and place-content: end alignment.- //- // NOTE: This padding represents, within the scrollable overflow rectangle, the box’s own padding so that when its- // content is scrolled to its end, there is padding between the edge of its in-flow (or floated) content and- // the border edge of the box. It typically ends up being exactly the same size as the box's own padding,- // except in a few cases--such as when an out-of-flow positioned element, or the visible overflow of a- // descendent, has already increased the size of the scrollable overflow rectangle outside the conceptual- // “content edge” of the scroll container’s content.- let box_is_scroll_container = style_queries::is_scroll_container(layout_arena, box_node);- in_flow_and_floated_content_bounds = clip_in_flow(in_flow_and_floated_content_bounds);- if box_is_scroll_container {- scrollable_overflow_rect.unite(padding_inflated_scrollable_overflow(- layout_arena,- box_paintable,- in_flow_and_floated_content_bounds,- ));- }-- let mut has_scrollable_overflow =- box_is_scroll_container && !paintable_absolute_padding_box.contains_rect(scrollable_overflow_rect);-- // Additionally, due to Web-compatibility constraints (caused by authors exploiting legacy bugs to surreptitiously- // hide content from visual readers but not search engines and/or speech output), UAs must clip any content in the- // unreachable scrollable overflow region.- //- // https://drafts.csswg.org/css-overflow-3/#unreachable-scrollable-overflow-region- // Unless otherwise adjusted (e.g. by content alignment [css-align-3]), the area beyond the scroll origin in either- // axis is considered the unreachable scrollable overflow region: content rendered here is not accessible to the- // reader, see § 2.2 Scrollable Overflow.- let left = if overflow_directions.horizontal_axis_is_positive {- scrollable_overflow_rect.x.max(paintable_absolute_padding_box.x)- } else {- scrollable_overflow_rect.x- };- let top = if overflow_directions.vertical_axis_is_positive {- scrollable_overflow_rect.y.max(paintable_absolute_padding_box.y)- } else {- scrollable_overflow_rect.y- };- let right = if overflow_directions.horizontal_axis_is_positive {- scrollable_overflow_rect.right()- } else {- scrollable_overflow_rect- .right()- .min(paintable_absolute_padding_box.right())- };- let bottom = if overflow_directions.vertical_axis_is_positive {- scrollable_overflow_rect.bottom()- } else {- scrollable_overflow_rect- .bottom()- .min(paintable_absolute_padding_box.bottom())- };- if left != scrollable_overflow_rect.x- || top != scrollable_overflow_rect.y- || right != scrollable_overflow_rect.right()- || bottom != scrollable_overflow_rect.bottom()- {- let zero = CssPixels::from_raw(0);- scrollable_overflow_rect = CssPixelRect::new(left, top, (right - left).max(zero), (bottom - top).max(zero));- has_scrollable_overflow =- !paintable_absolute_padding_box.contains_rect(scrollable_overflow_rect) && box_is_scroll_container;- }-- store_overflow_data(- assignments,- box_paintable,- paintable_absolute_padding_box,- scrollable_overflow_rect,- has_scrollable_overflow,- );-- scrollable_overflow_rect-}--/// Geometry caches and their pending effects belong to the arena, independently of the-/// visual-context state temporarily borrowed or taken by painting traversals.#[derive(Clone, Default)]pub(crate) struct ScrollableOverflowState {- pub(crate) viewport: Option<NodeSlotId>,- pub(crate) full_layout_commit: bool,- pub(crate) contained_boxes_dirty: bool,- pub(crate) non_child_boxes: HashMap<NodeSlotId, Vec<NodeSlotId>>,+ pub(crate) recalculation_requests: Vec<NodeSlotId>,+ pub(crate) scroll_offset_clamp_candidates: Vec<NodeSlotId>,pub(crate) geometry_changed: bool,pub(crate) scrollability_changed: bool,pub(crate) recalculations: u64,- pub(crate) contained_box_index_refills: u64,- /// Rows whose overflow a read could find unmeasured: new rows, and rows whose measurement was- /// invalidated. Reading overflow never measures it, so the pass measures these first.- pub(crate) rows_to_measure: Vec<NodeSlotId>,}impl ScrollableOverflowState {- /// Whether a measurement changed what rendering preparation answers, which no preparation settled since.- pub(crate) fn measurement_awaits_preparation(&self) -> bool {+ pub(crate) fn change_awaits_preparation(&self) -> bool {self.geometry_changed || self.scrollability_changed}}impl LayoutNodeArena {- // NB: An empty index stays valid through direct-child edits. New or reattached boxes- // only require a rebuild when their containing block differs from their parent.- pub(crate) fn note_overflow_contained_box_added(&mut self, node: NodeSlotId) {- if self.scrollable_overflow.contained_boxes_dirty {- return;+ pub(crate) fn note_scrollable_overflow_change(+ &mut self,+ node: NodeSlotId,+ had_scrollable_overflow: bool,+ has_scrollable_overflow: bool,+ changed_outside_layout: bool,+ ) {+ use crate::painting::record::damage::PaintDamage;+ if changed_outside_layout {+ self.scrollable_overflow.geometry_changed = true;}- let data = self.data(node);- if node_facts::kind_is_box(data.kind.get())- && self- .node_containing_block_if_live(node)- .is_some_and(|containing_block| containing_block != data.parent.get())+ self.push_paint_damage(+ node,+ PaintDamage::SCROLL_METADATA | PaintDamage::DRAW_OVERLAY | PaintDamage::HIT_OVERLAY,+ );+ // The root background covers the viewport united with the root's overflow.+ if self.node_kind_if_live(node) == Some(NodeKind::Viewport)+ && let Some(source) = self.paint_state().root_background_source{- self.scrollable_overflow.contained_boxes_dirty = true;+ self.push_paint_damage(source.root_layout_node, PaintDamage::DRAW_BACKGROUND);}- }-- /// 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(&mut self, root: NodeSlotId) {- if self.scrollable_overflow.contained_boxes_dirty || self.scrollable_overflow.non_child_boxes.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 = true;+ if had_scrollable_overflow != has_scrollable_overflow {+ self.scrollable_overflow.scrollability_changed = true;+ self.push_paint_damage(node, PaintDamage::ALL_PRODUCERS);+ self.paintable_rows_mut()+ .push_paint_damage_to_paint_subtree(node, PaintDamage::SCROLL_METADATA);+ self.note_visual_context_box_dirty(node, VisualContextBoxDirtyKind::ScrollableOverflowFlipped);}}- pub(crate) fn ensure_overflow_contained_boxes(&mut self) {- if !std::mem::replace(&mut self.scrollable_overflow.contained_boxes_dirty, false) {- return;+ pub(crate) fn note_scroll_offset_may_leave_range(&mut self, node: NodeSlotId) {+ if box_holds_scroll_state(self, node) {+ self.scrollable_overflow.scroll_offset_clamp_candidates.push(node);}- let mut index = std::mem::take(&mut self.scrollable_overflow.non_child_boxes);- if let Some(viewport) = self.scrollable_overflow.viewport {- self.scrollable_overflow.contained_box_index_refills += 1;- refill_contained_boxes_index(&self.paintable_rows(), viewport, &mut index);- } else {- index.clear();- }- self.scrollable_overflow.non_child_boxes = index;- }-- pub(crate) fn did_commit_full_layout(&mut self, viewport: NodeSlotId) {- if self.scrollable_overflow.viewport.replace(viewport) != Some(viewport) {- self.scrollable_overflow.contained_boxes_dirty = true;- self.set_needs_full_scrollable_overflow_recalculation();- }- self.scrollable_overflow.full_layout_commit = true;- // The full pass covered every subtree the last build rebuilt.- self.clear_pending_rebuilt_subtree_roots();- }-- /// Whether no row's overflow is waiting to be measured, which reading overflow then finds as- /// it is.- pub(crate) fn scrollable_overflow_is_measured(&self) -> bool {- self.scrollable_overflow.rows_to_measure.is_empty()- || !self- .scrollable_overflow- .viewport- .is_some_and(|viewport| self.paintable_row_is_populated(viewport))}- /// Measures every row whose overflow a read could find unmeasured, so that reading overflow- /// never measures it. Rendering preparation, hit testing, the recording and every query that- /// reads overflow run this first; it never clamps a stored scroll offset.- pub(crate) fn measure_scrollable_overflow(&mut self) {- if self.scrollable_overflow_is_measured() {- return;- }- let rows = std::mem::take(&mut self.scrollable_overflow.rows_to_measure);- let mut memo = Default::default();- for slot in rows {- if self.slot_is_live(slot) {- self.ensure_scrollable_overflow(slot, &mut memo);- }- }+ pub(crate) fn scrollable_overflow_is_settled(&self) -> bool {+ self.scrollable_overflow.recalculation_requests.is_empty()}- pub(crate) fn note_row_overflow_unmeasured(&mut self, slot: NodeSlotId) {- self.scrollable_overflow.rows_to_measure.push(slot);- }-- fn ensure_scrollable_overflow(- &mut self,- slot: NodeSlotId,- memo: &mut crate::painting::record::recorder_state::AbsoluteRectMemo,- ) {- if !self.paintable_row_is_populated(slot)- || !self- .scrollable_overflow- .viewport- .is_some_and(|viewport| self.paintable_row_is_populated(viewport))- {- return;- }- if self.committed_side_data(slot).overflow_valid_across_recommits {- self.paintable_side_data_mut(slot).overflow_measured_this_commit = true;- return;- }- // Ordinary inline fragments have paint geometry but no independently measured scrolling area.- // Rows holding scroll state still need measurement, as they do during rendering preparation.- if !self.node_kind_if_live(slot).is_some_and(node_facts::kind_is_box) && !box_holds_scroll_state(self, slot) {- return;- }- self.ensure_overflow_contained_boxes();- let rows = self.paintable_rows_with_absolute_rect_memo(std::mem::take(memo));- let assignments = measure_box_scrollable_overflow(&rows, &self.scrollable_overflow.non_child_boxes, slot);- *memo = rows.into_absolute_rect_memo();- let mut rows = self.paintable_rows_mut();- for assignment in assignments {- assignment.apply(&mut rows);- }+ pub(crate) fn settle_scrollable_overflow(&mut self) {+ self.recalculate_requested_fragment_overflow();}}-/// Whether a box is measured eagerly after a full commit rather than only when an ancestor's-/// measurement reaches it: a scroll container, or a box whose element or pseudo-element stores a-/// scroll offset that the new overflow may have to clamp. The arena sets `NodeFlag::HasScrollOffset`-/// whenever the offset a box holds changes and whenever a box becomes an element's or-/// pseudo-element's box, so the answer is one style query and one flag read.+/// Whether a box is a scroll container, or a box whose element or pseudo-element stores a scroll offset that new+/// overflow may have to clamp. The arena sets `NodeFlag::HasScrollOffset` whenever the offset a box holds changes and+/// whenever a box becomes an element's or pseudo-element's box, so the answer is one style query and one flag read.fn box_holds_scroll_state(arena: &LayoutNodeArena, slot: NodeSlotId) -> bool {crate::painting::style_queries::is_scroll_container(arena, slot)- || arena.node_flags_if_live(slot) & crate::layout::node_data::NodeFlag::HasScrollOffset as u32 != 0+ || arena.node_flags_if_live(slot) & NodeFlag::HasScrollOffset as u32 != 0}-/// Settles the scheduled recalculation, then measures every other row left unmeasured. Answers the scroll offsets the-/// new overflow moved out of range, each clamped into it, for the document to store.+/// Settles the requested overflow recalculation. Answers the scroll offsets new overflow moved out of range, each+/// clamped into it, for the document to store.#[must_use = "the document stores the clamped scroll offsets"]pub(crate) fn update_scrollable_overflow(arena: &mut LayoutNodeArena) -> Vec<(NodeSlotId, CssPixelPoint)> {- let clamped = settle_scheduled_scrollable_overflow(arena);- arena.measure_scrollable_overflow();- clamped-}--fn settle_scheduled_scrollable_overflow(arena: &mut LayoutNodeArena) -> Vec<(NodeSlotId, CssPixelPoint)> {+ arena.settle_scrollable_overflow();let mut clamped = Vec::new();- let Some(viewport) = arena.scrollable_overflow.viewport else {- return clamped;- };- let full_layout_commit = std::mem::replace(&mut arena.scrollable_overflow.full_layout_commit, false);- let (pending_boxes, needs_full_recalculation) = arena.take_scrollable_overflow_recalculation_state();- if (pending_boxes.is_empty() && !needs_full_recalculation) || !arena.paintable_row_is_populated(viewport) {- return clamped;- }- arena.scrollable_overflow.recalculations += 1;- arena.ensure_overflow_contained_boxes();-- // Settle scroll containers and stored offsets first. Keep already measured ancestors in the- // set so changes invalidate their paint caches even when a cached recording would otherwise- // skip the subtree.- let mut roots = Vec::new();- let mut seen = crate::fast_hash::FastSet::default();- let mut add = |slot: NodeSlotId| {- if arena.paintable_row_is_populated(slot) && seen.insert(slot) {- if !full_layout_commit || slot == viewport || box_holds_scroll_state(arena, slot) {- roots.push(slot);- }- true- } else {- false- }- };- if needs_full_recalculation {- arena.for_each_node_in_layout_subtree_in_pre_order(viewport, |slot| {- if arena.paintable_row_is_populated(slot)- && (slot == viewport- || box_holds_scroll_state(arena, slot)- || (!full_layout_commit && arena.paintable_side_data(slot).overflow_measured_this_commit))- {- add(slot);- }- });- } else {- for slot in pending_boxes {- if !arena.slot_is_live(slot) || !arena.paintable_row_is_populated(slot) {- continue;- }- // NB: A full commit queues changed descendants individually, including scroll- // containers behind clipping boundaries. Partial commits also queue their root.- if !full_layout_commit && !arena.paintable_side_data(slot).overflow_measured_this_commit {- // A subtree commit can replace scroll containers whose overflow does not- // propagate through the relayout root (for example, overflow: hidden).- arena.for_each_node_in_layout_subtree_in_pre_order(slot, |child| {- if arena.paintable_row_is_populated(child) && box_holds_scroll_state(arena, child) {- add(child);- }- });- }- add(slot);- let mut block = arena.node_containing_block_if_live(slot);- while let Some(slot) = block {- if !add(slot) {- break;- }- block = arena.node_containing_block_if_live(slot);- }+ let candidates = std::mem::take(&mut arena.scrollable_overflow.scroll_offset_clamp_candidates);+ let mut met = crate::fast_hash::FastSet::default();+ for slot in candidates {+ if !met.insert(slot) || !arena.slot_is_live(slot) || !arena.paintable_row_is_populated(slot) {+ continue;}- }- // The new overflow can leave a stored scroll offset outside the range the box now allows. The- // pass has the measurement, so it decides the offset itself, and tells the document what to- // store once every root is measured rather than handing each box back to be clamped.- let mut memo = Default::default();- for slot in roots {- arena.ensure_scrollable_overflow(slot, &mut memo);let offset = arena.row_scroll_offset(slot);if offset == CssPixelPoint::default() {continue;@@ -931,10 +194,22 @@ fn settle_scheduled_scrollable_overflow(arena: &mut LayoutNodeArena) -> Vec<(Nodclamped}-/// Retain the last published transform group so a style change can invalidate overflow+/// Retain the last published transform group, overflow values and overflow directions so a style change can invalidate overflow/// even after the DOM or an animation has released its previous style record. The snapshot owns/// its reference to the group, as a style record does, and shares the immutable payload.-pub(crate) struct OverflowStyle(crate::css::host_shared::HostShared<crate::css::computed_value_types::TransformValues>);+pub(crate) struct OverflowStyle {+ transform: crate::css::host_shared::HostShared<crate::css::computed_value_types::TransformValues>,+ overflow: (u8, u8),+ overflow_directions_are_positive: (bool, bool),+}++fn overflow_directions_are_positive(style: crate::css::computed_value_views::ComputedValuesView<'_>) -> (bool, bool) {+ let directions = physical_overflow_directions_of_style(style);+ (+ directions.horizontal_axis_is_positive,+ directions.vertical_axis_is_positive,+ )+}impl OverflowStyle {pub(crate) fn new(style: crate::css::computed_value_views::ComputedValuesView<'_>) -> Self {@@ -943,16 +218,20 @@ impl OverflowStyle {crate::css::computed_value_types::STYLE_GROUP_INDEX_TRANSFORM,values.cast(),);- Self(crate::css::host_shared::HostShared::new(values))+ Self {+ transform: crate::css::host_shared::HostShared::new(values),+ overflow: (style.overflow_x(), style.overflow_y()),+ overflow_directions_are_positive: overflow_directions_are_positive(style),+ }}- fn matches(&self, style: crate::css::computed_value_views::ComputedValuesView<'_>) -> bool {+ fn transform_matches(&self, style: crate::css::computed_value_views::ComputedValuesView<'_>) -> bool {let new = style.transform();- if std::ptr::eq(self.0.as_ptr().cast(), new) {+ if std::ptr::eq(self.transform.as_ptr().cast(), new) {return true;}// SAFETY: This snapshot retains the immutable group until it is replaced or dropped.- let old = unsafe { self.0.deref() };+ let old = unsafe { self.transform.deref() };old.transformations == new.transformations&& old.translate == new.translate&& old.rotate == new.rotate@@ -961,6 +240,17 @@ impl OverflowStyle {&& old.transform_origin_x == new.transform_origin_x&& old.transform_origin_y == new.transform_origin_y&& old.transform_origin_z == new.transform_origin_z+ && old.has_offset_path == new.has_offset_path+ && old.offset_path == new.offset_path+ && old.offset_distance == new.offset_distance+ && old.offset_position == new.offset_position+ && old.offset_anchor == new.offset_anchor+ && old.offset_rotate == new.offset_rotate+ }++ fn overflow_matches(&self, style: crate::css::computed_value_views::ComputedValuesView<'_>) -> bool {+ self.overflow == (style.overflow_x(), style.overflow_y())+ && self.overflow_directions_are_positive == overflow_directions_are_positive(style)}}@@ -969,9 +259,13 @@ impl Clone for OverflowStyle {fn clone(&self) -> Self {crate::css::computed_values::retain_group_payload(crate::css::computed_value_types::STYLE_GROUP_INDEX_TRANSFORM,- self.0.as_ptr().cast(),+ self.transform.as_ptr().cast(),);- Self(self.0)+ Self {+ transform: self.transform,+ overflow: self.overflow,+ overflow_directions_are_positive: self.overflow_directions_are_positive,+ }}}@@ -979,7 +273,7 @@ impl Drop for OverflowStyle {fn drop(&mut self) {crate::css::computed_values::release_group_payload(crate::css::computed_value_types::STYLE_GROUP_INDEX_TRANSFORM,- self.0.as_ptr().cast(),+ self.transform.as_ptr().cast(),);}}@@ -992,111 +286,30 @@ impl LayoutNodeArena {let Some(style) = self.node_style_if_live(slot) else {return;};- let changed = self+ let (transform_changed, overflow_changed) = self.paintable_side_data(slot).overflow_style.as_ref()- .is_some_and(|previous| !previous.matches(style));+ .map_or((false, false), |previous| {+ (!previous.transform_matches(style), !previous.overflow_matches(style))+ });let overflow_style = OverflowStyle::new(style);self.paintable_side_data_mut(slot).overflow_style = Some(overflow_style);- if !changed {+ if !transform_changed && !overflow_changed {return;}if self.node_kind_if_live(slot).is_some_and(node_facts::kind_is_svg_box) {// SVG consumes transforms during layout, unlike CSS box overflow measurement.- self.set_needs_layout_update(slot, true);- } else {- self.schedule_scrollable_overflow_recalculation(slot);- }- }-}--#[cfg(test)]-mod tests {- use super::*;- use crate::css::computed_values::{- BoxValues, ComputedLengthPercentageOrAuto, ComputedStyleValueHandle, GroupPayloadRef, InheritedBoxValues,- SurroundValues, clone_group_payload, release_group_payload,- };- use crate::css::table_group_builder::group_index;- use crate::layout::fragment_tree::FragmentLink;- use crate::layout::node_data::{FfiStylePayloads, StylePayloadsRef};-- #[test]- fn overflow_percentage_margins_use_the_containing_blocks_inline_size() {- for (mode, expected_bottom) in [- (writing_mode::HORIZONTAL_TB, 260),- (writing_mode::VERTICAL_LR, 310),- (writing_mode::VERTICAL_RL, 310),- ] {- let mut arena = LayoutNodeArena::new();- let mut container_style = FfiStylePayloads {- groups: std::array::from_fn(|index| GroupPayloadRef::default_payload(index).as_ptr()),- };- let mut child_style = container_style;- // SAFETY: These are private clones of the corresponding default payloads.- let (box_payload, inherited, surround) = unsafe {- (- clone_group_payload(group_index::BOX, container_style.groups[group_index::BOX]),- clone_group_payload(- group_index::INHERITED_BOX,- container_style.groups[group_index::INHERITED_BOX],- ),- clone_group_payload(group_index::SURROUND, child_style.groups[group_index::SURROUND]),- )- };- // SAFETY: Each private clone has its group's payload layout and no readers yet.- unsafe {- (*box_payload.cast::<BoxValues>()).display = FfiDisplay::block();- (*box_payload.cast::<BoxValues>()).overflow_x = overflow::AUTO;- (*box_payload.cast::<BoxValues>()).overflow_y = overflow::AUTO;- (*inherited.cast::<InheritedBoxValues>()).writing_mode = mode;- (*surround.cast::<SurroundValues>()).margin.bottom = ComputedLengthPercentageOrAuto {- is_auto: false,- value: ComputedStyleValueHandle::percentage(50.0),- };- }- container_style.groups[group_index::BOX] = box_payload;- container_style.groups[group_index::INHERITED_BOX] = inherited;- child_style.groups[group_index::BOX] = box_payload;- child_style.groups[group_index::INHERITED_BOX] = inherited;- child_style.groups[group_index::SURROUND] = surround;- let container = arena.allocate_for_test().slot;- let child = arena.allocate_for_test().slot;- for (node, style) in [(container, &container_style), (child, &child_style)] {- arena.write_shape(node).set_kind(NodeKind::BlockContainer);- arena.set_node_style(node, 0, StylePayloadsRef::new(style));- arena.populate_paintable_row(node);+ if transform_changed {+ self.set_needs_layout_update(slot, true);}- arena.insert_child(container, child, NodeSlotId::INVALID);- let mut container_link = FragmentLink::for_test(container);- let fragment = std::sync::Arc::get_mut(&mut container_link.fragment).unwrap();- fragment.content_inline_size = CssPixels::from_integer(100);- fragment.content_block_size = CssPixels::from_integer(200);- fragment.padding_bottom = CssPixels::from_integer(10);- arena.set_committed_fragment_link(container, container_link, None);- let mut child_link = FragmentLink::for_test(child);- let fragment = std::sync::Arc::get_mut(&mut child_link.fragment).unwrap();- fragment.content_inline_size = CssPixels::from_integer(20);- fragment.content_block_size = CssPixels::from_integer(20);- child_link.committed_offset.y = CssPixels::from_integer(180).into();- child_link.containing_block = container;- arena.set_committed_fragment_link(child, child_link, None);- let rows = arena.paintable_rows();- let mut assignments = Vec::new();- let actual = measure_scrollable_overflow_impl(&rows, &HashMap::default(), container, &mut assignments);- assert_eq!(- actual.bottom(),- CssPixels::from_integer(expected_bottom),- "writing mode {mode}"- );- drop(rows);- arena- .free_subtree(container)- .destroy_shells_and_invoke_callbacks(&crate::stage::MainThread::for_test());- release_group_payload(group_index::BOX, box_payload);- release_group_payload(group_index::INHERITED_BOX, inherited);- release_group_payload(group_index::SURROUND, surround);+ return;+ }+ // NB: No cached layout of the box or its ancestors may hold the overflow the style change made stale.+ self.invalidate_fragments_of_self_and_ancestors_for_change_that_sizes_no_box(slot);+ if overflow_changed {+ self.request_fragment_overflow_recalculation(slot);}+ self.request_fragment_overflow_recalculation_of_containing_block(slot);}}diff --git a/Libraries/LibWeb/Rust/src/painting/stacking_context/entries.rs b/Libraries/LibWeb/Rust/src/painting/stacking_context/entries.rsindex 0d7f39221db..54407b4cdb7 100644--- a/Libraries/LibWeb/Rust/src/painting/stacking_context/entries.rs+++ b/Libraries/LibWeb/Rust/src/painting/stacking_context/entries.rs@@ -350,7 +350,6 @@ impl LayoutNodeArena {let mut cursor = Some(subtree_root);while let Some(node) = cursor {if self.paintable_row_is_populated(node) {- self.note_overflow_contained_box_added(node);self.note_visual_context_box_dirty(node, VisualContextBoxDirtyKind::ReattachedInLayoutTree);self.push_paint_damage(node, crate::painting::record::damage::PaintDamage::ORDER);}diff --git a/Libraries/LibWeb/Rust/src/painting/style_queries.rs b/Libraries/LibWeb/Rust/src/painting/style_queries.rsindex 43bb33e9bef..7dfe140264e 100644--- a/Libraries/LibWeb/Rust/src/painting/style_queries.rs+++ b/Libraries/LibWeb/Rust/src/painting/style_queries.rs@@ -621,22 +621,11 @@ pub(crate) fn has_line_clamp_point(arena: &impl PaintRead, node: NodeSlotId) ->arena.with_committed_fragment_link(node, |link| link.is_some_and(|link| link.fragment.has_line_clamp_point))}-pub(crate) fn clamped_content_is_scrollable_overflow(arena: &impl PaintRead, container: NodeSlotId) -> bool {- arena.with_committed_fragment_link(container, |link| {- link.is_some_and(|link| link.fragment.clamped_content_is_scrollable_overflow)- })-}-fn line_clamp_container(arena: &impl PaintRead, start: Option<NodeSlotId>) -> Option<NodeSlotId> {std::iter::successors(start, |node| arena.node_parent_if_live(*node)).find(|node| has_line_clamp_point(arena, *node))}-pub(crate) fn is_excluded_from_scrollable_overflow_by_line_clamp(arena: &impl PaintRead, node: NodeSlotId) -> bool {- is_invisible_for_line_clamp(arena, node)- && !line_clamp_container(arena, arena.node_parent_if_live(node))- .is_some_and(|container| clamped_content_is_scrollable_overflow(arena, container))-}pub(crate) fn line_clamp_clip_rect(arena: &impl PaintRead, container: NodeSlotId) -> CssPixelRect {let style = arena.node_style_if_live(container)diff --git a/Libraries/LibWeb/Rust/src/render_state.rs b/Libraries/LibWeb/Rust/src/render_state.rsindex 91883f6a618..f8f6e76009b 100644--- a/Libraries/LibWeb/Rust/src/render_state.rs+++ b/Libraries/LibWeb/Rust/src/render_state.rs@@ -1131,7 +1131,7 @@ mod tests {}#[test]- fn a_read_that_first_measures_a_scrollability_flip_leaves_the_paint_preparation_stale() {+ fn a_read_that_first_settles_a_scrollability_flip_leaves_the_paint_preparation_stale() {use crate::layout::node_data::NodeKind;use document_host::{document_host_note_paint_preparation_is_current, document_host_paint_preparation_is_current,@@ -1142,18 +1142,19 @@ mod tests {let viewport = arena.allocate_for_test().slot;arena.write_shape(viewport).set_kind(NodeKind::Viewport);arena.populate_paintable_row(viewport);- arena.scrollable_overflow.viewport = Some(viewport);- // The viewport had scrollable overflow before it was laid out again, and a read measures it first since.- arena- .committed_side_data_mut(viewport)- .overflow_relative_to_padding_box- .has_scrollable_overflow = true;- arena.note_row_overflow_unmeasured(viewport);+ // The viewport's fragment holds scrollable overflow it no longer has, and a read settles it first since.+ let mut link = crate::layout::fragment_tree::FragmentLink::for_test(viewport);+ let fragment = std::sync::Arc::get_mut(&mut link.fragment).unwrap();+ fragment.content_inline_size = crate::css::css_pixels::CssPixels::from_integer(100);+ fragment.content_block_size = crate::css::css_pixels::CssPixels::from_integer(100);+ fragment.scrollable_overflow.has_scrollable_overflow = true;+ arena.set_committed_fragment_link(viewport, link, None);+ arena.request_fragment_overflow_recalculation(viewport);viewport});let measure = || {host.ask(ScriptForcedRead::for_test(), |state| {- state.arena_mut().measure_scrollable_overflow();+ state.arena_mut().settle_scrollable_overflow();});};@@ -1162,7 +1163,7 @@ mod tests {assert!(!document_host_paint_preparation_is_current(host));assert!(host.with_arena_for_test(|arena| arena.scrollable_overflow.scrollability_changed));- // A read that measures nothing leaves the preparation as it is.+ // A read that settles nothing leaves the preparation as it is.document_host_note_paint_preparation_is_current(host);measure();assert!(document_host_paint_preparation_is_current(host));diff --git a/Libraries/LibWeb/Rust/src/render_state/devtools.rs b/Libraries/LibWeb/Rust/src/render_state/devtools.rsindex ab0e699c0fc..11b7edc26bf 100644--- a/Libraries/LibWeb/Rust/src/render_state/devtools.rs+++ b/Libraries/LibWeb/Rust/src/render_state/devtools.rs@@ -83,7 +83,7 @@ pub extern "C" fn render_state_pre_order_label_violation_count(host: &DocumentHo})}-/// How many times paint preparation recalculated scrollable overflow, counting from zero again where `reset`.+/// How many times scrollable overflow was recalculated outside layout, counting from zero again where `reset`.#[unsafe(no_mangle)]pub extern "C" fn render_state_scrollable_overflow_recalculation_count(host: &DocumentHost, reset: bool) -> u64 {read_arena(host, |arena| {@@ -96,16 +96,6 @@ pub extern "C" fn render_state_scrollable_overflow_recalculation_count(host: &Do})}-/// How many times paint preparation rebuilt the index of boxes whose containing block is not their parent, counting-/// from zero again where `reset`.-#[unsafe(no_mangle)]-pub extern "C" fn render_state_overflow_contained_box_index_refill_count(host: &DocumentHost, reset: bool) -> u64 {- read_arena(host, |arena| {- let refills = &mut arena.scrollable_overflow.contained_box_index_refills;- if reset { std::mem::take(refills) } else { *refills }- })-}-/// Where the stacking context structure below `viewport` differs from what paint preparation recorded, handed to/// `consume` unless it does not.///diff --git a/Libraries/LibWeb/Rust/src/render_state/document_host.rs b/Libraries/LibWeb/Rust/src/render_state/document_host.rsindex ae49f96a527..a04be35f8bf 100644--- a/Libraries/LibWeb/Rust/src/render_state/document_host.rs+++ b/Libraries/LibWeb/Rust/src/render_state/document_host.rs@@ -1059,9 +1059,9 @@ impl DocumentHost {/// change what the preparation answers, and so writes the render state.pub(crate) fn ask<R>(&self, wait: impl RenderWait, read: impl FnOnce(&mut RenderState) -> R) -> R {let (answer, measured_for_preparation) = self.run(wait, false, |state| {- let awaited = state.arena_mut().scrollable_overflow.measurement_awaits_preparation();+ let awaited = state.arena_mut().scrollable_overflow.change_awaits_preparation();let answer = read(state);- let awaits = state.arena_mut().scrollable_overflow.measurement_awaits_preparation();+ let awaits = state.arena_mut().scrollable_overflow.change_awaits_preparation();(answer, !awaited && awaits)});if measured_for_preparation {@@ -1150,14 +1150,14 @@ impl DocumentHost {}/// Answers `read` from the rows as of every write the host made, through the paint side's reads, spending `wait`- /// where the rows have to be published again, with every row's overflow measured where `measure_overflow`.+ /// where the rows have to be published again, with every row's overflow settled where `settle_overflow`.pub(crate) fn read_rows<R>(&self,wait: impl RenderWait,- measure_overflow: bool,+ settle_overflow: bool,read: impl FnOnce(&PaintSource<'_>) -> R,) -> R {- let rows = self.rows_as_of_writes(wait, measure_overflow);+ let rows = self.rows_as_of_writes(wait, settle_overflow);read(&PaintSource::over_rows(&rows.paintable, &self.absolute_rects))}@@ -1198,19 +1198,19 @@ impl DocumentHost {/// The rows as of every write the host made: the ones the host has where it knows they still read as the arena,/// and otherwise those the render state answers, spending `wait`, which are the ones the host has where they still/// read as the arena once the owner has applied the host's writes.- fn rows_as_of_writes(&self, wait: impl RenderWait, measure_overflow: bool) -> Rc<RowSnapshot> {+ fn rows_as_of_writes(&self, wait: impl RenderWait, settle_overflow: bool) -> Rc<RowSnapshot> {let held = self.rows.borrow().clone()- .filter(|rows| !measure_overflow || rows.overflow_is_measured());+ .filter(|rows| !settle_overflow || rows.overflow_is_settled());if let Some(rows) = held.as_ref().filter(|rows| self.knows_rows_read_as_arena(rows)) {return Rc::clone(rows);}let held_version = held.as_ref().map(|rows| rows.version());let published = self.ask(wait, |state| {let arena = state.arena_mut();- (held_version != Some(arena.rows_version())).then(|| arena.publish_row_snapshot(measure_overflow))+ (held_version != Some(arena.rows_version())).then(|| arena.publish_row_snapshot(settle_overflow))});match published {Some(rows) => {diff --git a/Tests/LibWeb/Text/expected/scrollable-overflow-contained-box-edits.txt b/Tests/LibWeb/Text/expected/scrollable-overflow-contained-box-edits.txtnew file mode 100644index 00000000000..7a6ebd0b220--- /dev/null+++ b/Tests/LibWeb/Text/expected/scrollable-overflow-contained-box-edits.txt@@ -0,0 +1,7 @@+text edit: scrollHeight=300+plain block inserted: scrollHeight=300+plain block removed: scrollHeight=300+nested absolutely positioned box inserted: scrollHeight=500+nested absolutely positioned box removed: scrollHeight=300+inline-block moved out of its inline parent: scrollHeight=300+inline-block moved back into an inline parent: scrollHeight=300diff --git a/Tests/LibWeb/Text/expected/scrollable-overflow-contained-box-index-edits.txt b/Tests/LibWeb/Text/expected/scrollable-overflow-contained-box-index-edits.txtdeleted file mode 100644index cdeb5a76d4c..00000000000--- a/Tests/LibWeb/Text/expected/scrollable-overflow-contained-box-index-edits.txt+++ /dev/null@@ -1,7 +0,0 @@-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-inline-block moved back into an inline parent: refills=1 scrollHeight=300diff --git a/Tests/LibWeb/Text/expected/scrollable-overflow-focus-caret-without-relayout.txt b/Tests/LibWeb/Text/expected/scrollable-overflow-focus-caret-without-relayout.txtnew file mode 100644index 00000000000..9c319ddc22e--- /dev/null+++ b/Tests/LibWeb/Text/expected/scrollable-overflow-focus-caret-without-relayout.txt@@ -0,0 +1,2 @@+focusing reserves a pixel for the caret: true+blurring releases it: truediff --git a/Tests/LibWeb/Text/expected/scrollable-overflow-transform-survives-cached-relayout.txt b/Tests/LibWeb/Text/expected/scrollable-overflow-transform-survives-cached-relayout.txtnew file mode 100644index 00000000000..a0abfbb8778--- /dev/null+++ b/Tests/LibWeb/Text/expected/scrollable-overflow-transform-survives-cached-relayout.txt@@ -0,0 +1,4 @@+initial: 100+transformed: 250+after a relayout that reuses the child: 250+untransformed: 100diff --git a/Tests/LibWeb/Text/input/scrollable-overflow-contained-box-index-edits.html b/Tests/LibWeb/Text/input/scrollable-overflow-contained-box-edits.htmlsimilarity index 85%rename from Tests/LibWeb/Text/input/scrollable-overflow-contained-box-index-edits.htmlrename to Tests/LibWeb/Text/input/scrollable-overflow-contained-box-edits.htmlindex 73caf3c6d1f..6d2efdf1e3f 100644--- a/Tests/LibWeb/Text/input/scrollable-overflow-contained-box-index-edits.html+++ b/Tests/LibWeb/Text/input/scrollable-overflow-contained-box-edits.html@@ -16,11 +16,8 @@test(() => {function step(name, mutate) {scroller.scrollHeight;- internals.resetStyleInvalidationCounters();mutate();- const scrollHeight = scroller.scrollHeight;- const refills = internals.getStyleInvalidationCounters().overflowContainedBoxIndexRefills;- println(`${name}: refills=${refills} scrollHeight=${scrollHeight}`);+ println(`${name}: scrollHeight=${scroller.scrollHeight}`);}step("text edit", () => {diff --git a/Tests/LibWeb/Text/input/scrollable-overflow-focus-caret-without-relayout.html b/Tests/LibWeb/Text/input/scrollable-overflow-focus-caret-without-relayout.htmlnew file mode 100644index 00000000000..4c439c14b4f--- /dev/null+++ b/Tests/LibWeb/Text/input/scrollable-overflow-focus-caret-without-relayout.html@@ -0,0 +1,28 @@+<!DOCTYPE html>+<style>+input {+ font: 16px monospace;+ width: 32px;+ padding: 0;+ border: 0;+}+</style>+<input id="input" value="xxxxxx">+<script src="include.js"></script>+<script>+test(() => {+ const innerText = internals.getShadowRoot(input).querySelector("div > div");+ const scrollToEnd = () => {+ innerText.scrollLeft = 0;+ innerText.scrollLeft = 10000;+ return innerText.scrollLeft;+ };+ const unfocused = scrollToEnd();+ input.focus();+ const focused = scrollToEnd();+ input.blur();+ const blurred = scrollToEnd();+ println(`focusing reserves a pixel for the caret: ${focused - unfocused === 1}`);+ println(`blurring releases it: ${blurred === unfocused}`);+});+</script>diff --git a/Tests/LibWeb/Text/input/scrollable-overflow-transform-survives-cached-relayout.html b/Tests/LibWeb/Text/input/scrollable-overflow-transform-survives-cached-relayout.htmlnew file mode 100644index 00000000000..157232d3934--- /dev/null+++ b/Tests/LibWeb/Text/input/scrollable-overflow-transform-survives-cached-relayout.html@@ -0,0 +1,25 @@+<!DOCTYPE html>+<style>+#scroller {+ overflow: auto;+ width: 100px;+ height: 100px;+}+#child {+ width: 50px;+ height: 50px;+}+</style>+<div id="scroller"><div id="child"></div><div id="other">text</div></div>+<script src="include.js"></script>+<script>+test(() => {+ println(`initial: ${scroller.scrollWidth}`);+ child.style.transform = "translateX(200px)";+ println(`transformed: ${scroller.scrollWidth}`);+ other.textContent = "more text";+ println(`after a relayout that reuses the child: ${scroller.scrollWidth}`);+ child.style.transform = "none";+ println(`untransformed: ${scroller.scrollWidth}`);+});+</script>