Skip to content

Truly independent web browser

LibWeb: Keep containing block cells with the boxes placed in a run

Aliaksandr Kalenik595ec885bdf8
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
index 92929619f31..9bab26bbff1 100644
--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
@@ -151,11 +151,11 @@ impl<'pass> AbsposEngine<'pass> {
) -> ContainingBlockGeometry {
let containing_block = entry.containing_block();
let Some(containing_block_cells) = self
- .records
- .box_cells_in_frame_if_owned(containing_block, self.callbacks.frame)
+ .placed_box_fragments()
+ .cells_of_placed_containing_block(containing_block, self.callbacks.frame)
else {
panic!(
- "the run holds no containing block for slot {} (cb slot {})",
+ "the run placed no containing block for slot {} (cb slot {})",
entry.child_box.slot_index(),
containing_block.slot_index()
);
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 06db4abca74..fa70f5f776c 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -400,7 +400,7 @@ pub(crate) fn place_child_in_containing_block(
);
return None;
};
- fragments.note_placed_box(node, placement);
+ fragments.note_placed_box(node, placement, cells_kept_for_contained_abspos(run, node));
let facts_decided_by_parent = records.facts_decided_by_parent_of(node);
debug_assert!(
fragment_arrival
@@ -498,6 +498,22 @@ pub(crate) fn place_child_in_containing_block(
})
}
+/// The sizes and box sides of `node`, which `run` is placing, where the box may be the containing block of absolutely
+/// positioned boxes the run lays out at its placement or later.
+fn cells_kept_for_contained_abspos(run: &FormattingContextRun, node: Node) -> Option<fragment_tree::CellsInFrame> {
+ let data = run.callbacks.node_data(node);
+ let may_contain_abspos = node_facts::has_flag(data, NodeFlag::EstablishesAbsolutePositionContainingBlock)
+ || node_facts::has_flag(data, NodeFlag::EstablishesFixedPositionContainingBlock)
+ || data.parent.get().is_invalid();
+ may_contain_abspos.then(|| fragment_tree::CellsInFrame {
+ cells: run
+ .records
+ .box_cells_in_frame_if_owned(node, run.callbacks.frame)
+ .expect("a run holds the boxes it places"),
+ frame: run.callbacks.frame,
+ })
+}
+
/// Places an in-flow child whose committed subtree is reused as it is, with the committed fragment it was laid out
/// to. The child's record must already hold what its layout left in it.
pub(crate) fn place_reused_child(
@@ -518,7 +534,7 @@ pub(crate) fn place_reused_child(
.fragments
.as_deref()
.expect("a reused subtree is placed by a run that builds fragments");
- fragments.note_placed_box(node, placement);
+ fragments.note_placed_box(node, placement, cells_kept_for_contained_abspos(run, node));
fragments.attach_committed_fragment(
node,
fragment,
@@ -3699,7 +3715,7 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {
let placement = facts_decided_by_parent
.placement
.expect("the root of a partial relayout keeps the placement it committed");
- fragments.note_placed_box(root, placement);
+ fragments.note_placed_box(root, placement, cells_kept_for_contained_abspos(run, root));
// The retained offset already includes relative positioning. Publish it directly instead
// of applying placement adjustments a second time.
let Some(fragment_tree::ChildFragmentArrival::RunRoot {
diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
index abec587b94b..38c2b37b0b9 100644
--- a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
@@ -407,10 +407,19 @@ fn propagate_payload_toward_run_root_space<Payload: PropagatedPayload>(
}
}
-/// Where a run placed each box it placed so far, keyed by slot.
+/// The sizes and box sides of a box, in the frame `frame`.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub(crate) struct CellsInFrame {
+ pub(crate) cells: used_values::RootInputCells,
+ pub(crate) frame: geometry::Frame,
+}
+
+/// Where a run placed each box it placed so far, and the sizes and box sides of each placed box that may be the
+/// containing block of absolutely positioned boxes, as the run placed it. Both are keyed by slot.
#[derive(Default)]
pub(crate) struct PlacedBoxes {
placements: HashMap<u32, run_records::BoxPlacement>,
+ cells_of_abspos_containing_blocks: HashMap<u32, CellsInFrame>,
}
impl PlacedBoxes {
@@ -988,19 +997,38 @@ impl RunFragmentBuilder {
self.root_node
}
- /// Notes that the run placed `node` in `placement`, which is final.
+ /// Notes that the run placed `node` in `placement`, which is final, with the sizes and box sides
+ /// `cells_for_contained_abspos` of a box that may be the containing block of absolutely positioned boxes.
pub(crate) fn note_placed_box(
&self,
node: crate::layout::node_data::NodeSlotId,
placement: run_records::BoxPlacement,
+ cells_for_contained_abspos: Option<CellsInFrame>,
) {
- let previous = self
+ let placed_boxes = &mut self.inner.borrow_mut().placed_boxes;
+ let previous = placed_boxes.placements.insert(node.slot_index(), placement);
+ debug_assert!(previous.is_none(), "a box is placed once");
+ if let Some(cells) = cells_for_contained_abspos {
+ placed_boxes
+ .cells_of_abspos_containing_blocks
+ .insert(node.slot_index(), cells);
+ }
+ }
+
+ /// The sizes and box sides of `containing_block`, a box the run placed that may be the containing block of
+ /// absolutely positioned boxes, read in frame `reader`.
+ pub(crate) fn cells_of_placed_containing_block(
+ &self,
+ containing_block: crate::layout::node_data::NodeSlotId,
+ reader: geometry::Frame,
+ ) -> Option<used_values::RootInputCells> {
+ let kept = *self
.inner
- .borrow_mut()
+ .borrow()
.placed_boxes
- .placements
- .insert(node.slot_index(), placement);
- debug_assert!(previous.is_none(), "a box is placed once");
+ .cells_of_abspos_containing_blocks
+ .get(&containing_block.slot_index())?;
+ Some(kept.cells.in_frame(kept.frame, reader))
}
/// Where the run placed `node`, if it placed the box.