diff options
author | Oriol Brufau <obrufau@igalia.com> | 2024-03-25 17:19:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-25 16:19:06 +0000 |
commit | e77dc3684236ad6693b8df6131f2ba8f99bbef2f (patch) | |
tree | 1e1a127feaec0a3a9f0f4e84565ed843234565a8 /components/layout_2020 | |
parent | a53632c0e5fe223ca1c39a088ee46f49bb355243 (diff) | |
download | servo-e77dc3684236ad6693b8df6131f2ba8f99bbef2f.tar.gz servo-e77dc3684236ad6693b8df6131f2ba8f99bbef2f.zip |
Pick the first or last baseline as appropriate (#31705)
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.
Diffstat (limited to 'components/layout_2020')
-rw-r--r-- | components/layout_2020/flow/inline.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/components/layout_2020/flow/inline.rs b/components/layout_2020/flow/inline.rs index 7f31faf1e26..1ef642a4405 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, @@ -2114,9 +2116,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()); @@ -2139,6 +2140,18 @@ impl IndependentFormattingContext { ifc.have_deferred_soft_wrap_opportunity = true; } + /// Picks either the first or the last baseline, depending on `baseline-source`. + /// <https://drafts.csswg.org/css-inline/#baseline-source> + fn pick_baseline(&self, baselines: &Baselines) -> Option<Au> { + // 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, |