Skip to content

Truly independent web browser

LibWeb: Hand a child's baselines back only in its run's result

Aliaksandr Kalenik3e43205cb860
diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
index 53a67e8f472..2f3a467e0b9 100644
--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
@@ -323,11 +323,9 @@ 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(_) => (
+ match &self.outputs.root_outcome.input_cells_left_by_run {
+ Some(cells) => (cells.content_inline_size, cells.content_block_size),
+ None => (
self.key.root_cells.content_inline_size,
self.root_content_block_size_adopted_after_run
.unwrap_or(self.key.root_cells.content_block_size),
@@ -937,7 +935,7 @@ impl FcRunCacheAttempt {
.sizing
.table_cell_intrinsic_block_padding
.is_some()
- && outputs.root_outcome.cells.parent_owns_root_input_cells()
+ && outputs.root_outcome.parent_owns_root_input_cells()
&& !run_observes_root_block_padding(callbacks, box_, outputs),
root_content_block_size_adopted_after_run,
layout_commits_when_stored: callbacks.arena().layout_commit_count(),
@@ -1074,9 +1072,7 @@ mod tests {
result: formatting_context::ChildLayoutResult::default(),
root,
root_outcome: formatting_context::RunRootOutcome {
- cells: formatting_context::RootCellsOutcome::AllCells(used_values::UsedValuesCellState::capture(
- &UsedValues::default(),
- )),
+ input_cells_left_by_run: Some(used_values::RootInputCells::capture(&UsedValues::default())),
own_metrics_sealed: false,
line_data: None,
},
@@ -1333,7 +1329,7 @@ mod tests {
}
#[test]
- fn item_keys_leave_out_root_outputs_and_the_block_size_adopted_after_the_run_unless_the_run_reads_it() {
+ fn item_keys_leave_out_the_block_size_adopted_after_the_run_unless_the_run_reads_it() {
let record = UsedValues::default();
let item_input = LayoutInput::new(
AvailableSpace {
@@ -1347,8 +1343,6 @@ mod tests {
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));
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));
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index ef3c89c9dbb..e756e4ae76c 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -1068,6 +1068,9 @@ pub(crate) struct ChildLayoutResult {
pub depends_on_percentage_block_size: bool,
/// For an absolutely positioned box, the used insets its run gave it.
pub out_of_flow_root_used_insets: Option<run_records::UsedInsets>,
+ /// For a box that establishes an orthogonal flow, its baselines along the horizontal axis of its parent's frame,
+ /// from the left edge of its content box.
+ pub orthogonal_flow_baselines: Option<DerivedBaselines>,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
@@ -1077,67 +1080,41 @@ pub(crate) enum OwnBlockSizeObservation {
Unobserved,
}
-#[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: RootCellsOutcome,
+ /// The input cells the run left its root, unless its parent owns them.
+ pub(super) input_cells_left_by_run: Option<used_values::RootInputCells>,
pub(super) own_metrics_sealed: bool,
pub(super) line_data: Option<std::sync::Arc<inline_content::InlineContent>>,
}
impl RunRootOutcome {
- /// What the parent keeps of the root once its run returns, given the input cells it handed the run.
+ pub(super) fn parent_owns_root_input_cells(&self) -> bool {
+ self.input_cells_left_by_run.is_none()
+ }
+
+ /// What the parent keeps of the root once its run returned `result`, given the input cells it handed the run.
fn laid_out_child_box(
&self,
root_cells: used_values::RootInputCells,
+ result: &ChildLayoutResult,
content_block_size_adopted_after_run: Option<CssPixels>,
) -> run_records::LaidOutChildBox {
- let (mut cells, outputs) = match self.cells {
- RootCellsOutcome::AllCells(state) => (state.inputs, state.outputs),
- RootCellsOutcome::OutputCellsOnly(outputs) => (root_cells, outputs),
- };
+ let mut cells = self.input_cells_left_by_run.unwrap_or(root_cells);
if let Some(block_size) = content_block_size_adopted_after_run {
cells.content_block_size = clamp_to_max_dimension_value(block_size.max(CssPixels::default()));
}
run_records::LaidOutChildBox {
cells,
- baselines: DerivedBaselines {
- inline_alignment: outputs.inline_alignment_baseline,
- first: outputs.has_first_baseline.then_some(outputs.first_baseline),
- last: outputs.has_last_baseline.then_some(outputs.last_baseline),
- },
- orthogonal_flow_baselines: outputs.orthogonal_flow_baselines,
+ baselines: result.baselines,
+ orthogonal_flow_baselines: result.orthogonal_flow_baselines,
}
}
fn apply_to_record(self, record: &UsedValues, content_block_size_adopted_after_run: Option<CssPixels>) {
- self.cells.apply_to_record(record);
+ if let Some(cells) = self.input_cells_left_by_run {
+ 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()))
{
@@ -1405,7 +1382,8 @@ impl<'pass> FormattingContextRun<'pass> {
) -> RunOutputs {
let record = self.records.used_values(self.box_);
let root_outcome = RunRootOutcome {
- cells: RootCellsOutcome::capture(record, parent_owns_root_input_cells),
+ input_cells_left_by_run: (!parent_owns_root_input_cells)
+ .then(|| used_values::RootInputCells::capture(record)),
own_metrics_sealed: record.own_metrics_are_sealed(),
line_data: record.finish_line_data(&self.callbacks),
};
@@ -2183,10 +2161,11 @@ fn reuse_committed_subtree_as_it_is(
callbacks
.scratch()
.receive_host_findings(entry.outputs.host_findings.clone());
- let laid_out_box = entry
- .outputs
- .root_outcome
- .laid_out_child_box(root_cells, content_block_size_adopted_after_run);
+ let laid_out_box = entry.outputs.root_outcome.laid_out_child_box(
+ root_cells,
+ &entry.outputs.result,
+ content_block_size_adopted_after_run,
+ );
Some((entry.outputs.result, laid_out_box, fragment))
}
@@ -2369,13 +2348,11 @@ fn lay_out_run_root_and_contents<'pass>(
if NodeFacts::new(&body_run.callbacks, box_).display().is_math_inside() {
math_formatting_context::layout_operator(body_run, &input, &mut result);
}
- store_derived_baselines(run.records.used_values(run.box_), result.baselines);
result
}
FormattingContextImplementation::Flex(context) => {
context.run(body_run, body_input);
let baselines = context.derived_baselines_of_root_box();
- store_derived_baselines(run.records.used_values(run.box_), baselines);
ChildLayoutResult {
automatic_content_block_size: context.automatic_content_block_size(),
baselines,
@@ -2385,7 +2362,6 @@ fn lay_out_run_root_and_contents<'pass>(
FormattingContextImplementation::Grid(context) => {
context.run(body_run, body_input);
let baselines = context.derived_baselines_of_root_box();
- store_derived_baselines(run.records.used_values(run.box_), baselines);
ChildLayoutResult {
automatic_content_block_size: context.automatic_content_block_size(),
baselines,
@@ -2395,7 +2371,6 @@ fn lay_out_run_root_and_contents<'pass>(
FormattingContextImplementation::Table(context) => {
context.run(body_run, body_input, inline_layout_of_root_table_box.take());
let baselines = context.derived_baselines_of_root_box();
- store_derived_baselines(run.records.used_values(run.box_), baselines);
ChildLayoutResult {
automatic_content_block_size: context.automatic_content_block_size,
baselines,
@@ -2409,7 +2384,6 @@ fn lay_out_run_root_and_contents<'pass>(
FormattingContextImplementation::Math(context) => {
context.run(body_run, body_input);
let baselines = context.derived_baselines_of_root_box();
- store_derived_baselines(run.records.used_values(run.box_), baselines);
ChildLayoutResult {
automatic_content_block_size: context.automatic_content_block_size(),
baselines,
@@ -2707,8 +2681,8 @@ fn leave_own_frame(
first: along_parent_horizontal_axis(result.baselines.first),
last: along_parent_horizontal_axis(result.baselines.last),
};
- used.orthogonal_flow_baselines
- .set((orthogonal_flow_baselines != DerivedBaselines::default()).then_some(orthogonal_flow_baselines));
+ result.orthogonal_flow_baselines =
+ (orthogonal_flow_baselines != DerivedBaselines::default()).then_some(orthogonal_flow_baselines);
// NB: The inline size of a table wrapper in its parent's frame is the block size of its content in its own
// frame.
if result.table_wrapper_content_inline_size.is_some() {
@@ -3252,7 +3226,7 @@ fn absorb_run_outputs(
callbacks.scratch().receive_host_findings(host_findings);
let content_block_size_adopted_after_run =
content_block_size_adopted_after_run(input, result.automatic_content_block_size);
- let laid_out_box = root_outcome.laid_out_child_box(root_cells, content_block_size_adopted_after_run);
+ let laid_out_box = root_outcome.laid_out_child_box(root_cells, &result, content_block_size_adopted_after_run);
root_outcome.apply_to_record(parent_used, content_block_size_adopted_after_run);
let fragment_arrival = parent_fragments.and(root).map(|root| {
debug_assert!(root.node == child, "a child run returned a root for a different box");
diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rs
index 53425a7ea07..238f0a9d4da 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs
@@ -355,17 +355,6 @@ pub(crate) struct LaidOutChildBox {
pub(crate) orthogonal_flow_baselines: Option<DerivedBaselines>,
}
-impl LaidOutChildBox {
- /// The box as `record` holds it.
- pub(crate) fn as_record_holds_it(record: &UsedValues) -> Self {
- Self {
- cells: used_values::RootInputCells::capture(record),
- baselines: record.content_baselines_from_cells(),
- orthogonal_flow_baselines: record.orthogonal_flow_baselines.get(),
- }
- }
-}
-
/// The sizes, size constraints, box sides and baselines of a box as a run sees them: kept as a value for a child laid
/// out by a run of its own, or read from the record of a box the run lays out itself.
#[derive(Clone, Copy)]
@@ -385,7 +374,8 @@ impl BoxMetrics<'_> {
pub(crate) fn orthogonal_flow_baselines(&self) -> Option<DerivedBaselines> {
match self {
Self::LaidOutByItsOwnRun(laid_out) => laid_out.orthogonal_flow_baselines,
- Self::LaidOutByThisRun(record) => record.orthogonal_flow_baselines.get(),
+ // NB: A box that establishes an orthogonal flow is laid out by a run of its own.
+ Self::LaidOutByThisRun(_) => None,
}
}
}
@@ -951,8 +941,8 @@ impl<'arena> RunRecords<'arena> {
};
if cfg!(debug_assertions) || super::run_repeatability::verification_is_enabled() {
assert_eq!(
- laid_out,
- LaidOutChildBox::as_record_holds_it(record),
+ laid_out.cells,
+ used_values::RootInputCells::capture(record),
"the parent's record of {node:?} changed after its run handed the box back"
);
}
diff --git a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
index 94288ac7af4..62145b6b8b5 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
@@ -194,7 +194,8 @@ impl ComparedLayouts<'_> {
"{checked} returned a result {reference} does not"
);
assert_eq!(
- checked_outputs.root_outcome.cells, reference_outputs.root_outcome.cells,
+ checked_outputs.root_outcome.input_cells_left_by_run,
+ reference_outputs.root_outcome.input_cells_left_by_run,
"{checked} left a root record {reference} does not"
);
assert_eq!(
diff --git a/Libraries/LibWeb/Rust/src/layout/used_values.rs b/Libraries/LibWeb/Rust/src/layout/used_values.rs
index 43fef5d3138..f15321033d6 100644
--- a/Libraries/LibWeb/Rust/src/layout/used_values.rs
+++ b/Libraries/LibWeb/Rust/src/layout/used_values.rs
@@ -221,9 +221,6 @@ pub(crate) struct UsedValues {
pub has_last_baseline: Cell<bool>,
pub last_baseline: Cell<CssPixels>,
pub inline_alignment_baseline: Cell<Option<CssPixels>>,
- /// For a box that establishes an orthogonal flow, its baselines as distances along the horizontal axis of the frame
- /// it is laid out in, from the left edge of its content box.
- pub orthogonal_flow_baselines: Cell<Option<DerivedBaselines>>,
pub(crate) line_data: RefCell<LineDataState>,
/// The anchor-size() resolutions of an absolutely positioned box, set once as the abspos engine places it.
@@ -258,7 +255,6 @@ impl Default for UsedValues {
has_last_baseline: Cell::new(false),
last_baseline: Cell::new(zero),
inline_alignment_baseline: Cell::new(None),
- orthogonal_flow_baselines: Cell::new(None),
line_data: RefCell::new(LineDataState::Empty),
anchor_resolved_values: std::cell::OnceCell::new(),
}
@@ -372,10 +368,7 @@ impl UsedValues {
);
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.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);
+ formatting_context::store_derived_baselines(self, state.baselines);
}
pub(crate) fn own_metrics_are_sealed(&self) -> bool {
@@ -449,17 +442,6 @@ used_values_cells! {
}
}
-used_values_cells! {
- RootOutputCells {
- has_first_baseline: bool,
- first_baseline: CssPixels,
- has_last_baseline: bool,
- last_baseline: CssPixels,
- inline_alignment_baseline: Option<CssPixels>,
- orthogonal_flow_baselines: Option<DerivedBaselines>,
- }
-}
-
impl RootInputCells {
/// The input cells of `node` as its record starts out, before anything sizes the box.
pub(crate) fn of_box_before_sizing(
@@ -480,20 +462,20 @@ impl RootInputCells {
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct UsedValuesCellState {
pub(crate) inputs: RootInputCells,
- pub(crate) outputs: RootOutputCells,
+ pub(crate) baselines: DerivedBaselines,
}
impl UsedValuesCellState {
pub(crate) fn capture(used: &UsedValues) -> Self {
Self {
inputs: RootInputCells::capture(used),
- outputs: RootOutputCells::capture(used),
+ baselines: used.content_baselines_from_cells(),
}
}
pub(crate) fn apply_to_record(&self, used: &UsedValues) {
self.inputs.apply_to_record(used);
- self.outputs.apply_to_record(used);
+ formatting_context::store_derived_baselines(used, self.baselines);
}
/// The state, with the sizes, size constraints and box sides it holds in frame `from` read in frame `to` instead.
@@ -550,9 +532,7 @@ impl UsedValuesCellState {
&mut inputs.has_definite_inline_size,
&mut inputs.has_definite_block_size,
);
- self.outputs.has_first_baseline = false;
- self.outputs.has_last_baseline = false;
- self.outputs.inline_alignment_baseline = None;
+ self.baselines = DerivedBaselines::default();
}
self
}