Title: [267830] trunk/Source/WebCore
Revision
267830
Author
an...@apple.com
Date
2020-10-01 05:16:42 -0700 (Thu, 01 Oct 2020)

Log Message

[LFC][Integration] Add LineRunIterator
https://bugs.webkit.org/show_bug.cgi?id=217125

Reviewed by Zalan Bujtas.

Add LineRunIterator iterating line content.
Also remove end offset from modern path, instead set index to the content end position
in traversal functions.

* layout/integration/LayoutIntegrationLineLayout.cpp:
(WebCore::LayoutIntegration::LineLayout::textRunsFor const):
(WebCore::LayoutIntegration::LineLayout::runFor const):
* layout/integration/LayoutIntegrationRunIterator.cpp:
(WebCore::LayoutIntegration::TextRunIterator::traverseNextTextRunInVisualOrder):
(WebCore::LayoutIntegration::TextRunIterator::traverseNextTextRunInTextOrder):
(WebCore::LayoutIntegration::LineRunIterator::LineRunIterator):
(WebCore::LayoutIntegration::LineRunIterator::traverseNextOnLine):
(WebCore::LayoutIntegration::lineRun):
(WebCore::LayoutIntegration::RunIterator::traverseNextTextRunInVisualOrder): Deleted.
(WebCore::LayoutIntegration::RunIterator::traverseNextTextRunInTextOrder): Deleted.
* layout/integration/LayoutIntegrationRunIterator.h:
(WebCore::LayoutIntegration::TextRun::legacyInlineBox const):
(WebCore::LayoutIntegration::LineRunIterator::LineRunIterator):
(WebCore::LayoutIntegration::LineRunIterator::operator++):
(WebCore::LayoutIntegration::Run::legacyInlineBox const):
* layout/integration/LayoutIntegrationRunIteratorLegacyPath.h:
(WebCore::LayoutIntegration::LegacyPath::traverseNextOnLine):
(WebCore::LayoutIntegration::LegacyPath::legacyInlineBox const):
* layout/integration/LayoutIntegrationRunIteratorModernPath.h:
(WebCore::LayoutIntegration::ModernPath::ModernPath):
(WebCore::LayoutIntegration::ModernPath::isLastTextRunOnLine const):
(WebCore::LayoutIntegration::ModernPath::isLastTextRun const):
(WebCore::LayoutIntegration::ModernPath::traverseNextTextRunInVisualOrder):
(WebCore::LayoutIntegration::ModernPath::traverseNextTextRunInTextOrder):
(WebCore::LayoutIntegration::ModernPath::traverseNextOnLine):
(WebCore::LayoutIntegration::ModernPath::atEnd const):
(WebCore::LayoutIntegration::ModernPath::legacyInlineBox const):
(WebCore::LayoutIntegration::ModernPath::setAtEnd):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (267829 => 267830)


--- trunk/Source/WebCore/ChangeLog	2020-10-01 11:32:58 UTC (rev 267829)
+++ trunk/Source/WebCore/ChangeLog	2020-10-01 12:16:42 UTC (rev 267830)
@@ -1,3 +1,44 @@
+2020-10-01  Antti Koivisto  <an...@apple.com>
+
+        [LFC][Integration] Add LineRunIterator
+        https://bugs.webkit.org/show_bug.cgi?id=217125
+
+        Reviewed by Zalan Bujtas.
+
+        Add LineRunIterator iterating line content.
+        Also remove end offset from modern path, instead set index to the content end position
+        in traversal functions.
+
+        * layout/integration/LayoutIntegrationLineLayout.cpp:
+        (WebCore::LayoutIntegration::LineLayout::textRunsFor const):
+        (WebCore::LayoutIntegration::LineLayout::runFor const):
+        * layout/integration/LayoutIntegrationRunIterator.cpp:
+        (WebCore::LayoutIntegration::TextRunIterator::traverseNextTextRunInVisualOrder):
+        (WebCore::LayoutIntegration::TextRunIterator::traverseNextTextRunInTextOrder):
+        (WebCore::LayoutIntegration::LineRunIterator::LineRunIterator):
+        (WebCore::LayoutIntegration::LineRunIterator::traverseNextOnLine):
+        (WebCore::LayoutIntegration::lineRun):
+        (WebCore::LayoutIntegration::RunIterator::traverseNextTextRunInVisualOrder): Deleted.
+        (WebCore::LayoutIntegration::RunIterator::traverseNextTextRunInTextOrder): Deleted.
+        * layout/integration/LayoutIntegrationRunIterator.h:
+        (WebCore::LayoutIntegration::TextRun::legacyInlineBox const):
+        (WebCore::LayoutIntegration::LineRunIterator::LineRunIterator):
+        (WebCore::LayoutIntegration::LineRunIterator::operator++):
+        (WebCore::LayoutIntegration::Run::legacyInlineBox const):
+        * layout/integration/LayoutIntegrationRunIteratorLegacyPath.h:
+        (WebCore::LayoutIntegration::LegacyPath::traverseNextOnLine):
+        (WebCore::LayoutIntegration::LegacyPath::legacyInlineBox const):
+        * layout/integration/LayoutIntegrationRunIteratorModernPath.h:
+        (WebCore::LayoutIntegration::ModernPath::ModernPath):
+        (WebCore::LayoutIntegration::ModernPath::isLastTextRunOnLine const):
+        (WebCore::LayoutIntegration::ModernPath::isLastTextRun const):
+        (WebCore::LayoutIntegration::ModernPath::traverseNextTextRunInVisualOrder):
+        (WebCore::LayoutIntegration::ModernPath::traverseNextTextRunInTextOrder):
+        (WebCore::LayoutIntegration::ModernPath::traverseNextOnLine):
+        (WebCore::LayoutIntegration::ModernPath::atEnd const):
+        (WebCore::LayoutIntegration::ModernPath::legacyInlineBox const):
+        (WebCore::LayoutIntegration::ModernPath::setAtEnd):
+
 2020-09-21  Sergio Villar Senin  <svil...@igalia.com>
 
         [css-flexbox] Implement row-gap and column-gap for flex layout

Modified: trunk/Source/WebCore/layout/displaytree/DisplayRun.h (267829 => 267830)


--- trunk/Source/WebCore/layout/displaytree/DisplayRun.h	2020-10-01 11:32:58 UTC (rev 267829)
+++ trunk/Source/WebCore/layout/displaytree/DisplayRun.h	2020-10-01 12:16:42 UTC (rev 267830)
@@ -77,6 +77,8 @@
 
     CachedImage* image() const { return m_cachedImage; }
 
+    bool hasUnderlyingLayout() const { return !!m_layoutBox; }
+    
     const Layout::Box& layoutBox() const { return *m_layoutBox; }
     const RenderStyle& style() const { return m_layoutBox->style(); }
 

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp (267829 => 267830)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp	2020-10-01 11:32:58 UTC (rev 267829)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp	2020-10-01 12:16:42 UTC (rev 267830)
@@ -302,21 +302,18 @@
     auto* layoutBox = m_boxTree.layoutBoxForRenderer(renderText);
     ASSERT(layoutBox);
 
-    Optional<size_t> firstIndex;
-    size_t lastIndex = 0;
-    for (size_t i = 0; i < inlineContent->runs.size(); ++i) {
-        auto& run = inlineContent->runs[i];
-        if (&run.layoutBox() == layoutBox) {
-            if (!firstIndex)
-                firstIndex = i;
-            lastIndex = i;
-        } else if (firstIndex)
-            break;
-    }
+    auto firstIndex = [&]() -> Optional<size_t> {
+        for (size_t i = 0; i < inlineContent->runs.size(); ++i) {
+            if (&inlineContent->runs[i].layoutBox() == layoutBox)
+                return i;
+        }
+        return { };
+    }();
+
     if (!firstIndex)
         return { };
 
-    return { LayoutIntegration::ModernPath(*inlineContent, *firstIndex, lastIndex + 1) };
+    return { LayoutIntegration::ModernPath(*inlineContent, *firstIndex) };
 }
 
 RunIterator LineLayout::runFor(const RenderElement& renderElement) const
@@ -330,7 +327,7 @@
     for (size_t i = 0; i < inlineContent->runs.size(); ++i) {
         auto& run =  inlineContent->runs[i];
         if (&run.layoutBox() == layoutBox)
-            return { LayoutIntegration::ModernPath(*inlineContent, i, i + 1) };
+            return { LayoutIntegration::ModernPath(*inlineContent, i) };
     }
 
     return { };

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIterator.cpp (267829 => 267830)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIterator.cpp	2020-10-01 11:32:58 UTC (rev 267829)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIterator.cpp	2020-10-01 12:16:42 UTC (rev 267830)
@@ -38,22 +38,6 @@
 {
 }
 
-TextRunIterator& RunIterator::traverseNextTextRunInVisualOrder()
-{
-    WTF::switchOn(m_run.m_pathVariant, [](auto& path) {
-        path.traverseNextTextRunInVisualOrder();
-    });
-    return downcast<TextRunIterator>(*this);
-}
-
-TextRunIterator& RunIterator::traverseNextTextRunInTextOrder()
-{
-    WTF::switchOn(m_run.m_pathVariant, [](auto& path) {
-        path.traverseNextTextRunInTextOrder();
-    });
-    return downcast<TextRunIterator>(*this);
-}
-
 bool RunIterator::operator==(const RunIterator& other) const
 {
     if (m_run.m_pathVariant.index() != other.m_run.m_pathVariant.index())
@@ -76,6 +60,40 @@
 {
 }
 
+TextRunIterator& TextRunIterator::traverseNextTextRunInVisualOrder()
+{
+    WTF::switchOn(m_run.m_pathVariant, [](auto& path) {
+        path.traverseNextTextRunInVisualOrder();
+    });
+    return *this;
+}
+
+TextRunIterator& TextRunIterator::traverseNextTextRunInTextOrder()
+{
+    WTF::switchOn(m_run.m_pathVariant, [](auto& path) {
+        path.traverseNextTextRunInTextOrder();
+    });
+    return *this;
+}
+
+LineRunIterator::LineRunIterator(Run::PathVariant&& pathVariant)
+    : RunIterator(WTFMove(pathVariant))
+{
+}
+
+LineRunIterator::LineRunIterator(const RunIterator& runIterator)
+    : RunIterator(runIterator)
+{
+}
+
+LineRunIterator& LineRunIterator::traverseNextOnLine()
+{
+    WTF::switchOn(m_run.m_pathVariant, [](auto& path) {
+        path.traverseNextOnLine();
+    });
+    return *this;
+}
+
 static const RenderBlockFlow* lineLayoutSystemFlowForRenderer(const RenderObject& renderer)
 {
     // In currently supported cases the renderer is always direct child of the flow.
@@ -127,5 +145,20 @@
     return { LegacyPath(renderElement.inlineBoxWrapper()) };
 }
 
+LineRunIterator lineRun(const RunIterator& runIterator)
+{
+    return LineRunIterator(runIterator);
 }
+
+ModernPath& Run::modernPath()
+{
+    return WTF::get<ModernPath>(m_pathVariant);
 }
+
+LegacyPath& Run::legacyPath()
+{
+    return WTF::get<LegacyPath>(m_pathVariant);
+}
+
+}
+}

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIterator.h (267829 => 267830)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIterator.h	2020-10-01 11:32:58 UTC (rev 267829)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIterator.h	2020-10-01 12:16:42 UTC (rev 267830)
@@ -37,7 +37,7 @@
 
 namespace LayoutIntegration {
 
-class ElementRunIterator;
+class LineRunIterator;
 class TextRunIterator;
 
 struct EndIterator { };
@@ -68,10 +68,18 @@
     unsigned minimumCaretOffset() const;
     unsigned maximumCaretOffset() const;
 
+    // For intermediate porting steps only.
+    InlineBox* legacyInlineBox() const;
+
 protected:
     friend class RunIterator;
+    friend class LineRunIterator;
     friend class TextRunIterator;
 
+    // To help with debugging.
+    ModernPath& modernPath();
+    LegacyPath& legacyPath();
+
     PathVariant m_pathVariant;
 };
 
@@ -89,6 +97,8 @@
 
     bool isLastTextRunOnLine() const;
     bool isLastTextRun() const;
+
+    InlineTextBox* legacyInlineBox() const { return downcast<InlineTextBox>(Run::legacyInlineBox()); }
 };
 
 class RunIterator {
@@ -96,9 +106,6 @@
     RunIterator() : m_run(LegacyPath { nullptr, { } }) { };
     RunIterator(Run::PathVariant&&);
 
-    TextRunIterator& traverseNextTextRunInVisualOrder();
-    TextRunIterator& traverseNextTextRunInTextOrder();
-
     explicit operator bool() const { return !atEnd(); }
 
     bool operator==(const RunIterator&) const;
@@ -126,10 +133,24 @@
     const TextRun& operator*() const { return get(); }
     const TextRun* operator->() const { return &get(); }
 
+    TextRunIterator& traverseNextTextRunInVisualOrder();
+    TextRunIterator& traverseNextTextRunInTextOrder();
+
 private:
     const TextRun& get() const { return downcast<TextRun>(m_run); }
 };
 
+class LineRunIterator : public RunIterator {
+public:
+    LineRunIterator() { }
+    LineRunIterator(const RunIterator&);
+    LineRunIterator(Run::PathVariant&&);
+
+    LineRunIterator& operator++() { return traverseNextOnLine(); }
+
+    LineRunIterator& traverseNextOnLine();
+};
+
 class TextRunRange {
 public:
     TextRunRange(TextRunIterator begin)
@@ -148,6 +169,7 @@
 TextRunIterator firstTextRunInTextOrderFor(const RenderText&);
 TextRunRange textRunsFor(const RenderText&);
 RunIterator runFor(const RenderLineBreak&);
+LineRunIterator lineRun(const RunIterator&);
 
 // -----------------------------------------------
 
@@ -226,6 +248,13 @@
     });
 }
 
+inline InlineBox* Run::legacyInlineBox() const
+{
+    return WTF::switchOn(m_pathVariant, [](auto& path) {
+        return path.legacyInlineBox();
+    });
+}
+
 inline bool TextRun::hasHyphen() const
 {
     return WTF::switchOn(m_pathVariant, [](auto& path) {

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorLegacyPath.h (267829 => 267830)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorLegacyPath.h	2020-10-01 11:32:58 UTC (rev 267829)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorLegacyPath.h	2020-10-01 12:16:42 UTC (rev 267830)
@@ -79,9 +79,16 @@
             ++m_sortedInlineTextBoxIndex;
     }
 
+    void traverseNextOnLine()
+    {
+        m_inlineBox = m_inlineBox->nextLeafOnLine();
+    }
+
     bool operator==(const LegacyPath& other) const { return m_inlineBox == other.m_inlineBox; }
     bool atEnd() const { return !m_inlineBox; }
 
+    InlineBox* legacyInlineBox() const { return const_cast<InlineBox*>(m_inlineBox); }
+
 private:
     const InlineTextBox* inlineTextBox() const { return downcast<InlineTextBox>(m_inlineBox); }
     const InlineTextBox* nextInlineTextBoxInTextOrder() const;

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorModernPath.h (267829 => 267830)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorModernPath.h	2020-10-01 11:32:58 UTC (rev 267829)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorModernPath.h	2020-10-01 12:16:42 UTC (rev 267830)
@@ -40,11 +40,12 @@
 
 class ModernPath {
 public:
-    ModernPath(const Display::InlineContent& inlineContent, size_t startIndex, size_t endIndex)
+    ModernPath(const Display::InlineContent& inlineContent, size_t startIndex)
         : m_inlineContent(&inlineContent)
-        , m_endIndex(endIndex)
         , m_runIndex(startIndex)
-    { }
+    {
+
+    }
     ModernPath(ModernPath&&) = default;
     ModernPath(const ModernPath&) = default;
     ModernPath& operator=(const ModernPath&) = default;
@@ -82,31 +83,68 @@
     {
         if (isLastTextRun())
             return true;
+
         auto& next = runs()[m_runIndex + 1];
         return run().lineIndex() != next.lineIndex();
     }
+
     bool isLastTextRun() const
     {
-        return m_runIndex + 1 == m_endIndex;
+        ASSERT(!atEnd());
+        ASSERT(run().textContent());
+
+        if (m_runIndex + 1 == runs().size())
+            return true;
+        return &run().layoutBox() != &runs()[m_runIndex + 1].layoutBox();
     };
 
     void traverseNextTextRunInVisualOrder()
     {
         ASSERT(!atEnd());
+        ASSERT(run().textContent());
+
+        auto& layoutBox = run().layoutBox();
+
         ++m_runIndex;
+
+        if (!atEnd() && &layoutBox != &run().layoutBox())
+            setAtEnd();
     }
-    void traverseNextTextRunInTextOrder() {  traverseNextTextRunInVisualOrder(); }
 
+    void traverseNextTextRunInTextOrder()
+    {
+        // FIXME: No RTL in LFC.
+        traverseNextTextRunInVisualOrder();
+    }
+
+    void traverseNextOnLine()
+    {
+        ASSERT(!atEnd());
+
+        auto previouslineIndex = run().lineIndex();
+
+        ++m_runIndex;
+
+        if (!atEnd() && previouslineIndex != run().lineIndex())
+            setAtEnd();
+    }
+
     bool operator==(const ModernPath& other) const { return m_inlineContent == other.m_inlineContent && m_runIndex == other.m_runIndex; }
-    bool atEnd() const { return m_runIndex == m_endIndex; }
+    bool atEnd() const { return m_runIndex == runs().size() || !run().hasUnderlyingLayout(); }
 
+    InlineBox* legacyInlineBox() const
+    {
+        ASSERT_NOT_REACHED();
+        return nullptr;
+    }
+
 private:
     const Display::InlineContent::Runs& runs() const { return m_inlineContent->runs; }
     const Display::Run& run() const { return runs()[m_runIndex]; }
     const Display::Line& line() const { return m_inlineContent->lineForRun(run()); }
+    void setAtEnd() { m_runIndex = runs().size(); }
 
     RefPtr<const Display::InlineContent> m_inlineContent;
-    size_t m_endIndex { 0 };
     size_t m_runIndex { 0 };
 };
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to