mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
LibWeb: Ignore some collapsible whitespace when building lines
When collapsing whitespace, we can skip over all-whitespace chunks at the start of each line, and immediately following fragments that themselves end in whitespace.
This commit is contained in:
parent
766d816db3
commit
9f39ad8929
3 changed files with 6 additions and 0 deletions
|
@ -168,6 +168,10 @@ void InlineFormattingContext::generate_line_boxes(LayoutMode layout_mode)
|
||||||
break;
|
break;
|
||||||
auto& item = item_opt.value();
|
auto& item = item_opt.value();
|
||||||
|
|
||||||
|
// Ignore collapsible whitespace chunks at the start of line, and if the last fragment already ends in whitespace.
|
||||||
|
if (item.is_collapsible_whitespace && containing_block().line_boxes().last().is_empty_or_ends_in_whitespace())
|
||||||
|
continue;
|
||||||
|
|
||||||
switch (item.type) {
|
switch (item.type) {
|
||||||
case InlineLevelIterator::Item::Type::ForcedBreak:
|
case InlineLevelIterator::Item::Type::ForcedBreak:
|
||||||
line_builder.break_line();
|
line_builder.break_line();
|
||||||
|
|
|
@ -64,6 +64,7 @@ Optional<InlineLevelIterator::Item> InlineLevelIterator::next(float available_wi
|
||||||
.length_in_node = chunk.length,
|
.length_in_node = chunk.length,
|
||||||
.width = chunk_width,
|
.width = chunk_width,
|
||||||
.should_force_break = m_text_node_context->do_respect_linebreaks && chunk.has_breaking_newline,
|
.should_force_break = m_text_node_context->do_respect_linebreaks && chunk.has_breaking_newline,
|
||||||
|
.is_collapsible_whitespace = m_text_node_context->do_collapse && chunk.is_all_whitespace,
|
||||||
};
|
};
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
|
|
|
@ -32,6 +32,7 @@ public:
|
||||||
size_t length_in_node { 0 };
|
size_t length_in_node { 0 };
|
||||||
float width { 0.0f };
|
float width { 0.0f };
|
||||||
bool should_force_break { false };
|
bool should_force_break { false };
|
||||||
|
bool is_collapsible_whitespace { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit InlineLevelIterator(Layout::Box& container, LayoutMode layout_mode)
|
explicit InlineLevelIterator(Layout::Box& container, LayoutMode layout_mode)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue