Truly independent web browser
LibWeb: Size an abspos containing block from its box metrics
Aliaksandr Kalenik1ded0685496f
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rsindex 72f93531838..0ad27e4a69f 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs@@ -106,15 +106,18 @@ pub(crate) struct ContainingBlockGeometry {}impl ContainingBlockGeometry {- pub(crate) fn from_used_values(used: &UsedValues, content_origin_in_entry_space: FfiCssPixelPoint) -> Self {+ pub(crate) fn from_box_metrics(+ metrics: &impl BoxMetricCells,+ content_origin_in_entry_space: FfiCssPixelPoint,+ ) -> Self {Self {content_origin_in_entry_space,- padding_left: used.padding_left.get(),- padding_right: used.padding_right.get(),- padding_top: used.padding_top.get(),- padding_bottom: used.padding_bottom.get(),- content_inline_size: used.content_inline_size.get(),- content_block_size: used.content_block_size.get(),+ padding_left: metrics.padding_left(),+ padding_right: metrics.padding_right(),+ padding_top: metrics.padding_top(),+ padding_bottom: metrics.padding_bottom(),+ content_inline_size: metrics.content_inline_size(),+ content_block_size: metrics.content_block_size(),}}@@ -147,16 +150,16 @@ impl<'pass> AbsposEngine<'pass> {entry: &abspos_inputs::PendingAbsposChild,) -> ContainingBlockGeometry {let containing_block = entry.containing_block();- let Some(containing_block_used) = self.records.used_values_if_owned(containing_block) else {+ let Some(containing_block_metrics) = self.records.box_metrics_of_if_owned(containing_block) else {panic!(- "no owned record for the containing block of slot {} (cb slot {})",+ "the run holds no containing block for slot {} (cb slot {})",entry.child_box.slot_index(),containing_block.slot_index());};let content_origin_in_entry_space =self.origin_of_containing_block_in_entry_space(containing_block, entry.coordinate_space_box);- ContainingBlockGeometry::from_used_values(containing_block_used, content_origin_in_entry_space)+ ContainingBlockGeometry::from_box_metrics(&containing_block_metrics, content_origin_in_entry_space)}fn origin_of_containing_block_in_entry_space(&self, containing_block: Node, entry_space: Node) -> FfiCssPixelPoint {@@ -784,7 +787,7 @@ impl AbsposEngine<'_> {}let containing_block_geometry = match entry_containing_block_geometry {Some(geometry) => *geometry,- None => ContainingBlockGeometry::from_used_values(self.used(containing_block), FfiCssPixelPoint::default()),+ None => ContainingBlockGeometry::from_box_metrics(self.used(containing_block), FfiCssPixelPoint::default()),};let default_anchor_box = if style.has_position_anchor() {self.anchor_lookup(node, style.position_anchor_name())diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex dc5fba56dfb..7809513cd92 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -337,7 +337,7 @@ pub(crate) fn lay_out_pending_abspos_children(}}-/// Runs `body` with a run in the frame `node` establishes, with the record of `node` moved into that frame.+/// Runs `body` with a run in the frame `node` establishes, with the box metrics of `node` moved into that frame.pub(crate) fn in_frame_established_by<R>(run: &FormattingContextRun,node: Node,@@ -348,15 +348,10 @@ pub(crate) fn in_frame_established_by<R>(if own_frame == parent_frame {return body(run);}- let used = run.records.used_values_if_owned(node);- if let Some(used) = used {- used.move_box_metrics_to_frame(parent_frame, own_frame);- }+ run.records.move_box_metrics_to_frame(node, parent_frame, own_frame);let framed_run = run.in_frame_of(own_frame);let result = body(&framed_run);- if let Some(used) = used {- used.move_box_metrics_to_frame(own_frame, parent_frame);- }+ run.records.move_box_metrics_to_frame(node, own_frame, parent_frame);result}diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rsindex ca39ce108c1..851f4ad098c 100644--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs@@ -1020,6 +1020,37 @@ impl<'arena> RunRecords<'arena> {Some(BoxMetrics::LaidOutByItsOwnRun(laid_out))}+ /// Moves the sizes, size constraints and box sides this run holds for `node`, if it holds the box, from frame `from`+ /// to frame `to`.+ pub(crate) fn move_box_metrics_to_frame(&self, node: Node, from: geometry::Frame, to: geometry::Frame) {+ let index = match self.held_box(node) {+ None => return,+ Some(HeldBox::RootWithRecord) => {+ if let Some(root_used) = &self.root_used {+ root_used.move_box_metrics_to_frame(from, to);+ }+ return;+ }+ Some(HeldBox::Kept(index)) => index,+ };+ let mut kept_boxes = self.scratch.kept_boxes.borrow_mut();+ let KeptBoxHolding::Record {+ record,+ handed_back_by_its_run,+ } = &mut kept_boxes[index as usize].holding;+ // SAFETY: This run registered the record, and it stays on the stack until this run returns.+ unsafe { self.scratch.run_record_stack.get(*record).as_ref() }.move_box_metrics_to_frame(from, to);+ if let Some(laid_out) = handed_back_by_its_run {+ // NB: The baselines stay those of the parent's frame, which every reader of them is in.+ laid_out.cells = used_values::UsedValuesCellState {+ inputs: laid_out.cells,+ baselines: laid_out.baselines,+ }+ .in_frame(from, to)+ .inputs;+ }+ }+/// What the fragment of `node` shows of the box's own layout, which finishes the lines this run laid out in it.#[track_caller]pub(crate) fn fragment_geometry_of(