Truly independent web browser
LibWeb: Check a reused committed fragment against the run's box value
Aliaksandr Kalenika4fe17bc0981
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex 0db501c7f99..0284e489ab0 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -2170,10 +2170,9 @@ pub(super) fn run_formatting_context()}-/// Takes a committing run of `box_` from the cache hit `hit` with nothing replayed: its root record gets what the-/// stored run left, and the run's placement attaches the box's committed fragment as it is. That is exact where the-/// committed subtree is the one the stored run produced, the box is plain, and nothing from the stored run reaches-/// past its root.+/// Takes a committing run of `box_` from the cache hit `hit` with nothing replayed: the box gets what the stored run+/// left, and the run's placement attaches the box's committed fragment as it is. That is exact where the committed+/// subtree is the one the stored run produced, the box is plain, and nothing from the stored run reaches past its root.#[expect(clippy::too_many_arguments)]fn reuse_committed_subtree_as_it_is(parent_fragments: Option<&fragment_tree::RunFragmentBuilder>,@@ -2186,7 +2185,6 @@ fn reuse_committed_subtree_as_it_is(hit: &fc_run_cache::FcRunCacheHit,) -> Option<ChildRunOutcome> {parent_fragments?;- let root_used = root_used.expect("a parent that builds fragments keeps a record of its child");let entry = &*hit.entry;if !hit.reuses_committed_subtree|| !cache_key.has_no_table_cell_intrinsic_block_padding()@@ -2205,14 +2203,25 @@ fn reuse_committed_subtree_as_it_is(.flatten()?;let content_block_size_adopted_after_run =content_block_size_adopted_after_run(input, entry.outputs.result.automatic_content_block_size);- entry- .outputs- .root_outcome- .clone()- .apply_to_record(root_used, content_block_size_adopted_after_run);- if !root_used.shows_box_of_fragment(&fragment) {+ let laid_out_box = entry.outputs.root_outcome.laid_out_child_box(+ root_cells,+ &entry.outputs.result,+ content_block_size_adopted_after_run,+ );+ let geometry = fragment_tree::FragmentGeometry {+ cells: laid_out_box.cells,+ line_data: entry.outputs.root_outcome.line_data.clone(),+ };+ if !geometry.shows_box_of_fragment(&fragment) {return None;}+ if let Some(root_used) = root_used {+ entry+ .outputs+ .root_outcome+ .clone()+ .apply_to_record(root_used, content_block_size_adopted_after_run);+ }let _trace = callbacks.arena().layout_trace@@ -2220,15 +2229,10 @@ fn reuse_committed_subtree_as_it_is(callbacks.scratch().receive_host_findings(entry.outputs.host_findings.clone());- let laid_out_box = entry.outputs.root_outcome.laid_out_child_box(- root_cells,- &entry.outputs.result,- content_block_size_adopted_after_run,- );Some(ChildRunOutcome {result: entry.outputs.result,laid_out_box,- line_data: entry.outputs.root_outcome.line_data.clone(),+ line_data: geometry.line_data,fragment_arrival: Some(fragment_tree::ChildFragmentArrival::CommittedFragment {fragment,reuses_subtree: true,diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rsindex ae98dd6b940..29e164d7347 100644--- a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs+++ b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs@@ -467,6 +467,33 @@ pub(crate) struct FragmentGeometry {pub(crate) line_data: Option<std::sync::Arc<inline_content::InlineContent>>,}+impl FragmentGeometry {+ /// Whether `other` has the same cells and the same lines, as the same allocation.+ pub(crate) fn is_identical_to(&self, other: &Self) -> bool {+ self.cells == other.cells && same_allocation(self.line_data.as_ref(), other.line_data.as_ref())+ }++ pub(crate) fn shows_box_of_fragment(&self, fragment: &Fragment) -> bool {+ let cells = &self.cells;+ same_allocation(self.line_data.as_ref(), fragment.line_data.as_ref())+ && fragment.content_inline_size == cells.content_inline_size+ && fragment.content_block_size == cells.content_block_size+ && fragment.margin_left == cells.margin_left+ && fragment.margin_right == cells.margin_right+ && fragment.margin_top == cells.margin_top+ && fragment.margin_bottom == cells.margin_bottom+ && fragment.border_left == cells.border_left+ && fragment.border_right == cells.border_right+ && fragment.border_top == cells.border_top+ && fragment.border_bottom == cells.border_bottom+ && fragment.padding_left == cells.padding_left+ && fragment.padding_right == cells.padding_right+ && fragment.padding_top == cells.padding_top+ && fragment.padding_bottom == cells.padding_bottom+ && fragment.uses_collapsing_borders_model == cells.uses_collapsing_borders_model+ }+}+/// The committed fragment `fragment` of `node`, or a fragment of the box's `geometry` around the committed children/// where the box is now hidden or shown for line clamping unlike the committed fragment.pub(crate) fn committed_fragment_showing_box(diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rsindex 3b574c41409..b809fdc7dac 100644--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs@@ -1096,25 +1096,21 @@ impl<'arena> RunRecords<'arena> {let Some(handed_back) = handed_back else {return geometry_of_record;};+ let geometry = fragment_tree::FragmentGeometry {+ cells: handed_back.laid_out.cells,+ line_data: handed_back.line_data,+ };if checks_kept_boxes_against_records() {assert_eq!(handed_back.frame, callbacks.frame,"the fragment of {node:?} is built in another frame than the one its box is kept in");assert!(- handed_back.laid_out.cells == geometry_of_record.cells- && match (&handed_back.line_data, &geometry_of_record.line_data) {- (None, None) => true,- (Some(kept), Some(recorded)) => std::sync::Arc::ptr_eq(kept, recorded),- _ => false,- },+ geometry.is_identical_to(&geometry_of_record),"the parent's record of {node:?} changed after its run handed the box back");}- fragment_tree::FragmentGeometry {- cells: handed_back.laid_out.cells,- line_data: handed_back.line_data,- }+ geometry}pub(crate) fn store_table_inline_layout(&self, table: Node, layout: table_formatting_context::TableInlineLayout) {