diff --git a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp index da9d88c9299..bb170e7536a 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp @@ -123,11 +123,8 @@ 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()) { - auto& line_boxes = m_formatting_state.get(m_container).line_boxes; - bool previous_is_empty_or_ends_in_whitespace = line_boxes.is_empty() || line_boxes.last().is_empty_or_ends_in_whitespace(); - enter_text_node(text_node, previous_is_empty_or_ends_in_whitespace); - } + if (!m_text_node_context.has_value()) + enter_text_node(text_node); auto chunk_opt = m_text_node_context->next_chunk; if (!chunk_opt.has_value()) { @@ -225,7 +222,7 @@ Optional InlineLevelIterator::next(float available_wi return item; } -void InlineLevelIterator::enter_text_node(Layout::TextNode const& text_node, bool previous_is_empty_or_ends_in_whitespace) +void InlineLevelIterator::enter_text_node(Layout::TextNode const& text_node) { bool do_collapse = true; bool do_wrap_lines = true; @@ -250,7 +247,7 @@ void InlineLevelIterator::enter_text_node(Layout::TextNode const& text_node, boo } // FIXME: The const_cast here is gross. - const_cast(text_node).compute_text_for_rendering(do_collapse, previous_is_empty_or_ends_in_whitespace); + const_cast(text_node).compute_text_for_rendering(do_collapse); 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 6709c9735fa..21b7dd1a5e3 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.h +++ b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.h @@ -56,7 +56,7 @@ private: void skip_to_next(); void compute_next(); - void enter_text_node(Layout::TextNode const&, bool previous_is_empty_or_ends_in_whitespace); + void enter_text_node(Layout::TextNode const&); void enter_node_with_box_model_metrics(Layout::NodeWithStyleAndBoxModelMetrics const&); void exit_node_with_box_model_metrics(); diff --git a/Userland/Libraries/LibWeb/Layout/TextNode.cpp b/Userland/Libraries/LibWeb/Layout/TextNode.cpp index 089ab701a44..083f1500d41 100644 --- a/Userland/Libraries/LibWeb/Layout/TextNode.cpp +++ b/Userland/Libraries/LibWeb/Layout/TextNode.cpp @@ -32,8 +32,8 @@ static bool is_all_whitespace(StringView string) return true; } -// NOTE: This collapes whitespace into a single ASCII space if collapse is true. If previous_is_empty_or_ends_in_whitespace, it also strips leading whitespace. -void TextNode::compute_text_for_rendering(bool collapse, bool previous_is_empty_or_ends_in_whitespace) +// NOTE: This collapses whitespace into a single ASCII space if collapse is true. +void TextNode::compute_text_for_rendering(bool collapse) { auto& data = dom_node().data(); if (!collapse || data.is_empty()) { @@ -44,12 +44,8 @@ void TextNode::compute_text_for_rendering(bool collapse, bool previous_is_empty_ // NOTE: A couple fast returns to avoid unnecessarily allocating a StringBuilder. if (data.length() == 1) { if (is_ascii_space(data[0])) { - if (previous_is_empty_or_ends_in_whitespace) - m_text_for_rendering = String::empty(); - else { - static String s_single_space_string = " "; - m_text_for_rendering = s_single_space_string; - } + static String s_single_space_string = " "; + m_text_for_rendering = s_single_space_string; } else { m_text_for_rendering = data; } @@ -76,8 +72,6 @@ void TextNode::compute_text_for_rendering(bool collapse, bool previous_is_empty_ ++index; }; - if (previous_is_empty_or_ends_in_whitespace) - skip_over_whitespace(); while (index < data.length()) { if (is_ascii_space(data[index])) { builder.append(' '); diff --git a/Userland/Libraries/LibWeb/Layout/TextNode.h b/Userland/Libraries/LibWeb/Layout/TextNode.h index 3fcbd68e756..f468b870890 100644 --- a/Userland/Libraries/LibWeb/Layout/TextNode.h +++ b/Userland/Libraries/LibWeb/Layout/TextNode.h @@ -46,7 +46,7 @@ public: Utf8View::Iterator m_iterator; }; - void compute_text_for_rendering(bool collapse, bool previous_is_empty_or_ends_in_whitespace); + void compute_text_for_rendering(bool collapse); virtual RefPtr create_paintable() const override;