Skip to content

Truly independent web browser

LibWeb: Resolve insets into the record of the box they belong to

Aliaksandr Kalenike3caf60ee57f
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
index ed9d25afdf7..c10407bb2a2 100644
--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
@@ -2165,7 +2165,7 @@ impl AbsposEngine<'_> {
let used = sized.record;
used.set_content_inline_size(auto_px_value(used_inline_size));
- self.set_used_inline_insets(node, left, right);
+ Self::set_used_inline_insets(sized, left, right);
used.update(|cells| {
cells.margin_left = auto_px_value(margin_left);
cells.margin_right = auto_px_value(margin_right);
@@ -2180,7 +2180,6 @@ impl AbsposEngine<'_> {
static_position_rect: abspos_inputs::StaticPositionRect,
resolved_anchor_insets: Option<&formatting_context::ResolvedAnchorInsets>,
) {
- let node = sized.node;
let sizing = self.sizing();
// NB: A stretch inline size fills the inset-modified containing block, which replaced element sizing does not
// know about.
@@ -2220,7 +2219,7 @@ impl AbsposEngine<'_> {
);
let used = sized.record;
- self.set_used_inline_insets(node, solution.start, solution.end);
+ Self::set_used_inline_insets(sized, solution.start, solution.end);
used.update(|cells| {
cells.margin_left = solution.margin_start;
cells.margin_right = solution.margin_end;
@@ -2228,16 +2227,22 @@ impl AbsposEngine<'_> {
used.set_content_inline_size(inline_size);
}
- fn set_used_inline_insets(&self, node: Node, left: CssPixels, right: CssPixels) {
- let insets = self.records.used_insets_of(node);
- self.records
- .set_used_insets(node, run_records::UsedInsets { left, right, ..insets });
+ fn set_used_inline_insets(sized: sizing_context::SizedRecord<'_>, left: CssPixels, right: CssPixels) {
+ let insets = &sized.record.record().used_insets;
+ insets.set(run_records::UsedInsets {
+ left,
+ right,
+ ..insets.get()
+ });
}
- fn set_used_block_insets(&self, node: Node, top: CssPixels, bottom: CssPixels) {
- let insets = self.records.used_insets_of(node);
- self.records
- .set_used_insets(node, run_records::UsedInsets { top, bottom, ..insets });
+ fn set_used_block_insets(sized: sizing_context::SizedRecord<'_>, top: CssPixels, bottom: CssPixels) {
+ let insets = &sized.record.record().used_insets;
+ insets.set(run_records::UsedInsets {
+ top,
+ bottom,
+ ..insets.get()
+ });
}
fn compute_inline_size(
@@ -2646,7 +2651,7 @@ impl AbsposEngine<'_> {
if !style.height().is_intrinsic_sizing_constraint() {
used.update(|cells| cells.has_definite_block_size = true);
}
- self.set_used_block_insets(node, auto_px_value(solution.top), auto_px_value(solution.bottom));
+ Self::set_used_block_insets(sized, auto_px_value(solution.top), auto_px_value(solution.bottom));
// NOTE: solve_non_replaced_block_once() already resolved these against the bases the C++ layout code used:
// the insets against the containing block's block size, but the margins against its inline size.
used.update(|cells| {
@@ -2664,7 +2669,6 @@ impl AbsposEngine<'_> {
pass: BlockSizePass,
resolved_anchor_insets: Option<&formatting_context::ResolvedAnchorInsets>,
) {
- let node = sized.node;
// NB: As for the inline axis, a stretch block size fills the inset-modified containing block.
let mut block_size = if self.style_of(sized).height().is_stretch() {
self.calculate_inner_size(
@@ -2744,7 +2748,7 @@ impl AbsposEngine<'_> {
if !style.height().is_intrinsic_sizing_constraint() {
used.update(|cells| cells.has_definite_block_size = true);
}
- self.set_used_block_insets(node, solution.start, solution.end);
+ Self::set_used_block_insets(sized, solution.start, solution.end);
used.update(|cells| {
cells.margin_top = solution.margin_start;
cells.margin_bottom = solution.margin_end;
@@ -2870,7 +2874,6 @@ impl<'pass> AbsposEngine<'pass> {
inputs: abspos_inputs::AbsposLayoutInputs,
inside_layout: Option<InsideLayoutBlockSizes>,
) {
- let node = sized.node;
self.install_resolved_anchor_sizes(sized, &inputs);
let (available_space, constraints) = out_of_flow_root_space(inputs);
let containing_block_size = geometry::LogicalSize {
@@ -2973,7 +2976,7 @@ impl<'pass> AbsposEngine<'pass> {
margin_box_size,
inline_start_is_low_side,
);
- self.set_used_inline_insets(node, inset, inline_size - inset - margin_box_size);
+ Self::set_used_inline_insets(sized, inset, inline_size - inset - margin_box_size);
}
if inputs.containing_block_info.block_alignment.is_none()
&& !style.inset_top().is_auto()
@@ -2992,7 +2995,7 @@ impl<'pass> AbsposEngine<'pass> {
margin_box_size,
true,
);
- self.set_used_block_insets(node, inset, block_size - inset - margin_box_size);
+ Self::set_used_block_insets(sized, inset, block_size - inset - margin_box_size);
}
if let Some(inline_alignment) = inputs.containing_block_info.inline_alignment
&& let Some((start_inset, end_inset)) = alignment_insets(
@@ -3019,8 +3022,8 @@ impl<'pass> AbsposEngine<'pass> {
_ => None,
};
if let Some(inset) = inset {
- self.set_used_inline_insets(
- node,
+ Self::set_used_inline_insets(
+ sized,
inset,
containing_block_size.inline_size - inset - margin_box_size,
);
@@ -3049,7 +3052,11 @@ impl<'pass> AbsposEngine<'pass> {
_ => None,
};
if let Some(inset) = inset {
- self.set_used_block_insets(node, inset, containing_block_size.block_size - inset - margin_box_size);
+ Self::set_used_block_insets(
+ sized,
+ inset,
+ containing_block_size.block_size - inset - margin_box_size,
+ );
}
}
}
@@ -3165,7 +3172,11 @@ impl<'pass> AbsposEngine<'pass> {
ChildLayoutOutcome::Created(result) => result
.out_of_flow_root_used_insets
.expect("the run of an absolutely positioned box gives it used insets"),
- ChildLayoutOutcome::Skipped { .. } => self.records.used_insets_of(node),
+ ChildLayoutOutcome::Skipped {
+ out_of_flow_root_used_insets,
+ ..
+ } => out_of_flow_root_used_insets
+ .expect("the layout of a skipped absolutely positioned box gives it used insets"),
};
let metrics = laid_out_box.cells;
@@ -3214,7 +3225,6 @@ impl<'pass> AbsposEngine<'pass> {
used_insets.bottom = style.inset_bottom().to_px(containing_block_size.block_size);
}
}
- self.records.set_used_insets(node, used_insets);
let mut placed_child = formatting_context::PlacedChild::of_laid_out_box(&laid_out_box);
placed_child.facts_decided_by_parent.used_insets = used_insets;
placed_child.facts_decided_by_parent.default_scroll_shift = default_scroll_shift;
@@ -3246,8 +3256,6 @@ impl<'pass> AbsposEngine<'pass> {
.keep_child_for_its_run(&self.callbacks, child_box, ContainingBlockConstraints::default());
let (mut inputs, default_scroll_shift) = self.pending_child_layout_inputs(&mut child);
inputs.position_option = position_option.choice();
- self.records
- .set_default_scroll_shift(child_box, Some(default_scroll_shift));
let border_box_block_end = self.layout_element(run, child_box, cells, inputs, Some(default_scroll_shift));
drop(position_option);
border_box_block_end
@@ -3741,7 +3749,6 @@ impl<'pass> AbsposEngine<'pass> {
.callbacks
.committed_fragment_link(node)
.and_then(|link| link.default_scroll_shift);
- self.records.set_default_scroll_shift(node, 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 0c16f25db02..23d3a031ce9 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -906,7 +906,7 @@ impl<'pass> BlockFormattingContext<'pass> {
block_container: BlockContainer<'pass>,
) -> abspos_engine::InFlowBoxInsets {
let block_container_used = block_container.used;
- let insets = abspos_engine::compute_inset_native(
+ abspos_engine::compute_inset_native(
run,
node,
block_container_used,
@@ -915,9 +915,7 @@ impl<'pass> BlockFormattingContext<'pass> {
block_size: block_container_used.content_block_size.get(),
},
block_container.percentage_block_insets_have_definite_basis,
- );
- run.records.keep_in_flow_box_insets(node, insets);
- insets
+ )
}
fn containing_block_rect(
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
index 6aeca45c36d..1fe679f9bbe 100644
--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
@@ -3121,7 +3121,6 @@ impl<'pass> FlexFormattingContext<'pass> {
},
run.percentage_block_insets_of_root_children_have_definite_basis(),
);
- run.records.keep_in_flow_box_insets(node, insets);
(fragment_arrival, placed_item.with_in_flow_box_insets(insets))
}
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index e8e753911e9..a72b22f22bd 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -1115,7 +1115,11 @@ pub(crate) struct RunOutputs {
}
pub(crate) enum ChildLayoutOutcome {
- Skipped { depends_on_percentage_block_size: bool },
+ Skipped {
+ depends_on_percentage_block_size: bool,
+ /// For an absolutely positioned child, the used values of its inset properties.
+ out_of_flow_root_used_insets: Option<run_records::UsedInsets>,
+ },
Created(ChildLayoutResult),
}
@@ -1126,6 +1130,7 @@ impl ChildLayoutOutcome {
match self {
Self::Skipped {
depends_on_percentage_block_size,
+ ..
} => *depends_on_percentage_block_size,
Self::Created(result) => result.depends_on_percentage_block_size,
}
@@ -2478,7 +2483,7 @@ fn lay_out_run_root_and_contents<'pass>(
content_block_size_for_aspect_ratio_minimum: result.content_block_size_for_aspect_ratio_minimum,
}),
);
- result.out_of_flow_root_used_insets = Some(run.records.used_insets_of(run.box_));
+ result.out_of_flow_root_used_insets = Some(run.root_record().record().used_insets.get());
}
ParticipationInParentFormattingContext::Item => {
if run_reads_content_block_size_adopted_after_it(fc_type, &input)
@@ -2815,8 +2820,9 @@ pub(crate) fn layout_inside_child_with_input_cells(
if let Some(used) = record_kept_by_parent {
child_input_cells.apply_to_record(used);
}
- let skipped = || ChildLayoutOutcome::Skipped {
+ let skipped = |out_of_flow_root_used_insets| ChildLayoutOutcome::Skipped {
depends_on_percentage_block_size: run.sizing().skipped_child_depends_on_percentage_block_size(child),
+ out_of_flow_root_used_insets,
};
if !force_independent_context_run
&& !facts.node_has_size_containment()
@@ -2864,7 +2870,7 @@ pub(crate) fn layout_inside_child_with_input_cells(
run.records.note_child_handed_back(child);
}
return ChildLayout {
- outcome: skipped(),
+ outcome: skipped(None),
fragment_arrival,
laid_out_box,
};
@@ -2886,7 +2892,12 @@ pub(crate) fn layout_inside_child_with_input_cells(
}
};
size_skipped_independent_root(run, parent_block, child, used, &input);
- return ChildLayout::of_child_sized_in_parent_run(skipped(), used);
+ let out_of_flow_root_used_insets = matches!(
+ input.participation,
+ ParticipationInParentFormattingContext::AbsolutelyPositioned(_)
+ )
+ .then(|| used.used_insets.get());
+ return ChildLayout::of_child_sized_in_parent_run(skipped(out_of_flow_root_used_insets), used);
}
let ChildRunPlan {
diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
index a1972783938..108724bb242 100644
--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
@@ -4495,7 +4495,6 @@ impl<'pass> GridFormattingContext<'pass> {
area.size,
run.percentage_block_insets_of_root_children_have_definite_basis(),
);
- run.records.keep_in_flow_box_insets(item.box_, insets);
let placed_item = placed_item.with_in_flow_box_insets(insets);
if self.item_participates_in_row_baseline_alignment(item)
|| self.item_participates_in_column_baseline_alignment(item)
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
index 8ceae018d77..fc6a4335b42 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
@@ -1367,7 +1367,7 @@ impl<'context> InlineFormattingContext<'context> {
/// Resolves the insets of `node`, an in-flow box in this context's lines, and keeps them for the box.
pub(crate) fn compute_inset(&self, node: Node) -> abspos_engine::InFlowBoxInsets {
let used = self.block_container.used;
- let insets = abspos_engine::compute_inset_native(
+ abspos_engine::compute_inset_native(
self.run,
node,
used,
@@ -1376,9 +1376,7 @@ impl<'context> InlineFormattingContext<'context> {
block_size: used.content_block_size.get(),
},
self.block_container.percentage_block_insets_have_definite_basis,
- );
- self.run.records.keep_in_flow_box_insets(node, insets);
- insets
+ )
}
pub(crate) fn parent_commit_pending_margin_before_inline_content(&self) -> CssPixels {
diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rs
index 760a01bfe0b..6cb1c294637 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs
@@ -695,18 +695,6 @@ impl<'arena> RunRecords<'arena> {
}
}
- #[track_caller]
- pub(crate) fn set_default_scroll_shift(&self, node: Node, shift: Option<abspos_inputs::DefaultScrollShift>) {
- let facts = self.facts_decided_by_parent_of(node);
- self.keep_facts_decided_by_parent_of(
- node,
- FactsDecidedByParent {
- default_scroll_shift: shift,
- ..facts
- },
- );
- }
-
/// What the parent of `node` has decided about it so far.
#[track_caller]
pub(crate) fn facts_decided_by_parent_of(&self, node: Node) -> FactsDecidedByParent {
@@ -735,36 +723,6 @@ impl<'arena> RunRecords<'arena> {
})
}
- #[track_caller]
- pub(crate) fn used_insets_of(&self, node: Node) -> UsedInsets {
- self.facts_decided_by_parent_of(node).used_insets
- }
-
- /// Sets the used insets of `node`, which cannot change once the box is placed.
- #[track_caller]
- pub(crate) fn set_used_insets(&self, node: Node, insets: UsedInsets) {
- let facts = self.kept_facts_decided_by_parent_of(node).unwrap_or_default();
- assert!(facts.placement.is_none(), "the used insets of a placed box are final");
- self.keep_facts_decided_by_parent_of(
- node,
- FactsDecidedByParent {
- used_insets: insets,
- ..facts
- },
- );
- }
-
- /// Keeps for `node`, an in-flow box, what its insets resolved to.
- #[track_caller]
- pub(crate) fn keep_in_flow_box_insets(&self, node: Node, insets: abspos_engine::InFlowBoxInsets) {
- if let Some(default_scroll_shift) = insets.default_scroll_shift {
- self.set_default_scroll_shift(node, Some(default_scroll_shift));
- }
- if let Some(used_insets) = insets.used_insets {
- self.set_used_insets(node, used_insets);
- }
- }
-
/// Tracks the percentage block size dependency of `node` until the returned tracking is dropped, which the layout
/// of `node` holds while it is in progress.
pub(crate) fn track_percentage_block_size_dependency_while_laying_out(
diff --git a/Libraries/LibWeb/Rust/src/layout/used_values.rs b/Libraries/LibWeb/Rust/src/layout/used_values.rs
index 7e83cf4bdf5..7eb6f4888a1 100644
--- a/Libraries/LibWeb/Rust/src/layout/used_values.rs
+++ b/Libraries/LibWeb/Rust/src/layout/used_values.rs
@@ -207,6 +207,9 @@ pub(crate) struct UsedValues {
pub(crate) frame: Cell<geometry::Frame>,
/// The anchor-size() resolutions of an absolutely positioned box, set once as the abspos engine places it.
pub(crate) anchor_resolved_values: std::cell::OnceCell<Box<style_values::AnchorResolvedValues>>,
+ /// The used values of the inset properties of an absolutely positioned box, which the abspos engine resolves as it
+ /// sizes the box.
+ pub(crate) used_insets: Cell<super::run_records::UsedInsets>,
}
impl Default for UsedValues {
@@ -240,6 +243,7 @@ impl Default for UsedValues {
line_data: RefCell::new(LineDataState::Empty),
frame: Cell::new(geometry::Frame::PHYSICAL),
anchor_resolved_values: std::cell::OnceCell::new(),
+ used_insets: Cell::new(super::run_records::UsedInsets::default()),
}
}
}