Skip to content

Truly independent web browser

LibWeb: Keep an abspos box's anchor sizes and insets out of its record

Aliaksandr Kalenikdbebb0a830f3
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
index 785196f8145..386161c2fd0 100644
--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
@@ -130,6 +130,39 @@ impl ContainingBlockGeometry {
}
}
+/// An absolutely positioned box this engine sizes: its record, the used insets the engine resolves for it, and the
+/// anchor-size() resolutions its style reads.
+#[derive(Clone, Copy)]
+pub(crate) struct OutOfFlowBox<'a> {
+ pub(crate) node: Node,
+ pub(crate) record: used_values::RecordInFrame<'a>,
+ used_insets: &'a Cell<run_records::UsedInsets>,
+ anchor_resolved_values: Option<&'a style_values::AnchorResolvedValues>,
+}
+
+impl<'a> OutOfFlowBox<'a> {
+ pub(crate) fn new(
+ sized: sizing_context::SizedRecord<'a>,
+ used_insets: &'a Cell<run_records::UsedInsets>,
+ anchor_resolved_values: Option<&'a style_values::AnchorResolvedValues>,
+ ) -> Self {
+ Self {
+ node: sized.node,
+ record: sized.record,
+ used_insets,
+ anchor_resolved_values,
+ }
+ }
+
+ fn sized_record(&self) -> sizing_context::SizedRecord<'a> {
+ sizing_context::SizedRecord::new(self.node, self.record)
+ }
+
+ fn sized_box(&self) -> sizing_context::SizedBox<'_> {
+ sizing_context::SizedBox::new(self.node, &self.record)
+ }
+}
+
pub(crate) struct AbsposEngine<'pass> {
records: &'pass RunRecords<'pass>,
callbacks: LayoutPass<'pass>,
@@ -264,19 +297,12 @@ impl<'pass> AbsposEngine<'pass> {
StyleValues::for_node(&self.callbacks, node)
}
- /// The style of `sized`, an absolutely positioned box this engine sizes, with the anchor-size() resolutions its
- /// record holds.
- fn style_of<'sized>(&self, sized: sizing_context::SizedRecord<'sized>) -> StyleValues<'sized>
+ /// The style of `sized`, an absolutely positioned box this engine sizes, with its anchor-size() resolutions.
+ fn style_of<'sized>(&self, sized: OutOfFlowBox<'sized>) -> StyleValues<'sized>
where
'pass: 'sized,
{
- let anchor_resolved_values = sized
- .record
- .record()
- .anchor_resolved_values
- .get()
- .map(|resolved| &**resolved);
- StyleValues::for_node(&self.callbacks, sized.node).with_anchor_resolved_values(anchor_resolved_values)
+ StyleValues::for_node(&self.callbacks, sized.node).with_anchor_resolved_values(sized.anchor_resolved_values)
}
#[inline]
@@ -968,26 +994,6 @@ impl AbsposEngine<'_> {
}
}
- /// Makes the resolved anchor sizes of `inputs` visible to the style reads of `node` in this run's records.
- fn install_resolved_anchor_sizes(
- &self,
- sized: sizing_context::SizedRecord<'_>,
- inputs: &abspos_inputs::AbsposLayoutInputs,
- ) {
- if inputs.resolved_anchor_sizes.is_empty() {
- return;
- }
- let used = sized.record.record();
- if used.anchor_resolved_values.get().is_none() {
- let _ = used
- .anchor_resolved_values
- .set(Box::new(style_values::AnchorResolvedValues::new(
- &inputs.resolved_anchor_sizes,
- self.callbacks.frame,
- )));
- }
- }
-
/// https://drafts.csswg.org/css-anchor-position-1/#anchor-center
/// If the positioned box has a default anchor box, then it is centered (insofar as possible) over the default
/// anchor box in the relevant axis.
@@ -1827,7 +1833,7 @@ impl AbsposEngine<'_> {
fn static_offset(
&self,
- sized: sizing_context::SizedRecord<'_>,
+ sized: OutOfFlowBox<'_>,
rect: abspos_inputs::StaticPositionRect,
) -> geometry::LogicalOffset {
let metrics = sized.record;
@@ -1845,7 +1851,7 @@ impl AbsposEngine<'_> {
#[expect(clippy::too_many_arguments)]
fn calculate_inner_size(
&self,
- sized: sizing_context::SizedRecord<'_>,
+ sized: OutOfFlowBox<'_>,
axis: SizingAxis,
size: &ComputedSize,
available_space: AvailableSpace,
@@ -1937,7 +1943,7 @@ impl AbsposEngine<'_> {
#[expect(clippy::too_many_arguments)]
fn solve_non_replaced_inline_once(
&self,
- sized: sizing_context::SizedRecord<'_>,
+ sized: OutOfFlowBox<'_>,
containing_block_inline_size: CssPixels,
_available_space: AvailableSpace,
constraints: ContainingBlockConstraints,
@@ -2086,7 +2092,7 @@ impl AbsposEngine<'_> {
fn compute_inline_size_for_non_replaced(
&self,
- sized: sizing_context::SizedRecord<'_>,
+ sized: OutOfFlowBox<'_>,
available_space: AvailableSpace,
constraints: ContainingBlockConstraints,
static_position_rect: abspos_inputs::StaticPositionRect,
@@ -2229,7 +2235,7 @@ impl AbsposEngine<'_> {
fn compute_inline_size_for_replaced(
&self,
- sized: sizing_context::SizedRecord<'_>,
+ sized: OutOfFlowBox<'_>,
available_space: AvailableSpace,
constraints: ContainingBlockConstraints,
static_position_rect: abspos_inputs::StaticPositionRect,
@@ -2280,8 +2286,8 @@ impl AbsposEngine<'_> {
used.set_content_inline_size(inline_size);
}
- fn set_used_inline_insets(sized: sizing_context::SizedRecord<'_>, left: CssPixels, right: CssPixels) {
- let insets = &sized.record.record().used_insets;
+ fn set_used_inline_insets(sized: OutOfFlowBox<'_>, left: CssPixels, right: CssPixels) {
+ let insets = sized.used_insets;
insets.set(run_records::UsedInsets {
left,
right,
@@ -2289,8 +2295,8 @@ impl AbsposEngine<'_> {
});
}
- fn set_used_block_insets(sized: sizing_context::SizedRecord<'_>, top: CssPixels, bottom: CssPixels) {
- let insets = &sized.record.record().used_insets;
+ fn set_used_block_insets(sized: OutOfFlowBox<'_>, top: CssPixels, bottom: CssPixels) {
+ let insets = sized.used_insets;
insets.set(run_records::UsedInsets {
top,
bottom,
@@ -2300,7 +2306,7 @@ impl AbsposEngine<'_> {
fn compute_inline_size(
&self,
- sized: sizing_context::SizedRecord<'_>,
+ sized: OutOfFlowBox<'_>,
available_space: AvailableSpace,
constraints: ContainingBlockConstraints,
static_position_rect: abspos_inputs::StaticPositionRect,
@@ -2351,7 +2357,7 @@ enum BlockSizePass {
impl AbsposEngine<'_> {
fn apply_min_max_block_size_constraints(
&self,
- sized: sizing_context::SizedRecord<'_>,
+ sized: OutOfFlowBox<'_>,
available_space: AvailableSpace,
constraints: ContainingBlockConstraints,
static_position_rect: abspos_inputs::StaticPositionRect,
@@ -2388,7 +2394,7 @@ impl AbsposEngine<'_> {
fn automatic_block_size(
&self,
- sized: sizing_context::SizedRecord<'_>,
+ sized: OutOfFlowBox<'_>,
available_space: AvailableSpace,
constraints: ContainingBlockConstraints,
pass: BlockSizePass,
@@ -2437,7 +2443,7 @@ impl AbsposEngine<'_> {
#[expect(clippy::too_many_arguments)]
fn solve_non_replaced_block_once(
&self,
- sized: sizing_context::SizedRecord<'_>,
+ sized: OutOfFlowBox<'_>,
available_space: AvailableSpace,
constraints: ContainingBlockConstraints,
static_position_rect: abspos_inputs::StaticPositionRect,
@@ -2579,7 +2585,7 @@ impl AbsposEngine<'_> {
#[expect(clippy::too_many_arguments)]
fn compute_block_size_for_non_replaced(
&self,
- sized: sizing_context::SizedRecord<'_>,
+ sized: OutOfFlowBox<'_>,
available_space: AvailableSpace,
constraints: ContainingBlockConstraints,
static_position_rect: abspos_inputs::StaticPositionRect,
@@ -2731,7 +2737,7 @@ impl AbsposEngine<'_> {
#[expect(clippy::too_many_arguments)]
fn compute_block_size_for_replaced(
&self,
- sized: sizing_context::SizedRecord<'_>,
+ sized: OutOfFlowBox<'_>,
available_space: AvailableSpace,
constraints: ContainingBlockConstraints,
static_position_rect: abspos_inputs::StaticPositionRect,
@@ -2823,7 +2829,7 @@ impl AbsposEngine<'_> {
#[expect(clippy::too_many_arguments)]
fn compute_block_size(
&self,
- sized: sizing_context::SizedRecord<'_>,
+ sized: OutOfFlowBox<'_>,
available_space: AvailableSpace,
constraints: ContainingBlockConstraints,
static_position_rect: abspos_inputs::StaticPositionRect,
@@ -2864,11 +2870,10 @@ impl<'pass> AbsposEngine<'pass> {
// pass, and the definiteness overrides insets and aspect ratios provide.
pub(crate) fn dimension_out_of_flow_root(
&self,
- sized: sizing_context::SizedRecord<'_>,
+ sized: OutOfFlowBox<'_>,
inputs: abspos_inputs::AbsposLayoutInputs,
) {
let node = sized.node;
- self.install_resolved_anchor_sizes(sized, &inputs);
let (available_space, constraints) = out_of_flow_root_space(inputs);
let containing_block_inline_size = available_space.inline_size.to_px_or_zero();
let resolved = inputs.resolved_anchor_insets.as_ref();
@@ -2936,16 +2941,15 @@ impl<'pass> AbsposEngine<'pass> {
}
self.sizing()
- .make_form_control_content_box_definite(sized, available_space, constraints, None);
+ .make_form_control_content_box_definite(sized.sized_record(), available_space, constraints, None);
}
pub(crate) fn finalize_out_of_flow_root_after_inside_layout(
&self,
- sized: sizing_context::SizedRecord<'_>,
+ sized: OutOfFlowBox<'_>,
inputs: abspos_inputs::AbsposLayoutInputs,
inside_layout: Option<InsideLayoutBlockSizes>,
) {
- self.install_resolved_anchor_sizes(sized, &inputs);
let (available_space, constraints) = out_of_flow_root_space(inputs);
let containing_block_size = geometry::LogicalSize {
inline_size: available_space.inline_size.to_px_or_zero(),
@@ -3140,7 +3144,7 @@ impl<'pass> AbsposEngine<'pass> {
/// https://drafts.csswg.org/css-align-3/#align-abspos
fn self_alignment(
&self,
- sized: sizing_context::SizedRecord<'_>,
+ sized: OutOfFlowBox<'_>,
containing_block: Node,
inline_axis: bool,
) -> Option<AbsposAlignment> {
@@ -3185,7 +3189,7 @@ impl<'pass> AbsposEngine<'pass> {
/// Whether the box's self-alignment in an axis of its containing block's frame makes it take its fit-content size
/// within its inset-modified containing block, rather than fill it.
- fn self_alignment_sizes_to_fit_content(&self, sized: sizing_context::SizedRecord<'_>, inline_axis: bool) -> bool {
+ fn self_alignment_sizes_to_fit_content(&self, sized: OutOfFlowBox<'_>, inline_axis: bool) -> bool {
let style = self.style_of(sized);
let value = if inline_axis {
style.justify_self()
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
index 706d4639ac8..17929d69fad 100644
--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
@@ -4540,6 +4540,7 @@ mod stretch_cross_limit_tests {
Node::INVALID,
container_cells,
callbacks.frame,
+ None,
|records, callbacks| {
let run = FormattingContextRun {
records,
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 4b08cd40c36..76be334e26f 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -1663,6 +1663,7 @@ fn apply_root_sizing_directives(
run: &FormattingContextRun,
input: &LayoutInput,
fc_type: FormattingContextType,
+ root_used_insets: &Cell<run_records::UsedInsets>,
) -> RootSizingOutcome {
let sized_root = run.sized_root();
let mut atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above = None;
@@ -1699,7 +1700,14 @@ fn apply_root_sizing_directives(
body_input
}
ParticipationInParentFormattingContext::AbsolutelyPositioned(abspos_inputs) => {
- abspos_engine::AbsposEngine::for_run(run).dimension_out_of_flow_root(run.sized_root(), abspos_inputs);
+ abspos_engine::AbsposEngine::for_run(run).dimension_out_of_flow_root(
+ abspos_engine::OutOfFlowBox::new(
+ run.sized_root(),
+ root_used_insets,
+ run.records.anchor_resolved_values_of(run.box_),
+ ),
+ abspos_inputs,
+ );
body_input_with_inner_available_space(run, input)
}
ParticipationInParentFormattingContext::Item => {
@@ -1924,13 +1932,14 @@ fn finalize_float_root(run: &FormattingContextRun, input: &LayoutInput, body_res
);
}
+/// Sizes `child` in `record` without a run of its own. Returns the used insets of an absolutely positioned child.
fn size_skipped_independent_root(
run: &FormattingContextRun,
parent_block: Option<&block_formatting_context::BlockFormattingContext>,
child: Node,
record: &UsedValues,
input: &LayoutInput,
-) {
+) -> Option<run_records::UsedInsets> {
match input.participation {
ParticipationInParentFormattingContext::Float { .. } => {
let parent = parent_block.expect("a float requires an enclosing block formatting context");
@@ -1943,20 +1952,29 @@ fn size_skipped_independent_root(
None,
None,
);
+ None
}
ParticipationInParentFormattingContext::AbsolutelyPositioned(abspos_inputs) => {
let engine = abspos_engine::AbsposEngine::for_run(run);
- let sized_child =
- sizing_context::SizedRecord::new(child, used_values::RecordInFrame::new(record, run.callbacks.frame));
+ let anchor_resolved_values = (!abspos_inputs.resolved_anchor_sizes.is_empty()).then(|| {
+ style_values::AnchorResolvedValues::new(&abspos_inputs.resolved_anchor_sizes, run.callbacks.frame)
+ });
+ let used_insets = Cell::new(run_records::UsedInsets::default());
+ let sized_child = abspos_engine::OutOfFlowBox::new(
+ sizing_context::SizedRecord::new(child, used_values::RecordInFrame::new(record, run.callbacks.frame)),
+ &used_insets,
+ anchor_resolved_values.as_ref(),
+ );
engine.dimension_out_of_flow_root(sized_child, abspos_inputs);
engine.finalize_out_of_flow_root_after_inside_layout(sized_child, abspos_inputs, None);
+ Some(used_insets.get())
}
ParticipationInParentFormattingContext::BlockLevel => {
unreachable!("a block formatting context lays out only boxes, and every block-level box can have children")
}
ParticipationInParentFormattingContext::AtomicInline
| ParticipationInParentFormattingContext::Item
- | ParticipationInParentFormattingContext::Root => {}
+ | ParticipationInParentFormattingContext::Root => None,
}
}
@@ -2227,12 +2245,25 @@ fn execute_formatting_context_run(
// NB: The root's record holds its metrics in the frame the root lays its contents out in, for its whole life. The
// root's own box is sized in its parent's frame, through views of the record.
let own_frame = frame_established_by(&callbacks, box_);
+ // NB: The anchor-size() resolutions apply only in the parent's frame, where the root's own box is sized.
+ let root_anchor_resolved_values = match input.participation {
+ ParticipationInParentFormattingContext::AbsolutelyPositioned(inputs)
+ if !inputs.resolved_anchor_sizes.is_empty() =>
+ {
+ Some(Box::new(style_values::AnchorResolvedValues::new(
+ &inputs.resolved_anchor_sizes,
+ callbacks.frame,
+ )))
+ }
+ _ => None,
+ };
let (outputs, root_cells_left_by_run) = RunRecords::with_root(
callbacks,
box_,
root_containing_block,
root_cells.in_frame(callbacks.frame, own_frame),
own_frame,
+ root_anchor_resolved_values,
|records, callbacks| {
let outputs = lay_out_run_root_and_contents(
records,
@@ -2327,10 +2358,11 @@ fn lay_out_run_root_and_contents<'pass>(
Some(table_inline_layout) if table_inline_layout.table_box() == box_ => (Some(table_inline_layout), None),
table_inline_layout => (None, table_inline_layout),
};
+ let root_used_insets = Cell::new(run_records::UsedInsets::default());
let RootSizingOutcome {
body_input,
atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,
- } = apply_root_sizing_directives(run, &input, fc_type);
+ } = apply_root_sizing_directives(run, &input, fc_type, &root_used_insets);
debug_assert!(
!body_input.available_space.inline_size.is_intrinsic_sizing_constraint(),
"no run lays out its contents under an intrinsic inline size"
@@ -2478,14 +2510,18 @@ fn lay_out_run_root_and_contents<'pass>(
}
ParticipationInParentFormattingContext::AbsolutelyPositioned(abspos_inputs) => {
abspos_engine::AbsposEngine::for_run(run).finalize_out_of_flow_root_after_inside_layout(
- run.sized_root(),
+ abspos_engine::OutOfFlowBox::new(
+ run.sized_root(),
+ &root_used_insets,
+ run.records.anchor_resolved_values_of(run.box_),
+ ),
abspos_inputs,
Some(abspos_engine::InsideLayoutBlockSizes {
automatic_content_block_size: result.automatic_content_block_size,
content_block_size_for_aspect_ratio_minimum: result.content_block_size_for_aspect_ratio_minimum,
}),
);
- result.out_of_flow_root_used_insets = Some(run.root_record().record().used_insets.get());
+ result.out_of_flow_root_used_insets = Some(root_used_insets.get());
}
ParticipationInParentFormattingContext::Item => {
if run_reads_content_block_size_adopted_after_it(fc_type, &input)
@@ -2874,12 +2910,8 @@ pub(crate) fn layout_inside_child_with_input_cells(
);
if !facts.can_have_children() && !creates_replaced_context {
let record_of_this_layout = child_input_cells.materialize_record(run.callbacks.frame);
- size_skipped_independent_root(run, parent_block, child, &record_of_this_layout, &input);
- let out_of_flow_root_used_insets = matches!(
- input.participation,
- ParticipationInParentFormattingContext::AbsolutelyPositioned(_)
- )
- .then(|| record_of_this_layout.used_insets.get());
+ let out_of_flow_root_used_insets =
+ size_skipped_independent_root(run, parent_block, child, &record_of_this_layout, &input);
return ChildLayout::of_child_sized_in_parent_run(
skipped(out_of_flow_root_used_insets),
&record_of_this_layout,
@@ -3812,6 +3844,7 @@ mod baseline_tests {
Node::INVALID,
parent_cells,
callbacks.frame,
+ None,
|_, callbacks| {
let child_cells = used_values::RootInputCells::default();
assert!(child_gives_container_baselines(&callbacks, parent, child));
diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
index 28143c5d4ab..81e35b951a2 100644
--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
@@ -3167,6 +3167,7 @@ impl<'pass> GridFormattingContext<'pass> {
containing_block,
scratch_root,
self.run.callbacks.frame,
+ None,
|records, callbacks| {
let scratch_run = FormattingContextRun {
records,
diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rs
index c01a408750b..a4e29844133 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs
@@ -235,10 +235,10 @@ impl LayoutScratch {
}
}
-/// What a run keeps while it is in progress: the record of its root, built from the input cells its caller hands it, and
-/// the percentage block size dependencies it resolves. Every other box the run lays out is laid out in a record the
-/// call laying it out owns, or handed to a run of its own. The scoped constructors lend the records to the run, so
-/// callers cannot extend their lifetime.
+/// What a run keeps while it is in progress: the record of its root, built from the input cells its caller hands it, the
+/// anchor-size() resolutions of its root, and the percentage block size dependencies it resolves. Every other box the
+/// run lays out is laid out in a record the call laying it out owns, or handed to a run of its own. The scoped
+/// constructors lend the records to the run, so callers cannot extend their lifetime.
pub(crate) struct RunRecords<'arena> {
root: Node,
root_used: Option<UsedValues>,
@@ -249,6 +249,8 @@ pub(crate) struct RunRecords<'arena> {
/// What the run found so far about the percentage block size dependency of its root and of the boxes whose
/// layout in it is in progress, the innermost last. Only these boxes have their dependency resolved.
percentage_block_size_dependencies_in_progress: PercentageBlockSizeDependenciesInProgress,
+ /// The anchor-size() resolutions of an absolutely positioned root, a run input that is constant for the run.
+ root_anchor_resolved_values: Option<Box<style_values::AnchorResolvedValues>>,
}
/// Where a box is placed: the offset of its content box in the containing block it is placed in.
@@ -358,13 +360,15 @@ enum ContentSizing {
impl<'arena> RunRecords<'arena> {
/// Runs `run` with the records of a run rooted at `root`, and the pass as that run sees it. The root's record holds
- /// `root_cells`, which hold its metrics in `root_frame`, the frame it lays its contents out in.
+ /// `root_cells`, which hold its metrics in `root_frame`, the frame it lays its contents out in. The style reads of
+ /// an absolutely positioned root see `root_anchor_resolved_values`.
pub(crate) fn with_root<R>(
callbacks: LayoutPass<'arena>,
root: Node,
root_containing_block: Node,
root_cells: used_values::RootInputCells,
root_frame: geometry::Frame,
+ root_anchor_resolved_values: Option<Box<style_values::AnchorResolvedValues>>,
run: impl FnOnce(&Self, LayoutPass<'arena>) -> R,
) -> R {
Self::enter(
@@ -372,6 +376,7 @@ impl<'arena> RunRecords<'arena> {
root,
root_containing_block,
Some((root_cells, root_frame)),
+ root_anchor_resolved_values,
ContentSizing::Layout,
run,
)
@@ -389,6 +394,7 @@ impl<'arena> RunRecords<'arena> {
root,
root_containing_block,
Some((root_cells, callbacks.frame)),
+ None,
ContentSizing::RootContributions,
run,
)
@@ -406,6 +412,7 @@ impl<'arena> RunRecords<'arena> {
root,
root_containing_block,
Some((root_cells, callbacks.frame)),
+ None,
ContentSizing::RootContentInlineSizes,
run,
)
@@ -417,7 +424,15 @@ impl<'arena> RunRecords<'arena> {
root_containing_block: Node,
run: impl FnOnce(&Self, LayoutPass<'arena>) -> R,
) -> R {
- Self::enter(callbacks, root, root_containing_block, None, ContentSizing::Layout, run)
+ Self::enter(
+ callbacks,
+ root,
+ root_containing_block,
+ None,
+ None,
+ ContentSizing::Layout,
+ run,
+ )
}
fn enter<R>(
@@ -425,6 +440,7 @@ impl<'arena> RunRecords<'arena> {
root: Node,
root_containing_block: Node,
root_cells: Option<(used_values::RootInputCells, geometry::Frame)>,
+ root_anchor_resolved_values: Option<Box<style_values::AnchorResolvedValues>>,
content_sizing: ContentSizing,
run: impl FnOnce(&Self, LayoutPass<'arena>) -> R,
) -> R {
@@ -443,6 +459,7 @@ impl<'arena> RunRecords<'arena> {
root,
PercentageBlockSizeDependency::default()
)]),
+ root_anchor_resolved_values,
};
run(&records, callbacks.for_run(root, root_containing_block))
}
@@ -499,6 +516,14 @@ impl<'arena> RunRecords<'arena> {
self.root
}
+ /// The anchor-size() resolutions the style reads of `node` see, which only an absolutely positioned run root has.
+ pub(crate) fn anchor_resolved_values_of(&self, node: Node) -> Option<&style_values::AnchorResolvedValues> {
+ if node != self.root {
+ return None;
+ }
+ self.root_anchor_resolved_values.as_deref()
+ }
+
/// 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(
@@ -591,6 +616,7 @@ mod tests {
NodeSlotId::INVALID,
used_values::RootInputCells::default(),
geometry::Frame::PHYSICAL,
+ None,
|parent, _| {
let root_used: *const UsedValues = parent.used_values(root);
RunRecords::with_root(
@@ -599,6 +625,7 @@ mod tests {
root,
used_values::RootInputCells::default(),
geometry::Frame::PHYSICAL,
+ None,
|nested, _| {
assert!(nested.used_values_if_owned(root).is_none());
assert!(nested.used_values_if_owned(child).is_some());
@@ -631,6 +658,7 @@ mod tests {
NodeSlotId::INVALID,
used_values::RootInputCells::default(),
geometry::Frame::PHYSICAL,
+ None,
|parent, _| {
let root_used: *const UsedValues = parent.used_values(root);
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
@@ -640,6 +668,7 @@ mod tests {
root,
used_values::RootInputCells::default(),
geometry::Frame::PHYSICAL,
+ None,
|_, _| panic!("abort the nested measurement"),
);
}));
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
index af088df2348..cefe16d60d5 100644
--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
@@ -288,12 +288,7 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
if !style.is_absolutely_positioned() {
return style;
}
- let anchor_resolved_values = self
- .records
- .used_values_if_owned(node)
- .and_then(|used| used.anchor_resolved_values.get())
- .map(|resolved| &**resolved);
- style.with_anchor_resolved_values(anchor_resolved_values)
+ style.with_anchor_resolved_values(self.records.anchor_resolved_values_of(node))
}
fn first_child(&self, node: Node) -> Node {
@@ -4377,6 +4372,7 @@ mod replaced_ratio_tests {
Node::INVALID,
used_values::RootInputCells::capture(&UsedValues::default()),
callbacks.frame,
+ None,
|records, callbacks| {
let context = SizingContext::new(records, callbacks);
let mut metrics = used_values::RootInputCells::capture(&UsedValues::default());
diff --git a/Libraries/LibWeb/Rust/src/layout/used_values.rs b/Libraries/LibWeb/Rust/src/layout/used_values.rs
index ada0711c827..bb195f2e33d 100644
--- a/Libraries/LibWeb/Rust/src/layout/used_values.rs
+++ b/Libraries/LibWeb/Rust/src/layout/used_values.rs
@@ -205,11 +205,6 @@ pub(crate) struct UsedValues {
pub(crate) line_data: RefCell<LineDataState>,
/// The frame the box's sizes, size constraints and box sides are held in.
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 {
@@ -242,8 +237,6 @@ impl Default for UsedValues {
inline_alignment_baseline: Cell::new(None),
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()),
}
}
}