Title: [269041] trunk/Source/WebCore
Revision
269041
Author
[email protected]
Date
2020-10-27 08:57:15 -0700 (Tue, 27 Oct 2020)

Log Message

[LFC][Integration] Use iterator for next/previousLinePosition
https://bugs.webkit.org/show_bug.cgi?id=218233

Reviewed by Zalan Bujtas.

Add the required capabilities to the line iterator and also use them in a few other places.

* editing/VisibleUnits.cpp:
(WebCore::absoluteLineDirectionPointToLocalPointInBlock):
(WebCore::previousLinePosition):
(WebCore::nextLinePosition):
* layout/integration/LayoutIntegrationInlineContent.cpp:
(WebCore::LayoutIntegration::InlineContent::containingBlock const):
* layout/integration/LayoutIntegrationInlineContent.h:
* layout/integration/LayoutIntegrationLineIterator.cpp:
(WebCore::LayoutIntegration::firstLineFor):
(WebCore::LayoutIntegration::lastLineFor):
(WebCore::LayoutIntegration::LineIterator::closestRunForPoint):
(WebCore::LayoutIntegration::LineIterator::closestRunForLogicalLeftPosition):
(WebCore::LayoutIntegration::PathLine::blockDirectionPointInLine const):
* layout/integration/LayoutIntegrationLineIterator.h:
(WebCore::LayoutIntegration::LineIterator::LineIterator):
(WebCore::LayoutIntegration::PathLine::y const):
(WebCore::LayoutIntegration::PathLine::logicalHeight const):
(WebCore::LayoutIntegration::PathLine::isHorizontal const):
(WebCore::LayoutIntegration::PathLine::containingBlock const):
* layout/integration/LayoutIntegrationLineIteratorLegacyPath.h:
(WebCore::LayoutIntegration::LineIteratorLegacyPath::y const):
(WebCore::LayoutIntegration::LineIteratorLegacyPath::logicalHeight const):
(WebCore::LayoutIntegration::LineIteratorLegacyPath::isHorizontal const):
(WebCore::LayoutIntegration::LineIteratorLegacyPath::containingBlock const):
* layout/integration/LayoutIntegrationLineIteratorModernPath.h:
(WebCore::LayoutIntegration::LineIteratorModernPath::y const):
(WebCore::LayoutIntegration::LineIteratorModernPath::logicalHeight const):
(WebCore::LayoutIntegration::LineIteratorModernPath::isHorizontal const):
(WebCore::LayoutIntegration::LineIteratorModernPath::containingBlock const):
* layout/integration/LayoutIntegrationLineLayout.cpp:
(WebCore::LayoutIntegration::LineLayout::firstLine const):
(WebCore::LayoutIntegration::LineLayout::lastLine const):
* layout/integration/LayoutIntegrationLineLayout.h:
(WebCore::LayoutIntegration::LineLayout::flow const):
(WebCore::LayoutIntegration::LineLayout::flow):
* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::findClosestTextAtAbsolutePoint):
(WebCore::RenderBlockFlow::positionForPointWithInlineChildren):
* rendering/RootInlineBox.cpp:
(WebCore::isEditableLeaf): Deleted.
(WebCore::RootInlineBox::closestLeafChildForPoint): Deleted.
(WebCore::RootInlineBox::closestLeafChildForLogicalLeftPosition): Deleted.

This functionality moves to the line iterator.

* rendering/RootInlineBox.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (269040 => 269041)


--- trunk/Source/WebCore/ChangeLog	2020-10-27 15:34:01 UTC (rev 269040)
+++ trunk/Source/WebCore/ChangeLog	2020-10-27 15:57:15 UTC (rev 269041)
@@ -1,3 +1,59 @@
+2020-10-27  Antti Koivisto  <[email protected]>
+
+        [LFC][Integration] Use iterator for next/previousLinePosition
+        https://bugs.webkit.org/show_bug.cgi?id=218233
+
+        Reviewed by Zalan Bujtas.
+
+        Add the required capabilities to the line iterator and also use them in a few other places.
+
+        * editing/VisibleUnits.cpp:
+        (WebCore::absoluteLineDirectionPointToLocalPointInBlock):
+        (WebCore::previousLinePosition):
+        (WebCore::nextLinePosition):
+        * layout/integration/LayoutIntegrationInlineContent.cpp:
+        (WebCore::LayoutIntegration::InlineContent::containingBlock const):
+        * layout/integration/LayoutIntegrationInlineContent.h:
+        * layout/integration/LayoutIntegrationLineIterator.cpp:
+        (WebCore::LayoutIntegration::firstLineFor):
+        (WebCore::LayoutIntegration::lastLineFor):
+        (WebCore::LayoutIntegration::LineIterator::closestRunForPoint):
+        (WebCore::LayoutIntegration::LineIterator::closestRunForLogicalLeftPosition):
+        (WebCore::LayoutIntegration::PathLine::blockDirectionPointInLine const):
+        * layout/integration/LayoutIntegrationLineIterator.h:
+        (WebCore::LayoutIntegration::LineIterator::LineIterator):
+        (WebCore::LayoutIntegration::PathLine::y const):
+        (WebCore::LayoutIntegration::PathLine::logicalHeight const):
+        (WebCore::LayoutIntegration::PathLine::isHorizontal const):
+        (WebCore::LayoutIntegration::PathLine::containingBlock const):
+        * layout/integration/LayoutIntegrationLineIteratorLegacyPath.h:
+        (WebCore::LayoutIntegration::LineIteratorLegacyPath::y const):
+        (WebCore::LayoutIntegration::LineIteratorLegacyPath::logicalHeight const):
+        (WebCore::LayoutIntegration::LineIteratorLegacyPath::isHorizontal const):
+        (WebCore::LayoutIntegration::LineIteratorLegacyPath::containingBlock const):
+        * layout/integration/LayoutIntegrationLineIteratorModernPath.h:
+        (WebCore::LayoutIntegration::LineIteratorModernPath::y const):
+        (WebCore::LayoutIntegration::LineIteratorModernPath::logicalHeight const):
+        (WebCore::LayoutIntegration::LineIteratorModernPath::isHorizontal const):
+        (WebCore::LayoutIntegration::LineIteratorModernPath::containingBlock const):
+        * layout/integration/LayoutIntegrationLineLayout.cpp:
+        (WebCore::LayoutIntegration::LineLayout::firstLine const):
+        (WebCore::LayoutIntegration::LineLayout::lastLine const):
+        * layout/integration/LayoutIntegrationLineLayout.h:
+        (WebCore::LayoutIntegration::LineLayout::flow const):
+        (WebCore::LayoutIntegration::LineLayout::flow):
+        * rendering/RenderBlockFlow.cpp:
+        (WebCore::RenderBlockFlow::findClosestTextAtAbsolutePoint):
+        (WebCore::RenderBlockFlow::positionForPointWithInlineChildren):
+        * rendering/RootInlineBox.cpp:
+        (WebCore::isEditableLeaf): Deleted.
+        (WebCore::RootInlineBox::closestLeafChildForPoint): Deleted.
+        (WebCore::RootInlineBox::closestLeafChildForLogicalLeftPosition): Deleted.
+
+        This functionality moves to the line iterator.
+
+        * rendering/RootInlineBox.h:
+
 2020-10-27  Miguel Gomez  <[email protected]>
 
         [WPE] REGRESSION(r268992) Redefinition of min() inside TextureMapperShaderProgram for GLES > 3.0

Modified: trunk/Source/WebCore/editing/VisibleUnits.cpp (269040 => 269041)


--- trunk/Source/WebCore/editing/VisibleUnits.cpp	2020-10-27 15:34:01 UTC (rev 269040)
+++ trunk/Source/WebCore/editing/VisibleUnits.cpp	2020-10-27 15:57:15 UTC (rev 269041)
@@ -981,15 +981,15 @@
     return p.isNotNull() && p == logicalEndOfLine(p);
 }
 
-static inline IntPoint absoluteLineDirectionPointToLocalPointInBlock(RootInlineBox& root, int lineDirectionPoint)
+static inline IntPoint absoluteLineDirectionPointToLocalPointInBlock(LayoutIntegration::LineIterator& line, int lineDirectionPoint)
 {
-    RenderBlockFlow& containingBlock = root.blockFlow();
+    auto& containingBlock = line->containingBlock();
     FloatPoint absoluteBlockPoint = containingBlock.localToAbsolute(FloatPoint()) - toFloatSize(containingBlock.scrollPosition());
 
     if (containingBlock.isHorizontalWritingMode())
-        return IntPoint(lineDirectionPoint - absoluteBlockPoint.x(), root.blockDirectionPointInLine());
+        return IntPoint(lineDirectionPoint - absoluteBlockPoint.x(), line->blockDirectionPointInLine());
 
-    return IntPoint(root.blockDirectionPointInLine(), lineDirectionPoint - absoluteBlockPoint.y());
+    return IntPoint(line->blockDirectionPointInLine(), lineDirectionPoint - absoluteBlockPoint.y());
 }
 
 static Element* rootEditableOrDocumentElement(Node& node, EditableType editableType)
@@ -1013,33 +1013,33 @@
     if (!renderer)
         return VisiblePosition();
 
-    RootInlineBox* root = nullptr;
-    if (auto box = visiblePosition.inlineBoxAndOffset().box) {
-        root = box->root().prevRootBox();
+    LayoutIntegration::LineIterator line;
+    if (auto run = visiblePosition.inlineRunAndOffset().run) {
+        line = run.line().previous();
         // We want to skip zero height boxes.
         // This could happen in case it is a TrailingFloatsRootInlineBox.
-        if (!root || !root->logicalHeight() || !root->firstLeafDescendant())
-            root = nullptr;
+        if (!line || !line->logicalHeight() || !line.firstRun())
+            line = { };
     }
 
-    if (!root) {
+    if (!line) {
         Position position = previousRootInlineBoxCandidatePosition(node, visiblePosition, editableType);
         if (position.isNotNull()) {
             RenderedPosition renderedPosition(position);
-            root = renderedPosition.rootBox();
-            if (!root)
+            line = renderedPosition.line();
+            if (!line)
                 return position;
         }
     }
     
-    if (root) {
+    if (line) {
         // FIXME: Can be wrong for multi-column layout and with transforms.
-        IntPoint pointInLine = absoluteLineDirectionPointToLocalPointInBlock(*root, lineDirectionPoint);
-        RenderObject& renderer = root->closestLeafChildForPoint(pointInLine, isEditablePosition(p))->renderer();
+        auto pointInLine = absoluteLineDirectionPointToLocalPointInBlock(line, lineDirectionPoint);
+        auto& renderer = line.closestRunForPoint(pointInLine, isEditablePosition(p))->renderer();
         Node* node = renderer.node();
         if (node && editingIgnoresContent(*node))
             return positionInParentBeforeNode(node);
-        return renderer.positionForPoint(pointInLine, nullptr);
+        return const_cast<RenderObject&>(renderer).positionForPoint(pointInLine, nullptr);
     }
     
     // Could not find a previous line. This means we must already be on the first line.
@@ -1063,16 +1063,16 @@
     if (!node->renderer())
         return VisiblePosition();
 
-    RootInlineBox* root = nullptr;
-    if (auto box = visiblePosition.inlineBoxAndOffset().box) {
-        root = box->root().nextRootBox();
+    LayoutIntegration::LineIterator line;
+    if (auto run = visiblePosition.inlineRunAndOffset().run) {
+        line = run.line().next();
         // We want to skip zero height boxes.
         // This could happen in case it is a TrailingFloatsRootInlineBox.
-        if (!root || !root->logicalHeight() || !root->firstLeafDescendant())
-            root = nullptr;
+        if (!line || !line->logicalHeight() || !line.firstRun())
+            line = { };
     }
 
-    if (!root) {
+    if (!line) {
         // FIXME: We need do the same in previousLinePosition.
         Node* child = node->traverseToChildAt(p.deprecatedEditingOffset());
         node = child ? child : node->lastDescendant();
@@ -1079,20 +1079,20 @@
         Position position = nextRootInlineBoxCandidatePosition(node, visiblePosition, editableType);
         if (position.isNotNull()) {
             RenderedPosition renderedPosition(position);
-            root = renderedPosition.rootBox();
-            if (!root)
+            line = renderedPosition.line();
+            if (!line)
                 return position;
         }
     }
     
-    if (root) {
+    if (line) {
         // FIXME: Can be wrong for multi-column layout and with transforms.
-        IntPoint pointInLine = absoluteLineDirectionPointToLocalPointInBlock(*root, lineDirectionPoint);
-        RenderObject& renderer = root->closestLeafChildForPoint(pointInLine, isEditablePosition(p))->renderer();
+        auto pointInLine = absoluteLineDirectionPointToLocalPointInBlock(line, lineDirectionPoint);
+        auto& renderer = line.closestRunForPoint(pointInLine, isEditablePosition(p))->renderer();
         Node* node = renderer.node();
         if (node && editingIgnoresContent(*node))
             return positionInParentBeforeNode(node);
-        return renderer.positionForPoint(pointInLine, nullptr);
+        return const_cast<RenderObject&>(renderer).positionForPoint(pointInLine, nullptr);
     }
 
     // Could not find a next line. This means we must already be on the last line.

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContent.cpp (269040 => 269041)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContent.cpp	2020-10-27 15:34:01 UTC (rev 269040)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContent.cpp	2020-10-27 15:57:15 UTC (rev 269041)
@@ -66,6 +66,10 @@
     return m_lineLayout->rendererForLayoutBox(layoutBox);
 }
 
+const RenderBlockFlow& InlineContent::containingBlock() const
+{
+    return m_lineLayout->flow();
+}
 
 }
 }

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContent.h (269040 => 269041)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContent.h	2020-10-27 15:34:01 UTC (rev 269040)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContent.h	2020-10-27 15:57:15 UTC (rev 269041)
@@ -35,6 +35,7 @@
 
 namespace WebCore {
 
+class RenderBlockFlow;
 class RenderObject;
 
 namespace Layout {
@@ -62,6 +63,7 @@
 
     const LineLayout& lineLayout() const;
     const RenderObject& rendererForLayoutBox(const Layout::Box&) const;
+    const RenderBlockFlow& containingBlock() const;
 
 private:
     InlineContent(const LineLayout&);

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.cpp (269040 => 269041)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.cpp	2020-10-27 15:34:01 UTC (rev 269040)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.cpp	2020-10-27 15:57:15 UTC (rev 269041)
@@ -108,7 +108,76 @@
     });
 }
 
+LineIterator firstLineFor(const RenderBlockFlow& flow)
+{
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+    if (auto* lineLayout = flow.modernLineLayout())
+        return lineLayout->firstLine();
+#endif
 
+    return { LineIteratorLegacyPath { flow.firstRootBox() } };
 }
+
+LineIterator lastLineFor(const RenderBlockFlow& flow)
+{
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+    if (auto* lineLayout = flow.modernLineLayout())
+        return lineLayout->lastLine();
+#endif
+
+    return { LineIteratorLegacyPath { flow.lastRootBox() } };
 }
 
+LineRunIterator LineIterator::closestRunForPoint(const IntPoint& pointInContents, bool editableOnly)
+{
+    if (atEnd())
+        return { };
+    return closestRunForLogicalLeftPosition(m_line.isHorizontal() ? pointInContents.x() : pointInContents.y(), editableOnly);
+}
+
+LineRunIterator LineIterator::closestRunForLogicalLeftPosition(int leftPosition, bool editableOnly)
+{
+    auto isEditable = [&](auto run)
+    {
+        return run && run->renderer().node() && run->renderer().node()->hasEditableStyle();
+    };
+
+    auto firstRun = this->firstRun();
+    auto lastRun = this->lastRun();
+
+    if (firstRun != lastRun) {
+        if (firstRun->isLineBreak())
+            firstRun = firstRun.nextOnLineIgnoringLineBreak();
+        else if (lastRun->isLineBreak())
+            lastRun = lastRun.previousOnLineIgnoringLineBreak();
+    }
+
+    if (firstRun == lastRun && (!editableOnly || isEditable(firstRun)))
+        return firstRun;
+
+    if (firstRun && leftPosition <= firstRun->logicalLeft() && !firstRun->renderer().isListMarker() && (!editableOnly || isEditable(firstRun)))
+        return firstRun;
+
+    if (lastRun && leftPosition >= lastRun->logicalRight() && !lastRun->renderer().isListMarker() && (!editableOnly || isEditable(lastRun)))
+        return lastRun;
+
+    auto closestRun = lastRun;
+    for (auto run = firstRun; run; run = run.traverseNextOnLineIgnoringLineBreak()) {
+        if (!run->renderer().isListMarker() && (!editableOnly || isEditable(run))) {
+            if (leftPosition < run->logicalRight())
+                return run;
+            closestRun = run;
+        }
+    }
+
+    return closestRun;
+}
+
+int PathLine::blockDirectionPointInLine() const
+{
+    return !containingBlock().style().isFlippedBlocksWritingMode() ? std::max(top(), selectionTop()) : std::min(bottom(), selectionBottom());
+}
+
+}
+}
+

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.h (269040 => 269041)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.h	2020-10-27 15:34:01 UTC (rev 269040)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.h	2020-10-27 15:57:15 UTC (rev 269041)
@@ -56,6 +56,15 @@
     LayoutUnit selectionTopForHitTesting() const;
     LayoutUnit selectionBottom() const;
 
+    float y() const;
+    float logicalHeight() const;
+
+    int blockDirectionPointInLine() const;
+
+    bool isHorizontal() const;
+
+    const RenderBlockFlow& containingBlock() const;
+
 protected:
     friend class LineIterator;
 
@@ -65,6 +74,7 @@
 class LineIterator {
 public:
     LineIterator() : m_line(LineIteratorLegacyPath { nullptr }) { };
+    LineIterator(const RootInlineBox* rootInlineBox) : m_line(LineIteratorLegacyPath { rootInlineBox }) { };
     LineIterator(PathLine::PathVariant&&);
 
     LineIterator& operator++() { return traverseNext(); }
@@ -91,12 +101,15 @@
     LineRunIterator lastRun() const;
     LineRunIterator logicalStartRunWithNode() const;
     LineRunIterator logicalEndRunWithNode() const;
+    LineRunIterator closestRunForPoint(const IntPoint& pointInContents, bool editableOnly);
+    LineRunIterator closestRunForLogicalLeftPosition(int position, bool editableOnly = false);
 
 private:
     PathLine m_line;
 };
 
-LineIterator lineFor(const PathIterator&);
+LineIterator firstLineFor(const RenderBlockFlow&);
+LineIterator lastLineFor(const RenderBlockFlow&);
 
 // -----------------------------------------------
 
@@ -140,6 +153,34 @@
     });
 }
 
+inline float PathLine::y() const
+{
+    return WTF::switchOn(m_pathVariant, [](const auto& path) {
+        return path.y();
+    });
 }
+
+inline float PathLine::logicalHeight() const
+{
+    return WTF::switchOn(m_pathVariant, [](const auto& path) {
+        return path.logicalHeight();
+    });
 }
 
+inline bool PathLine::isHorizontal() const
+{
+    return WTF::switchOn(m_pathVariant, [](const auto& path) {
+        return path.isHorizontal();
+    });
+}
+
+inline const RenderBlockFlow& PathLine::containingBlock() const
+{
+    return WTF::switchOn(m_pathVariant, [](const auto& path) -> const RenderBlockFlow& {
+        return path.containingBlock();
+    });
+}
+
+}
+}
+

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIteratorLegacyPath.h (269040 => 269041)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIteratorLegacyPath.h	2020-10-27 15:34:01 UTC (rev 269040)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIteratorLegacyPath.h	2020-10-27 15:57:15 UTC (rev 269041)
@@ -50,6 +50,12 @@
     LayoutUnit selectionTopForHitTesting() const { return m_rootInlineBox->selectionTop(RootInlineBox::ForHitTesting::Yes); }
     LayoutUnit selectionBottom() const { return m_rootInlineBox->selectionBottom(); }
 
+    float y() const { return m_rootInlineBox->y(); }
+    float logicalHeight() const { return m_rootInlineBox->logicalHeight(); }
+    bool isHorizontal() const { return m_rootInlineBox->isHorizontal(); }
+
+    const RenderBlockFlow& containingBlock() const { return m_rootInlineBox->blockFlow(); }
+
     void traverseNext()
     {
         m_rootInlineBox = m_rootInlineBox->nextRootBox();

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIteratorModernPath.h (269040 => 269041)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIteratorModernPath.h	2020-10-27 15:34:01 UTC (rev 269040)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIteratorModernPath.h	2020-10-27 15:57:15 UTC (rev 269041)
@@ -55,6 +55,12 @@
     LayoutUnit selectionTopForHitTesting() const { return top(); }
     LayoutUnit selectionBottom() const { return bottom(); }
 
+    float y() const { return top(); }
+    float logicalHeight() const { return line().rect().height(); }
+    bool isHorizontal() const { return true; }
+
+    const RenderBlockFlow& containingBlock() const { return m_inlineContent->containingBlock(); }
+
     void traverseNext()
     {
         ASSERT(!atEnd());

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp (269040 => 269041)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp	2020-10-27 15:34:01 UTC (rev 269040)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp	2020-10-27 15:57:15 UTC (rev 269041)
@@ -404,6 +404,22 @@
     return { };
 }
 
+LineIterator LineLayout::firstLine() const
+{
+    if (!m_inlineContent)
+        return { };
+
+    return { LineIteratorModernPath(*m_inlineContent, 0) };
+}
+
+LineIterator LineLayout::lastLine() const
+{
+    if (!m_inlineContent)
+        return { };
+
+    return { LineIteratorModernPath(*m_inlineContent, m_inlineContent->lines.isEmpty() ? 0 : m_inlineContent->lines.size() - 1) };
+}
+
 const RenderObject& LineLayout::rendererForLayoutBox(const Layout::Box& layoutBox) const
 {
     return m_boxTree.rendererForLayoutBox(layoutBox);

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.h (269040 => 269041)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.h	2020-10-27 15:34:01 UTC (rev 269040)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.h	2020-10-27 15:57:15 UTC (rev 269041)
@@ -28,6 +28,7 @@
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
 #include "LayoutIntegrationBoxTree.h"
+#include "LayoutIntegrationLineIterator.h"
 #include "LayoutIntegrationRunIterator.h"
 #include "LayoutPoint.h"
 #include "LayoutState.h"
@@ -83,8 +84,11 @@
 
     TextRunIterator textRunsFor(const RenderText&) const;
     RunIterator runFor(const RenderElement&) const;
+    LineIterator firstLine() const;
+    LineIterator lastLine() const;
 
     const RenderObject& rendererForLayoutBox(const Layout::Box&) const;
+    const RenderBlockFlow& flow() const { return m_boxTree.flow(); }
 
     static void releaseCaches(RenderView&);
 
@@ -95,7 +99,6 @@
     InlineContent& ensureInlineContent();
 
     RenderBlockFlow& flow() { return m_boxTree.flow(); }
-    const RenderBlockFlow& flow() const { return m_boxTree.flow(); }
 
     const Layout::ContainerBox& rootLayoutBox() const;
     Layout::ContainerBox& rootLayoutBox();

Modified: trunk/Source/WebCore/rendering/RenderBlockFlow.cpp (269040 => 269041)


--- trunk/Source/WebCore/rendering/RenderBlockFlow.cpp	2020-10-27 15:34:01 UTC (rev 269040)
+++ trunk/Source/WebCore/rendering/RenderBlockFlow.cpp	2020-10-27 15:57:15 UTC (rev 269041)
@@ -3369,17 +3369,17 @@
     // Only check the gaps between the root line boxes. We deliberately ignore overflow because
     // experience has shown that hit tests on an exploded text node can fail when within the
     // overflow fragment.
-    for (RootInlineBox* current = blockFlow.firstRootBox(); current && current != blockFlow.lastRootBox(); current = current->nextRootBox()) {
+    for (auto current = LayoutIntegration::firstLineFor(blockFlow), last = LayoutIntegration::lastLineFor(blockFlow); current && current != last; current.traverseNext()) {
         float currentBottom = current->y() + current->logicalHeight();
         if (localPoint.y() < currentBottom)
             return nullptr;
         
-        RootInlineBox* next = current->nextRootBox();
+        auto next = current.next();
         float nextTop = next->y();
         if (localPoint.y() < nextTop) {
-            InlineBox* inlineBox = current->closestLeafChildForLogicalLeftPosition(localPoint.x());
-            if (inlineBox && inlineBox->behavesLikeText() && is<RenderText>(inlineBox->renderer()))
-                return &downcast<RenderText>(inlineBox->renderer());
+            auto run = current.closestRunForLogicalLeftPosition(localPoint.x());
+            if (run && is<RenderText>(run->renderer()))
+                return const_cast<RenderText*>(&downcast<RenderText>(run->renderer()));
         }
     }
     return nullptr;
@@ -3427,7 +3427,8 @@
                     || (!blocksAreFlipped && pointInLogicalContents.y() == nextRootBoxWithChildren->lineTopWithLeading())))
                     continue;
             }
-            closestBox = root->closestLeafChildForLogicalLeftPosition(pointInLogicalContents.x());
+            if (auto closestRun = LayoutIntegration::LineIterator(root).closestRunForLogicalLeftPosition(pointInLogicalContents.x()))
+                closestBox = closestRun->legacyInlineBox();
             if (closestBox)
                 break;
         }
@@ -3437,7 +3438,8 @@
 
     if (!moveCaretToBoundary && !closestBox && lastRootBoxWithChildren) {
         // y coordinate is below last root line box, pretend we hit it
-        closestBox = lastRootBoxWithChildren->closestLeafChildForLogicalLeftPosition(pointInLogicalContents.x());
+        auto closestRun = LayoutIntegration::LineIterator(lastRootBoxWithChildren).closestRunForLogicalLeftPosition(pointInLogicalContents.x());
+        closestBox = closestRun ? closestRun->legacyInlineBox() : nullptr;
     }
 
     if (closestBox) {

Modified: trunk/Source/WebCore/rendering/RootInlineBox.cpp (269040 => 269041)


--- trunk/Source/WebCore/rendering/RootInlineBox.cpp	2020-10-27 15:34:01 UTC (rev 269040)
+++ trunk/Source/WebCore/rendering/RootInlineBox.cpp	2020-10-27 15:57:15 UTC (rev 269041)
@@ -760,56 +760,6 @@
     return downcast<RenderBlockFlow>(renderer());
 }
 
-static bool isEditableLeaf(InlineBox* leaf)
-{
-    return leaf && leaf->renderer().node() && leaf->renderer().node()->hasEditableStyle();
-}
-
-InlineBox* RootInlineBox::closestLeafChildForPoint(const IntPoint& pointInContents, bool onlyEditableLeaves)
-{
-    return closestLeafChildForLogicalLeftPosition(blockFlow().isHorizontalWritingMode() ? pointInContents.x() : pointInContents.y(), onlyEditableLeaves);
-}
-
-InlineBox* RootInlineBox::closestLeafChildForLogicalLeftPosition(int leftPosition, bool onlyEditableLeaves)
-{
-    InlineBox* firstLeaf = firstLeafDescendant();
-    InlineBox* lastLeaf = lastLeafDescendant();
-
-    if (firstLeaf != lastLeaf) {
-        if (firstLeaf->isLineBreak())
-            firstLeaf = firstLeaf->nextLeafOnLineIgnoringLineBreak();
-        else if (lastLeaf->isLineBreak())
-            lastLeaf = lastLeaf->previousLeafOnLineIgnoringLineBreak();
-    }
-
-    if (firstLeaf == lastLeaf && (!onlyEditableLeaves || isEditableLeaf(firstLeaf)))
-        return firstLeaf;
-
-    // Avoid returning a list marker when possible.
-    if (firstLeaf && leftPosition <= firstLeaf->logicalLeft() && !firstLeaf->renderer().isListMarker() && (!onlyEditableLeaves || isEditableLeaf(firstLeaf)))
-        // The leftPosition coordinate is less or equal to left edge of the firstLeaf.
-        // Return it.
-        return firstLeaf;
-
-    if (lastLeaf && leftPosition >= lastLeaf->logicalRight() && !lastLeaf->renderer().isListMarker() && (!onlyEditableLeaves || isEditableLeaf(lastLeaf)))
-        // The leftPosition coordinate is greater or equal to right edge of the lastLeaf.
-        // Return it.
-        return lastLeaf;
-
-    InlineBox* closestLeaf = nullptr;
-    for (InlineBox* leaf = firstLeaf; leaf; leaf = leaf->nextLeafOnLineIgnoringLineBreak()) {
-        if (!leaf->renderer().isListMarker() && (!onlyEditableLeaves || isEditableLeaf(leaf))) {
-            closestLeaf = leaf;
-            if (leftPosition < leaf->logicalRight())
-                // The x coordinate is less than the right edge of the box.
-                // Return it.
-                return leaf;
-        }
-    }
-
-    return closestLeaf ? closestLeaf : lastLeaf;
-}
-
 BidiStatus RootInlineBox::lineBreakBidiStatus() const
 { 
     return { static_cast<UCharDirection>(m_lineBreakBidiStatusEor), static_cast<UCharDirection>(m_lineBreakBidiStatusLastStrong), static_cast<UCharDirection>(m_lineBreakBidiStatusLast), m_lineBreakContext.copyRef() };

Modified: trunk/Source/WebCore/rendering/RootInlineBox.h (269040 => 269041)


--- trunk/Source/WebCore/rendering/RootInlineBox.h	2020-10-27 15:34:01 UTC (rev 269040)
+++ trunk/Source/WebCore/rendering/RootInlineBox.h	2020-10-27 15:57:15 UTC (rev 269041)
@@ -136,9 +136,6 @@
 
     IntRect computeCaretRect(float logicalLeftPosition, unsigned caretWidth, LayoutUnit* extraWidthToEndOfLine) const;
 
-    InlineBox* closestLeafChildForPoint(const IntPoint&, bool onlyEditableLeaves);
-    InlineBox* closestLeafChildForLogicalLeftPosition(int, bool _onlyEditableLeaves_ = false);
-
     using CleanLineFloatList = Vector<WeakPtr<RenderBox>>;
     void appendFloat(RenderBox& floatingBox)
     {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to