Kaynağa Gözat

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.
Andreas Kling 3 yıl önce
ebeveyn
işleme
b1fd801436

+ 6 - 5
Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp

@@ -45,8 +45,10 @@ Optional<InlineLevelIterator::Item> InlineLevelIterator::next(float available_wi
     if (is<Layout::TextNode>(*m_current_node)) {
         auto& text_node = static_cast<Layout::TextNode&>(*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::Item> 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,

+ 1 - 1
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 };