2022-01-19 07:57:58 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2022-01-19 07:57:58 -03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <LibWeb/Layout/InlineFormattingContext.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::Layout {
|
|
|
|
|
|
|
|
|
|
class LineBuilder {
|
|
|
|
|
AK_MAKE_NONCOPYABLE(LineBuilder);
|
|
|
|
|
AK_MAKE_NONMOVABLE(LineBuilder);
|
|
|
|
|
|
|
|
|
|
public:
|
2024-10-29 08:32:59 -03:00
|
|
|
LineBuilder(InlineFormattingContext&, LayoutState&, LayoutState::UsedValues& containing_block_used_values, CSS::Direction, CSS::WritingMode);
|
2022-01-19 07:57:58 -03:00
|
|
|
|
2023-06-10 10:49:17 -03:00
|
|
|
enum class ForcedBreak {
|
|
|
|
|
No,
|
|
|
|
|
Yes,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void break_line(ForcedBreak, Optional<CSSPixels> next_item_width = {});
|
2022-11-04 14:19:11 -03:00
|
|
|
void append_box(Box const&, CSSPixels leading_size, CSSPixels trailing_size, CSSPixels leading_margin, CSSPixels trailing_margin);
|
2024-06-29 12:14:23 -03:00
|
|
|
void append_text_chunk(TextNode const&, size_t offset_in_node, size_t length_in_node, CSSPixels leading_size, CSSPixels trailing_size, CSSPixels leading_margin, CSSPixels trailing_margin, CSSPixels content_width, CSSPixels content_height, RefPtr<Gfx::GlyphRun>);
|
2022-01-19 07:57:58 -03:00
|
|
|
|
2022-03-26 14:50:43 -03:00
|
|
|
// Returns whether a line break occurred.
|
2022-11-04 14:19:11 -03:00
|
|
|
bool break_if_needed(CSSPixels next_item_width)
|
2022-01-20 12:19:05 -03:00
|
|
|
{
|
2022-07-09 10:17:47 -03:00
|
|
|
if (should_break(next_item_width)) {
|
2023-06-10 10:49:17 -03:00
|
|
|
break_line(LineBuilder::ForcedBreak::No, next_item_width);
|
2022-03-26 14:50:43 -03:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2022-01-20 12:19:05 -03:00
|
|
|
}
|
2022-01-19 07:57:58 -03:00
|
|
|
|
|
|
|
|
void update_last_line();
|
|
|
|
|
|
2022-01-22 06:32:49 -03:00
|
|
|
void remove_last_line_if_empty();
|
|
|
|
|
|
2024-10-29 08:32:59 -03:00
|
|
|
CSSPixels current_block_offset() const { return m_current_block_offset; }
|
2022-03-22 15:18:05 -03:00
|
|
|
|
2022-09-16 09:21:52 -03:00
|
|
|
void recalculate_available_space();
|
2022-11-04 14:19:11 -03:00
|
|
|
CSSPixels y_for_float_to_be_inserted_here(Box const&);
|
2022-03-22 15:18:05 -03:00
|
|
|
|
2025-04-01 06:01:15 -03:00
|
|
|
void did_introduce_clearance(CSSPixels);
|
|
|
|
|
|
2022-01-19 07:57:58 -03:00
|
|
|
private:
|
2022-09-16 09:21:52 -03:00
|
|
|
void begin_new_line(bool increment_y, bool is_first_break_in_sequence = true);
|
2022-01-22 21:34:26 -03:00
|
|
|
|
2022-11-04 14:19:11 -03:00
|
|
|
bool should_break(CSSPixels next_item_width);
|
2022-01-20 12:19:05 -03:00
|
|
|
|
2022-02-20 11:51:24 -03:00
|
|
|
LineBox& ensure_last_line_box();
|
|
|
|
|
|
2022-01-19 07:57:58 -03:00
|
|
|
InlineFormattingContext& m_context;
|
2022-07-16 18:43:48 -03:00
|
|
|
LayoutState& m_layout_state;
|
2024-03-15 15:25:00 -03:00
|
|
|
LayoutState::UsedValues& m_containing_block_used_values;
|
2023-08-12 13:30:18 -03:00
|
|
|
AvailableSize m_available_width_for_current_line { AvailableSize::make_indefinite() };
|
2024-10-29 08:32:59 -03:00
|
|
|
CSSPixels m_current_block_offset { 0 };
|
2022-11-04 14:19:11 -03:00
|
|
|
CSSPixels m_max_height_on_current_line { 0 };
|
2023-05-15 11:42:28 -03:00
|
|
|
CSSPixels m_text_indent { 0 };
|
2024-08-18 13:58:05 -03:00
|
|
|
CSS::Direction m_direction { CSS::Direction::Ltr };
|
2024-10-29 08:32:59 -03:00
|
|
|
CSS::WritingMode m_writing_mode { CSS::WritingMode::HorizontalTb };
|
2022-01-22 06:32:49 -03:00
|
|
|
|
|
|
|
|
bool m_last_line_needs_update { false };
|
2022-01-19 07:57:58 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|