diff options
author | Andreas Kling <kling@serenityos.org> | 2022-01-21 14:15:10 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-23 01:22:41 +0100 |
commit | 9f39ad89293ac2140e3605080426cd998fca3d94 (patch) | |
tree | eaef1e3862ec9a340f20d748bff27898968faae2 /Userland | |
parent | 766d816db3642635e79dc4a8026534098c4d922a (diff) | |
download | serenity-9f39ad89293ac2140e3605080426cd998fca3d94.zip |
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.
Diffstat (limited to 'Userland')
3 files changed, 6 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 27ca5447aa..0e16fa1f21 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -168,6 +168,10 @@ void InlineFormattingContext::generate_line_boxes(LayoutMode layout_mode) break; 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) { case InlineLevelIterator::Item::Type::ForcedBreak: line_builder.break_line(); diff --git a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp index 192fb3431e..266c9a2461 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp @@ -64,6 +64,7 @@ Optional<InlineLevelIterator::Item> InlineLevelIterator::next(float available_wi .length_in_node = chunk.length, .width = chunk_width, .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; diff --git a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.h b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.h index d605f53bc7..a3fee1c3b1 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.h +++ b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.h @@ -32,6 +32,7 @@ public: size_t length_in_node { 0 }; float width { 0.0f }; bool should_force_break { false }; + bool is_collapsible_whitespace { false }; }; explicit InlineLevelIterator(Layout::Box& container, LayoutMode layout_mode) |