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
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
#include <LibGC/Ptr.h>
|
2020-09-18 09:49:51 +02:00
|
|
|
#include <LibGfx/Rect.h>
|
2023-12-02 18:38:05 +01:00
|
|
|
#include <LibGfx/TextLayout.h>
|
2025-07-25 10:05:24 -04:00
|
|
|
#include <LibWeb/CSS/Enums.h>
|
2022-10-31 19:46:55 +00:00
|
|
|
#include <LibWeb/PixelUnits.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
|
|
|
|
2022-02-27 10:26:38 +01:00
|
|
|
class LineBoxFragment {
|
2019-10-03 15:20:13 +02:00
|
|
|
friend class LineBox;
|
2020-06-10 10:42:29 +02:00
|
|
|
|
2019-10-03 15:20:13 +02:00
|
|
|
public:
|
2025-06-11 09:07:16 +02:00
|
|
|
LineBoxFragment(Node const& layout_node, size_t start, size_t length, CSSPixels inline_offset, CSSPixels block_offset, CSSPixels inline_length, CSSPixels block_length, CSSPixels border_box_top, CSS::Direction, CSS::WritingMode, RefPtr<Gfx::GlyphRun>);
|
2019-10-03 15:20:13 +02:00
|
|
|
|
2022-02-20 15:51:24 +01:00
|
|
|
Node const& layout_node() const { return m_layout_node; }
|
2025-06-11 09:07:16 +02:00
|
|
|
size_t start() const { return m_start; }
|
2025-09-12 10:06:27 +02:00
|
|
|
size_t length_in_code_units() const { return m_length_in_code_units; }
|
2020-06-10 10:42:29 +02:00
|
|
|
|
2024-10-29 11:32:59 +00:00
|
|
|
CSSPixelPoint offset() const;
|
|
|
|
CSSPixels inline_offset() const { return m_inline_offset; }
|
|
|
|
CSSPixels block_offset() const { return m_block_offset; }
|
|
|
|
void set_inline_offset(CSSPixels inline_offset) { m_inline_offset = inline_offset; }
|
|
|
|
void set_block_offset(CSSPixels block_offset) { m_block_offset = block_offset; }
|
2020-06-10 10:42:29 +02:00
|
|
|
|
2022-03-28 21:05:51 +02:00
|
|
|
// The baseline of a fragment is the number of pixels from the top to the text baseline.
|
2022-10-31 19:46:55 +00:00
|
|
|
void set_baseline(CSSPixels y) { m_baseline = y; }
|
|
|
|
CSSPixels baseline() const { return m_baseline; }
|
2022-03-28 21:05:51 +02:00
|
|
|
|
2024-10-29 11:32:59 +00:00
|
|
|
CSSPixelSize size() const;
|
|
|
|
CSSPixels width() const { return size().width(); }
|
|
|
|
CSSPixels height() const { return size().height(); }
|
|
|
|
CSSPixels inline_length() const { return m_inline_length; }
|
|
|
|
CSSPixels block_length() const { return m_block_length; }
|
|
|
|
void set_inline_length(CSSPixels inline_length) { m_inline_length = inline_length; }
|
|
|
|
void set_block_length(CSSPixels block_length) { m_block_length = block_length; }
|
2019-10-03 15:20:13 +02:00
|
|
|
|
2022-10-31 19:46:55 +00:00
|
|
|
CSSPixels border_box_top() const { return m_border_box_top; }
|
2019-10-20 17:18:28 +02:00
|
|
|
|
2020-06-13 14:59:17 +02:00
|
|
|
bool ends_in_whitespace() const;
|
2019-10-20 12:30:25 +02:00
|
|
|
bool is_justifiable_whitespace() const;
|
2025-07-25 09:34:41 -04:00
|
|
|
Utf16View text() const;
|
2019-10-20 12:30:25 +02:00
|
|
|
|
2023-03-14 10:28:01 +01:00
|
|
|
bool is_atomic_inline() const;
|
|
|
|
|
2024-06-29 17:14:23 +02:00
|
|
|
RefPtr<Gfx::GlyphRun> glyph_run() const { return m_glyph_run; }
|
2024-10-29 14:29:00 +00:00
|
|
|
CSS::WritingMode writing_mode() const { return m_writing_mode; }
|
2024-08-18 17:58:05 +01:00
|
|
|
void append_glyph_run(RefPtr<Gfx::GlyphRun> const&, CSSPixels run_width);
|
2023-12-02 18:38:05 +01:00
|
|
|
|
2019-10-03 15:20:13 +02:00
|
|
|
private:
|
2024-08-18 17:58:05 +01:00
|
|
|
CSS::Direction resolve_glyph_run_direction(Gfx::GlyphRun::TextType) const;
|
|
|
|
void append_glyph_run_ltr(RefPtr<Gfx::GlyphRun> const&, CSSPixels run_width);
|
|
|
|
void append_glyph_run_rtl(RefPtr<Gfx::GlyphRun> const&, CSSPixels run_width);
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<Node const> m_layout_node;
|
2025-06-11 09:07:16 +02:00
|
|
|
size_t m_start { 0 };
|
2025-09-12 10:06:27 +02:00
|
|
|
size_t m_length_in_code_units { 0 };
|
2024-10-29 11:32:59 +00:00
|
|
|
CSSPixels m_inline_offset;
|
|
|
|
CSSPixels m_block_offset;
|
|
|
|
CSSPixels m_inline_length;
|
|
|
|
CSSPixels m_block_length;
|
2022-10-31 19:46:55 +00:00
|
|
|
CSSPixels m_border_box_top { 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 };
|
2024-08-18 17:58:05 +01:00
|
|
|
|
2024-06-29 17:14:23 +02:00
|
|
|
RefPtr<Gfx::GlyphRun> m_glyph_run;
|
2024-08-18 17:58:05 +01:00
|
|
|
float m_insert_position { 0 };
|
|
|
|
CSS::Direction m_current_insert_direction { CSS::Direction::Ltr };
|
2019-10-03 15:20:13 +02:00
|
|
|
};
|
2020-03-07 10:27:02 +01:00
|
|
|
|
|
|
|
}
|