Skip to content

Truly independent web browser

LibWeb: Keep what a parent decides about a box on its fragment link

Aliaksandr Kalenik09e1ad2e59c6
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index ad369d43a3d..7e2ccf97f69 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -475,16 +475,7 @@ pub(crate) fn place_child(
Some(fragment_tree::ChildFragmentArrival::CommittedFragment {
fragment,
reuses_subtree,
- }) => Some((
- fragment_tree::committed_fragment_showing_box(
- callbacks,
- node,
- || geometry.clone(),
- facts_decided_by_parent.fragment_facts,
- fragment,
- ),
- reuses_subtree,
- )),
+ }) => Some((fragment, reuses_subtree)),
Some(fragment_tree::ChildFragmentArrival::RunRoot {
root,
reuses_committed_subtree,
@@ -501,6 +492,7 @@ pub(crate) fn place_child(
reuses_subtree,
(!containing_block.is_invalid()).then_some(containing_block),
facts_decided_by_parent,
+ &geometry.cells,
abspos_layout_inputs,
resolve_containing_line_box_index(callbacks, node, containing_line_box_fragment),
point_add(
diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
index eb297f7d76c..2d3e1b5a6e2 100644
--- a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
@@ -13,10 +13,6 @@ pub(crate) struct Fragment {
pub(crate) node: crate::layout::node_data::NodeSlotId,
pub(crate) content_inline_size: CssPixels,
pub(crate) content_block_size: CssPixels,
- pub(crate) margin_left: CssPixels,
- pub(crate) margin_right: CssPixels,
- pub(crate) margin_top: CssPixels,
- pub(crate) margin_bottom: CssPixels,
pub(crate) border_left: CssPixels,
pub(crate) border_right: CssPixels,
pub(crate) border_top: CssPixels,
@@ -27,9 +23,6 @@ pub(crate) struct Fragment {
pub(crate) padding_bottom: CssPixels,
pub(crate) uses_collapsing_borders_model: bool,
pub(crate) is_collapsed_borders_table_box: bool,
- pub(crate) table_column_index: u32,
- pub(crate) table_column_span: u32,
- pub(crate) hidden_by_collapsed_columns: bool,
pub(crate) collapsed_table_borders: Option<std::sync::Arc<table_formatting_context::OwnedCollapsedTableBorders>>,
pub(crate) line_data: Option<std::sync::Arc<inline_content::InlineContent>>,
pub(crate) grid_layout_data: Option<std::sync::Arc<grid_formatting_context::GridLayoutData>>,
@@ -42,7 +35,6 @@ pub(crate) struct Fragment {
pub(crate) computed_svg_path: Option<std::sync::Arc<libgfx_rust::path::Path>>,
pub(crate) svg_text_character_cells: Option<std::sync::Arc<Vec<svg_formatting_context::FfiSvgTextCharacterCell>>>,
pub(crate) has_line_clamp_point: bool,
- pub(crate) is_invisible_for_line_clamp: bool,
pub(crate) clamped_content_is_scrollable_overflow: bool,
pub(crate) continues_from_previous_fragment: bool,
pub(crate) continues_in_next_fragment: bool,
@@ -57,6 +49,16 @@ pub(crate) struct FragmentLink {
pub(crate) inset_right: CssPixels,
pub(crate) inset_top: CssPixels,
pub(crate) inset_bottom: CssPixels,
+ /// The used margins, which the placement of the box decides, so that a change to them alone keeps the fragment.
+ pub(crate) margin_left: CssPixels,
+ pub(crate) margin_right: CssPixels,
+ pub(crate) margin_top: CssPixels,
+ pub(crate) margin_bottom: CssPixels,
+ /// What the parent decided about how the box shows, as `run_state::FragmentFactsDecidedByParent` describes it.
+ pub(crate) table_column_index: u32,
+ pub(crate) table_column_span: u32,
+ pub(crate) hidden_by_collapsed_columns: bool,
+ pub(crate) is_invisible_for_line_clamp: bool,
pub(crate) containing_line_box_index: Option<usize>,
/// Shared, as few links place an absolutely positioned box, the inputs are larger than the rest of the link, and
/// layout run cache entries keep copies of links.
@@ -109,9 +111,6 @@ impl Fragment {
/// SVG or line clamp state.
pub(crate) fn is_plain_box(&self) -> bool {
!self.is_collapsed_borders_table_box
- && self.table_column_index == 0
- && self.table_column_span == 0
- && !self.hidden_by_collapsed_columns
&& self.collapsed_table_borders.is_none()
&& self.grid_layout_data.is_none()
&& self.flex_layout_data.is_none()
@@ -122,7 +121,6 @@ impl Fragment {
&& self.computed_svg_path.is_none()
&& self.svg_text_character_cells.is_none()
&& !self.has_line_clamp_point
- && !self.is_invisible_for_line_clamp
&& !self.clamped_content_is_scrollable_overflow
&& !self.continues_from_previous_fragment
&& !self.continues_in_next_fragment
@@ -143,10 +141,6 @@ impl Fragment {
self.node == previous.node
&& self.content_inline_size == previous.content_inline_size
&& self.content_block_size == previous.content_block_size
- && self.margin_left == previous.margin_left
- && self.margin_right == previous.margin_right
- && self.margin_top == previous.margin_top
- && self.margin_bottom == previous.margin_bottom
&& self.border_left == previous.border_left
&& self.border_right == previous.border_right
&& self.border_top == previous.border_top
@@ -157,9 +151,6 @@ impl Fragment {
&& self.padding_bottom == previous.padding_bottom
&& self.uses_collapsing_borders_model == previous.uses_collapsing_borders_model
&& self.is_collapsed_borders_table_box == previous.is_collapsed_borders_table_box
- && self.table_column_index == previous.table_column_index
- && self.table_column_span == previous.table_column_span
- && self.hidden_by_collapsed_columns == previous.hidden_by_collapsed_columns
&& payloads.matches(
self.collapsed_table_borders.as_ref(),
previous.collapsed_table_borders.as_ref(),
@@ -176,7 +167,6 @@ impl Fragment {
previous.svg_text_character_cells.as_ref(),
)
&& self.has_line_clamp_point == previous.has_line_clamp_point
- && self.is_invisible_for_line_clamp == previous.is_invisible_for_line_clamp
&& self.clamped_content_is_scrollable_overflow == previous.clamped_content_is_scrollable_overflow
&& self.continues_from_previous_fragment == previous.continues_from_previous_fragment
&& self.continues_in_next_fragment == previous.continues_in_next_fragment
@@ -211,10 +201,6 @@ impl FragmentLink {
node,
content_inline_size: CssPixels::default(),
content_block_size: CssPixels::default(),
- margin_left: CssPixels::default(),
- margin_right: CssPixels::default(),
- margin_top: CssPixels::default(),
- margin_bottom: CssPixels::default(),
border_left: CssPixels::default(),
border_right: CssPixels::default(),
border_top: CssPixels::default(),
@@ -225,9 +211,6 @@ impl FragmentLink {
padding_bottom: CssPixels::default(),
uses_collapsing_borders_model: false,
is_collapsed_borders_table_box: false,
- table_column_index: 0,
- table_column_span: 0,
- hidden_by_collapsed_columns: false,
collapsed_table_borders: None,
line_data: None,
grid_layout_data: None,
@@ -239,7 +222,6 @@ impl FragmentLink {
computed_svg_path: None,
svg_text_character_cells: None,
has_line_clamp_point: false,
- is_invisible_for_line_clamp: false,
clamped_content_is_scrollable_overflow: false,
continues_from_previous_fragment: false,
continues_in_next_fragment: false,
@@ -250,6 +232,14 @@ impl FragmentLink {
inset_right: CssPixels::default(),
inset_top: CssPixels::default(),
inset_bottom: CssPixels::default(),
+ margin_left: CssPixels::default(),
+ margin_right: CssPixels::default(),
+ margin_top: CssPixels::default(),
+ margin_bottom: CssPixels::default(),
+ table_column_index: 0,
+ table_column_span: 0,
+ hidden_by_collapsed_columns: false,
+ is_invisible_for_line_clamp: false,
containing_line_box_index: None,
abspos_layout_inputs: None,
default_scroll_shift: None,
@@ -262,6 +252,19 @@ impl FragmentLink {
std::sync::Arc::ptr_eq(&self.fragment, &previous.fragment) && self.has_same_placement(previous)
}
+ /// Whether the link shows its fragment with the same margins and the same facts its parent decided about the box,
+ /// which change what painting shows of the box while the fragment stays the same.
+ pub(crate) fn shows_box_as(&self, previous: &FragmentLink) -> bool {
+ self.margin_left == previous.margin_left
+ && self.margin_right == previous.margin_right
+ && self.margin_top == previous.margin_top
+ && self.margin_bottom == previous.margin_bottom
+ && self.table_column_index == previous.table_column_index
+ && self.table_column_span == previous.table_column_span
+ && self.hidden_by_collapsed_columns == previous.hidden_by_collapsed_columns
+ && self.is_invisible_for_line_clamp == previous.is_invisible_for_line_clamp
+ }
+
pub(crate) fn has_same_placement(&self, previous: &FragmentLink) -> bool {
self.fragment.node == previous.fragment.node
&& self.committed_offset == previous.committed_offset
@@ -269,6 +272,7 @@ impl FragmentLink {
&& self.inset_right == previous.inset_right
&& self.inset_top == previous.inset_top
&& self.inset_bottom == previous.inset_bottom
+ && self.shows_box_as(previous)
&& self.containing_line_box_index == previous.containing_line_box_index
&& self.abspos_layout_inputs == previous.abspos_layout_inputs
&& self.default_scroll_shift == previous.default_scroll_shift
@@ -498,8 +502,8 @@ impl FragmentPayloads {
}
}
-/// What the fragment of a placed box shows of the box's own layout: its sizes and box sides in the frame of the run that
-/// places it, and its lines.
+/// What the placement of a box shows of the box's own layout, in the frame of the run that places it: the fragment shows
+/// its sizes, borders, paddings and lines, and the link shows its margins.
#[derive(Clone)]
pub(crate) struct FragmentGeometry {
pub(crate) cells: used_values::RootInputCells,
@@ -512,10 +516,6 @@ impl FragmentGeometry {
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
@@ -528,28 +528,6 @@ impl FragmentGeometry {
}
}
-/// 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(
- callbacks: &LayoutPass<'_>,
- node: crate::layout::node_data::NodeSlotId,
- geometry: impl FnOnce() -> FragmentGeometry,
- fragment_facts: run_state::FragmentFactsDecidedByParent,
- fragment: std::sync::Arc<Fragment>,
-) -> std::sync::Arc<Fragment> {
- if fragment_facts.is_invisible_for_line_clamp == fragment.is_invisible_for_line_clamp {
- return fragment;
- }
- snapshot_fragment(
- callbacks,
- node,
- fragment.children.clone(),
- geometry(),
- fragment_facts,
- Some(Box::new(FragmentPayloads::of_fragment(&fragment))),
- )
-}
-
fn snapshot_fragment(
callbacks: &LayoutPass<'_>,
node: crate::layout::node_data::NodeSlotId,
@@ -578,10 +556,6 @@ fn snapshot_fragment(
node,
content_inline_size: cells.content_inline_size,
content_block_size: cells.content_block_size,
- margin_left: cells.margin_left,
- margin_right: cells.margin_right,
- margin_top: cells.margin_top,
- margin_bottom: cells.margin_bottom,
border_left: cells.border_left,
border_right: cells.border_right,
border_top: cells.border_top,
@@ -592,9 +566,6 @@ fn snapshot_fragment(
padding_bottom: cells.padding_bottom,
uses_collapsing_borders_model: cells.uses_collapsing_borders_model,
is_collapsed_borders_table_box: cells.is_collapsed_borders_table_box,
- table_column_index: fragment_facts.table_column_index,
- table_column_span: fragment_facts.table_column_span,
- hidden_by_collapsed_columns: fragment_facts.hidden_by_collapsed_columns,
collapsed_table_borders,
line_data,
grid_layout_data,
@@ -606,7 +577,6 @@ fn snapshot_fragment(
computed_svg_path,
svg_text_character_cells,
has_line_clamp_point,
- is_invisible_for_line_clamp: fragment_facts.is_invisible_for_line_clamp,
clamped_content_is_scrollable_overflow,
continues_from_previous_fragment: fragment_facts.continues_from_previous_fragment,
continues_in_next_fragment: fragment_facts.continues_in_next_fragment,
@@ -643,6 +613,14 @@ pub(crate) struct PlacementData {
pub(crate) inset_right: CssPixels,
pub(crate) inset_top: CssPixels,
pub(crate) inset_bottom: CssPixels,
+ pub(crate) margin_left: CssPixels,
+ pub(crate) margin_right: CssPixels,
+ pub(crate) margin_top: CssPixels,
+ pub(crate) margin_bottom: CssPixels,
+ pub(crate) table_column_index: u32,
+ pub(crate) table_column_span: u32,
+ pub(crate) hidden_by_collapsed_columns: bool,
+ pub(crate) is_invisible_for_line_clamp: bool,
pub(crate) containing_line_box_index: Option<usize>,
pub(crate) abspos_layout_inputs: Option<abspos_inputs::AbsposLayoutInputs>,
pub(crate) default_scroll_shift: Option<abspos_inputs::DefaultScrollShift>,
@@ -653,6 +631,7 @@ pub(crate) struct PlacementData {
impl PlacementData {
fn of_box(
facts: &run_state::FactsDecidedByParent,
+ cells: &used_values::RootInputCells,
abspos_layout_inputs: Option<abspos_inputs::AbsposLayoutInputs>,
containing_line_box_index: Option<usize>,
committed_offset: FfiCssPixelPoint,
@@ -665,6 +644,14 @@ impl PlacementData {
inset_right: facts.used_insets.right,
inset_top: facts.used_insets.top,
inset_bottom: facts.used_insets.bottom,
+ margin_left: cells.margin_left,
+ margin_right: cells.margin_right,
+ margin_top: cells.margin_top,
+ margin_bottom: cells.margin_bottom,
+ table_column_index: facts.fragment_facts.table_column_index,
+ table_column_span: facts.fragment_facts.table_column_span,
+ hidden_by_collapsed_columns: facts.fragment_facts.hidden_by_collapsed_columns,
+ is_invisible_for_line_clamp: facts.fragment_facts.is_invisible_for_line_clamp,
containing_line_box_index,
abspos_layout_inputs,
default_scroll_shift: facts.default_scroll_shift,
@@ -683,6 +670,7 @@ impl PlacementData {
) -> Self {
Self::of_box(
&unplaced_child.facts_decided_by_parent,
+ &unplaced_child.geometry.cells,
None,
None,
FfiCssPixelPoint::default(),
@@ -699,6 +687,14 @@ fn link_fragment(fragment: std::sync::Arc<Fragment>, placement: PlacementData) -
inset_right: placement.inset_right,
inset_top: placement.inset_top,
inset_bottom: placement.inset_bottom,
+ margin_left: placement.margin_left,
+ margin_right: placement.margin_right,
+ margin_top: placement.margin_top,
+ margin_bottom: placement.margin_bottom,
+ table_column_index: placement.table_column_index,
+ table_column_span: placement.table_column_span,
+ hidden_by_collapsed_columns: placement.hidden_by_collapsed_columns,
+ is_invisible_for_line_clamp: placement.is_invisible_for_line_clamp,
containing_line_box_index: placement.containing_line_box_index,
abspos_layout_inputs: placement.abspos_layout_inputs.map(std::sync::Arc::new),
default_scroll_shift: placement.default_scroll_shift,
@@ -1517,17 +1513,16 @@ impl RunFragmentBuilder {
.remove(&slot)
.unwrap_or_else(|| PendingFragment::new(node));
let content_size = (geometry.cells.content_inline_size, geometry.cells.content_block_size);
- let fragment = snapshot_fragment(callbacks, node, children, geometry, facts.fragment_facts, payloads);
- let link = link_fragment(
- fragment.clone(),
- PlacementData::of_box(
- &facts,
- abspos_layout_inputs,
- containing_line_box_index,
- committed_offset,
- callbacks.frame,
- ),
+ let link_placement = PlacementData::of_box(
+ &facts,
+ &geometry.cells,
+ abspos_layout_inputs,
+ containing_line_box_index,
+ committed_offset,
+ callbacks.frame,
);
+ let fragment = snapshot_fragment(callbacks, node, children, geometry, facts.fragment_facts, payloads);
+ let link = link_fragment(fragment.clone(), link_placement);
self.attach(&mut inner, link, containing_block);
let exports_payloads = !pending_abspos_from_placed_box.is_empty()
|| !anchor_candidates_from_placed_box.is_empty()
@@ -1597,8 +1592,8 @@ impl RunFragmentBuilder {
}
}
- /// Places the committed fragment of a box as it is. Where the box's subtree is reused as it is, commit stops at the
- /// box, so its committed descendants stay as they are.
+ /// Places the committed fragment of a box as it is, with the margins in `cells_of_placed_box`. Where the box's
+ /// subtree is reused as it is, commit stops at the box, so its committed descendants stay as they are.
#[expect(clippy::too_many_arguments)]
pub(crate) fn attach_committed_fragment(
&self,
@@ -1607,6 +1602,7 @@ impl RunFragmentBuilder {
reuses_subtree: bool,
containing_block: Option<crate::layout::node_data::NodeSlotId>,
facts: run_state::FactsDecidedByParent,
+ cells_of_placed_box: &used_values::RootInputCells,
abspos_layout_inputs: Option<abspos_inputs::AbsposLayoutInputs>,
containing_line_box_index: Option<usize>,
committed_offset: FfiCssPixelPoint,
@@ -1626,6 +1622,7 @@ impl RunFragmentBuilder {
fragment,
PlacementData::of_box(
&facts,
+ cells_of_placed_box,
abspos_layout_inputs,
containing_line_box_index,
committed_offset,
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
index c9a6b044e15..3ab59a701e3 100644
--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
@@ -5225,7 +5225,15 @@ impl LayoutNodeArena {
node: NodeSlotId,
read: impl FnOnce(&std::sync::Arc<super::fragment_tree::Fragment>) -> R,
) -> Option<R> {
- self.paintable_rows.with_current_committed_fragment(
+ self.with_current_committed_fragment_link(node, |link| read(&link.fragment))
+ }
+
+ pub(crate) fn with_current_committed_fragment_link<R>(
+ &self,
+ node: NodeSlotId,
+ read: impl FnOnce(&super::fragment_tree::FragmentLink) -> R,
+ ) -> Option<R> {
+ self.paintable_rows.with_current_committed_fragment_link(
node.slot_index(),
node.generation(),
self.data(node).fragment_cache_epoch,
diff --git a/Libraries/LibWeb/Rust/src/layout/run_state.rs b/Libraries/LibWeb/Rust/src/layout/run_state.rs
index 8806124f29d..a827e2dcf70 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_state.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_state.rs
@@ -190,7 +190,8 @@ pub(crate) struct BoxPlacement {
pub(crate) containing_block: Node,
}
-/// What a box's fragment shows of the layout of its parent, which decides it.
+/// What the placement of a box shows of the layout of its parent, which decides it: the link that places the box's
+/// fragment shows the table and line clamp facts, and the fragment shows whether fragmentation broke the box.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub(crate) struct FragmentFactsDecidedByParent {
/// For table cells and table-column(-group) boxes: the first grid column the box occupies and the number of grid
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
index 298c36d4b61..b26170879e8 100644
--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
@@ -2222,9 +2222,9 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
let used = sized_cells.cells;
self.callbacks
.arena()
- .with_current_committed_fragment(node, |fragment| {
- used.update_cells(|cells| cells.take_box_metrics_of_fragment(fragment));
- fragment.clone()
+ .with_current_committed_fragment_link(node, |link| {
+ used.update_cells(|cells| cells.take_box_metrics_of_committed_link(link));
+ link.fragment.clone()
})
}
diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
index 4bf5def0a71..e8248a54953 100644
--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
@@ -2244,17 +2244,14 @@ impl<'pass> SvgFormattingContext<'pass> {
}
self.run.fragments.as_ref()?;
// A committed fragment stops being current when something marks its box for layout.
- let fragment = self
+ let link = self
.run
.callbacks
.arena()
- .with_current_committed_fragment(shape, |fragment| fragment.clone())?;
+ .with_current_committed_fragment_link(shape, |link| link.clone())?;
+ let fragment = link.fragment.clone();
fragment.computed_svg_path.as_ref()?;
- let committed_offset = crate::painting::paint_read::GeometryRead::with_committed_fragment_link(
- self.run.callbacks.arena(),
- shape,
- |link| link.map(|link| link.committed_offset),
- )?;
+ let committed_offset = link.committed_offset;
// The transforms and the stroke's percentage basis are what the shape's facts take from outside its own
// geometry.
let committed = fragment.svg.as_deref().copied().unwrap_or_default();
@@ -2266,7 +2263,7 @@ impl<'pass> SvgFormattingContext<'pass> {
return None;
}
cells.update_cells(|cells| {
- cells.take_box_metrics_of_fragment(&fragment);
+ cells.take_box_metrics_of_committed_link(&link);
cells.has_definite_block_size = true;
});
self.place_laid_out_child(
diff --git a/Libraries/LibWeb/Rust/src/layout/used_values.rs b/Libraries/LibWeb/Rust/src/layout/used_values.rs
index b4e2e09e4a0..722049f031b 100644
--- a/Libraries/LibWeb/Rust/src/layout/used_values.rs
+++ b/Libraries/LibWeb/Rust/src/layout/used_values.rs
@@ -201,24 +201,25 @@ impl RootInputCells {
self.resolve_vertical_box_model(style, basis);
}
- /// The sizes and box sides `fragment` shows, with both sizes definite.
- pub(crate) fn of_committed_fragment(fragment: &fragment_tree::Fragment) -> Self {
+ /// The sizes and box sides `link` and its fragment show, with both sizes definite.
+ pub(crate) fn of_committed_fragment_link(link: &fragment_tree::FragmentLink) -> Self {
let mut cells = Self {
has_definite_block_size: true,
..Self::default()
};
- cells.take_box_metrics_of_fragment(fragment);
+ cells.take_box_metrics_of_committed_link(link);
cells
}
- /// Takes the sizes and box sides `fragment` shows.
- pub(crate) fn take_box_metrics_of_fragment(&mut self, fragment: &fragment_tree::Fragment) {
+ /// Takes the sizes and box sides `link` and its fragment show.
+ pub(crate) fn take_box_metrics_of_committed_link(&mut self, link: &fragment_tree::FragmentLink) {
+ let fragment = &link.fragment;
self.set_content_inline_size(fragment.content_inline_size);
self.set_content_block_size(fragment.content_block_size);
- self.margin_left = fragment.margin_left;
- self.margin_right = fragment.margin_right;
- self.margin_top = fragment.margin_top;
- self.margin_bottom = fragment.margin_bottom;
+ self.margin_left = link.margin_left;
+ self.margin_right = link.margin_right;
+ self.margin_top = link.margin_top;
+ self.margin_bottom = link.margin_bottom;
self.border_left = fragment.border_left;
self.border_right = fragment.border_right;
self.border_top = fragment.border_top;
@@ -669,10 +670,9 @@ pub(crate) struct CommittedBox {
pub(crate) fn committed_box_from_fragment_link(callbacks: &LayoutPass<'_>, node: Node) -> Option<CommittedBox> {
let link = callbacks.committed_fragment_link(node)?;
- let fragment = &link.fragment;
Some(CommittedBox {
- cells: RootInputCells::of_committed_fragment(fragment),
+ cells: RootInputCells::of_committed_fragment_link(&link),
facts_decided_by_parent: super::run_state::FactsDecidedByParent {
placement: Some(super::run_state::BoxPlacement {
content_offset_in_containing_block: link.committed_offset,
@@ -686,9 +686,9 @@ pub(crate) fn committed_box_from_fragment_link(callbacks: &LayoutPass<'_>, node:
},
default_scroll_shift: None,
fragment_facts: super::run_state::FragmentFactsDecidedByParent {
- table_column_index: fragment.table_column_index,
- table_column_span: fragment.table_column_span,
- hidden_by_collapsed_columns: fragment.hidden_by_collapsed_columns,
+ table_column_index: link.table_column_index,
+ table_column_span: link.table_column_span,
+ hidden_by_collapsed_columns: link.hidden_by_collapsed_columns,
..super::run_state::FragmentFactsDecidedByParent::default()
},
},
diff --git a/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs b/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs
index 951b1864047..aa168cd8b3c 100644
--- a/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs
@@ -156,7 +156,7 @@ impl PaintOrderInputs {
link.map_or((false, false), |link| {
(
link.fragment.collapsed_table_borders.is_some(),
- link.fragment.hidden_by_collapsed_columns,
+ link.hidden_by_collapsed_columns,
)
})
});
diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
index 837649adc77..9e83b4a41f5 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
@@ -251,6 +251,7 @@ impl<'a> PaintableCommit<'a> {
let mut inline_content_unchanged = false;
let mut inline_item_order_unchanged = false;
let mut child_sequence_unchanged = false;
+ let mut link_shows_box_the_same = true;
let (old_identity, old_content_size, old_content_inline_size) =
self.arena().with_committed_fragment_link(node, |old_link| {
old_link.map_or((0, used_values::FfiCssPixelSize::default(), None), |old_link| {
@@ -277,6 +278,7 @@ impl<'a> PaintableCommit<'a> {
child_sequence_unchanged = fragment.has_same_child_sequence(previous);
}
own_paint_unchanged &= old_link.has_same_placement(link);
+ link_shows_box_the_same = link.shows_box_as(old_link);
(
old_link.fragment.identity,
frame.size_to_physical(
@@ -311,8 +313,10 @@ impl<'a> PaintableCommit<'a> {
|| (enclosing_line_root_changes.fragment_changed && painted_geometry_lives_in_enclosing_line_root);
// Keep fragment identity as the conservative signal for overflow and visual contexts.
// A reused run root can have a new identity while its box and subtree are unchanged.
- let fragment_content_unchanged =
- (reuses_committed_subtree && root_box_unchanged) || (old_identity != 0 && !fragment_content_changed);
+ // The fragment stays the same when only the link's margins or parent-decided facts change, but margin-box clip
+ // paths, line clamp clips and overflow read those.
+ let fragment_content_unchanged = link_shows_box_the_same
+ && ((reuses_committed_subtree && root_box_unchanged) || (old_identity != 0 && !fragment_content_changed));
let offset_unchanged = previous_offset == Some(new_offset);
let enclosing_inline_paint_changed = painted_geometry_lives_in_enclosing_line_root
&& (enclosing_line_root_changes.inline_content_changed
diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs b/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs
index f14bbae2d79..78e94f6f198 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs
@@ -104,10 +104,10 @@ pub(crate) fn committed_margin(arena: &impl GeometryRead, slot: NodeSlotId) -> F
sides_to_physical(
frame,
FfiPixelBox {
- top: link.fragment.margin_top,
- right: link.fragment.margin_right,
- bottom: link.fragment.margin_bottom,
- left: link.fragment.margin_left,
+ top: link.margin_top,
+ right: link.margin_right,
+ bottom: link.margin_bottom,
+ left: link.margin_left,
},
)
})
@@ -178,18 +178,14 @@ pub(crate) fn committed_uses_collapsing_borders_model(arena: &impl GeometryRead,
/// For a table cell: whether every column it spans has 'visibility: collapse', which removes the cell from the display
/// along with the columns (CSS 2.2 §17.5.5).
pub(crate) fn committed_hidden_by_collapsed_columns(arena: &impl GeometryRead, slot: NodeSlotId) -> bool {
- arena.with_committed_fragment_link(slot, |link| {
- link.is_some_and(|link| link.fragment.hidden_by_collapsed_columns)
- })
+ arena.with_committed_fragment_link(slot, |link| link.is_some_and(|link| link.hidden_by_collapsed_columns))
}
/// For a table cell or a table-column(-group) box: the first grid column it occupies and the number of grid columns
/// it spans.
pub(crate) fn committed_table_column_range(arena: &impl GeometryRead, slot: NodeSlotId) -> (u32, u32) {
arena.with_committed_fragment_link(slot, |link| {
- link.map_or((0, 0), |link| {
- (link.fragment.table_column_index, link.fragment.table_column_span)
- })
+ link.map_or((0, 0), |link| (link.table_column_index, link.table_column_span))
})
}
@@ -476,7 +472,7 @@ pub(crate) fn unbroken_box_model(
);
if let Some(last) = arena.committed_side_data(slot).box_fragments().last() {
let fragment = &last.link.fragment;
- margin.bottom = fragment.margin_bottom;
+ margin.bottom = last.link.margin_bottom;
padding.bottom = fragment.padding_bottom;
border.bottom = fragment.border_bottom;
}
diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs
index 45e325762fd..5d390b7cf54 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs
@@ -594,12 +594,12 @@ impl CommittedFragmentLinkSlot {
}
impl PaintableRowStore {
- pub(crate) fn with_current_committed_fragment<R>(
+ pub(crate) fn with_current_committed_fragment_link<R>(
&self,
layout_slot_index: u32,
layout_slot_generation: u8,
geometry_epoch: u32,
- read: impl FnOnce(&std::sync::Arc<fragment_tree::Fragment>) -> R,
+ read: impl FnOnce(&fragment_tree::FragmentLink) -> R,
) -> Option<R> {
let slots = &self.committed_fragment_links;
let slot = slots.get(layout_slot_index as usize)?;
@@ -609,7 +609,7 @@ impl PaintableRowStore {
{
return None;
}
- Some(read(&slot.link.as_ref()?.fragment))
+ Some(read(slot.link.as_ref()?))
}
/// Whether the slot holds `link` already, placed the same way, with geometry current for `geometry_epoch`.
@@ -620,16 +620,13 @@ impl PaintableRowStore {
geometry_epoch: u32,
link: &fragment_tree::FragmentLink,
) -> bool {
- let slots = &self.committed_fragment_links;
- slots.get(layout_slot_index as usize).is_some_and(|slot| {
- slot.layout_slot_generation == layout_slot_generation
- && slot.geometry_is_current
- && slot.geometry_epoch == geometry_epoch
- && slot
- .link
- .as_ref()
- .is_some_and(|committed| link.places_same_fragment_identically_to(committed))
- })
+ self.with_current_committed_fragment_link(
+ layout_slot_index,
+ layout_slot_generation,
+ geometry_epoch,
+ |committed| link.places_same_fragment_identically_to(committed),
+ )
+ .unwrap_or(false)
}
pub(crate) fn invalidate_committed_geometry(&mut self, layout_slot_index: u32) {
diff --git a/Libraries/LibWeb/Rust/src/painting/style_queries.rs b/Libraries/LibWeb/Rust/src/painting/style_queries.rs
index d9519925e64..43bb33e9bef 100644
--- a/Libraries/LibWeb/Rust/src/painting/style_queries.rs
+++ b/Libraries/LibWeb/Rust/src/painting/style_queries.rs
@@ -614,9 +614,7 @@ pub(crate) fn is_floating(arena: &impl PaintRead, node: NodeSlotId) -> bool {
}
pub(crate) fn is_invisible_for_line_clamp(arena: &impl PaintRead, node: NodeSlotId) -> bool {
- arena.with_committed_fragment_link(node, |link| {
- link.is_some_and(|link| link.fragment.is_invisible_for_line_clamp)
- })
+ arena.with_committed_fragment_link(node, |link| link.is_some_and(|link| link.is_invisible_for_line_clamp))
}
pub(crate) fn has_line_clamp_point(arena: &impl PaintRead, node: NodeSlotId) -> bool {