Skip to content

Truly independent web browser

LibWeb: Group what a fragment link shows of its box into LinkPlacement

Aliaksandr Kalenik32a32de227ee
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
index 5fa50509f2f..cec7a60834d 100644
--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
@@ -3904,7 +3904,7 @@ impl<'pass> AbsposEngine<'pass> {
let default_scroll_shift = self
.pass
.committed_fragment_link(node)
- .and_then(|link| link.default_scroll_shift);
+ .and_then(|link| link.placement.default_scroll_shift);
self.layout_element(run, node, cells, inputs, default_scroll_shift);
}
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index 0873f9a7135..91a82e6461f 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -3193,7 +3193,7 @@ impl<'pass> BlockFormattingContext<'pass> {
cells,
content_baselines,
collapses_through: laid_out.collapses_through,
- is_invisible_for_line_clamp: laid_out.fragment_facts.is_invisible_for_line_clamp,
+ is_invisible_for_line_clamp: laid_out.fragment_facts.show.is_invisible_for_line_clamp,
can_break_inside: self.box_can_break_inside(node, laid_out.has_unbreakable_lines),
broken_inside: laid_out.broken_inside,
baselines_in_containing_block,
@@ -3275,7 +3275,7 @@ impl<'pass> BlockFormattingContext<'pass> {
.track_percentage_block_size_dependency_while_laying_out(node);
let mut fragment_facts = run_state::FragmentFactsDecidedByParent::default();
if self.laying_out_invisible_line_clamp_content.get() {
- fragment_facts.hide_after_clamp_point();
+ fragment_facts.show.hide_after_clamp_point();
}
if facts.is_anonymous_button_content_wrapper() {
let only_for_button_content_alignment = block_container
@@ -3317,7 +3317,7 @@ impl<'pass> BlockFormattingContext<'pass> {
cells.border_top = CssPixels::default();
cells.padding_top = CssPixels::default();
});
- fragment_facts.continues_from_previous_fragment = true;
+ fragment_facts.breaks.continues_from_previous = true;
}
if facts.is_floating() {
@@ -3938,7 +3938,7 @@ impl<'pass> BlockFormattingContext<'pass> {
cells.border_bottom = CssPixels::default();
cells.margin_bottom = CssPixels::default();
});
- fragment_facts.continues_in_next_fragment = true;
+ fragment_facts.breaks.continues_in_next = true;
std::rc::Rc::make_mut(&mut token).consumed_block_size = continuation
.as_ref()
.map_or(CssPixels::default(), |continuation| continuation.consumed_block_size)
@@ -4102,7 +4102,7 @@ impl<'pass> BlockFormattingContext<'pass> {
self.collapse_margins_after_block_level_box(
margins_left_by_contents.as_ref(),
collapses_through,
- fragment_facts.continues_in_next_fragment,
+ fragment_facts.breaks.continues_in_next,
metrics.margin_bottom(),
);
diff --git a/Libraries/LibWeb/Rust/src/layout/commit.rs b/Libraries/LibWeb/Rust/src/layout/commit.rs
index d0f9d36c0ae..ce57ffbb21d 100644
--- a/Libraries/LibWeb/Rust/src/layout/commit.rs
+++ b/Libraries/LibWeb/Rust/src/layout/commit.rs
@@ -141,7 +141,7 @@ impl Holder {
fn placement_of(&self, link: &FragmentLink) -> (Option<u32>, usize) {
match self.fragment_index {
None => (None, 0),
- Some(index) if link.containing_block == self.node => (Some(index), self.line_index_offset),
+ Some(index) if link.placement.containing_block == self.node => (Some(index), self.line_index_offset),
Some(_) => (Some(0), 0),
}
}
@@ -214,7 +214,7 @@ 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;
+ let containing_block = link.placement.containing_block;
if !containing_block.is_invalid() {
let held_by_containing_block = recorded_holder == containing_block
|| self
@@ -231,7 +231,7 @@ impl<'tree> Commit<'_, 'tree> {
if holder.node.is_invalid() && !keeps_its_holder && (self.is_full_commit || !was_at_pass_level) {
self.pass_level_links.push(node);
}
- if let Some(inputs) = &link.abspos_layout_inputs {
+ if let Some(inputs) = &link.placement.abspos_layout_inputs {
self.out_of_flow_boxes.push((node, inputs.clone()));
}
let (containing_block_fragment, line_index_offset) = holder.placement_of(link);
@@ -273,7 +273,7 @@ impl<'tree> Commit<'_, 'tree> {
// its line root.
node_facts::kind_is_box(kind)
&& kind != NodeKind::NavigableContainerViewport
- && !link.containing_block.is_invalid()
+ && !link.placement.containing_block.is_invalid()
&& !(holder.line_root_changes.any()
&& node_facts::node_is_fragmented_inline(data, node_facts::node_style_view(data)))
&& arena.paintable_row_is_populated(node)
@@ -370,15 +370,15 @@ impl<'tree> Commit<'_, 'tree> {
) -> Option<Holder> {
let first = fragments.first().expect("a committed box has a fragment");
let link_with_merged_line_index;
- let link = if first.containing_block_line_index_offset != 0 && first.link.containing_line_box_index.is_some() {
- link_with_merged_line_index = FragmentLink {
- containing_line_box_index: first.link.containing_line_box_index.map(|index| {
- index
- + u32::try_from(first.containing_block_line_index_offset)
- .expect("a line box index fits in 32 bits")
- }),
- ..first.link.clone()
- };
+ let link = if first.containing_block_line_index_offset != 0
+ && first.link.placement.containing_line_box_index.is_some()
+ {
+ let mut link = first.link.clone();
+ if let Some(index) = link.placement.containing_line_box_index.as_mut() {
+ *index +=
+ u32::try_from(first.containing_block_line_index_offset).expect("a line box index fits in 32 bits");
+ }
+ link_with_merged_line_index = link;
&link_with_merged_line_index
} else {
first.link
@@ -410,7 +410,7 @@ impl<'tree> Commit<'_, 'tree> {
})
})
.flatten();
- if let Some(shift) = link.default_scroll_shift {
+ if let Some(shift) = link.placement.default_scroll_shift {
self.arena_mut().set_default_scroll_shift(
node,
shift.anchor,
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 6a2b116cf26..cc1308a50ba 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -4141,9 +4141,10 @@ fn compute_subtree_layout_fragments(input: LayoutStageInput<'_>, containing_bloc
fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {
let root = run.box_;
let pass = &run.pass;
- let committed_root = used_values::committed_box_from_fragment_link(pass, root)
+ let committed_root_link = pass
+ .committed_fragment_link(root)
.expect("partial relayout root must have committed geometry");
- let root_cells = committed_root.cells;
+ let root_cells = used_values::RootInputCells::of_committed_fragment_link(&committed_root_link);
let fragments = run.fragments.expect("partial relayout must build fragments");
let input = LayoutInput::new(
AvailableSpace {
@@ -4186,7 +4187,7 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {
cells: root_box.cells,
line_data: root_box.line_data,
};
- let facts_decided_by_parent = committed_root.facts_decided_by_parent;
+ let facts_decided_by_parent = run_state::FactsDecidedByParent::of_committed_link(&committed_root_link);
let placement = facts_decided_by_parent
.placement
.expect("the root of a partial relayout keeps the placement it committed");
diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs b/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs
index 28c1a3fc36e..0fca73a5fbf 100644
--- a/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs
@@ -100,6 +100,7 @@ impl ContainedBoxesRelativeToContainerPaddingBox {
fn of(link: &FragmentLink, container: &BoxesRelativeToOwnPaddingBox) -> Self {
let fragment = &link.fragment;
let content_box = link
+ .placement
.frame
.rect_to_physical(
CssPixelRect::new(
@@ -111,11 +112,11 @@ impl ContainedBoxesRelativeToContainerPaddingBox {
container.content_size,
)
.translated_by(container.content_box.location());
- let padding_box = inflated_by(content_box, physical_padding(fragment, link.frame));
+ let padding_box = inflated_by(content_box, physical_padding(fragment, link.placement.frame));
Self {
content_box,
padding_box,
- border_box: inflated_by(padding_box, physical_border_box_edges(fragment, link.frame)),
+ border_box: inflated_by(padding_box, physical_border_box_edges(fragment, link.placement.frame)),
}
}
}
@@ -166,8 +167,8 @@ pub(crate) fn contained_links(fragment: &Fragment) -> impl Iterator<Item = &Frag
.then_some(&link.fragment.children)
.into_iter()
.flatten()
- .filter(move |outer_link| outer_link.containing_block == node);
- (link.containing_block == node)
+ .filter(move |outer_link| outer_link.placement.containing_block == node);
+ (link.placement.containing_block == node)
.then_some(link)
.into_iter()
.chain(outer_links)
@@ -181,8 +182,11 @@ pub(crate) fn include_links_held_beside_their_containing_blocks(
) {
let mut held_beside: crate::fast_hash::FastMap<NodeSlotId, smallvec::SmallVec<[usize; 2]>> = Default::default();
for (index, link) in links.iter().enumerate() {
- if !link.containing_block.is_invalid() && link.containing_block != run_root {
- held_beside.entry(link.containing_block).or_default().push(index);
+ if !link.placement.containing_block.is_invalid() && link.placement.containing_block != run_root {
+ held_beside
+ .entry(link.placement.containing_block)
+ .or_default()
+ .push(index);
}
}
for index in 0..links.len() {
@@ -193,7 +197,7 @@ pub(crate) fn include_links_held_beside_their_containing_blocks(
let overflow = scrollable_overflow_of(
arena,
fragment,
- links[index].frame,
+ links[index].placement.frame,
contained_links(fragment).chain(held_beside_indices.iter().map(|&held| &links[held])),
);
if overflow != fragment.scrollable_overflow {
@@ -205,7 +209,7 @@ pub(crate) fn include_links_held_beside_their_containing_blocks(
pub(crate) fn holds_links_of_outer_containing_blocks(node: NodeSlotId, children: &[FragmentLink]) -> bool {
children
.iter()
- .any(|link| !link.containing_block.is_invalid() && link.containing_block != node)
+ .any(|link| !link.placement.containing_block.is_invalid() && link.placement.containing_block != node)
}
// NB: The nearest line-clamp container among a hidden box's ancestors is the one whose formatting context hid it.
@@ -253,8 +257,8 @@ fn inline_box_unions(
link: &FragmentLink,
content_origin: CssPixelPoint,
) -> Option<InlineBoxUnions> {
- let padding_widths = physical_padding(&link.fragment, link.frame);
- let border_widths = physical_border(&link.fragment, link.frame);
+ let padding_widths = physical_padding(&link.fragment, link.placement.frame);
+ let border_widths = physical_border(&link.fragment, link.placement.frame);
let unite = |union: &mut Option<CssPixelRect>, rect: CssPixelRect| match union {
None => *union = Some(rect),
Some(_) if rect.is_empty() => {}
@@ -422,7 +426,9 @@ pub(crate) fn scrollable_overflow_of<'link>(
if child_position == positioning::FIXED {
continue;
}
- if link.is_invisible_for_line_clamp && !hidden_content_is_scrollable_overflow(arena, fragment, child_node) {
+ if link.placement.shown_as.facts.is_invisible_for_line_clamp
+ && !hidden_content_is_scrollable_overflow(arena, fragment, child_node)
+ {
continue;
}
@@ -452,15 +458,7 @@ pub(crate) fn scrollable_overflow_of<'link>(
if box_is_scroll_container && (child_is_in_flow || child_is_floating) {
let mut normal_flow_border_box = untransformed_child_border_box;
if child_position == positioning::RELATIVE {
- let inset = sides_to_physical(
- link.frame,
- FfiPixelBox {
- top: link.inset_top,
- right: link.inset_right,
- bottom: link.inset_bottom,
- left: link.inset_left,
- },
- );
+ let inset = sides_to_physical(link.placement.frame, link.placement.insets.into());
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,
@@ -734,7 +732,7 @@ impl LayoutNodeArena {
let links_held_beside = holder_fragment
.iter()
.flat_map(|holder_fragment| holder_fragment.children.iter())
- .filter(|held| held.containing_block == node)
+ .filter(|held| held.placement.containing_block == node)
.map(|held| held.fragment.node);
let candidates = contained_links(&link.fragment)
.map(|contained_link| contained_link.fragment.node)
@@ -749,7 +747,7 @@ impl LayoutNodeArena {
self.committed_links_in_containing_block_fragment(candidate, fragment_index, &mut contained);
}
}
- scrollable_overflow_of(self, &link.fragment, link.frame, contained.iter())
+ scrollable_overflow_of(self, &link.fragment, link.placement.frame, contained.iter())
}
fn has_scrollable_overflow_in_any_fragment(&self, node: NodeSlotId) -> bool {
@@ -887,7 +885,7 @@ mod tests {
fragment.sides.content_size.width = CssPixels::from_integer(20);
fragment.sides.content_size.height = CssPixels::from_integer(20);
child_link.committed_offset.y = CssPixels::from_integer(180).into();
- child_link.containing_block = container;
+ child_link.placement.containing_block = container;
let overflow = scrollable_overflow_of(
&arena,
&container_link.fragment,
diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
index 718f771e47f..fef449bc417 100644
--- a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
@@ -89,25 +89,45 @@ pub(crate) struct Fragment {
pub(crate) children: Vec<FragmentLink>,
}
-#[derive(Clone)]
-pub(crate) struct FragmentLink {
- pub(crate) fragment: std::sync::Arc<Fragment>,
- pub(crate) committed_offset: FfiCssPixelPoint,
- pub(crate) inset_left: CssPixels,
- 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.
+/// What the layout of its parent decides about how a box shows, which the link placing the box's fragment holds.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
+pub(crate) struct ParentShowFacts {
+ /// For table cells and table-column(-group) boxes: the first grid column the box occupies and the number of grid
+ /// columns it spans, so painting can find the cells that originate in a column (CSS 2.2 §17.5.1).
pub(crate) table_column_index: u32,
pub(crate) table_column_span: u32,
+ /// 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,
+ /// The physical clip an ancestor's layout puts on the box and its contents, relative to the box's border box: empty
+ /// for a box hidden after a clamp point, and the area before the block-end content edge of a line-clamp container
+ /// for a float inside it.
pub(crate) clip_decided_by_parent: Option<CssPixelRect>,
+}
+
+impl ParentShowFacts {
+ pub(crate) fn hide_after_clamp_point(&mut self) {
+ self.is_invisible_for_line_clamp = true;
+ self.clip_decided_by_parent = Some(CssPixelRect::default());
+ }
+}
+
+/// What a link shows of its box apart from the fragment, which change what painting shows of the box while the
+/// fragment stays the same: the used margins, which the placement of the box decides, and what the parent decided
+/// about how the box shows.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
+pub(crate) struct ShownAs {
+ pub(crate) margins: geometry::Sides,
+ pub(crate) facts: ParentShowFacts,
+}
+
+/// Where and how a link places its fragment, apart from its offset.
+#[derive(Clone, PartialEq)]
+pub(crate) struct LinkPlacement {
+ pub(crate) insets: geometry::Sides,
+ pub(crate) shown_as: ShownAs,
pub(crate) containing_line_box_index: Option<u32>,
/// 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.
@@ -119,6 +139,46 @@ pub(crate) struct FragmentLink {
pub(crate) frame: geometry::Frame,
}
+impl LinkPlacement {
+ fn of_box(
+ facts: &run_state::FactsDecidedByParent,
+ cells: &used_values::RootInputCells,
+ abspos_layout_inputs: Option<std::sync::Arc<abspos_inputs::AbsposLayoutInputs>>,
+ containing_line_box_index: Option<u32>,
+ frame: geometry::Frame,
+ ) -> Self {
+ let insets = facts.used_insets;
+ Self {
+ insets: geometry::Sides {
+ top: insets.top,
+ right: insets.right,
+ bottom: insets.bottom,
+ left: insets.left,
+ },
+ shown_as: ShownAs {
+ margins: cells.margins(),
+ facts: facts.fragment_facts.show,
+ },
+ containing_line_box_index,
+ abspos_layout_inputs,
+ default_scroll_shift: facts.default_scroll_shift,
+ containing_block: facts
+ .placement
+ .map_or(crate::layout::node_data::NodeSlotId::INVALID, |placement| {
+ placement.containing_block
+ }),
+ frame,
+ }
+ }
+}
+
+#[derive(Clone)]
+pub(crate) struct FragmentLink {
+ pub(crate) fragment: std::sync::Arc<Fragment>,
+ pub(crate) committed_offset: FfiCssPixelPoint,
+ pub(crate) placement: LinkPlacement,
+}
+
fn same_allocation<T>(left: Option<&std::sync::Arc<T>>, right: Option<&std::sync::Arc<T>>) -> bool {
match (left, right) {
(None, None) => true,
@@ -278,24 +338,15 @@ impl FragmentLink {
children: Vec::new(),
}),
committed_offset: Default::default(),
- inset_left: CssPixels::default(),
- 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,
- clip_decided_by_parent: None,
- containing_line_box_index: None,
- abspos_layout_inputs: None,
- default_scroll_shift: None,
- containing_block: crate::layout::node_data::NodeSlotId::INVALID,
- frame: geometry::Frame::PHYSICAL,
+ placement: LinkPlacement {
+ insets: geometry::Sides::default(),
+ shown_as: ShownAs::default(),
+ containing_line_box_index: None,
+ abspos_layout_inputs: None,
+ default_scroll_shift: None,
+ containing_block: crate::layout::node_data::NodeSlotId::INVALID,
+ frame: geometry::Frame::PHYSICAL,
+ },
}
}
@@ -303,33 +354,10 @@ 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
- && self.clip_decided_by_parent == previous.clip_decided_by_parent
- }
-
pub(crate) fn has_same_placement(&self, previous: &FragmentLink) -> bool {
self.fragment.node == previous.fragment.node
&& self.committed_offset == previous.committed_offset
- && self.inset_left == previous.inset_left
- && 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
- && self.containing_block == previous.containing_block
- && self.frame == previous.frame
+ && self.placement == previous.placement
}
}
@@ -700,7 +728,7 @@ fn snapshot_fragment(
node: crate::layout::node_data::NodeSlotId,
mut children: Vec<FragmentLink>,
geometry: FragmentGeometry,
- fragment_facts: run_state::FragmentFactsDecidedByParent,
+ breaks: BreakFacts,
payloads: Option<Box<FragmentPayloads>>,
) -> std::sync::Arc<Fragment> {
let FragmentGeometry { cells, line_data } = geometry;
@@ -716,7 +744,7 @@ fn snapshot_fragment(
svg_text_character_cells,
line_clamp,
} = payloads.map(|payloads| *payloads).unwrap_or_default();
- if line_clamp.has_line_clamp_point && !fragment_facts.continues_in_next_fragment {
+ if line_clamp.has_line_clamp_point && !breaks.continues_in_next {
line_clamp_edge::clip_floats_at_block_end_content_edge(
pass,
node,
@@ -741,10 +769,7 @@ fn snapshot_fragment(
computed_svg_path,
svg_text_character_cells,
line_clamp,
- breaks: BreakFacts {
- continues_from_previous: fragment_facts.continues_from_previous_fragment,
- continues_in_next: fragment_facts.continues_in_next_fragment,
- },
+ breaks,
scrollable_overflow: Default::default(),
holds_links_of_outer_containing_blocks: fragment_overflow::holds_links_of_outer_containing_blocks(
node, &children,
@@ -791,16 +816,14 @@ fn fragment_of_placed_box(
arrived: Option<std::sync::Arc<Fragment>>,
children: Vec<FragmentLink>,
geometry: FragmentGeometry,
- fragment_facts: run_state::FragmentFactsDecidedByParent,
+ breaks: BreakFacts,
payloads: Option<Box<FragmentPayloads>>,
) -> std::sync::Arc<Fragment> {
let Some(arrived) = arrived else {
- return snapshot_fragment(pass, node, children, geometry, fragment_facts, payloads);
+ return snapshot_fragment(pass, node, children, geometry, breaks, payloads);
};
- let shows_box_as_placed = children.is_empty()
- && geometry.shows_box_of_fragment(&arrived)
- && arrived.breaks.continues_from_previous == fragment_facts.continues_from_previous_fragment
- && arrived.breaks.continues_in_next == fragment_facts.continues_in_next_fragment;
+ let shows_box_as_placed =
+ children.is_empty() && geometry.shows_box_of_fragment(&arrived) && arrived.breaks == breaks;
if shows_box_as_placed {
return arrived;
}
@@ -811,7 +834,7 @@ fn fragment_of_placed_box(
node,
all_children,
geometry,
- fragment_facts,
+ breaks,
Some(Box::new(FragmentPayloads::of_fragment(&arrived))),
)
}
@@ -831,105 +854,6 @@ pub(crate) struct PlacedAbsposBox {
pub(crate) border_box_block_end: CssPixels,
}
-pub(crate) struct PlacementData {
- pub(crate) committed_offset: FfiCssPixelPoint,
- pub(crate) inset_left: CssPixels,
- 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) clip_decided_by_parent: Option<CssPixelRect>,
- pub(crate) containing_line_box_index: Option<u32>,
- pub(crate) abspos_layout_inputs: Option<std::sync::Arc<abspos_inputs::AbsposLayoutInputs>>,
- pub(crate) default_scroll_shift: Option<abspos_inputs::DefaultScrollShift>,
- pub(crate) containing_block: crate::layout::node_data::NodeSlotId,
- pub(crate) frame: geometry::Frame,
-}
-
-impl PlacementData {
- fn of_box(
- facts: &run_state::FactsDecidedByParent,
- cells: &used_values::RootInputCells,
- abspos_layout_inputs: Option<std::sync::Arc<abspos_inputs::AbsposLayoutInputs>>,
- containing_line_box_index: Option<u32>,
- committed_offset: FfiCssPixelPoint,
- frame: geometry::Frame,
- ) -> Self {
- Self {
- frame,
- committed_offset,
- inset_left: facts.used_insets.left,
- 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,
- clip_decided_by_parent: facts.fragment_facts.clip_decided_by_parent,
- containing_line_box_index,
- abspos_layout_inputs,
- default_scroll_shift: facts.default_scroll_shift,
- containing_block: facts
- .placement
- .map_or(crate::layout::node_data::NodeSlotId::INVALID, |placement| {
- placement.containing_block
- }),
- }
- }
-
- /// The placement data of a child the run left unplaced, which `close()` hands on as `unplaced_child` shows it.
- fn of_unplaced_child(
- unplaced_child: &crate::layout::formatting_context::PlacedChild,
- frame: geometry::Frame,
- ) -> Self {
- Self::of_box(
- &unplaced_child.facts_decided_by_parent,
- &unplaced_child.geometry.cells,
- None,
- None,
- FfiCssPixelPoint::default(),
- frame,
- )
- }
-}
-
-fn link_fragment(fragment: std::sync::Arc<Fragment>, placement: PlacementData) -> FragmentLink {
- FragmentLink {
- fragment,
- committed_offset: placement.committed_offset,
- inset_left: placement.inset_left,
- 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,
- clip_decided_by_parent: placement.clip_decided_by_parent,
- containing_line_box_index: placement.containing_line_box_index,
- abspos_layout_inputs: placement.abspos_layout_inputs,
- default_scroll_shift: placement.default_scroll_shift,
- containing_block: placement.containing_block,
- frame: placement.frame,
- }
-}
-
/// A child the run laid out but does not place: the root fragment its layout handed its placement, and what placing
/// it would have taken.
struct ChildLeftUnplaced {
@@ -993,7 +917,7 @@ impl RunContents {
node,
scoped_descendants,
geometry,
- run_state::FragmentFactsDecidedByParent::default(),
+ BreakFacts::default(),
root_payloads,
),
payloads_past_run,
@@ -1581,8 +1505,8 @@ impl RunFragmentBuilder {
contents.holds_links_beside_their_sealed_containing_blocks;
for mut link in contents.scoped_descendants {
link.committed_offset = formatting_context::point_add(link.committed_offset, offset);
- if link.containing_block == self.root_node
- && let Some(line_index) = link.containing_line_box_index.as_mut()
+ if link.placement.containing_block == self.root_node
+ && let Some(line_index) = link.placement.containing_line_box_index.as_mut()
{
*line_index += u32::try_from(root_line_index_offset).expect("a line box index fits in 32 bits");
}
@@ -1625,7 +1549,7 @@ impl RunFragmentBuilder {
for link in inner
.top_scope_links
.iter_mut()
- .filter(|link| link.containing_block == root)
+ .filter(|link| link.placement.containing_block == root)
{
link.committed_offset = formatting_context::point_add(link.committed_offset, offset);
}
@@ -1806,16 +1730,27 @@ impl RunFragmentBuilder {
.remove(&slot)
.unwrap_or_else(|| PendingFragment::new(node));
let content_size = (geometry.cells.content_inline_size, geometry.cells.content_block_size);
- let link_placement = PlacementData::of_box(
+ let link_placement = LinkPlacement::of_box(
&facts,
&geometry.cells,
abspos_layout_inputs,
containing_line_box_index,
- committed_offset,
pass.frame,
);
- let fragment = fragment_of_placed_box(pass, node, arrived, children, geometry, facts.fragment_facts, payloads);
- let link = link_fragment(fragment.clone(), link_placement);
+ let fragment = fragment_of_placed_box(
+ pass,
+ node,
+ arrived,
+ children,
+ geometry,
+ facts.fragment_facts.breaks,
+ payloads,
+ );
+ let link = FragmentLink {
+ fragment: fragment.clone(),
+ committed_offset,
+ placement: link_placement,
+ };
self.attach(pass, &mut inner, link, containing_block);
let exports_payloads = !pending_abspos_from_placed_box.is_empty()
|| !anchor_candidates_from_placed_box.is_empty()
@@ -1976,19 +1911,21 @@ impl RunFragmentBuilder {
// subtree goes with it.
for ChildLeftUnplaced { root, unplaced_child } in std::mem::take(&mut inner.children_left_unplaced) {
let node = root.fragment.node;
- let placement = PlacementData::of_unplaced_child(&unplaced_child, pass.frame);
- inner.top_scope_links.push(link_fragment(
- fragment_of_placed_box(
+ let facts = unplaced_child.facts_decided_by_parent;
+ let placement = LinkPlacement::of_box(&facts, &unplaced_child.geometry.cells, None, None, pass.frame);
+ inner.top_scope_links.push(FragmentLink {
+ fragment: fragment_of_placed_box(
pass,
node,
Some(root.fragment),
Vec::new(),
unplaced_child.geometry,
- unplaced_child.facts_decided_by_parent.fragment_facts,
+ facts.fragment_facts.breaks,
None,
),
+ committed_offset: FfiCssPixelPoint::default(),
placement,
- ));
+ });
}
self.with_placements(pass, |placements| {
for entry in &mut payloads_past_run.pending_abspos {
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
index 89ae694ebc0..8280343fcf7 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
@@ -1112,6 +1112,7 @@ impl<'context> InlineFormattingContext<'context> {
placed_child
.facts_decided_by_parent
.fragment_facts
+ .show
.hide_after_clamp_point();
placed_child
});
@@ -2261,7 +2262,7 @@ impl<'context> InlineFormattingContext<'context> {
}
let mut fragment_facts = run_state::FragmentFactsDecidedByParent::default();
if state_at_clamp_point.is_some() {
- fragment_facts.hide_after_clamp_point();
+ fragment_facts.show.hide_after_clamp_point();
}
let laid_out_ahead = self.floats_laid_out_ahead_of_lines.borrow_mut().remove(&item.node);
let laid_out_float =
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
index 78eb66b5a61..c95c3fe33e1 100644
--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
@@ -5197,7 +5197,7 @@ impl LayoutNodeArena {
);
self.paintable_rows
.with_committed_fragment_link(node.slot_index(), node.generation(), |link| {
- link.and_then(|link| link.abspos_layout_inputs.as_deref().copied())
+ link.and_then(|link| link.placement.abspos_layout_inputs.as_deref().copied())
})
.or_else(|| self.confined_abspos_layout_inputs.get(&node).copied())
}
@@ -7638,7 +7638,7 @@ mod tests {
let allocation = arena.allocate_for_test();
let inputs = test_abspos_layout_inputs();
let mut link = fragment_tree::FragmentLink::for_test(allocation.slot);
- link.abspos_layout_inputs = Some(std::sync::Arc::new(inputs));
+ link.placement.abspos_layout_inputs = Some(std::sync::Arc::new(inputs));
arena.set_committed_fragment_link(allocation.slot, link, None);
assert!(arena.committed_fragment_link(allocation.slot).is_some());
assert_eq!(arena.saved_abspos_layout_inputs(allocation.slot), Some(inputs));
@@ -7664,7 +7664,7 @@ mod tests {
let new = arena.allocate_for_test();
let inputs = test_abspos_layout_inputs();
let mut link = fragment_tree::FragmentLink::for_test(old.slot);
- link.abspos_layout_inputs = Some(std::sync::Arc::new(inputs));
+ link.placement.abspos_layout_inputs = Some(std::sync::Arc::new(inputs));
let retained_fragment = link.fragment.clone();
arena.set_committed_fragment_link(old.slot, link, None);
diff --git a/Libraries/LibWeb/Rust/src/layout/line_clamp_edge.rs b/Libraries/LibWeb/Rust/src/layout/line_clamp_edge.rs
index 0ab0fac3712..66bf0885d63 100644
--- a/Libraries/LibWeb/Rust/src/layout/line_clamp_edge.rs
+++ b/Libraries/LibWeb/Rust/src/layout/line_clamp_edge.rs
@@ -81,16 +81,17 @@ impl ClampEdgeWalk<'_, '_> {
}
fn link_with_clipped_floats(&mut self, link: &FragmentLink) -> LinkOutcome {
- let Some(&containing_block) = self.content_boxes.get(&link.containing_block) else {
+ let Some(&containing_block) = self.content_boxes.get(&link.placement.containing_block) else {
return LinkOutcome::ContainingBlockNotEntered;
};
- if link.is_invisible_for_line_clamp {
+ if link.placement.shown_as.facts.is_invisible_for_line_clamp {
return LinkOutcome::Unchanged;
}
let fragment = &link.fragment;
let data = self.pass.arena().data(fragment.node);
let style = node_facts::node_style_view(data);
let content_box = link
+ .placement
.frame
.rect_to_physical(
CssPixelRect::new(
@@ -107,15 +108,14 @@ impl ClampEdgeWalk<'_, '_> {
.translated_by(containing_block.location());
if node_facts::node_is_floating(data, style) {
- let border_box = fragment_overflow::physical_border_box_around(content_box, fragment, link.frame);
+ let border_box = fragment_overflow::physical_border_box_around(content_box, fragment, link.placement.frame);
let clip = Some(self.area_before_block_end_edge.translated(-border_box.x, -border_box.y));
- if link.clip_decided_by_parent == clip {
+ if link.placement.shown_as.facts.clip_decided_by_parent == clip {
return LinkOutcome::Unchanged;
}
- return LinkOutcome::Changed(FragmentLink {
- clip_decided_by_parent: clip,
- ..link.clone()
- });
+ let mut link = link.clone();
+ link.placement.shown_as.facts.clip_decided_by_parent = clip;
+ return LinkOutcome::Changed(link);
}
// NB: Line clamping does not reach into a box that establishes a formatting context of its own, and a nested
diff --git a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs
index 2297f3af5d9..45ad4aa4349 100644
--- a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs
+++ b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs
@@ -438,7 +438,7 @@ impl LayoutNodeArena {
let committed = if node_facts::node_style_view(data).is_some_and(|style| style.is_absolutely_positioned()) {
self.saved_abspos_layout_inputs(node)?.containing_block
} else {
- self.with_committed_fragment_link(node, |link| link.map(|link| link.containing_block))?
+ self.with_committed_fragment_link(node, |link| link.map(|link| link.placement.containing_block))?
};
(!committed.is_invalid() && committed == self.containing_block_by_walking_ancestors(node)).then_some(committed)
}
@@ -1064,7 +1064,7 @@ mod tests {
arena.populate_paintable_row(svg_root.slot);
let plan_with_committed_containing_block = |arena: &mut LayoutNodeArena, containing_block| {
let mut link = crate::layout::fragment_tree::FragmentLink::for_test(svg_root.slot);
- link.containing_block = containing_block;
+ link.placement.containing_block = containing_block;
arena.set_committed_fragment_link(svg_root.slot, link, None);
arena.collect_partial_relayout_roots(&[svg_root.slot], &[])
};
diff --git a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
index c0f9899135a..c79a740fec8 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
@@ -388,13 +388,13 @@ fn describe_placement(link: &fragment_tree::FragmentLink) -> String {
"offset ({:?}, {:?}) insets ({:?} {:?} {:?} {:?}) line box {:?} in {:?}, abspos inputs {}",
link.committed_offset.x,
link.committed_offset.y,
- link.inset_top,
- link.inset_right,
- link.inset_bottom,
- link.inset_left,
- link.containing_line_box_index,
- link.containing_block,
- if link.abspos_layout_inputs.is_some() {
+ link.placement.insets.top,
+ link.placement.insets.right,
+ link.placement.insets.bottom,
+ link.placement.insets.left,
+ link.placement.containing_line_box_index,
+ link.placement.containing_block,
+ if link.placement.abspos_layout_inputs.is_some() {
"present"
} else {
"absent"
diff --git a/Libraries/LibWeb/Rust/src/layout/run_state.rs b/Libraries/LibWeb/Rust/src/layout/run_state.rs
index 505c29075ca..80fb87afe17 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_state.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_state.rs
@@ -230,30 +230,8 @@ pub(crate) struct BoxPlacement {
/// 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
- /// columns it spans, so painting can find the cells that originate in a column (CSS 2.2 §17.5.1).
- pub(crate) table_column_index: u32,
- pub(crate) table_column_span: u32,
- /// 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,
- /// The physical clip an ancestor's layout puts on the box and its contents, relative to the box's border box: empty
- /// for a box hidden after a clamp point, and the area before the block-end content edge of a line-clamp container
- /// for a float inside it.
- pub(crate) clip_decided_by_parent: Option<CssPixelRect>,
- /// Whether fragmentation broke the box, so that this fragment continues one in an earlier fragmentainer, or
- /// continues in a later one.
- pub(crate) continues_from_previous_fragment: bool,
- pub(crate) continues_in_next_fragment: bool,
-}
-
-impl FragmentFactsDecidedByParent {
- pub(crate) fn hide_after_clamp_point(&mut self) {
- self.is_invisible_for_line_clamp = true;
- self.clip_decided_by_parent = Some(CssPixelRect::default());
- }
+ pub(crate) show: fragment_tree::ParentShowFacts,
+ pub(crate) breaks: fragment_tree::BreakFacts,
}
/// What the parent of a box decides about the box, kept with the box by the run that holds it.
@@ -266,6 +244,30 @@ pub(crate) struct FactsDecidedByParent {
pub(crate) fragment_facts: FragmentFactsDecidedByParent,
}
+impl FactsDecidedByParent {
+ /// What the parent decided about a box, as the committed link of the box shows it in the frame of the link.
+ pub(crate) fn of_committed_link(link: &fragment_tree::FragmentLink) -> Self {
+ let insets = link.placement.insets;
+ Self {
+ placement: Some(BoxPlacement {
+ content_offset_in_containing_block: link.committed_offset,
+ containing_block: link.placement.containing_block,
+ }),
+ used_insets: UsedInsets {
+ left: insets.left,
+ right: insets.right,
+ top: insets.top,
+ bottom: insets.bottom,
+ },
+ default_scroll_shift: None,
+ fragment_facts: FragmentFactsDecidedByParent {
+ show: link.placement.shown_as.facts,
+ breaks: fragment_tree::BreakFacts::default(),
+ },
+ }
+ }
+}
+
/// What the parent of a box laid out by a run of its own keeps of the box once that run returns: its sizes, size
/// constraints and box sides in the parent's frame, its baselines, and the lines the run laid out in it.
#[derive(Clone)]
diff --git a/Libraries/LibWeb/Rust/src/layout/script_entries.rs b/Libraries/LibWeb/Rust/src/layout/script_entries.rs
index 75f89f7a44f..c7f280cbe3c 100644
--- a/Libraries/LibWeb/Rust/src/layout/script_entries.rs
+++ b/Libraries/LibWeb/Rust/src/layout/script_entries.rs
@@ -801,9 +801,9 @@ pub extern "C" fn layout_script_anchor_resolved_size(
}
arena.with_committed_fragment_link(slot, |link| {
let link = link?;
- let sizes = link.abspos_layout_inputs.as_ref()?.resolved_anchor_sizes;
+ let sizes = link.placement.abspos_layout_inputs.as_ref()?.resolved_anchor_sizes;
// NB: The sizes lie in the frame the box was laid out in, whose axes a vertical writing mode transposes.
- let (physical_width, physical_height) = if link.frame.is_transposed() {
+ let (physical_width, physical_height) = if link.placement.frame.is_transposed() {
((sizes.min_height, sizes.max_height), (sizes.min_width, sizes.max_width))
} else {
((sizes.min_width, sizes.max_width), (sizes.min_height, sizes.max_height))
diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
index 8309d870c7e..0ea0f41f28a 100644
--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
@@ -1678,8 +1678,11 @@ impl<'pass> TableFormattingContext<'pass> {
.cells
.iter()
.map(|cell| run_state::FragmentFactsDecidedByParent {
- table_column_index: cell.column_index as u32,
- table_column_span: cell.column_span as u32,
+ show: fragment_tree::ParentShowFacts {
+ table_column_index: cell.column_index as u32,
+ table_column_span: cell.column_span as u32,
+ ..fragment_tree::ParentShowFacts::default()
+ },
..run_state::FragmentFactsDecidedByParent::default()
})
.collect();
@@ -3062,7 +3065,7 @@ impl<'pass> TableFormattingContext<'pass> {
// out like any other cell (with no inline size, see remove_collapsed_columns), and painting skips it.
// https://www.w3.org/TR/CSS22/tables.html#dynamic-effects
let hidden_by_collapsed_columns = self.visible_spanned_columns(cell) == 0;
- self.cell_fragment_facts[cell_index].hidden_by_collapsed_columns = hidden_by_collapsed_columns;
+ self.cell_fragment_facts[cell_index].show.hidden_by_collapsed_columns = hidden_by_collapsed_columns;
let height = style.height();
if !self.rows[cell.row_index].is_collapsed && height.is_length() {
let offsets = cell_box.border_box_top(collapsed) + cell_box.border_box_bottom(collapsed);
@@ -3740,8 +3743,11 @@ impl<'pass> TableFormattingContext<'pass> {
CssPixels::default()
};
let fragment_facts = run_state::FragmentFactsDecidedByParent {
- table_column_index: start as u32,
- table_column_span: (end - start) as u32,
+ show: fragment_tree::ParentShowFacts {
+ table_column_index: start as u32,
+ table_column_span: (end - start) as u32,
+ ..fragment_tree::ParentShowFacts::default()
+ },
..run_state::FragmentFactsDecidedByParent::default()
};
let (column_node, column_box) = &self.column_group_and_column_boxes[placement_index];
diff --git a/Libraries/LibWeb/Rust/src/layout/used_values.rs b/Libraries/LibWeb/Rust/src/layout/used_values.rs
index 5877f9b6d64..f78d10deee1 100644
--- a/Libraries/LibWeb/Rust/src/layout/used_values.rs
+++ b/Libraries/LibWeb/Rust/src/layout/used_values.rs
@@ -229,6 +229,16 @@ impl RootInputCells {
}
}
+ /// The used margins of the box.
+ pub(crate) fn margins(&self) -> geometry::Sides {
+ geometry::Sides {
+ top: self.margin_top,
+ right: self.margin_right,
+ bottom: self.margin_bottom,
+ left: self.margin_left,
+ }
+ }
+
/// 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 {
@@ -242,12 +252,13 @@ impl RootInputCells {
/// 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 sides = &link.fragment.sides;
+ let margins = link.placement.shown_as.margins;
self.set_content_inline_size(sides.content_size.width);
self.set_content_block_size(sides.content_size.height);
- 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.margin_left = margins.left;
+ self.margin_right = margins.right;
+ self.margin_top = margins.top;
+ self.margin_bottom = margins.bottom;
self.border_left = sides.border.left;
self.border_right = sides.border.right;
self.border_top = sides.border.top;
@@ -688,39 +699,3 @@ pub(crate) fn cells_before_sizing(
cells
}
-
-/// The input cells of a box and what its parent decided about it, as its committed fragment link has them in the frame
-/// of the link, which a run adopts as they are.
-pub(crate) struct CommittedBox {
- pub(crate) cells: RootInputCells,
- pub(crate) facts_decided_by_parent: super::run_state::FactsDecidedByParent,
-}
-
-pub(crate) fn committed_box_from_fragment_link(pass: &LayoutPass<'_>, node: Node) -> Option<CommittedBox> {
- let link = pass.committed_fragment_link(node)?;
-
- Some(CommittedBox {
- 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,
- containing_block: link.containing_block,
- }),
- used_insets: super::run_state::UsedInsets {
- left: link.inset_left,
- right: link.inset_right,
- top: link.inset_top,
- bottom: link.inset_bottom,
- },
- default_scroll_shift: None,
- fragment_facts: super::run_state::FragmentFactsDecidedByParent {
- table_column_index: link.table_column_index,
- table_column_span: link.table_column_span,
- hidden_by_collapsed_columns: link.hidden_by_collapsed_columns,
- is_invisible_for_line_clamp: link.is_invisible_for_line_clamp,
- clip_decided_by_parent: link.clip_decided_by_parent,
- ..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 aa168cd8b3c..4797250e513 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.hidden_by_collapsed_columns,
+ link.placement.shown_as.facts.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 4a5e0e7a649..fd5607ff126 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
@@ -235,7 +235,7 @@ impl<'a> PaintableCommit<'a> {
previous_offset: Option<used_values::FfiCssPixelPoint>,
) -> ReplacedCommittedFragmentLink {
let fragment = &link.fragment;
- let frame = link.frame;
+ let frame = link.placement.frame;
let new_content_size =
frame.size_to_physical(fragment.sides.content_size.width, fragment.sides.content_size.height);
let new_offset: used_values::FfiCssPixelPoint = if frame.is_physical() {
@@ -287,7 +287,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);
+ link_shows_box_the_same = link.placement.shown_as == old_link.placement.shown_as;
(
old_link.fragment.identity,
frame.size_to_physical(
@@ -546,7 +546,7 @@ impl<'a> PaintableCommit<'a> {
node: formatting_context::Node,
link: Option<&fragment_tree::FragmentLink>,
) -> NodeSlotId {
- match link.map(|link| link.containing_block) {
+ match link.map(|link| link.placement.containing_block) {
Some(containing_block) if !containing_block.is_invalid() => containing_block,
_ => self.arena().containing_block_by_walking_ancestors(node),
}
diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs b/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs
index e60dae70627..64e8b2632bf 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs
@@ -107,15 +107,7 @@ pub(crate) fn committed_margin(arena: &impl GeometryRead, slot: NodeSlotId) -> F
let frame = committed_frame(arena, slot);
arena.with_committed_fragment_link(slot, |link| {
link.map_or_else(FfiPixelBox::default, |link| {
- sides_to_physical(
- frame,
- FfiPixelBox {
- top: link.margin_top,
- right: link.margin_right,
- bottom: link.margin_bottom,
- left: link.margin_left,
- },
- )
+ sides_to_physical(frame, link.placement.shown_as.margins.into())
})
})
}
@@ -146,15 +138,7 @@ pub(crate) fn committed_inset(arena: &impl GeometryRead, slot: NodeSlotId) -> Ff
let frame = committed_frame(arena, slot);
arena.with_committed_fragment_link(slot, |link| {
link.map_or_else(FfiPixelBox::default, |link| {
- sides_to_physical(
- frame,
- FfiPixelBox {
- top: link.inset_top,
- right: link.inset_right,
- bottom: link.inset_bottom,
- left: link.inset_left,
- },
- )
+ sides_to_physical(frame, link.placement.insets.into())
})
})
}
@@ -168,14 +152,21 @@ 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.hidden_by_collapsed_columns))
+ arena.with_committed_fragment_link(slot, |link| {
+ link.is_some_and(|link| link.placement.shown_as.facts.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.table_column_index, link.table_column_span))
+ link.map_or((0, 0), |link| {
+ (
+ link.placement.shown_as.facts.table_column_index,
+ link.placement.shown_as.facts.table_column_span,
+ )
+ })
})
}
@@ -262,7 +253,7 @@ pub(crate) fn committed_svg_text_character_cells(
pub(crate) fn committed_containing_line_box_index(arena: &impl GeometryRead, slot: NodeSlotId) -> Option<usize> {
arena.with_committed_fragment_link(slot, |link| {
- link.and_then(|link| link.containing_line_box_index)
+ link.and_then(|link| link.placement.containing_line_box_index)
.map(|index| index as usize)
})
}
@@ -473,7 +464,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 = last.link.margin_bottom;
+ margin.bottom = last.link.placement.shown_as.margins.bottom;
padding.bottom = fragment.sides.padding.bottom;
border.bottom = fragment.sides.border.bottom;
}
diff --git a/Libraries/LibWeb/Rust/src/painting/published_frame.rs b/Libraries/LibWeb/Rust/src/painting/published_frame.rs
index c048a5ae799..d1766ef83d1 100644
--- a/Libraries/LibWeb/Rust/src/painting/published_frame.rs
+++ b/Libraries/LibWeb/Rust/src/painting/published_frame.rs
@@ -293,13 +293,13 @@ mod tests {
let node = arena.allocate_for_test().slot;
arena.populate_paintable_row(node);
let mut link = fragment_tree::FragmentLink::for_test(node);
- link.inset_left = CssPixels::from_integer(10);
+ link.placement.insets.left = CssPixels::from_integer(10);
arena.set_committed_fragment_link(node, link.clone(), None);
arena.paintable_rows_mut().paintable_data_mut(node).offset.x = CssPixels::from_integer(10).into();
arena.committed_side_data_mut(node).inline_content = Some(Default::default());
let published = arena.publish_rows();
- link.inset_left = CssPixels::from_integer(20);
+ link.placement.insets.left = CssPixels::from_integer(20);
arena.set_committed_fragment_link(node, link, None);
arena.paintable_rows_mut().paintable_data_mut(node).offset.x = CssPixels::from_integer(20).into();
arena.committed_side_data_mut(node).inline_content = None;
@@ -309,7 +309,7 @@ mod tests {
CssPixels::from_integer(10).into()
);
assert_eq!(
- published.with_committed_fragment_link(node, |link| link.map(|link| link.inset_left)),
+ published.with_committed_fragment_link(node, |link| link.map(|link| link.placement.insets.left)),
Some(CssPixels::from_integer(10))
);
assert!(published.committed_side_data(node).inline_content.is_some());
@@ -318,7 +318,7 @@ mod tests {
CssPixels::from_integer(20).into()
);
assert_eq!(
- arena.with_committed_fragment_link(node, |link| link.map(|link| link.inset_left)),
+ arena.with_committed_fragment_link(node, |link| link.map(|link| link.placement.insets.left)),
Some(CssPixels::from_integer(20))
);
assert!(arena.committed_side_data(node).inline_content.is_none());
@@ -352,7 +352,7 @@ mod tests {
arena.paintable_rows_mut().paintable_data_mut(node).offset.x = CssPixels::from_integer(index as i64).into();
if index % 2 == 0 {
let mut link = fragment_tree::FragmentLink::for_test(node);
- link.inset_top = CssPixels::from_integer(index as i64);
+ link.placement.insets.top = CssPixels::from_integer(index as i64);
arena.set_committed_fragment_link(node, link, None);
}
}
@@ -406,8 +406,8 @@ mod tests {
}
assert_eq!(source.paintable_data(node), arena.live_paintable_data(node));
assert_eq!(
- source.with_committed_fragment_link(node, |link| link.map(|link| link.inset_top)),
- arena.with_committed_fragment_link(node, |link| link.map(|link| link.inset_top))
+ source.with_committed_fragment_link(node, |link| link.map(|link| link.placement.insets.top)),
+ arena.with_committed_fragment_link(node, |link| link.map(|link| link.placement.insets.top))
);
assert!(*source.committed_side_data(node) == *arena.committed_side_data(node));
assert_eq!(source.paint_damage_of_row(node), arena.paint_damage_of_row(node));
diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs
index fe03b2a75c2..b1daaf44654 100644
--- a/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs
+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs
@@ -204,7 +204,9 @@ impl BoxFacts {
.collect();
facts.css_clip = super::node_values::compute_css_clip_data(layout_arena, slot, pixel_ratio);
facts.clip_decided_by_parent = layout_arena
- .with_committed_fragment_link(slot, |link| link.and_then(|link| link.clip_decided_by_parent))
+ .with_committed_fragment_link(slot, |link| {
+ link.and_then(|link| link.placement.shown_as.facts.clip_decided_by_parent)
+ })
.map(|clip_relative_to_border_box| {
let border_box =
crate::painting::paintable_geometry::first_fragment_border_box_rect(layout_arena, slot);