From 433a6bf47b20dd36b4b0328dc3612a131552bddc Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Wed, 10 Sep 2025 07:17:25 +0200 Subject: [PATCH] layout: Set baseline even if line box has no fragment (#39235) `InlineFormattingContextLayout::finish_current_line_and_reset()` has an early return in case the line has no fragment. However, if the line only has a forced line break, then we still need to set the baseline. Testing: Adding new test. Signed-off-by: Oriol Brufau --- components/layout/flow/inline/mod.rs | 12 ++--- tests/wpt/meta/MANIFEST.json | 13 +++++ .../visudet/inline-block-baseline-016.html | 50 +++++++++++++++++++ 3 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 tests/wpt/tests/css/CSS2/visudet/inline-block-baseline-016.html diff --git a/components/layout/flow/inline/mod.rs b/components/layout/flow/inline/mod.rs index dbc39b5d7db..01c7cd6aa6c 100644 --- a/components/layout/flow/inline/mod.rs +++ b/components/layout/flow/inline/mod.rs @@ -986,6 +986,12 @@ impl InlineFormattingContextLayout<'_> { justification_adjustment, ); + if line_to_layout.has_content { + let baseline = baseline_offset + block_start_position; + self.baselines.first.get_or_insert(baseline); + self.baselines.last = Some(baseline); + } + // If the line doesn't have any fragments, we don't need to add a containing fragment for it. if fragments.is_empty() && self.positioning_context.len() == start_positioning_context_length @@ -993,12 +999,6 @@ impl InlineFormattingContextLayout<'_> { return; } - if line_to_layout.has_content { - let baseline = baseline_offset + block_start_position; - self.baselines.first.get_or_insert(baseline); - self.baselines.last = Some(baseline); - } - // The inline part of this start offset was taken into account when determining // the inline start of the line in `calculate_inline_start_for_current_line` so // we do not need to include it in the `start_corner` of the line's main Fragment. diff --git a/tests/wpt/meta/MANIFEST.json b/tests/wpt/meta/MANIFEST.json index 469bf1b6213..22c5789da4c 100644 --- a/tests/wpt/meta/MANIFEST.json +++ b/tests/wpt/meta/MANIFEST.json @@ -118917,6 +118917,19 @@ {} ] ], + "inline-block-baseline-016.html": [ + "c4efa04d4a66ea59d55888a1b5d175b1da7660ef", + [ + null, + [ + [ + "/css/reference/ref-filled-green-200px-square.html", + "==" + ] + ], + {} + ] + ], "line-height-201.html": [ "00ab2aa52755d27c5bbd3b41d91a6f8e138c2899", [ diff --git a/tests/wpt/tests/css/CSS2/visudet/inline-block-baseline-016.html b/tests/wpt/tests/css/CSS2/visudet/inline-block-baseline-016.html new file mode 100644 index 00000000000..c4efa04d4a6 --- /dev/null +++ b/tests/wpt/tests/css/CSS2/visudet/inline-block-baseline-016.html @@ -0,0 +1,50 @@ + +Vertical-align: baseline of inline-block with only forced line break + + + + + + + + +

Test passes if there is a filled green square and no red.

+ +
+
text
+
+