LibWeb: Exclude trailing whitespace from line width when placing floats

When generating line boxes, we place floats simultaneously with the
other items on the same line. The CSS text spec requires us to trim the
whitespace at the end of each line, but we only did so after laying out
all the line boxes.

This changes the way we calculate the current line box width for floats
by subtracting the amount of pixels that the current trailing whitespace
is using.

Fixes #4050.
This commit is contained in:
Jelle Raaijmakers 2025-03-26 16:11:50 +00:00
commit 002e79a658
Notes: github-actions[bot] 2025-03-26 19:36:31 +00:00
5 changed files with 99 additions and 19 deletions

View file

@ -32,6 +32,7 @@ public:
Vector<LineBoxFragment> const& fragments() const { return m_fragments; }
Vector<LineBoxFragment>& fragments() { return m_fragments; }
CSSPixels get_trailing_whitespace_width() const;
void trim_trailing_whitespace();
bool is_empty_or_ends_in_whitespace() const;
@ -44,6 +45,13 @@ private:
friend class InlineFormattingContext;
friend class LineBuilder;
enum class RemoveTrailingWhitespace : u8 {
Yes,
No,
};
CSSPixels calculate_or_trim_trailing_whitespace(RemoveTrailingWhitespace);
Vector<LineBoxFragment> m_fragments;
CSSPixels m_inline_length { 0 };
CSSPixels m_block_length { 0 };