From b1fd80143618f33d35b2a6b121d07ccf1fe9d52a Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 21 Jan 2022 14:38:17 +0100 Subject: [PATCH] LibWeb: Pass correct state to TextNode::compute_text_for_rendering() This is poorly factored. TextNode needs to know whether the most recently inserted fragment on the current line was empty or ended in whitespace. This is used when deciding what to do with leading whitespace in text nodes. Let's keep this working for now, but we should eventually sort this out and make text chunk iteration not depend on this information. --- .../Libraries/LibWeb/Layout/InlineLevelIterator.cpp | 11 ++++++----- .../Libraries/LibWeb/Layout/InlineLevelIterator.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp index 266c9a2461..ac7993cea9 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp @@ -45,8 +45,10 @@ Optional InlineLevelIterator::next(float available_wi if (is(*m_current_node)) { auto& text_node = static_cast(*m_current_node); - if (!m_text_node_context.has_value()) - enter_text_node(text_node); + if (!m_text_node_context.has_value()) { + bool previous_is_empty_or_ends_in_whitespace = m_container.line_boxes().is_empty() || m_container.line_boxes().last().is_empty_or_ends_in_whitespace(); + enter_text_node(text_node, previous_is_empty_or_ends_in_whitespace); + } auto chunk_opt = m_text_node_context->chunk_iterator.next(); if (!chunk_opt.has_value()) { @@ -104,7 +106,7 @@ Optional InlineLevelIterator::next(float available_wi }; } -void InlineLevelIterator::enter_text_node(Layout::TextNode& text_node) +void InlineLevelIterator::enter_text_node(Layout::TextNode& text_node, bool previous_is_empty_or_ends_in_whitespace) { bool do_collapse = true; bool do_wrap_lines = true; @@ -128,8 +130,7 @@ void InlineLevelIterator::enter_text_node(Layout::TextNode& text_node) do_respect_linebreaks = true; } - // FIXME: Pass the correct value for the last boolean! - text_node.compute_text_for_rendering(do_collapse, true); + text_node.compute_text_for_rendering(do_collapse, previous_is_empty_or_ends_in_whitespace); m_text_node_context = TextNodeContext { .do_collapse = do_collapse, diff --git a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.h b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.h index 44a7608f38..9621d92570 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.h +++ b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.h @@ -47,7 +47,7 @@ public: private: void skip_to_next(); - void enter_text_node(Layout::TextNode&); + void enter_text_node(Layout::TextNode&, bool previous_is_empty_or_ends_in_whitespace); Layout::BlockContainer& m_container; Layout::Node* m_current_node { nullptr };