1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 05:27:14 +09:00
ladybird/Libraries/LibWeb/Layout/LineBox.h
Jelle Raaijmakers 002e79a658 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.
2025-03-26 19:35:38 +00:00

70 lines
2.3 KiB
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Vector.h>
#include <LibWeb/Layout/LineBoxFragment.h>
namespace Web::Layout {
class LineBox {
public:
LineBox(CSS::Direction direction, CSS::WritingMode writing_mode)
: m_direction(direction)
, m_writing_mode(writing_mode)
{
}
CSSPixels width() const;
CSSPixels height() const;
CSSPixels bottom() const;
CSSPixels inline_length() const { return m_inline_length; }
CSSPixels block_length() const { return m_block_length; }
CSSPixels baseline() const { return m_baseline; }
void add_fragment(Node const& layout_node, int start, int length, CSSPixels leading_size, CSSPixels trailing_size, CSSPixels leading_margin, CSSPixels trailing_margin, CSSPixels content_width, CSSPixels content_height, CSSPixels border_box_top, CSSPixels border_box_bottom, RefPtr<Gfx::GlyphRun> glyph_run = {});
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;
bool is_empty() const { return m_fragments.is_empty() && !m_has_break; }
AvailableSize original_available_width() const { return m_original_available_width; }
private:
friend class BlockContainer;
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 };
CSSPixels m_bottom { 0 };
CSSPixels m_baseline { 0 };
CSS::Direction m_direction { CSS::Direction::Ltr };
CSS::WritingMode m_writing_mode { CSS::WritingMode::HorizontalTb };
// The amount of available width that was originally available when creating this line box. Used for text justification.
AvailableSize m_original_available_width { AvailableSize::make_indefinite() };
bool m_has_break { false };
bool m_has_forced_break { false };
};
}