Truly independent web browser
LibWeb: Hand back the baselines of a box laid out in its parent's flow
Aliaksandr Kalenik7dc5997d0498
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex fac1ff517be..6b07b7b6a47 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -2485,7 +2485,7 @@ impl<'pass> BlockFormattingContext<'pass> {content_offset: Some(content_offset),margin_box_block_end: Some(margin_box_block_end),..LaidOutBlockLevelBox::of_box(- Self::laid_out_box_in_record_its_layout_owns(sized_child),+ Self::laid_out_box_in_record_its_layout_owns(sized_child, entry.baselines),fragment_facts,)});@@ -2554,7 +2554,7 @@ impl<'pass> BlockFormattingContext<'pass> {return Some(LaidOutBlockLevelBox {collapses_through: self.margins_collapse_through(sized_child, None),..LaidOutBlockLevelBox::of_box(- Self::laid_out_box_in_record_its_layout_owns(sized_child),+ Self::laid_out_box_in_record_its_layout_owns(sized_child, DerivedBaselines::default()),fragment_facts,)});@@ -2840,7 +2840,6 @@ impl<'pass> BlockFormattingContext<'pass> {space_available_for_children,)};- formatting_context::store_derived_baselines(self.record_of(sized_child), children_summary.baselines);baselines_of_contents_laid_out_in_this_flow = Some(children_summary.baselines);summary_of_children_laid_out_in_this_flow = Some(children_summary);if is_in_flow_candidate {@@ -3112,6 +3111,7 @@ impl<'pass> BlockFormattingContext<'pass> {self.conclude_in_flow_reuse(in_flow_reuse,sized_child,+ baselines_of_contents_laid_out_in_this_flow.unwrap_or_default(),placed.map(|placed| (content_offset, placed)),depends_on_percentage_block_size,);@@ -3126,8 +3126,12 @@ impl<'pass> BlockFormattingContext<'pass> {broken_inside,has_unbreakable_lines,collapses_through,- laid_out_box: laid_out_box_handed_back_by_its_run- .unwrap_or_else(|| Self::laid_out_box_in_record_its_layout_owns(sized_child)),+ laid_out_box: laid_out_box_handed_back_by_its_run.unwrap_or_else(|| {+ Self::laid_out_box_in_record_its_layout_owns(+ sized_child,+ baselines_of_contents_laid_out_in_this_flow.unwrap_or_default(),+ )+ }),fragment_facts,content_offset: pending_position,margin_box_block_end: Some(margin_box_block_end),@@ -3135,12 +3139,16 @@ impl<'pass> BlockFormattingContext<'pass> {})}- /// The box `child` as this flow laid it out in a record its layout owns.- fn laid_out_box_in_record_its_layout_owns(child: ChildSizedHere<'_>) -> run_records::LaidOutChildBox {+ /// The box `child` as this flow laid it out in a record its layout owns, with the `baselines` of its contents.+ fn laid_out_box_in_record_its_layout_owns(+ child: ChildSizedHere<'_>,+ baselines: DerivedBaselines,+ ) -> run_records::LaidOutChildBox {run_records::LaidOutChildBox::sized_in_parent_run(child.record().expect("a box laid out in this flow is laid out in a record its layout owns"),+ baselines,)}@@ -3281,6 +3289,7 @@ impl<'pass> BlockFormattingContext<'pass> {&self,attempt: InFlowReuse,sized_child: ChildSizedHere<'_>,+ baselines: DerivedBaselines,placed: Option<(FfiCssPixelPoint, fragment_tree::PlacedFragment)>,depends_on_percentage_block_size: bool,) {@@ -3309,11 +3318,11 @@ impl<'pass> BlockFormattingContext<'pass> {if !reusable {return;}- let cells = used_values::UsedValuesCellState::capture(used);let entry = in_flow_block_cache::InFlowBlockEntry {key,validity,- cells,+ cells: used_values::RootInputCells::capture(used),+ baselines,offset_from_flow_position: FfiCssPixelPoint {x: content_offset.x,y: content_offset.y - flow_position,diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex 824d59744db..cd07cedb03e 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -843,9 +843,8 @@ fn box_baseline_for_purpose(/// First and last baseline sets derived for one box, relative to its content/// box. Laying out a box's contents returns them. A formatting context records-/// its own root box's baselines on the instance, and the side that ran the-/// context stores them into the root's used values; the layout of an interior-/// box stores them into that box's used values.+/// its own root box's baselines on the instance. The side that ran the context+/// or laid the box out hands them back with the box.#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]pub(crate) struct DerivedBaselines {pub(crate) first: Option<CssPixels>,@@ -855,23 +854,6 @@ pub(crate) struct DerivedBaselines {pub(crate) inline_alignment: Option<CssPixels>,}-// NOTE: A box can be baselined more than once (e.g. table cells are laid out-// twice), so both presence bits are re-assigned on every store. The-// payload cells are left untouched for an absent baseline so that-// resetting the presence bits does not perturb payloads observed by the-// existing derivation flow.-pub(crate) fn store_derived_baselines(used: &UsedValues, baselines: DerivedBaselines) {- used.inline_alignment_baseline.set(baselines.inline_alignment);- used.has_first_baseline.set(baselines.first.is_some());- if let Some(value) = baselines.first {- used.first_baseline.set(value);- }- used.has_last_baseline.set(baselines.last.is_some());- if let Some(value) = baselines.last {- used.last_baseline.set(value);- }-}-/// The first, last and inline-alignment baselines of a line, relative to the content box of its block container.#[derive(Clone, Copy, Debug, PartialEq, Eq)]pub(crate) struct LineBaselines {@@ -2859,7 +2841,7 @@ impl ChildLayout {Self {outcome,fragment_arrival: None,- laid_out_box: run_records::LaidOutChildBox::sized_in_parent_run(record),+ laid_out_box: run_records::LaidOutChildBox::sized_in_parent_run(record, DerivedBaselines::default()),}}}@@ -2930,8 +2912,8 @@ pub(crate) fn layout_inside_child_with_input_cells(fragment,reuses_subtree: false,});- store_derived_baselines(&record_of_this_layout, DerivedBaselines::default());- let laid_out_box = run_records::LaidOutChildBox::sized_in_parent_run(&record_of_this_layout);+ let laid_out_box =+ run_records::LaidOutChildBox::sized_in_parent_run(&record_of_this_layout, DerivedBaselines::default());return ChildLayout {outcome: skipped(None),fragment_arrival,diff --git a/Libraries/LibWeb/Rust/src/layout/in_flow_block_cache.rs b/Libraries/LibWeb/Rust/src/layout/in_flow_block_cache.rsindex 172348bb143..eb5804432b1 100644--- a/Libraries/LibWeb/Rust/src/layout/in_flow_block_cache.rs+++ b/Libraries/LibWeb/Rust/src/layout/in_flow_block_cache.rs@@ -60,8 +60,10 @@ impl InFlowBlockKey {pub(super) struct InFlowBlockEntry {pub(super) key: InFlowBlockKey,pub(super) validity: fc_run_cache::FcRunCacheValidity,- /// The child's record as its layout left it.- pub(super) cells: used_values::UsedValuesCellState,+ /// The child's cells as its layout left them.+ pub(super) cells: used_values::RootInputCells,+ /// The baselines of the child's contents as its layout left them.+ pub(super) baselines: formatting_context::DerivedBaselines,pub(super) offset_from_flow_position: FfiCssPixelPoint,pub(super) flow_position_advance: CssPixels,pub(super) outgoing_margins: block_formatting_context::BlockMarginState,diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rsindex 6f952f05849..3cd82bf2b22 100644--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs@@ -300,12 +300,12 @@ pub(crate) struct LaidOutChildBox {}impl LaidOutChildBox {- /// A child as the run of its parent left it in `record`, where that run sizes the child itself instead of handing- /// it to a run of its own.- pub(crate) fn sized_in_parent_run(record: &UsedValues) -> Self {+ /// A child as the run of its parent left it in `record`, with the `baselines` of its contents, where that run+ /// sizes the child itself instead of handing it to a run of its own.+ pub(crate) fn sized_in_parent_run(record: &UsedValues, baselines: DerivedBaselines) -> Self {Self {cells: used_values::RootInputCells::capture(record),- baselines: record.content_baselines_from_cells(),+ baselines,// NB: A box that establishes an orthogonal flow is laid out by a run of its own.orthogonal_flow_baselines: None,line_data: None,diff --git a/Libraries/LibWeb/Rust/src/layout/used_values.rs b/Libraries/LibWeb/Rust/src/layout/used_values.rsindex 3bacca8497a..a91f0951aa8 100644--- a/Libraries/LibWeb/Rust/src/layout/used_values.rs+++ b/Libraries/LibWeb/Rust/src/layout/used_values.rs@@ -198,14 +198,6 @@ pub(crate) struct UsedValues {/// side of the first or last grid line, while a cell owns the part on the inner side of its grid lines.pub is_collapsed_borders_table_box: Cell<bool>,- // Keep baseline payloads separate so resetting the presence bits does not- // perturb the payloads observed by the existing derivation flow.- pub has_first_baseline: Cell<bool>,- pub first_baseline: Cell<CssPixels>,- pub has_last_baseline: Cell<bool>,- pub last_baseline: Cell<CssPixels>,- pub inline_alignment_baseline: Cell<Option<CssPixels>>,-/// The frame the box's sizes, size constraints and box sides are held in.pub(crate) frame: Cell<geometry::Frame>,}@@ -233,25 +225,12 @@ impl Default for UsedValues {has_definite_block_size_only_for_button_content_alignment: Cell::new(false),uses_collapsing_borders_model: Cell::new(false),is_collapsed_borders_table_box: Cell::new(false),- has_first_baseline: Cell::new(false),- first_baseline: Cell::new(zero),- has_last_baseline: Cell::new(false),- last_baseline: Cell::new(zero),- inline_alignment_baseline: Cell::new(None),frame: Cell::new(geometry::Frame::PHYSICAL),}}}impl UsedValues {- pub(crate) fn content_baselines_from_cells(&self) -> DerivedBaselines {- DerivedBaselines {- inline_alignment: self.inline_alignment_baseline.get(),- first: self.has_first_baseline.get().then(|| self.first_baseline.get()),- last: self.has_last_baseline.get().then(|| self.last_baseline.get()),- }- }-pub(crate) fn seal_own_metrics(&self) {self.content_inline_size.seal();self.content_block_size.seal();@@ -428,26 +407,6 @@ impl RootInputCells {}}-#[derive(Clone, Copy, Debug, PartialEq, Eq)]-pub(crate) struct UsedValuesCellState {- pub(crate) inputs: RootInputCells,- pub(crate) baselines: DerivedBaselines,-}--impl UsedValuesCellState {- pub(crate) fn capture(used: &UsedValues) -> Self {- Self {- inputs: RootInputCells::capture(used),- baselines: used.content_baselines_from_cells(),- }- }-- pub(crate) fn apply_to_record(&self, used: &UsedValues) {- self.inputs.apply_to_record(used);- formatting_context::store_derived_baselines(used, self.baselines);- }-}-impl UsedValues {pub(crate) fn set_content_inline_size(&self, value: CssPixels) {// Negative inline sizes are not allowed in CSS. We have a bug somewhere! Clamp to 0 to avoid doing too much damage.