Skip to content

Truly independent web browser

LibWeb: Keep no record but the root's in a layout run

Aliaksandr Kalenik5634cfe02c06
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
index 3ea3545d916..b1972154fd5 100644
--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
@@ -3255,9 +3255,7 @@ impl<'pass> AbsposEngine<'pass> {
) -> CssPixels {
let child_box = child.child_box;
let position_option = self.determine_position_fallback_styles(&child);
- let cells =
- self.records
- .keep_child_for_its_run(&self.callbacks, child_box, ContainingBlockConstraints::default());
+ let cells = used_values::cells_before_sizing(&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();
let border_box_block_end = self.layout_element(run, child_box, cells, inputs, Some(default_scroll_shift));
@@ -3746,9 +3744,7 @@ impl<'pass> AbsposEngine<'pass> {
}
// Partial relayout uses a fresh state and keeps the replay root
// exactly once.
- let cells = self
- .records
- .keep_child_for_its_run(&self.callbacks, node, ContainingBlockConstraints::default());
+ let cells = used_values::cells_before_sizing(&self.callbacks, node, ContainingBlockConstraints::default());
let default_scroll_shift = self
.callbacks
.committed_fragment_link(node)
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index cac54b454be..334792b7194 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -2088,9 +2088,7 @@ impl<'pass> BlockFormattingContext<'pass> {
.then(|| list_item_used.content_block_size.get()),
..ContainingBlockConstraints::default()
};
- self.run
- .records
- .keep_child_for_its_run(&self.run.callbacks, marker, marker_constraints)
+ used_values::cells_before_sizing(&self.run.callbacks, marker, marker_constraints)
}
/// Lays out and places the outside marker of `list_item`, and returns the block end of the marker's border box in
@@ -2358,7 +2356,7 @@ impl<'pass> BlockFormattingContext<'pass> {
let cells_of_child_ahead_of_its_run;
let record_of_box_without_formatting_context_of_its_own;
let sized_child = if formatting_context::formatting_context_type_created_by_box(facts).is_some() {
- cells_of_child_ahead_of_its_run = Cell::new(self.run.records.keep_child_for_its_run(
+ cells_of_child_ahead_of_its_run = Cell::new(used_values::cells_before_sizing(
&self.run.callbacks,
node,
input.containing_block_constraints,
@@ -2367,7 +2365,6 @@ impl<'pass> BlockFormattingContext<'pass> {
} else {
record_of_box_without_formatting_context_of_its_own =
used_values::create_used_values(&self.run.callbacks, node, input.containing_block_constraints);
- self.run.records.keep_box_laid_out_in_record_its_layout_owns(node);
ChildSizedHere::laid_out_in(node, &record_of_box_without_formatting_context_of_its_own)
};
let _percentage_block_size_dependency_tracking = self
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
index 1fe679f9bbe..e4b0b727a80 100644
--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
@@ -291,9 +291,7 @@ impl<'pass> FlexFormattingContext<'pass> {
fn keep_item_for_its_run(&self, node: Node) -> used_values::RootInputCells {
let constraints = self.item_percentage_bases;
- self.run
- .records
- .keep_child_for_its_run(&self.run.callbacks, node, constraints)
+ used_values::cells_before_sizing(&self.run.callbacks, node, constraints)
}
/// The constraints the children of the container are laid out with, where the container is laid out with the
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 1b8c6bb820d..b205c6b248e 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -1969,13 +1969,6 @@ pub(crate) struct ChildRunOutcome {
}
impl ChildRunOutcome {
- /// Hands the laid out box back to the formatting context of `run`, the run that holds `child`, which keeps what it
- /// reads of the box.
- pub(crate) fn hand_box_back_to(self, run: &FormattingContextRun, child: Node) -> Self {
- run.records.note_child_handed_back(child);
- self
- }
-
/// What placing the child takes of the box its run handed back.
pub(crate) fn placed_child(&self) -> PlacedChild {
PlacedChild::of_laid_out_box(&self.laid_out_box)
@@ -2869,9 +2862,6 @@ pub(crate) fn layout_inside_child_with_input_cells(
});
store_derived_baselines(used, DerivedBaselines::default());
let laid_out_box = run_records::LaidOutChildBox::sized_in_parent_run(used);
- if record_kept_by_parent.is_none() {
- run.records.note_child_handed_back(child);
- }
return ChildLayout {
outcome: skipped(None),
fragment_arrival,
@@ -2890,7 +2880,6 @@ pub(crate) fn layout_inside_child_with_input_cells(
Some(used) => used,
None => {
record_of_this_layout = child_input_cells.materialize_record(run.callbacks.frame);
- run.records.note_child_handed_back(child);
&record_of_this_layout
}
};
@@ -2936,7 +2925,7 @@ pub(crate) fn layout_inside_child_with_input_cells(
result,
laid_out_box,
fragment_arrival,
- } = child_run_outcome.hand_box_back_to(run, child);
+ } = child_run_outcome;
ChildLayout {
outcome: ChildLayoutOutcome::Created(result),
fragment_arrival,
@@ -3516,13 +3505,16 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layo
let first_child = callbacks.first_child(root);
let root_for_layout = if !first_child.is_invalid() && NodeFacts::new(&callbacks, first_child).is_svg_svg_box() {
- let viewport_used = entry_records.create_used_values(&callbacks, root, root_constraints);
- viewport_used.set_content_inline_size(viewport_inline_size);
- viewport_used.set_content_block_size(viewport_block_size);
+ let mut viewport_cells = used_values::cells_before_sizing(&callbacks, root, root_constraints);
+ viewport_cells.set_content_inline_size(viewport_inline_size);
+ viewport_cells.set_content_block_size(viewport_block_size);
place_child(
&entry_run,
root,
- PlacedChild::of_record(viewport_used, &entry_run),
+ PlacedChild::new(fragment_tree::FragmentGeometry {
+ cells: viewport_cells,
+ line_data: None,
+ }),
FfiCssPixelPoint::default(),
None,
None,
@@ -3531,7 +3523,7 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layo
} else {
root
};
- let root_cells = entry_records.keep_child_for_its_run(&callbacks, root_for_layout, root_constraints);
+ let root_cells = used_values::cells_before_sizing(&callbacks, root_for_layout, root_constraints);
let input = LayoutInput::new(
AvailableSpace {
inline_size: AvailableSize::definite(viewport_inline_size),
@@ -3554,7 +3546,6 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layo
input,
None,
);
- let root_outcome = root_outcome.hand_box_back_to(&entry_run, root_for_layout);
place_child(
&entry_run,
root_for_layout,
@@ -3676,7 +3667,6 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {
let committed_root = used_values::committed_box_from_fragment_link(callbacks, root)
.expect("partial relayout root must have committed geometry");
let root_cells = committed_root.cells;
- run.records.hold_child_for_its_run(root);
let fragments = run.fragments.as_deref().expect("partial relayout must build fragments");
let mut input = LayoutInput::new(
AvailableSpace {
@@ -3710,7 +3700,7 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {
laid_out_box: root_box,
fragment_arrival,
..
- } = root_outcome.hand_box_back_to(run, root);
+ } = root_outcome;
let root_geometry = fragment_tree::FragmentGeometry {
cells: root_box.cells,
line_data: root_box.line_data,
diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
index 63cbe4a6fa5..39fb3d7f284 100644
--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
@@ -1931,7 +1931,7 @@ impl<'pass> GridFormattingContext<'pass> {
child_grid_style.names.raws(),
),
});
- let cells = self.run.records.keep_child_for_its_run(
+ let cells = used_values::cells_before_sizing(
&self.run.callbacks,
child,
ContainingBlockConstraints::default(),
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
index b6a1f5edc2d..2202b4a7701 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
@@ -1304,9 +1304,7 @@ impl<'context> InlineFormattingContext<'context> {
/// Starts holding `node`, an atomic inline-level box, which a run of its own lays out in the formatting context it
/// establishes. Returns the cells the box starts out with.
pub(crate) fn hold_atomic_inline(&self, node: Node) -> used_values::RootInputCells {
- self.run
- .records
- .keep_child_for_its_run(&self.callbacks, node, self.input.containing_block_constraints)
+ used_values::cells_before_sizing(&self.callbacks, node, self.input.containing_block_constraints)
}
pub(crate) fn parent_node(&self, node: Node) -> Node {
@@ -2041,7 +2039,7 @@ impl<'context> InlineFormattingContext<'context> {
))
.is_some()
{
- cells_of_float_ahead_of_its_run = Cell::new(self.run.records.keep_child_for_its_run(
+ cells_of_float_ahead_of_its_run = Cell::new(used_values::cells_before_sizing(
&self.callbacks,
item.node,
constraints,
@@ -2053,7 +2051,6 @@ impl<'context> InlineFormattingContext<'context> {
} else {
record_of_float_without_formatting_context_of_its_own =
used_values::create_used_values(&self.callbacks, item.node, constraints);
- self.run.records.keep_box_laid_out_in_record_its_layout_owns(item.node);
block_formatting_context::ChildSizedHere::laid_out_in(
item.node,
&record_of_float_without_formatting_context_of_its_own,
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
index 7d7183e0de0..25a92e5b658 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
@@ -1009,7 +1009,6 @@ fn record_entered_inline_box(
) -> used_values::RootInputCells {
let constraints = context.input.containing_block_constraints;
let record_of_this_call = used_values::create_used_values(&context.callbacks, node, constraints);
- context.run.records.keep_box_laid_out_in_record_its_layout_owns(node);
let used = &record_of_this_call;
let style = context.style(node);
let basis = constraints.inline_basis();
diff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
index c3c3d7e862d..6e32791ae56 100644
--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
@@ -2145,7 +2145,7 @@ impl<'pass> MathFormattingContext<'pass> {
stretch_size_constraint: Option<MathStretchSizeConstraint>,
) -> Child {
let run = &self.run;
- let child_cells = run.records.keep_child_for_its_run(&run.callbacks, child, constraints);
+ let child_cells = used_values::cells_before_sizing(&run.callbacks, child, constraints);
// NB: MathML layout does not break lines, so each child is laid out at its max-content inline size, as an
// atomic box whose block size follows from its content.
let mut input = LayoutInput::new(
diff --git a/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs
index a9d3dcf2aab..5974bcf8d36 100644
--- a/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs
@@ -43,9 +43,7 @@ pub(super) fn layout_replaced_with_children(
&run.root_record(),
layout_input.containing_block_constraints,
);
- let mut wrapper_cells = run
- .records
- .keep_child_for_its_run(&run.callbacks, wrapper, wrapper_constraints);
+ let mut wrapper_cells = used_values::cells_before_sizing(&run.callbacks, wrapper, wrapper_constraints);
wrapper_cells.set_content_inline_size(content_inline_size);
let wrapper_outcome = formatting_context::run_formatting_context(
@@ -68,7 +66,6 @@ pub(super) fn layout_replaced_with_children(
},
None,
);
- let wrapper_outcome = wrapper_outcome.hand_box_back_to(run, wrapper);
let wrapper_result = wrapper_outcome.result;
formatting_context::propagate_percentage_block_size_dependency_to_containing_block(
run.records,
diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rs
index 6dbf8a52689..c01a408750b 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs
@@ -5,7 +5,6 @@
*/
use super::*;
-use std::ptr::NonNull;
/// What the layout stage keeps for itself besides what each of its runs keeps: what the runs of a layout pass share and
/// what the runs in progress found out for the host. It is the stage's scratch rather than arena columns: nothing
@@ -109,20 +108,6 @@ const _: () = {
assert_send::<LayoutScratch>();
};
-enum KeptBoxHolding {
- /// A box this run lays out itself, in a record the run keeps for it until the run is dropped.
- LaidOutByThisRun { record: NonNull<UsedValues> },
- /// A box this run lays out itself, in a record that the layout of the box owns: the call laying it out, or the
- /// formatting context it lays the box out for.
- LaidOutInRecordItsLayoutOwns,
- /// A child this run keeps for a layout of its own, a run of its own or a record the call laying it out owns,
- /// until that layout returns.
- ChildNotYetLaidOut,
- /// A child whose own layout handed the box back to the formatting context of this run, which keeps what it reads
- /// of the box.
- ChildHandedBack,
-}
-
impl Default for LayoutScratch {
fn default() -> Self {
Self {
@@ -250,20 +235,16 @@ impl LayoutScratch {
}
}
-/// The per-run registry of the boxes a run holds. A run owns its root's record, built from the input cells its caller
-/// hands it, and keeps what it holds of every other box: what the box's parent decides about it, with the record of a
-/// box it lays out in a record it keeps, or with the cells a child it keeps for a layout of its own starts out with,
-/// until that layout hands the box back to the run's formatting context. A box whose layout owns its record keeps it
-/// there. The run releases what it keeps when it returns. The scoped constructors lend records to the run, so callers cannot extend
-/// the registry's lifetime.
+/// 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.
pub(crate) struct RunRecords<'arena> {
root: Node,
root_used: Option<UsedValues>,
scratch: &'arena LayoutScratch,
- /// How many runs are in progress with this one, which only the innermost of them may register boxes with.
+ /// How many runs are in progress with this one, of which only the innermost hands over what it found out.
runs_in_progress_with_it: usize,
- /// What the run keeps of each box it holds but its root.
- held_boxes: RefCell<HashMap<Node, KeptBoxHolding>>,
content_sizing: ContentSizing,
/// 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.
@@ -457,7 +438,6 @@ impl<'arena> RunRecords<'arena> {
root_used: root_cells.map(|(cells, frame)| cells.materialize_record(frame)),
scratch,
runs_in_progress_with_it: scratch.begin_run(),
- held_boxes: RefCell::new(HashMap::default()),
content_sizing,
percentage_block_size_dependencies_in_progress: RefCell::new(smallvec::smallvec![(
root,
@@ -491,81 +471,10 @@ impl<'arena> RunRecords<'arena> {
self.content_sizing == ContentSizing::RootContentInlineSizes && node == self.root
}
- pub(crate) fn register(&self, node: Node, used: UsedValues) -> &UsedValues {
- self.assert_registers_in_innermost_run(node);
- let record = NonNull::from(Box::leak(Box::new(used)));
- self.keep(node, KeptBoxHolding::LaidOutByThisRun { record });
- // SAFETY: The run keeps the record until it is dropped, which ends this borrow of the run.
- unsafe { record.as_ref() }
- }
-
- /// Keeps `node`, a box this run lays out in a record that the layout of the box owns, for what the box's parent
- /// decides about it.
- pub(crate) fn keep_box_laid_out_in_record_its_layout_owns(&self, node: Node) {
- self.assert_registers_in_innermost_run(node);
- self.keep(node, KeptBoxHolding::LaidOutInRecordItsLayoutOwns);
- }
-
- /// Keeps `child`, which this run hands to a run of its own, and returns the cells it starts out with.
- pub(crate) fn keep_child_for_its_run(
- &self,
- callbacks: &LayoutPass<'_>,
- child: Node,
- constraints: ContainingBlockConstraints,
- ) -> used_values::RootInputCells {
- self.hold_child_for_its_run(child);
- used_values::cells_before_sizing(callbacks, child, constraints)
- }
-
- /// Keeps `child`, which this run hands to a run of its own.
- pub(crate) fn hold_child_for_its_run(&self, child: Node) {
- self.assert_registers_in_innermost_run(child);
- self.keep(child, KeptBoxHolding::ChildNotYetLaidOut);
- }
-
- fn assert_registers_in_innermost_run(&self, node: Node) {
- if self.is_root_with_record(node) {
- self.panic_for_box_registered_twice(node);
- }
- assert!(
- self.is_innermost_run(),
- "only the innermost layout run may register records"
- );
- }
-
fn is_innermost_run(&self) -> bool {
self.scratch.runs_in_progress() == self.runs_in_progress_with_it
}
- fn is_root_with_record(&self, node: Node) -> bool {
- node == self.root && self.root_used.is_some()
- }
-
- fn panic_for_box_registered_twice(&self, node: Node) -> ! {
- panic!(
- "slot {} registered twice in the run rooted at slot {}",
- node.slot_index(),
- self.root.slot_index()
- )
- }
-
- fn keep(&self, node: Node, holding: KeptBoxHolding) {
- let mut held_boxes = self.held_boxes.borrow_mut();
- if held_boxes.contains_key(&node) {
- self.panic_for_box_registered_twice(node);
- }
- held_boxes.insert(node, holding);
- }
-
- pub(crate) fn create_used_values(
- &self,
- callbacks: &LayoutPass<'_>,
- node: Node,
- constraints: ContainingBlockConstraints,
- ) -> &UsedValues {
- self.register(node, used_values::create_used_values(callbacks, node, constraints))
- }
-
#[track_caller]
pub(crate) fn used_values(&self, node: Node) -> &UsedValues {
let caller = std::panic::Location::caller();
@@ -578,33 +487,12 @@ impl<'arena> RunRecords<'arena> {
})
}
+ /// The record of `node` where it is the run's root, the only box a run keeps a record of.
pub(crate) fn used_values_if_owned(&self, node: Node) -> Option<&UsedValues> {
- if self.is_root_with_record(node) {
- return self.root_used.as_ref();
- }
- let record = self.record_this_run_keeps(node)?;
- // SAFETY: The run keeps the record until it is dropped, which ends this borrow of the run.
- Some(unsafe { record.as_ref() })
- }
-
- /// The record this run keeps for `node`, a box it holds but its root, where it keeps one.
- fn record_this_run_keeps(&self, node: Node) -> Option<NonNull<UsedValues>> {
- match *self.held_boxes.borrow().get(&node)? {
- KeptBoxHolding::LaidOutByThisRun { record } => Some(record),
- KeptBoxHolding::LaidOutInRecordItsLayoutOwns
- | KeptBoxHolding::ChildNotYetLaidOut
- | KeptBoxHolding::ChildHandedBack => None,
+ if node != self.root {
+ return None;
}
- }
-
- #[track_caller]
- fn panic_for_box_not_held(&self, node: Node) -> ! {
- panic!(
- "the run rooted at slot {} does not hold slot {} (read at {})",
- self.root.slot_index(),
- node.slot_index(),
- std::panic::Location::caller(),
- )
+ self.root_used.as_ref()
}
pub(crate) fn root(&self) -> Node {
@@ -679,37 +567,10 @@ impl<'arena> RunRecords<'arena> {
update(dependency);
}
}
-
- /// Notes that the layout of `child`, a box this run keeps for a layout of its own, handed the box back once it
- /// returned.
- #[track_caller]
- pub(crate) fn note_child_handed_back(&self, child: Node) {
- if self.is_root_with_record(child) {
- self.panic_for_box_not_held(child)
- }
- let mut held_boxes = self.held_boxes.borrow_mut();
- let Some(kept) = held_boxes.get_mut(&child) else {
- self.panic_for_box_not_held(child)
- };
- assert!(
- !matches!(
- kept,
- KeptBoxHolding::LaidOutByThisRun { .. } | KeptBoxHolding::LaidOutInRecordItsLayoutOwns
- ),
- "{child:?} is handed back by a run of its own to a parent that lays it out itself"
- );
- *kept = KeptBoxHolding::ChildHandedBack;
- }
}
impl Drop for RunRecords<'_> {
fn drop(&mut self) {
- for kept in self.held_boxes.get_mut().values() {
- if let KeptBoxHolding::LaidOutByThisRun { record } = *kept {
- // SAFETY: The run leaked the record into its keeping, and nothing borrows it once the run is dropped.
- drop(unsafe { Box::from_raw(record.as_ptr()) });
- }
- }
self.scratch.end_run(self.runs_in_progress_with_it);
}
}
@@ -718,12 +579,8 @@ impl Drop for RunRecords<'_> {
mod tests {
use super::*;
- fn default_root_cells() -> used_values::RootInputCells {
- used_values::RootInputCells::default()
- }
-
#[test]
- fn nested_runs_leave_their_parents_records_in_place() {
+ fn a_nested_run_keeps_its_own_root_record() {
let mut arena = LayoutNodeArena::new();
let scratch = LayoutScratch::default();
let root = arena.allocate_for_test().slot;
@@ -732,128 +589,36 @@ mod tests {
LayoutPass::for_test(&arena, &scratch),
root,
NodeSlotId::INVALID,
- default_root_cells(),
+ used_values::RootInputCells::default(),
geometry::Frame::PHYSICAL,
|parent, _| {
let root_used: *const UsedValues = parent.used_values(root);
- let child_used: *const UsedValues = parent.register(child, UsedValues::default());
RunRecords::with_root(
LayoutPass::for_test(&arena, &scratch),
child,
root,
- default_root_cells(),
+ used_values::RootInputCells::default(),
geometry::Frame::PHYSICAL,
|nested, _| {
- let nested_used: *const UsedValues = nested.used_values(child);
- assert!(!std::ptr::eq(nested_used, child_used));
- assert!(std::ptr::eq(parent.used_values(child), child_used));
- assert!(std::ptr::eq(parent.used_values(root), root_used));
assert!(nested.used_values_if_owned(root).is_none());
+ assert!(nested.used_values_if_owned(child).is_some());
+ assert!(parent.used_values_if_owned(child).is_none());
RunRecords::with_unrooted(
LayoutPass::for_test(&arena, &scratch),
child,
root,
- |measurement, _| {
- let measured: *const UsedValues = measurement.register(child, UsedValues::default());
- assert!(std::ptr::eq(measurement.used_values(child), measured));
- assert!(std::ptr::eq(parent.used_values(child), child_used));
- assert!(std::ptr::eq(nested.used_values(child), nested_used));
+ |unrooted, _| {
+ assert!(unrooted.used_values_if_owned(child).is_none());
},
);
- assert!(std::ptr::eq(parent.used_values(child), child_used));
},
);
- assert!(std::ptr::eq(parent.used_values(child), child_used));
+ assert!(std::ptr::eq(parent.used_values(root), root_used));
},
);
assert_eq!(scratch.runs_in_progress(), 0);
}
- #[test]
- fn returning_runs_release_their_records() {
- let mut arena = LayoutNodeArena::new();
- let scratch = LayoutScratch::default();
- let root = arena.allocate_for_test().slot;
- let child = arena.allocate_for_test().slot;
- let lines = std::sync::Arc::new(crate::layout::inline_content::InlineContent::default());
- let weak_lines = std::sync::Arc::downgrade(&lines);
- RunRecords::with_root(
- LayoutPass::for_test(&arena, &scratch),
- root,
- NodeSlotId::INVALID,
- default_root_cells(),
- geometry::Frame::PHYSICAL,
- |records, _| {
- let used = records.register(child, UsedValues::default());
- used.set_finished_line_data(lines);
- },
- );
- assert!(weak_lines.upgrade().is_none());
- }
-
- #[test]
- fn a_box_registered_by_a_returned_run_can_be_freed() {
- let mut arena = LayoutNodeArena::new();
- let scratch = LayoutScratch::default();
- let root = arena.allocate_for_test().slot;
- let child = arena.allocate_for_test().slot;
- RunRecords::with_root(
- LayoutPass::for_test(&arena, &scratch),
- root,
- NodeSlotId::INVALID,
- default_root_cells(),
- geometry::Frame::PHYSICAL,
- |records, _| {
- records.register(child, UsedValues::default());
- },
- );
- let _ = arena.free_subtree(child);
- }
-
- #[test]
- #[should_panic(expected = "registered twice")]
- fn registering_the_root_of_a_rooted_run_panics() {
- let mut arena = LayoutNodeArena::new();
- let scratch = LayoutScratch::default();
- let root = arena.allocate_for_test().slot;
- RunRecords::with_root(
- LayoutPass::for_test(&arena, &scratch),
- root,
- NodeSlotId::INVALID,
- default_root_cells(),
- geometry::Frame::PHYSICAL,
- |records, _| {
- records.register(root, UsedValues::default());
- },
- );
- }
-
- #[test]
- #[should_panic(expected = "only the innermost layout run may register records")]
- fn an_enclosing_run_cannot_register_while_a_nested_run_is_in_progress() {
- let mut arena = LayoutNodeArena::new();
- let scratch = LayoutScratch::default();
- let root = arena.allocate_for_test().slot;
- let child = arena.allocate_for_test().slot;
- RunRecords::with_unrooted(
- LayoutPass::for_test(&arena, &scratch),
- root,
- NodeSlotId::INVALID,
- |parent, _| {
- RunRecords::with_root(
- LayoutPass::for_test(&arena, &scratch),
- root,
- NodeSlotId::INVALID,
- default_root_cells(),
- geometry::Frame::PHYSICAL,
- |_, _| {
- parent.register(child, UsedValues::default());
- },
- );
- },
- );
- }
-
#[test]
fn unwinding_a_nested_run_restores_its_parent() {
let mut arena = LayoutNodeArena::new();
@@ -864,27 +629,23 @@ mod tests {
LayoutPass::for_test(&arena, &scratch),
root,
NodeSlotId::INVALID,
- default_root_cells(),
+ used_values::RootInputCells::default(),
geometry::Frame::PHYSICAL,
|parent, _| {
let root_used: *const UsedValues = parent.used_values(root);
- let child_used: *const UsedValues = parent.register(child, UsedValues::default());
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
RunRecords::with_root(
LayoutPass::for_test(&arena, &scratch),
child,
root,
- default_root_cells(),
+ used_values::RootInputCells::default(),
geometry::Frame::PHYSICAL,
- |nested, _| {
- nested.register(root, UsedValues::default());
- panic!("abort the nested measurement");
- },
+ |_, _| panic!("abort the nested measurement"),
);
}));
assert!(result.is_err());
assert!(std::ptr::eq(parent.used_values(root), root_used));
- assert!(std::ptr::eq(parent.used_values(child), child_used));
+ assert_eq!(scratch.runs_in_progress(), 1);
},
);
}
diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
index 7986c15759b..7f09a7f5861 100644
--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
@@ -1837,14 +1837,12 @@ impl<'pass> SvgFormattingContext<'pass> {
self.run.records.used_values(node)
}
- /// A record for `node`, a box this context lays out in it, which the run keeps the box for without.
+ /// A record for `node`, a box this context lays out in it.
fn create_used_values(&self, node: Node) -> UsedValues {
// SVG descendants deliberately carry no percentage basis.
// SVG layout resolves percentages against the SVG viewport, not a CSS containing
// block, so boxes inside the SVG subtree carry no percentage basis.
- let record = used_values::create_used_values(&self.run.callbacks, node, ContainingBlockConstraints::default());
- self.run.records.keep_box_laid_out_in_record_its_layout_owns(node);
- record
+ used_values::create_used_values(&self.run.callbacks, node, ContainingBlockConstraints::default())
}
fn set_svg_viewport_transform(&self, node: Node, transform: FfiAffineTransform) {
@@ -2060,11 +2058,8 @@ impl<'pass> SvgFormattingContext<'pass> {
return Some(self.layout_nested_viewport(run, child));
} else if kind == NodeKind::SVGForeignObjectBox {
// SVG descendants carry no percentage basis, as `create_used_values` explains.
- let mut child_cells = self.run.records.keep_child_for_its_run(
- &self.run.callbacks,
- child,
- ContainingBlockConstraints::default(),
- );
+ let mut child_cells =
+ used_values::cells_before_sizing(&self.run.callbacks, child, ContainingBlockConstraints::default());
let style = self.style(child);
let rect = SvgCssPixelRect {
x: style.x().to_px(self.viewport_width),
diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
index 6868aace041..7da3f22c902 100644
--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
@@ -1515,9 +1515,6 @@ impl<'pass> TableFormattingContext<'pass> {
let participant_box = |participant| {
let record =
used_values::create_used_values(&self.run.callbacks, participant, self.participant_constraints);
- self.run
- .records
- .keep_box_laid_out_in_record_its_layout_owns(participant);
TableParticipantBox {
record,
content_offset: Cell::new(FfiCssPixelPoint::default()),
@@ -1543,11 +1540,8 @@ impl<'pass> TableFormattingContext<'pass> {
.cells
.iter()
.map(|cell| {
- let cells = self.run.records.keep_child_for_its_run(
- &self.run.callbacks,
- cell.box_,
- self.participant_constraints,
- );
+ let cells =
+ used_values::cells_before_sizing(&self.run.callbacks, cell.box_, self.participant_constraints);
note_percentage_block_size_dependency_of(cell.box_);
cells
})
@@ -3269,7 +3263,6 @@ impl<'pass> TableFormattingContext<'pass> {
};
self.placed_cells[cell_index] = Some(formatting_context::PlacedChild::of_laid_out_box(&laid_out));
self.content_baselines_of_handed_back_cells[cell_index] = Some(laid_out.baselines);
- run.records.note_child_handed_back(cell.box_);
formatting_context::propagate_percentage_block_size_dependency_to_containing_block(
run.records,
&run.callbacks,