mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:07:44 +00:00
LibWeb: Remove old Layout::Node::split_into_lines() API
Now that we build lines incrementally, we no longer need the atomic line splitting API. The new InlineLevelIterator and LineBuilder setup does have some regressions from the old behavior, but we can deal with them as we go.
This commit is contained in:
parent
ba49dc82e0
commit
766d816db3
12 changed files with 0 additions and 167 deletions
|
@ -192,95 +192,6 @@ void TextNode::compute_text_for_rendering(bool collapse, bool previous_is_empty_
|
|||
m_text_for_rendering = builder.to_string();
|
||||
}
|
||||
|
||||
void TextNode::split_into_lines_by_rules(InlineFormattingContext& context, LayoutMode layout_mode, bool do_collapse, bool do_wrap_lines, bool do_respect_linebreaks)
|
||||
{
|
||||
auto& containing_block = context.containing_block();
|
||||
|
||||
auto& font = this->font();
|
||||
|
||||
auto& line_boxes = containing_block.line_boxes();
|
||||
containing_block.ensure_last_line_box();
|
||||
float available_width = context.available_width_at_line(line_boxes.size() - 1) - line_boxes.last().width();
|
||||
|
||||
compute_text_for_rendering(do_collapse, line_boxes.last().is_empty_or_ends_in_whitespace());
|
||||
ChunkIterator iterator(m_text_for_rendering, layout_mode, do_wrap_lines, do_respect_linebreaks);
|
||||
|
||||
for (;;) {
|
||||
auto chunk_opt = iterator.next();
|
||||
if (!chunk_opt.has_value())
|
||||
break;
|
||||
auto& chunk = chunk_opt.value();
|
||||
|
||||
// Collapse entire fragment into non-existence if previous fragment on line ended in whitespace.
|
||||
if (do_collapse && line_boxes.last().is_empty_or_ends_in_whitespace() && chunk.is_all_whitespace)
|
||||
continue;
|
||||
|
||||
float chunk_width;
|
||||
if (do_wrap_lines) {
|
||||
if (do_collapse && is_ascii_space(*chunk.view.begin()) && (line_boxes.last().is_empty_or_ends_in_whitespace() || line_boxes.last().ends_with_forced_line_break())) {
|
||||
// This is a non-empty chunk that starts with collapsible whitespace.
|
||||
// We are at either at the start of a new line, or after something that ended in whitespace,
|
||||
// so we don't need to contribute our own whitespace to the line. Skip over it instead!
|
||||
++chunk.start;
|
||||
--chunk.length;
|
||||
chunk.view = chunk.view.substring_view(1, chunk.view.byte_length() - 1);
|
||||
}
|
||||
|
||||
chunk_width = font.width(chunk.view) + font.glyph_spacing();
|
||||
|
||||
if (line_boxes.last().width() > 0 && chunk_width > available_width) {
|
||||
containing_block.add_line_box();
|
||||
available_width = context.available_width_at_line(line_boxes.size() - 1);
|
||||
|
||||
if (do_collapse && chunk.is_all_whitespace)
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
chunk_width = font.width(chunk.view);
|
||||
}
|
||||
|
||||
line_boxes.last().add_fragment(*this, chunk.start, chunk.length, chunk_width, font.glyph_height());
|
||||
available_width -= chunk_width;
|
||||
|
||||
if (do_wrap_lines && available_width < 0) {
|
||||
containing_block.add_line_box();
|
||||
available_width = context.available_width_at_line(line_boxes.size() - 1);
|
||||
}
|
||||
|
||||
if (do_respect_linebreaks && chunk.has_breaking_newline) {
|
||||
containing_block.add_line_box();
|
||||
available_width = context.available_width_at_line(line_boxes.size() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextNode::split_into_lines(InlineFormattingContext& context, LayoutMode layout_mode)
|
||||
{
|
||||
bool do_collapse = true;
|
||||
bool do_wrap_lines = true;
|
||||
bool do_respect_linebreaks = false;
|
||||
|
||||
if (computed_values().white_space() == CSS::WhiteSpace::Nowrap) {
|
||||
do_collapse = true;
|
||||
do_wrap_lines = false;
|
||||
do_respect_linebreaks = false;
|
||||
} else if (computed_values().white_space() == CSS::WhiteSpace::Pre) {
|
||||
do_collapse = false;
|
||||
do_wrap_lines = false;
|
||||
do_respect_linebreaks = true;
|
||||
} else if (computed_values().white_space() == CSS::WhiteSpace::PreLine) {
|
||||
do_collapse = true;
|
||||
do_wrap_lines = true;
|
||||
do_respect_linebreaks = true;
|
||||
} else if (computed_values().white_space() == CSS::WhiteSpace::PreWrap) {
|
||||
do_collapse = false;
|
||||
do_wrap_lines = true;
|
||||
do_respect_linebreaks = true;
|
||||
}
|
||||
|
||||
split_into_lines_by_rules(context, layout_mode, do_collapse, do_wrap_lines, do_respect_linebreaks);
|
||||
}
|
||||
|
||||
bool TextNode::wants_mouse_events() const
|
||||
{
|
||||
return parent() && is<Label>(parent());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue