Skip to content

Truly independent web browser

LibWeb: Keep line clamp invisibility beside a box's record

Aliaksandr Kalenikfc2a83527829
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index add28bf694d..eda7f881220 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -1895,8 +1895,9 @@ impl<'pass> BlockFormattingContext<'pass> {
.run
.records
.track_percentage_block_size_dependency_while_laying_out(node);
- used.is_invisible_for_line_clamp
- .set(self.laying_out_invisible_line_clamp_content.get());
+ if self.laying_out_invisible_line_clamp_content.get() {
+ self.run.records.hide_for_line_clamp(node);
+ }
if facts.is_anonymous_button_content_wrapper() {
used.has_definite_block_size_only_for_button_content_alignment.set(
self.used(block_container)
@@ -3179,11 +3180,8 @@ impl<'pass> BlockFormattingContext<'pass> {
!child_facts.is_absolutely_positioned()
&& !child_facts.is_floating()
&& !child_facts.is_list_item_marker_box()
- && self
- .run
- .records
- .used_values_if_owned(child)
- .is_some_and(|used| !used.is_invisible_for_line_clamp.get())
+ && self.run.records.used_values_if_owned(child).is_some()
+ && !self.run.records.is_invisible_for_line_clamp(child)
&& !self.margins_collapse_through(child)
})
}
@@ -4423,7 +4421,7 @@ impl<'pass> BlockFormattingContext<'pass> {
// https://drafts.csswg.org/css-overflow-4/#line-clamp-containers
// If a block container contains a clamp point, within itself or in any of its descendants, its
// automatic block size will not take into account any invisible boxes, nor any clipped float.
- if child_used.is_invisible_for_line_clamp.get() {
+ if self.run.records.is_invisible_for_line_clamp(child) {
continue;
}
if self.margins_collapse_through(child) {
@@ -4738,7 +4736,7 @@ pub(crate) fn automatic_block_size_for_bfc_root(
let Some(child_used) = records.used_values_if_owned(child) else {
continue;
};
- if child_used.is_invisible_for_line_clamp.get() {
+ if records.is_invisible_for_line_clamp(child) {
continue;
}
// Margins cannot collapse out of a BFC root: below the last real in-flow
diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
index 169aa634e04..2181a2e9026 100644
--- a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
@@ -507,7 +507,7 @@ fn snapshot_fragment(
computed_svg_path,
svg_text_character_cells,
has_line_clamp_point: used.has_line_clamp_point.get(),
- is_invisible_for_line_clamp: used.is_invisible_for_line_clamp.get(),
+ is_invisible_for_line_clamp: fragment_facts.is_invisible_for_line_clamp,
clamped_content_is_scrollable_overflow: used.clamped_content_is_scrollable_overflow.get(),
continues_from_previous_fragment: used.continues_from_previous_fragment.get(),
continues_in_next_fragment: used.continues_in_next_fragment.get(),
@@ -1185,7 +1185,7 @@ impl RunFragmentBuilder {
fragment_facts: run_records::FragmentFactsDecidedByParent,
) -> 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 {
+ let fragment = if fragment_facts.is_invisible_for_line_clamp == held.fragment.is_invisible_for_line_clamp {
held.fragment
} else {
snapshot_fragment(callbacks, node, held.fragment.children.clone(), used, fragment_facts)
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
index 47d2a3406e9..879cb742ac7 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
@@ -1020,7 +1020,7 @@ impl<'context> InlineFormattingContext<'context> {
if let Some(fragments) = self.run.fragments.as_deref() {
fragments.discard_unplaced_subtree(node, self.used(node));
}
- self.used(node).is_invisible_for_line_clamp.set(true);
+ self.run.records.hide_for_line_clamp(node);
}
fn stops_at_line_clamp_point<'builder>(
@@ -1822,9 +1822,10 @@ impl<'context> InlineFormattingContext<'context> {
}
inline_level_iterator::ItemType::FloatingElement => {
line_builder.commit_pending_margin_before_float();
- self.create_used_values(item.node, self.input.containing_block_constraints)
- .is_invisible_for_line_clamp
- .set(state_at_clamp_point.is_some());
+ self.create_used_values(item.node, self.input.containing_block_constraints);
+ if state_at_clamp_point.is_some() {
+ self.run.records.hide_for_line_clamp(item.node);
+ }
self.clear_floating_boxes(item.node);
line_builder.set_unbreakable_run_inline_size_interrupted_by_float(
iterator.next_unbreakable_run_inline_size(self),
@@ -1955,7 +1956,7 @@ impl<'context> InlineFormattingContext<'context> {
.parent
.take_floating_boxes_from(state_at_clamp_point.floating_box_count);
for (node, position) in atomic_inlines_after_clamp_point {
- self.used(node).is_invisible_for_line_clamp.set(true);
+ self.run.records.hide_for_line_clamp(node);
formatting_context::place_child(self.run, node, position, None);
}
}
diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rs
index 09e24a05b25..ffb56b28f0c 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs
@@ -325,6 +325,8 @@ pub(crate) struct FragmentFactsDecidedByParent {
/// For table cells: whether every column the cell spans has 'visibility: collapse', which removes the cell from
/// the display along with the columns (CSS 2.2 §17.5.5).
pub(crate) hidden_by_collapsed_columns: bool,
+ /// Whether the box lies after the clamp point of a line-clamp container, which hides it.
+ pub(crate) is_invisible_for_line_clamp: bool,
}
/// What the parent of a box decides about the box, kept beside the box's record.
@@ -677,6 +679,18 @@ impl<'arena> RunRecords<'arena> {
self.update_fragment_facts_decided_by_parent_of(node, |facts| facts.hidden_by_collapsed_columns = hidden);
}
+ #[track_caller]
+ pub(crate) fn hide_for_line_clamp(&self, node: Node) {
+ self.update_fragment_facts_decided_by_parent_of(node, |facts| facts.is_invisible_for_line_clamp = true);
+ }
+
+ #[track_caller]
+ pub(crate) fn is_invisible_for_line_clamp(&self, node: Node) -> bool {
+ self.facts_decided_by_parent_of(node)
+ .fragment_facts
+ .is_invisible_for_line_clamp
+ }
+
/// Where `node` is placed, if this run placed it.
pub(crate) fn placement_of(&self, node: Node) -> Option<BoxPlacement> {
self.kept_facts_decided_by_parent_of(node)?.placement
diff --git a/Libraries/LibWeb/Rust/src/layout/used_values.rs b/Libraries/LibWeb/Rust/src/layout/used_values.rs
index 905f3e10680..d3abf332b9e 100644
--- a/Libraries/LibWeb/Rust/src/layout/used_values.rs
+++ b/Libraries/LibWeb/Rust/src/layout/used_values.rs
@@ -353,7 +353,6 @@ pub(crate) struct UsedValues {
/// side of the first or last grid line, while a cell owns the part on the inner side of its grid lines.
pub is_collapsed_borders_table_box: Cell<bool>,
pub has_line_clamp_point: Cell<bool>,
- pub is_invisible_for_line_clamp: Cell<bool>,
pub clamped_content_is_scrollable_overflow: Cell<bool>,
pub continues_from_previous_fragment: Cell<bool>,
pub continues_in_next_fragment: Cell<bool>,
@@ -397,7 +396,6 @@ impl Default for UsedValues {
uses_collapsing_borders_model: Cell::new(false),
is_collapsed_borders_table_box: Cell::new(false),
has_line_clamp_point: Cell::new(false),
- is_invisible_for_line_clamp: Cell::new(false),
continues_from_previous_fragment: Cell::new(false),
continues_in_next_fragment: Cell::new(false),
clamped_content_is_scrollable_overflow: Cell::new(false),
@@ -603,7 +601,6 @@ used_values_cells! {
has_definite_block_size_only_for_button_content_alignment: bool,
uses_collapsing_borders_model: bool,
is_collapsed_borders_table_box: bool,
- is_invisible_for_line_clamp: bool,
continues_from_previous_fragment: bool,
continues_in_next_fragment: bool,
}
@@ -1161,6 +1158,7 @@ pub(crate) fn committed_box_from_fragment_link(callbacks: &LayoutPass<'_>, node:
table_column_index: fragment.table_column_index,
table_column_span: fragment.table_column_span,
hidden_by_collapsed_columns: fragment.hidden_by_collapsed_columns,
+ ..super::run_records::FragmentFactsDecidedByParent::default()
},
},
})