Skip to content

Truly independent web browser

LibWeb: Key layout runs by their root's input cells

Aliaksandr Kalenik0b107ed80959
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index de7df6478ee..c9a2acb9f6c 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -2649,8 +2649,8 @@ impl<'pass> BlockFormattingContext<'pass> {
return;
}
let mut cells = used_values::UsedValuesCellState::capture(used);
- cells.has_content_offset = false;
- cells.content_offset = FfiCssPixelPoint::default();
+ cells.inputs.has_content_offset = false;
+ cells.inputs.content_offset = FfiCssPixelPoint::default();
let content_offset = used.content_offset.get();
let entry = in_flow_block_cache::InFlowBlockEntry {
key,
@@ -3857,7 +3857,7 @@ impl<'pass> BlockFormattingContext<'pass> {
} else if automatic_block_size.is_some() {
let measurement = formatting_context::MeasurementState::create(self.run.callbacks);
let measurement_root =
- used_values::UsedValuesCellState::capture(self.used(self.run.box_)).materialize_record();
+ used_values::RootInputCells::capture(self.used(self.run.box_)).materialize_record();
let measurement_result = measurement.run_with_layout_mode(
self.run.box_,
&measurement_root,
diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
index bcc95427794..67e0cd58c2d 100644
--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
@@ -7,17 +7,18 @@
use super::*;
/// The complete identity of a memoizable run: the layout input plus the
-/// pre-run root record state the dispatch seam captures anyway, so every
-/// value a parent hands a spawned run is part of the key. Viewport changes
-/// reach a run through that input or through the normal style/layout epoch
-/// invalidation for viewport-dependent computed values.
+/// pre-run root input cells the dispatch seam captures anyway, so every
+/// value a parent hands a spawned run that the run reads is part of the
+/// key. Viewport changes reach a run through that input or through the
+/// normal style/layout epoch invalidation for viewport-dependent computed
+/// values.
#[derive(Clone, Copy, PartialEq)]
pub(super) struct FcRunCacheKey {
fc_type: formatting_context::FormattingContextType,
purpose: formatting_context::LayoutPurpose,
layout_mode: LayoutMode,
input: LayoutInput,
- root_cells: used_values::UsedValuesCellState,
+ root_cells: used_values::RootInputCells,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
@@ -66,9 +67,13 @@ impl FcRunCacheKey {
fc_type: formatting_context::FormattingContextType,
purpose: formatting_context::LayoutPurpose,
layout_mode: LayoutMode,
- input: LayoutInput,
- root_cells: used_values::UsedValuesCellState,
+ mut input: LayoutInput,
+ root_cells: used_values::RootInputCells,
) -> Self {
+ if !formatting_context::run_reads_content_block_size_adopted_after_it(fc_type, &input) {
+ input.sizing.adopt_automatic_content_block_size = false;
+ input.sizing.content_block_size_after_inside_layout = None;
+ }
Self {
fc_type,
purpose,
@@ -247,6 +252,7 @@ pub(super) struct FcRunCacheEntry {
/// Whether the run is a table cell's that cannot observe the intrinsic block padding its table hands it (see
/// table_cell_contents_never_observe_intrinsic_block_padding), so that it stands for runs with any such padding.
table_cell_intrinsic_block_padding_unobserved: bool,
+ root_content_block_size_adopted_after_run: Option<CssPixels>,
/// How many layouts the arena had committed when the run was stored. The subtrees the run took from the cache as
/// they were committed are only known to be so while no layout was committed since.
layout_commits_when_stored: u64,
@@ -276,14 +282,14 @@ impl FcRunCacheEntry {
if !arena.paintable_row_is_populated(box_) {
return false;
}
- let cells = &self.outputs.root_outcome.cells;
+ let (content_inline_size, content_block_size) = self.root_content_size_as_its_parent_holds_it();
let root_fragment_is_the_stored_one = arena
.with_current_committed_fragment(box_, |fragment| {
same_allocation(
fragment.line_data.as_ref(),
self.outputs.root_outcome.line_data.as_ref(),
- ) && fragment.content_inline_size == cells.content_inline_size
- && fragment.content_block_size == cells.content_block_size
+ ) && fragment.content_inline_size == content_inline_size
+ && fragment.content_block_size == content_block_size
})
.unwrap_or(false);
root_fragment_is_the_stored_one
@@ -293,6 +299,19 @@ impl FcRunCacheEntry {
}
}
+ fn root_content_size_as_its_parent_holds_it(&self) -> (CssPixels, CssPixels) {
+ match &self.outputs.root_outcome.cells {
+ formatting_context::RootCellsOutcome::AllCells(cells) => {
+ (cells.inputs.content_inline_size, cells.inputs.content_block_size)
+ }
+ formatting_context::RootCellsOutcome::OutputCellsOnly(_) => (
+ self.key.root_cells.content_inline_size,
+ self.root_content_block_size_adopted_after_run
+ .unwrap_or(self.key.root_cells.content_block_size),
+ ),
+ }
+ }
+
/// Whether the stored fragments can be replayed. Those of the subtrees the stored run took from the cache are the
/// committed ones, so such a run is replayed only before anything else is committed.
fn can_be_replayed(&self, callbacks: &LayoutPass<'_>) -> bool {
@@ -311,32 +330,20 @@ impl FcRunCacheEntry {
validity: self.validity,
outputs: outputs_without_descendant_fragments(&self.outputs),
table_cell_intrinsic_block_padding_unobserved: self.table_cell_intrinsic_block_padding_unobserved,
+ root_content_block_size_adopted_after_run: self.root_content_block_size_adopted_after_run,
layout_commits_when_stored: self.layout_commits_when_stored,
committed_subtree_token_when_descendants_dropped: Some(token),
}
}
- /// The outputs a hit for `probe` absorbs: the stored ones, or only what escapes the stored run where the hit keeps
- /// the committed subtree, with the root's block paddings moved by however much the intrinsic block padding `probe`
- /// carries differs from the stored run's.
- pub(super) fn outputs_to_replay(
- &self,
- probe: &FcRunCacheKey,
- reuses_committed_subtree: bool,
- ) -> formatting_context::RunOutputs {
- let mut outputs = if reuses_committed_subtree {
+ /// The outputs a hit absorbs: the stored ones, or only what escapes the stored run where the hit keeps the
+ /// committed subtree.
+ pub(super) fn outputs_to_replay(&self, reuses_committed_subtree: bool) -> formatting_context::RunOutputs {
+ if reuses_committed_subtree {
outputs_without_descendant_fragments(&self.outputs)
} else {
self.outputs.clone()
- };
- self.move_root_block_paddings_to(probe, &mut outputs);
- outputs
- }
-
- fn move_root_block_paddings_to(&self, probe: &FcRunCacheKey, outputs: &mut formatting_context::RunOutputs) {
- let cells = &mut outputs.root_outcome.cells;
- cells.padding_top += probe.root_cells.padding_top - self.key.root_cells.padding_top;
- cells.padding_bottom += probe.root_cells.padding_bottom - self.key.root_cells.padding_bottom;
+ }
}
}
@@ -750,8 +757,14 @@ impl FcRunCacheAttempt {
callbacks: &LayoutPass<'_>,
box_: Node,
key: FcRunCacheKey,
+ input: &LayoutInput,
outputs: &formatting_context::RunOutputs,
) {
+ let root_content_block_size_adopted_after_run = formatting_context::content_block_size_adopted_after_run(
+ input,
+ outputs.result.automatic_content_block_size,
+ )
+ .map(|block_size| clamp_to_max_dimension_value(block_size.max(CssPixels::default())));
let store = callbacks.arena().fc_run_cache_store();
let (validity, structurally_damaged_entry) = match self {
Self::Bypass => return,
@@ -764,6 +777,7 @@ impl FcRunCacheAttempt {
validity,
outputs: outputs.clone(),
table_cell_intrinsic_block_padding_unobserved: false,
+ root_content_block_size_adopted_after_run,
layout_commits_when_stored: callbacks.arena().layout_commit_count(),
committed_subtree_token_when_descendants_dropped: None,
},
@@ -795,7 +809,9 @@ impl FcRunCacheAttempt {
.sizing
.table_cell_intrinsic_block_padding
.is_some()
+ && outputs.root_outcome.cells.parent_owns_root_input_cells()
&& table_cell_contents_never_observe_intrinsic_block_padding(callbacks, box_),
+ root_content_block_size_adopted_after_run,
layout_commits_when_stored: callbacks.arena().layout_commit_count(),
committed_subtree_token_when_descendants_dropped: None,
};
@@ -904,7 +920,7 @@ mod tests {
},
ParticipationInParentFormattingContext::AtomicInline,
),
- root_cells: used_values::UsedValuesCellState::capture(&UsedValues::default()),
+ root_cells: used_values::RootInputCells::capture(&UsedValues::default()),
}
}
@@ -933,7 +949,9 @@ mod tests {
result: formatting_context::ChildLayoutResult::default(),
root: None,
root_outcome: formatting_context::RunRootOutcome {
- cells: used_values::UsedValuesCellState::capture(&UsedValues::default()),
+ cells: formatting_context::RootCellsOutcome::AllCells(used_values::UsedValuesCellState::capture(
+ &UsedValues::default(),
+ )),
own_metrics_sealed: false,
line_data: None,
rare: None,
@@ -942,6 +960,7 @@ mod tests {
host_findings: None,
},
table_cell_intrinsic_block_padding_unobserved: false,
+ root_content_block_size_adopted_after_run: None,
layout_commits_when_stored: 0,
committed_subtree_token_when_descendants_dropped: None,
};
@@ -977,6 +996,48 @@ mod tests {
assert!(store.entries.borrow()[0].is_none());
}
+ #[test]
+ fn item_keys_leave_out_root_outputs_and_the_block_size_adopted_after_the_run_unless_the_run_reads_it() {
+ let record = UsedValues::default();
+ let item_input = LayoutInput::new(
+ AvailableSpace {
+ inline_size: AvailableSize::definite(px(300)),
+ block_size: AvailableSize::Indefinite,
+ },
+ ContainingBlockConstraints::default(),
+ ParticipationInParentFormattingContext::Item,
+ );
+ let key_of = |fc_type, input| {
+ FcRunCacheKey::new(
+ fc_type,
+ formatting_context::LayoutPurpose::Commit,
+ LayoutMode::Normal,
+ input,
+ used_values::RootInputCells::capture(&record),
+ )
+ };
+ let stored_block_key = key_of(formatting_context::FormattingContextType::Block, item_input);
+ let stored_flex_key = key_of(formatting_context::FormattingContextType::Flex, item_input);
+
+ record.has_first_baseline.set(true);
+ record.first_baseline.set(px(12));
+ record.has_line_clamp_point.set(true);
+ record.clamped_content_is_scrollable_overflow.set(true);
+ let mut adopting_input = item_input;
+ adopting_input.sizing.adopt_automatic_content_block_size = true;
+ adopting_input.sizing.content_block_size_after_inside_layout = Some(px(40));
+
+ let exact = RunInputsTheStoredRunNeverObserved::default();
+ assert!(stored_block_key.matches(
+ &key_of(formatting_context::FormattingContextType::Block, adopting_input),
+ exact
+ ));
+ assert!(!stored_flex_key.matches(
+ &key_of(formatting_context::FormattingContextType::Flex, adopting_input),
+ exact
+ ));
+ }
+
#[test]
fn identical_keys_match_without_relaxations() {
let stored = key(AvailableSize::definite(px(300)), Some(px(300)));
@@ -1054,7 +1115,7 @@ mod tests {
let mutators: [fn(&mut FcRunCacheKey); 4] = [
|probe| probe.input.containing_block_constraints.percentage_basis_block_size = Some(px(10)),
|probe| probe.input.available_space.block_size = AvailableSize::definite(px(10)),
- |probe| probe.input.sizing.adopt_automatic_content_block_size = true,
+ |probe| probe.input.sizing.forced_min_border_box_block_size = Some(px(10)),
|probe| probe.input.participation = ParticipationInParentFormattingContext::Float,
];
for mutate in mutators {
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 2902e3a36b4..8ed18c20934 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -187,7 +187,7 @@ pub(crate) fn run_fragmentainer(
.containing_block_for_child_run(box_, &input.participation);
execute_formatting_context_run(
purpose,
- used_values::UsedValuesCellState::capture(outer.records.used_values(box_)),
+ used_values::RootInputCells::capture(outer.records.used_values(box_)),
box_,
root_containing_block,
None,
@@ -999,6 +999,16 @@ pub enum FormattingContextType {
InternalDummy,
}
+impl FormattingContextType {
+ fn registers_abspos_children_against_its_final_block_size(self) -> bool {
+ matches!(self, Self::Flex | Self::Grid)
+ }
+
+ fn lays_out_inside_its_root_as_definite_in_both_axes(self) -> bool {
+ matches!(self, Self::Svg | Self::ReplacedWithChildren)
+ }
+}
+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct BorderData {
pub color: u32,
@@ -1018,9 +1028,36 @@ pub(crate) struct ChildLayoutResult {
pub depends_on_percentage_block_size: bool,
}
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub(crate) enum RootCellsOutcome {
+ AllCells(used_values::UsedValuesCellState),
+ OutputCellsOnly(used_values::RootOutputCells),
+}
+
+impl RootCellsOutcome {
+ fn capture(record: &UsedValues, parent_owns_root_input_cells: bool) -> Self {
+ if parent_owns_root_input_cells {
+ Self::OutputCellsOnly(used_values::RootOutputCells::capture(record))
+ } else {
+ Self::AllCells(used_values::UsedValuesCellState::capture(record))
+ }
+ }
+
+ fn apply_to_record(&self, record: &UsedValues) {
+ match self {
+ Self::AllCells(cells) => cells.apply_to_record(record),
+ Self::OutputCellsOnly(output_cells) => output_cells.apply_to_record(record),
+ }
+ }
+
+ pub(super) fn parent_owns_root_input_cells(&self) -> bool {
+ matches!(self, Self::OutputCellsOnly(_))
+ }
+}
+
#[derive(Clone)]
pub(crate) struct RunRootOutcome {
- pub(super) cells: used_values::UsedValuesCellState,
+ pub(super) cells: RootCellsOutcome,
pub(super) own_metrics_sealed: bool,
pub(super) line_data: Option<std::sync::Arc<inline_content::InlineContent>>,
/// Boxed, as most roots have none and a cached run holds its outcome for as long as it is reusable.
@@ -1028,8 +1065,13 @@ pub(crate) struct RunRootOutcome {
}
impl RunRootOutcome {
- fn apply_to_record(self, record: &UsedValues) {
+ fn apply_to_record(self, record: &UsedValues, content_block_size_adopted_after_run: Option<CssPixels>) {
self.cells.apply_to_record(record);
+ if let Some(block_size) = content_block_size_adopted_after_run
+ && record.content_block_size.get() != clamp_to_max_dimension_value(block_size.max(CssPixels::default()))
+ {
+ record.set_content_block_size(block_size);
+ }
if let Some(line_data) = self.line_data {
record.set_finished_line_data(line_data);
}
@@ -1260,10 +1302,11 @@ impl<'pass> FormattingContextRun<'pass> {
result: ChildLayoutResult,
root: Option<fragment_tree::UnplacedRootFragment>,
atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above: Option<CssPixels>,
+ parent_owns_root_input_cells: bool,
) -> RunOutputs {
let record = self.records.used_values(self.box_);
let root_outcome = RunRootOutcome {
- cells: used_values::UsedValuesCellState::capture(record),
+ cells: RootCellsOutcome::capture(record, parent_owns_root_input_cells),
own_metrics_sealed: record.own_metrics_are_sealed(),
line_data: record.finish_line_data(&self.callbacks),
rare: record.rare_data.get().map(|rare| Box::new(rare.take())),
@@ -1862,7 +1905,7 @@ pub(super) fn run_formatting_context(
// A later run for this root supersedes a hit recorded earlier in the same pass.
parent_fragments.clear_reused_subtree_root(box_, parent_used);
}
- let root_cells = used_values::UsedValuesCellState::capture(parent_used);
+ let root_cells = used_values::RootInputCells::capture(parent_used);
if callbacks.scratch().reads_no_memoized_layout() {
let outputs = execute_formatting_context_run(
purpose,
@@ -1880,7 +1923,7 @@ pub(super) fn run_formatting_context(
table_inline_layout,
None,
);
- return absorb_run_outputs(&callbacks, parent_fragments, parent_used, box_, outputs, false);
+ return absorb_run_outputs(&callbacks, parent_fragments, parent_used, box_, &input, outputs, false);
}
let cache_key = fc_run_cache::FcRunCacheKey::new(fc_type, purpose, layout_mode, input, root_cells);
let memoizes_measurement = purpose.is_measurement()
@@ -1897,7 +1940,7 @@ pub(super) fn run_formatting_context(
.scratch()
.memoized_measurement(box_, purpose, layout_mode, &cache_key)
{
- return absorb_run_outputs(&callbacks, parent_fragments, parent_used, box_, outputs, false);
+ return absorb_run_outputs(&callbacks, parent_fragments, parent_used, box_, &input, outputs, false);
}
let cache_attempt = match fc_run_cache::FcRunCacheAttempt::probe(
box_,
@@ -1914,6 +1957,7 @@ pub(super) fn run_formatting_context(
parent_fragments,
parent_used,
box_,
+ &input,
&callbacks,
&cache_key,
&hit,
@@ -1934,12 +1978,13 @@ pub(super) fn run_formatting_context(
"REPLAY FRAGMENTS"
}
});
- let outputs = hit.entry.outputs_to_replay(&cache_key, reuses_committed_subtree);
+ let outputs = hit.entry.outputs_to_replay(reuses_committed_subtree);
return absorb_run_outputs(
&callbacks,
parent_fragments,
parent_used,
box_,
+ &input,
outputs,
reuses_committed_subtree,
);
@@ -1992,19 +2037,21 @@ pub(super) fn run_formatting_context(
.scratch()
.memoize_measurement(box_, purpose, layout_mode, cache_key, &outputs);
}
- cache_attempt.conclude(&callbacks, box_, cache_key, &outputs);
- absorb_run_outputs(&callbacks, parent_fragments, parent_used, box_, outputs, false)
+ cache_attempt.conclude(&callbacks, box_, cache_key, &input, &outputs);
+ absorb_run_outputs(&callbacks, parent_fragments, parent_used, box_, &input, outputs, false)
}
/// Takes a committing run of `box_` from the cache hit `hit` with nothing replayed: its root record gets what the
/// stored run left, and the run's placement attaches the box's committed fragment as it is. That is exact where the
/// committed subtree is the one the stored run produced, the box is plain, and nothing from the stored run reaches
/// past its root.
+#[expect(clippy::too_many_arguments)]
fn reuse_committed_subtree_as_it_is(
purpose: LayoutPurpose,
parent_fragments: Option<&fragment_tree::RunFragmentBuilder>,
root_used: &UsedValues,
box_: Node,
+ input: &LayoutInput,
callbacks: &LayoutPass<'_>,
cache_key: &fc_run_cache::FcRunCacheKey,
hit: &fc_run_cache::FcRunCacheHit,
@@ -2026,7 +2073,10 @@ fn reuse_committed_subtree_as_it_is(
.arena()
.with_current_committed_fragment(box_, |fragment| fragment.is_plain_box().then(|| fragment.clone()))
.flatten()?;
- entry.outputs.root_outcome.clone().apply_to_record(root_used);
+ entry.outputs.root_outcome.clone().apply_to_record(
+ root_used,
+ content_block_size_adopted_after_run(input, entry.outputs.result.automatic_content_block_size),
+ );
if !root_used.shows_box_of_fragment(&fragment) {
return None;
}
@@ -2077,7 +2127,7 @@ fn lays_out_box_for_its_content_inline_sizes(
#[expect(clippy::too_many_arguments)]
fn execute_formatting_context_run(
purpose: LayoutPurpose,
- root_cells: used_values::UsedValuesCellState,
+ root_cells: used_values::RootInputCells,
box_: Node,
root_containing_block: Node,
parent_grid: Option<&grid_formatting_context::GridFormattingContext>,
@@ -2092,8 +2142,9 @@ fn execute_formatting_context_run(
fragmentainer: Option<std::rc::Rc<fragmentation::FragmentainerContext>>,
) -> RunOutputs {
assert!(!box_.is_invalid());
+ let parent_owns_root_input_cells = parent_owns_root_input_cells(&callbacks, box_, &input);
let root_used = root_cells.materialize_record();
- RunRecords::with_root(
+ let outputs = RunRecords::with_root(
callbacks,
box_,
root_containing_block,
@@ -2311,11 +2362,10 @@ fn execute_formatting_context_run(
);
}
ParticipationInParentFormattingContext::Item => {
- if input.sizing.adopt_automatic_content_block_size {
- let used = run.records.used_values(run.box_);
- used.set_content_block_size(result.automatic_content_block_size);
- }
- if let Some(block_size) = input.sizing.content_block_size_after_inside_layout {
+ if run_reads_content_block_size_adopted_after_it(fc_type, &input)
+ && let Some(block_size) =
+ content_block_size_adopted_after_run(&input, result.automatic_content_block_size)
+ {
run.records.used_values(run.box_).set_content_block_size(block_size);
}
}
@@ -2354,6 +2404,7 @@ fn execute_formatting_context_run(
result,
take_run_fragments(),
atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,
+ parent_owns_root_input_cells,
);
}
if let Some(implementation) = implementation {
@@ -2382,6 +2433,7 @@ fn execute_formatting_context_run(
result,
take_run_fragments(),
atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,
+ parent_owns_root_input_cells,
);
}
}
@@ -2391,9 +2443,28 @@ fn execute_formatting_context_run(
result,
take_run_fragments(),
atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,
+ parent_owns_root_input_cells,
)
},
- )
+ );
+ if parent_owns_root_input_cells && (cfg!(debug_assertions) || run_repeatability::verification_is_enabled()) {
+ let mut root_input_cells_the_run_must_leave = root_cells;
+ if fc_type.lays_out_inside_its_root_as_definite_in_both_axes() {
+ root_input_cells_the_run_must_leave.has_definite_inline_size = true;
+ root_input_cells_the_run_must_leave.has_definite_block_size = true;
+ }
+ if run_reads_content_block_size_adopted_after_it(fc_type, &input)
+ && content_block_size_adopted_after_run(&input, outputs.result.automatic_content_block_size).is_some()
+ {
+ root_input_cells_the_run_must_leave.content_block_size = root_used.content_block_size.get();
+ }
+ assert_eq!(
+ used_values::RootInputCells::capture(&root_used),
+ root_input_cells_the_run_must_leave,
+ "the run of {box_:?} changed root cells its parent owns"
+ );
+ }
+ outputs
}
/// The frame in which `node` lays out its contents: that of its writing mode.
@@ -2793,7 +2864,7 @@ pub(crate) fn run_table_cell_ahead_of_its_intrinsic_block_padding(
run.treat_block_axis_percentage_insets_as_auto_beyond_root,
);
input.sizing.flex_self_block_size_resolution_space = None;
- let root_cells = used_values::UsedValuesCellState::capture(run.records.used_values(cell));
+ let root_cells = used_values::RootInputCells::capture(run.records.used_values(cell));
let cache_key = fc_run_cache::FcRunCacheKey::new(
FormattingContextType::Block,
LayoutPurpose::Commit,
@@ -2866,15 +2937,46 @@ pub(crate) fn run_table_cell_ahead_of_its_intrinsic_block_padding(
if let Some(discarded_outputs) = &discarded_outputs {
run_repeatability::verify_repeated_run(&run.callbacks, cell, discarded_outputs, &outputs);
}
- cache_attempt.conclude(&run.callbacks, cell, cache_key, &outputs);
+ cache_attempt.conclude(&run.callbacks, cell, cache_key, &input, &outputs);
Some(outputs.result)
}
+// NB: An item that establishes an orthogonal flow sizes itself along its container's block axis, so its run owns its
+// root input cells.
+pub(super) fn parent_owns_root_input_cells(callbacks: &LayoutPass<'_>, box_: Node, input: &LayoutInput) -> bool {
+ input.participation == ParticipationInParentFormattingContext::Item
+ && !input.available_space.inline_size.is_intrinsic_sizing_constraint()
+ && !input.available_space.block_size.is_intrinsic_sizing_constraint()
+ && !frame_established_by(callbacks, box_).is_orthogonal_to(callbacks.frame)
+}
+
+pub(super) fn content_block_size_adopted_after_run(
+ input: &LayoutInput,
+ automatic_content_block_size: CssPixels,
+) -> Option<CssPixels> {
+ if input.participation != ParticipationInParentFormattingContext::Item {
+ return None;
+ }
+ input.sizing.content_block_size_after_inside_layout.or(input
+ .sizing
+ .adopt_automatic_content_block_size
+ .then_some(automatic_content_block_size))
+}
+
+pub(super) fn run_reads_content_block_size_adopted_after_it(
+ fc_type: FormattingContextType,
+ input: &LayoutInput,
+) -> bool {
+ input.participation == ParticipationInParentFormattingContext::Item
+ && fc_type.registers_abspos_children_against_its_final_block_size()
+}
+
fn absorb_run_outputs(
callbacks: &LayoutPass<'_>,
parent_fragments: Option<&fragment_tree::RunFragmentBuilder>,
parent_used: &UsedValues,
child: Node,
+ input: &LayoutInput,
outputs: RunOutputs,
reuses_committed_subtree: bool,
) -> ChildLayoutResult {
@@ -2886,7 +2988,10 @@ fn absorb_run_outputs(
host_findings,
} = outputs;
callbacks.scratch().receive_host_findings(host_findings);
- root_outcome.apply_to_record(parent_used);
+ root_outcome.apply_to_record(
+ parent_used,
+ content_block_size_adopted_after_run(input, result.automatic_content_block_size),
+ );
if let (Some(fragments), Some(root)) = (parent_fragments, root) {
debug_assert!(root.node == child, "a child run returned a root for a different box");
if reuses_committed_subtree {
diff --git a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
index 810825a26b2..82f56c080fc 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
@@ -26,6 +26,10 @@ fn run_repeatability_verification() -> RunRepeatabilityVerification {
})
}
+pub(super) fn verification_is_enabled() -> bool {
+ run_repeatability_verification() != RunRepeatabilityVerification::Off
+}
+
/// Lays out a run whose result is discarded through `run`, where the verification is on and no such run is in
/// progress around it already. Nothing it does is traced.
pub(super) fn lay_out_discarded_run(
diff --git a/Libraries/LibWeb/Rust/src/layout/used_values.rs b/Libraries/LibWeb/Rust/src/layout/used_values.rs
index 1a429de571a..367d8d6f723 100644
--- a/Libraries/LibWeb/Rust/src/layout/used_values.rs
+++ b/Libraries/LibWeb/Rust/src/layout/used_values.rs
@@ -581,7 +581,7 @@ impl UsedValues {
let state = UsedValuesCellState::capture(self).in_frame(from, to);
macro_rules! move_sealable {
($($field:ident),+) => {
- $(self.$field.set_ignoring_seal(state.$field);)+
+ $(self.$field.set_ignoring_seal(state.inputs.$field);)+
};
}
move_sealable!(
@@ -604,12 +604,13 @@ impl UsedValues {
inset_top,
inset_bottom
);
- self.has_definite_inline_size.set(state.has_definite_inline_size);
- self.has_definite_block_size.set(state.has_definite_block_size);
- self.block_size_constraint.set(state.block_size_constraint);
- self.has_first_baseline.set(state.has_first_baseline);
- self.has_last_baseline.set(state.has_last_baseline);
- self.inline_alignment_baseline.set(state.inline_alignment_baseline);
+ self.has_definite_inline_size.set(state.inputs.has_definite_inline_size);
+ self.has_definite_block_size.set(state.inputs.has_definite_block_size);
+ self.block_size_constraint.set(state.inputs.block_size_constraint);
+ self.has_first_baseline.set(state.outputs.has_first_baseline);
+ self.has_last_baseline.set(state.outputs.has_last_baseline);
+ self.inline_alignment_baseline
+ .set(state.outputs.inline_alignment_baseline);
}
pub(crate) fn own_metrics_are_sealed(&self) -> bool {
@@ -634,14 +635,14 @@ impl UsedValues {
}
}
-macro_rules! used_values_cell_state {
- ($($field:ident: $type:ty,)+) => {
+macro_rules! used_values_cells {
+ ($name:ident { $($field:ident: $type:ty,)+ }) => {
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
- pub(crate) struct UsedValuesCellState {
+ pub(crate) struct $name {
$(pub(crate) $field: $type,)+
}
- impl UsedValuesCellState {
+ impl $name {
pub(crate) fn capture(used: &UsedValues) -> Self {
Self {
$($field: used.$field.get(),)+
@@ -659,102 +660,163 @@ macro_rules! used_values_cell_state {
};
}
-used_values_cell_state! {
- content_inline_size: CssPixels,
- content_block_size: CssPixels,
- margin_left: CssPixels,
- margin_right: CssPixels,
- margin_top: CssPixels,
- margin_bottom: CssPixels,
- border_left: CssPixels,
- border_right: CssPixels,
- border_top: CssPixels,
- border_bottom: CssPixels,
- padding_left: CssPixels,
- padding_right: CssPixels,
- padding_top: CssPixels,
- padding_bottom: CssPixels,
- inset_left: CssPixels,
- inset_right: CssPixels,
- inset_top: CssPixels,
- inset_bottom: CssPixels,
- has_definite_inline_size: bool,
- has_definite_block_size: bool,
- has_definite_block_size_only_for_button_content_alignment: bool,
- uses_collapsing_borders_model: bool,
- is_collapsed_borders_table_box: bool,
- has_line_clamp_point: bool,
- is_invisible_for_line_clamp: bool,
- clamped_content_is_scrollable_overflow: bool,
- continues_from_previous_fragment: bool,
- continues_in_next_fragment: bool,
- table_column_index: u32,
- table_column_span: u32,
- hidden_by_collapsed_columns: bool,
- block_size_constraint: SizeConstraint,
- has_content_offset: bool,
- content_offset: FfiCssPixelPoint,
- has_first_baseline: bool,
- first_baseline: CssPixels,
- has_last_baseline: bool,
- last_baseline: CssPixels,
- inline_alignment_baseline: Option<CssPixels>,
+used_values_cells! {
+ RootInputCells {
+ content_inline_size: CssPixels,
+ content_block_size: CssPixels,
+ margin_left: CssPixels,
+ margin_right: CssPixels,
+ margin_top: CssPixels,
+ margin_bottom: CssPixels,
+ border_left: CssPixels,
+ border_right: CssPixels,
+ border_top: CssPixels,
+ border_bottom: CssPixels,
+ padding_left: CssPixels,
+ padding_right: CssPixels,
+ padding_top: CssPixels,
+ padding_bottom: CssPixels,
+ inset_left: CssPixels,
+ inset_right: CssPixels,
+ inset_top: CssPixels,
+ inset_bottom: CssPixels,
+ has_definite_inline_size: bool,
+ has_definite_block_size: bool,
+ has_definite_block_size_only_for_button_content_alignment: bool,
+ uses_collapsing_borders_model: bool,
+ is_collapsed_borders_table_box: bool,
+ is_invisible_for_line_clamp: bool,
+ continues_from_previous_fragment: bool,
+ continues_in_next_fragment: bool,
+ table_column_index: u32,
+ table_column_span: u32,
+ hidden_by_collapsed_columns: bool,
+ block_size_constraint: SizeConstraint,
+ has_content_offset: bool,
+ content_offset: FfiCssPixelPoint,
+ }
+}
+
+used_values_cells! {
+ RootOutputCells {
+ has_line_clamp_point: bool,
+ clamped_content_is_scrollable_overflow: bool,
+ has_first_baseline: bool,
+ first_baseline: CssPixels,
+ has_last_baseline: bool,
+ last_baseline: CssPixels,
+ inline_alignment_baseline: Option<CssPixels>,
+ }
+}
+
+impl RootInputCells {
+ pub(crate) fn materialize_record(&self) -> UsedValues {
+ let record = UsedValues::default();
+ self.apply_to_record(&record);
+ if self.has_content_offset {
+ record.seal_committed_box_metrics();
+ }
+ record
+ }
+}
+
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub(crate) struct UsedValuesCellState {
+ pub(crate) inputs: RootInputCells,
+ pub(crate) outputs: RootOutputCells,
}
impl UsedValuesCellState {
+ pub(crate) fn capture(used: &UsedValues) -> Self {
+ Self {
+ inputs: RootInputCells::capture(used),
+ outputs: RootOutputCells::capture(used),
+ }
+ }
+
+ pub(crate) fn apply_to_record(&self, used: &UsedValues) {
+ self.inputs.apply_to_record(used);
+ self.outputs.apply_to_record(used);
+ }
+
/// The state, with the sizes, size constraints and box sides it holds in frame `from` read in frame `to` instead.
pub(crate) fn in_frame(mut self, from: geometry::Frame, to: geometry::Frame) -> Self {
if from == to {
return self;
}
- [self.margin_top, self.margin_right, self.margin_bottom, self.margin_left] = from.sides_in(
- [self.margin_top, self.margin_right, self.margin_bottom, self.margin_left],
+ let inputs = &mut self.inputs;
+ [
+ inputs.margin_top,
+ inputs.margin_right,
+ inputs.margin_bottom,
+ inputs.margin_left,
+ ] = from.sides_in(
+ [
+ inputs.margin_top,
+ inputs.margin_right,
+ inputs.margin_bottom,
+ inputs.margin_left,
+ ],
to,
);
- [self.border_top, self.border_right, self.border_bottom, self.border_left] = from.sides_in(
- [self.border_top, self.border_right, self.border_bottom, self.border_left],
+ [
+ inputs.border_top,
+ inputs.border_right,
+ inputs.border_bottom,
+ inputs.border_left,
+ ] = from.sides_in(
+ [
+ inputs.border_top,
+ inputs.border_right,
+ inputs.border_bottom,
+ inputs.border_left,
+ ],
to,
);
[
- self.padding_top,
- self.padding_right,
- self.padding_bottom,
- self.padding_left,
+ inputs.padding_top,
+ inputs.padding_right,
+ inputs.padding_bottom,
+ inputs.padding_left,
] = from.sides_in(
[
- self.padding_top,
- self.padding_right,
- self.padding_bottom,
- self.padding_left,
+ inputs.padding_top,
+ inputs.padding_right,
+ inputs.padding_bottom,
+ inputs.padding_left,
],
to,
);
- [self.inset_top, self.inset_right, self.inset_bottom, self.inset_left] = from.sides_in(
- [self.inset_top, self.inset_right, self.inset_bottom, self.inset_left],
+ [
+ inputs.inset_top,
+ inputs.inset_right,
+ inputs.inset_bottom,
+ inputs.inset_left,
+ ] = from.sides_in(
+ [
+ inputs.inset_top,
+ inputs.inset_right,
+ inputs.inset_bottom,
+ inputs.inset_left,
+ ],
to,
);
if from.is_orthogonal_to(to) {
- std::mem::swap(&mut self.content_inline_size, &mut self.content_block_size);
- std::mem::swap(&mut self.has_definite_inline_size, &mut self.has_definite_block_size);
+ std::mem::swap(&mut inputs.content_inline_size, &mut inputs.content_block_size);
+ std::mem::swap(
+ &mut inputs.has_definite_inline_size,
+ &mut inputs.has_definite_block_size,
+ );
debug_assert!(
- self.block_size_constraint == SizeConstraint::None,
+ inputs.block_size_constraint == SizeConstraint::None,
"a box measured for its block size never lays out in an orthogonal frame"
);
- self.has_first_baseline = false;
- self.has_last_baseline = false;
- self.inline_alignment_baseline = None;
+ self.outputs.has_first_baseline = false;
+ self.outputs.has_last_baseline = false;
+ self.outputs.inline_alignment_baseline = None;
}
self
}
-
- pub(crate) fn materialize_record(&self) -> UsedValues {
- let record = UsedValues::default();
- self.apply_to_record(&record);
- if self.has_content_offset {
- record.seal_committed_box_metrics();
- }
- record
- }
}
impl UsedValues {