2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2019-10-03 15:20:13 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Vector.h>
|
2020-03-07 10:32:51 +01:00
|
|
|
#include <LibWeb/Layout/LineBoxFragment.h>
|
2019-10-03 15:20:13 +02:00
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
namespace Web::Layout {
|
2020-03-07 10:27:02 +01:00
|
|
|
|
2019-10-03 15:20:13 +02:00
|
|
|
class LineBox {
|
|
|
|
public:
|
2024-10-29 11:32:59 +00:00
|
|
|
LineBox(CSS::Direction direction, CSS::WritingMode writing_mode)
|
2024-08-18 17:58:05 +01:00
|
|
|
: m_direction(direction)
|
2024-10-29 11:32:59 +00:00
|
|
|
, m_writing_mode(writing_mode)
|
2024-08-18 17:58:05 +01:00
|
|
|
{
|
|
|
|
}
|
2019-10-03 15:20:13 +02:00
|
|
|
|
2024-10-29 11:32:59 +00:00
|
|
|
CSSPixels width() const;
|
|
|
|
CSSPixels height() const;
|
|
|
|
CSSPixels bottom() const;
|
2024-10-29 11:32:59 +00:00
|
|
|
|
|
|
|
CSSPixels inline_length() const { return m_inline_length; }
|
|
|
|
CSSPixels block_length() const { return m_block_length; }
|
2022-11-04 17:19:11 +00:00
|
|
|
CSSPixels baseline() const { return m_baseline; }
|
2019-10-03 15:20:13 +02:00
|
|
|
|
2025-06-11 09:07:16 +02:00
|
|
|
void add_fragment(Node const& layout_node, size_t start, size_t 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 = {});
|
2019-10-03 15:20:13 +02:00
|
|
|
|
2022-02-27 10:32:00 +01:00
|
|
|
Vector<LineBoxFragment> const& fragments() const { return m_fragments; }
|
|
|
|
Vector<LineBoxFragment>& fragments() { return m_fragments; }
|
2019-10-03 15:20:13 +02:00
|
|
|
|
2025-03-26 16:11:50 +00:00
|
|
|
CSSPixels get_trailing_whitespace_width() const;
|
2019-10-20 17:18:28 +02:00
|
|
|
void trim_trailing_whitespace();
|
2020-06-10 10:42:29 +02:00
|
|
|
|
2020-12-17 20:17:29 +01:00
|
|
|
bool is_empty_or_ends_in_whitespace() const;
|
2023-03-15 21:11:38 +01:00
|
|
|
bool is_empty() const { return m_fragments.is_empty() && !m_has_break; }
|
2020-06-13 14:59:17 +02:00
|
|
|
|
2023-08-12 18:30:18 +02:00
|
|
|
AvailableSize original_available_width() const { return m_original_available_width; }
|
2023-05-16 09:51:33 +02:00
|
|
|
|
2019-10-03 15:20:13 +02:00
|
|
|
private:
|
2021-10-06 20:02:41 +02:00
|
|
|
friend class BlockContainer;
|
2020-11-22 15:53:01 +01:00
|
|
|
friend class InlineFormattingContext;
|
2022-01-19 11:57:58 +01:00
|
|
|
friend class LineBuilder;
|
|
|
|
|
2025-03-26 16:11:50 +00:00
|
|
|
enum class RemoveTrailingWhitespace : u8 {
|
|
|
|
Yes,
|
|
|
|
No,
|
|
|
|
};
|
|
|
|
|
|
|
|
CSSPixels calculate_or_trim_trailing_whitespace(RemoveTrailingWhitespace);
|
|
|
|
|
2022-02-27 10:32:00 +01:00
|
|
|
Vector<LineBoxFragment> m_fragments;
|
2024-10-29 11:32:59 +00:00
|
|
|
CSSPixels m_inline_length { 0 };
|
|
|
|
CSSPixels m_block_length { 0 };
|
2022-11-04 17:19:11 +00:00
|
|
|
CSSPixels m_bottom { 0 };
|
|
|
|
CSSPixels m_baseline { 0 };
|
2024-08-18 17:58:05 +01:00
|
|
|
CSS::Direction m_direction { CSS::Direction::Ltr };
|
2024-10-29 11:32:59 +00:00
|
|
|
CSS::WritingMode m_writing_mode { CSS::WritingMode::HorizontalTb };
|
2023-05-16 09:51:33 +02:00
|
|
|
|
|
|
|
// The amount of available width that was originally available when creating this line box. Used for text justification.
|
2023-08-12 18:30:18 +02:00
|
|
|
AvailableSize m_original_available_width { AvailableSize::make_indefinite() };
|
2023-05-16 09:51:33 +02:00
|
|
|
|
2023-03-15 21:11:38 +01:00
|
|
|
bool m_has_break { false };
|
2023-06-10 15:49:17 +02:00
|
|
|
bool m_has_forced_break { false };
|
2019-10-03 15:20:13 +02:00
|
|
|
};
|
2020-03-07 10:27:02 +01:00
|
|
|
|
|
|
|
}
|