Truly independent web browser
LibWeb: Keep a held committed fragment true to the box's final record
Andreas Klingb284f03bda05
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex ef787a7250f..dc555fea7fd 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -348,7 +348,7 @@ pub(crate) fn place_child_in_containing_block(let used = records.used_values(node);set_placement(used, containing_block, offset);let fragments = run.fragments.as_deref()?;- if let Some((fragment, reuses_subtree)) = fragments.take_reused_committed_fragment(used) {+ if let Some((fragment, reuses_subtree)) = fragments.take_reused_committed_fragment(callbacks, node, used) {fragments.attach_committed_fragment(node,fragment.clone(),@@ -1635,6 +1635,10 @@ pub(super) fn run_formatting_context(} else {purpose};+ if let Some(parent_fragments) = parent_fragments {+ // A later run for this root supersedes a hit recorded earlier in the same pass.+ parent_fragments.clear_reused_subtree_root(box_, parent_used);+ }let root_cells = used_values::UsedValuesCellState::capture(parent_used);let cache_key = fc_run_cache::FcRunCacheKey::new(fc_type, input, root_cells);let cache_attempt = match fc_run_cache::FcRunCacheAttempt::probe(@@ -1677,10 +1681,6 @@ pub(super) fn run_formatting_context(return absorb_run_outputs(parent_fragments, parent_used, box_, outputs, reuses_committed_subtree);}};- if let Some(parent_fragments) = parent_fragments {- // A later fresh run for this root supersedes a hit recorded earlier in the same pass.- parent_fragments.clear_reused_subtree_root(box_, parent_used);- }let _trace = callbacks.arena().layout_trace@@ -2171,6 +2171,8 @@ pub(crate) fn layout_inside_child({// OPTIMIZATION: An empty atomic block has no formatting-context body output. Size it in the// parent run, which will also construct its fragment when placing the box.+ // A fragment held by an earlier sizing of the box in this run may no longer match the record.+ used.held_committed_fragment.take();let committed_fragment = run.sizing().dimension_empty_atomic_root(child,input.available_space,diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rsindex 13ebfb4ad1e..1a526cd408c 100644--- a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs+++ b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs@@ -659,7 +659,7 @@ impl HeldCommittedFragmentCell {}));}- fn take(&self) -> Option<HeldCommittedFragment> {+ pub(crate) fn take(&self) -> Option<HeldCommittedFragment> {self.0.take()}}@@ -968,11 +968,22 @@ impl RunFragmentBuilder {used.held_committed_fragment.hold(fragment, false);}- /// The committed fragment held in the record `used` of a box, and whether the box roots a reused subtree.- pub(crate) fn take_reused_committed_fragment(&self, used: &UsedValues) -> Option<(std::sync::Arc<Fragment>, bool)> {- used.held_committed_fragment- .take()- .map(|held| (held.fragment, held.reuses_subtree))+ /// The committed fragment held in the record `used` of the box `node`, and whether the box roots a reused subtree.+ /// A box the run hid for line clamping after holding the fragment gets a fragment of its record around the+ /// committed children instead.+ pub(crate) fn take_reused_committed_fragment(+ &self,+ callbacks: &LayoutPass<'_>,+ node: crate::layout::node_data::NodeSlotId,+ used: &UsedValues,+ ) -> Option<(std::sync::Arc<Fragment>, bool)> {+ let held = used.held_committed_fragment.take()?;+ let fragment = if used.is_invisible_for_line_clamp.get() == held.fragment.is_invisible_for_line_clamp {+ held.fragment+ } else {+ snapshot_fragment(callbacks, node, held.fragment.children.clone(), used)+ };+ Some((fragment, held.reuses_subtree))}pub(crate) fn discard_unplaced_subtree(&self, node: crate::layout::node_data::NodeSlotId, used: &UsedValues) {diff --git a/Tests/LibWeb/Ref/expected/webkit-line-clamp-hides-reused-atomic-inlines-ref.html b/Tests/LibWeb/Ref/expected/webkit-line-clamp-hides-reused-atomic-inlines-ref.htmlnew file mode 100644index 00000000000..8df6e2f1bea--- /dev/null+++ b/Tests/LibWeb/Ref/expected/webkit-line-clamp-hides-reused-atomic-inlines-ref.html@@ -0,0 +1,14 @@+<!doctype html>+<style>+ body {+ margin: 0;+ }++ div {+ display: inline-block;+ width: 40px;+ height: 20px;+ background: green;+ }+</style>+<div></div><div></div>diff --git a/Tests/LibWeb/Ref/input/webkit-line-clamp-hides-reused-atomic-inlines.html b/Tests/LibWeb/Ref/input/webkit-line-clamp-hides-reused-atomic-inlines.htmlnew file mode 100644index 00000000000..7a101cf3bd2--- /dev/null+++ b/Tests/LibWeb/Ref/input/webkit-line-clamp-hides-reused-atomic-inlines.html@@ -0,0 +1,42 @@+<!doctype html>+<link rel="match" href="../expected/webkit-line-clamp-hides-reused-atomic-inlines-ref.html">+<style>+ body {+ margin: 0;+ }++ #container {+ width: 100px;+ height: 40px;+ display: -webkit-box;+ -webkit-box-orient: vertical;+ -webkit-line-clamp: 1;+ font-size: 0;+ }++ .box {+ display: inline-block;+ width: 40px;+ height: 20px;+ background: green;+ }++ .pushed {+ background: red;+ }++ .pushed > div {+ width: 10px;+ height: 10px;+ background: red;+ }+</style>+<div id="container"><div class="box"></div><div class="box pushed"><div></div></div><div class="box pushed"></div></div>+<script>+ // The boxes after the first are laid out before the insertion pushes them past the clamp point.+ document.body.offsetWidth;+ const box = document.createElement("div");+ box.className = "box";+ container.insertBefore(box, container.firstChild);+ document.body.offsetWidth;+</script>