From 06f631f4d128fe3440438459216c2e788082576f Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Fri, 15 Mar 2024 19:52:02 +0100 Subject: [PATCH] Pick the first or last baseline as appropriate The old logic was always picking the last baseline, but this should only happen for inline-blocks. Since replaced elements and flex containers aren't currently setting their baselines, this is only an improvement for inline-tables. --- components/layout_2020/flow/inline.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/components/layout_2020/flow/inline.rs b/components/layout_2020/flow/inline.rs index 843838ad33a77..c6cb614e68237 100644 --- a/components/layout_2020/flow/inline.rs +++ b/components/layout_2020/flow/inline.rs @@ -101,7 +101,9 @@ use crate::cell::ArcRefCell; use crate::context::LayoutContext; use crate::flow::float::{FloatBox, SequentialLayoutState}; use crate::flow::FlowLayout; -use crate::formatting_contexts::{Baselines, IndependentFormattingContext}; +use crate::formatting_contexts::{ + Baselines, IndependentFormattingContext, NonReplacedFormattingContextContents, +}; use crate::fragment_tree::{ BaseFragmentInfo, BoxFragment, CollapsedBlockMargins, CollapsedMargin, Fragment, FragmentFlags, PositioningFragment, @@ -2112,9 +2114,8 @@ impl IndependentFormattingContext { } let size = &pbm_sums.sum().into() + &fragment.content_rect.size; - let baseline_offset = fragment - .baselines - .last + let baseline_offset = self + .pick_baseline(&fragment.baselines) .map(|baseline| pbm_sums.block_start + baseline) .unwrap_or(size.block.into()); @@ -2137,6 +2138,18 @@ impl IndependentFormattingContext { ifc.have_deferred_soft_wrap_opportunity = true; } + /// Picks either the first or the last baseline, depending on `baseline-source`. + /// + fn pick_baseline(&self, baselines: &Baselines) -> Option { + // TODO: Currently this only supports the initial `baseline-source: auto`. + if let Self::NonReplaced(non_replaced) = self { + if let NonReplacedFormattingContextContents::Flow(_) = non_replaced.contents { + return baselines.last; + } + } + baselines.first + } + fn get_block_sizes_and_baseline_offset( &self, ifc: &InlineFormattingContextState,