Title: [282661] trunk/Source/WebCore
Revision
282661
Author
[email protected]
Date
2021-09-17 08:01:00 -0700 (Fri, 17 Sep 2021)

Log Message

[LFC][Integration] Add some useful functions to iterators
https://bugs.webkit.org/show_bug.cgi?id=230398

Reviewed by Alan Bujtas.

For future use.

* layout/integration/LayoutIntegrationLineIterator.cpp:
(WebCore::LayoutIntegration::LineIterator::closestRunForLogicalLeftPosition):
(WebCore::LayoutIntegration::PathLine::selectionTopAdjustedForPrecedingBlock const):
(WebCore::LayoutIntegration::PathLine::selectionHeightAdjustedForPrecedingBlock const):
(WebCore::LayoutIntegration::PathLine::firstSelectedBox const):
(WebCore::LayoutIntegration::PathLine::lastSelectedBox const):
* layout/integration/LayoutIntegrationLineIterator.h:
(WebCore::LayoutIntegration::PathLine::contentLogicalWidth const):
* layout/integration/LayoutIntegrationLineIteratorModernPath.h:
* layout/integration/LayoutIntegrationRunIterator.h:
(WebCore::LayoutIntegration::PathTextRun::legacyInlineBox const):
(WebCore::LayoutIntegration::PathRun::legacyInlineBox const):
(WebCore::LayoutIntegration::PathRun::inlineBox const):
(WebCore::LayoutIntegration::PathTextRun::createTextRun const):
* layout/integration/LayoutIntegrationRunIteratorLegacyPath.h:
(WebCore::LayoutIntegration::RunIteratorLegacyPath::createTextRun const):
* layout/integration/LayoutIntegrationRunIteratorModernPath.h:
(WebCore::LayoutIntegration::RunIteratorModernPath::createTextRun const):
(WebCore::LayoutIntegration::RunIteratorModernPath::run const):
(WebCore::LayoutIntegration::RunIteratorModernPath::runs const):
(WebCore::LayoutIntegration::RunIteratorModernPath::legacyInlineBox const): Deleted.
* rendering/LegacyInlineTextBox.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (282660 => 282661)


--- trunk/Source/WebCore/ChangeLog	2021-09-17 13:41:07 UTC (rev 282660)
+++ trunk/Source/WebCore/ChangeLog	2021-09-17 15:01:00 UTC (rev 282661)
@@ -1,5 +1,37 @@
 2021-09-17  Antti Koivisto  <[email protected]>
 
+        [LFC][Integration] Add some useful functions to iterators
+        https://bugs.webkit.org/show_bug.cgi?id=230398
+
+        Reviewed by Alan Bujtas.
+
+        For future use.
+
+        * layout/integration/LayoutIntegrationLineIterator.cpp:
+        (WebCore::LayoutIntegration::LineIterator::closestRunForLogicalLeftPosition):
+        (WebCore::LayoutIntegration::PathLine::selectionTopAdjustedForPrecedingBlock const):
+        (WebCore::LayoutIntegration::PathLine::selectionHeightAdjustedForPrecedingBlock const):
+        (WebCore::LayoutIntegration::PathLine::firstSelectedBox const):
+        (WebCore::LayoutIntegration::PathLine::lastSelectedBox const):
+        * layout/integration/LayoutIntegrationLineIterator.h:
+        (WebCore::LayoutIntegration::PathLine::contentLogicalWidth const):
+        * layout/integration/LayoutIntegrationLineIteratorModernPath.h:
+        * layout/integration/LayoutIntegrationRunIterator.h:
+        (WebCore::LayoutIntegration::PathTextRun::legacyInlineBox const):
+        (WebCore::LayoutIntegration::PathRun::legacyInlineBox const):
+        (WebCore::LayoutIntegration::PathRun::inlineBox const):
+        (WebCore::LayoutIntegration::PathTextRun::createTextRun const):
+        * layout/integration/LayoutIntegrationRunIteratorLegacyPath.h:
+        (WebCore::LayoutIntegration::RunIteratorLegacyPath::createTextRun const):
+        * layout/integration/LayoutIntegrationRunIteratorModernPath.h:
+        (WebCore::LayoutIntegration::RunIteratorModernPath::createTextRun const):
+        (WebCore::LayoutIntegration::RunIteratorModernPath::run const):
+        (WebCore::LayoutIntegration::RunIteratorModernPath::runs const):
+        (WebCore::LayoutIntegration::RunIteratorModernPath::legacyInlineBox const): Deleted.
+        * rendering/LegacyInlineTextBox.h:
+
+2021-09-17  Antti Koivisto  <[email protected]>
+
         [LFC][Integration] Move non-traversal functions from iterator to the dereferenced type
         https://bugs.webkit.org/show_bug.cgi?id=230396
 

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.cpp (282660 => 282661)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.cpp	2021-09-17 13:41:07 UTC (rev 282660)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.cpp	2021-09-17 15:01:00 UTC (rev 282661)
@@ -154,8 +154,7 @@
 
 RunIterator PathLine::closestRunForLogicalLeftPosition(int leftPosition, bool editableOnly) const
 {
-    auto isEditable = [&](auto run)
-    {
+    auto isEditable = [&](auto run) {
         return run && run->renderer().node() && run->renderer().node()->hasEditableStyle();
     };
 
@@ -195,6 +194,16 @@
     return !containingBlock().style().isFlippedBlocksWritingMode() ? std::max(top(), selectionTop()) : std::min(bottom(), selectionBottom());
 }
 
+LayoutUnit PathLine::selectionTopAdjustedForPrecedingBlock() const
+{
+    return containingBlock().adjustSelectionTopForPrecedingBlock(selectionTop());
+}
+
+LayoutUnit PathLine::selectionHeightAdjustedForPrecedingBlock() const
+{
+    return std::max<LayoutUnit>(0, selectionBottom() - selectionTopAdjustedForPrecedingBlock());
+}
+
 RenderObject::HighlightState PathLine::selectionState() const
 {
     auto& block = containingBlock();
@@ -220,6 +229,24 @@
     return state;
 }
 
+RunIterator PathLine::firstSelectedBox() const
+{
+    for (auto box = firstRun(); box; box.traverseNextOnLine()) {
+        if (box->selectionState() != RenderObject::HighlightState::None)
+            return box;
+    }
+    return { };
 }
+
+RunIterator PathLine::lastSelectedBox() const
+{
+    for (auto box = lastRun(); box; box.traversePreviousOnLine()) {
+        if (box->selectionState() != RenderObject::HighlightState::None)
+            return box;
+    }
+    return { };
 }
 
+}
+}
+

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.h (282660 => 282661)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.h	2021-09-17 13:41:07 UTC (rev 282660)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.h	2021-09-17 15:01:00 UTC (rev 282661)
@@ -57,6 +57,8 @@
     LayoutUnit selectionTopForHitTesting() const;
     LayoutUnit selectionBottom() const;
     LayoutUnit selectionHeight() const;
+    LayoutUnit selectionTopAdjustedForPrecedingBlock() const;
+    LayoutUnit selectionHeightAdjustedForPrecedingBlock() const;
     LayoutUnit lineBoxTop() const;
     LayoutUnit lineBoxBottom() const;
 
@@ -66,6 +68,7 @@
     float y() const;
     float contentLogicalLeft() const;
     float contentLogicalRight() const;
+    float contentLogicalWidth() const;
     float logicalHeight() const;
 
     int blockDirectionPointInLine() const;
@@ -92,6 +95,9 @@
     RunIterator logicalEndRun() const;
     RunIterator logicalStartRunWithNode() const;
     RunIterator logicalEndRunWithNode() const;
+    
+    RunIterator firstSelectedBox() const;
+    RunIterator lastSelectedBox() const;
 
 private:
     friend class LineIterator;
@@ -217,6 +223,11 @@
     });
 }
 
+inline float PathLine::contentLogicalWidth() const
+{
+    return contentLogicalRight() - contentLogicalLeft();
+}
+
 inline float PathLine::logicalHeight() const
 {
     return WTF::switchOn(m_pathVariant, [](const auto& path) {

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIteratorModernPath.h (282660 => 282661)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIteratorModernPath.h	2021-09-17 13:41:07 UTC (rev 282660)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIteratorModernPath.h	2021-09-17 15:01:00 UTC (rev 282661)
@@ -60,6 +60,7 @@
     // - the "before" value is already factored in to the line offset
     // - this logic negates the first line's natural offset (e.g. block has no border/padding but the first line has a computed offset).
     LayoutUnit selectionTopForHitTesting() const { return !m_lineIndex ? containingBlock().borderAndPaddingBefore() : selectionTop(); };
+    // FIXME: Implement or replace.
     LayoutUnit selectionBottom() const { return bottom(); }
 
     float contentLogicalLeft() const { return line().lineBoxLeft() + line().contentLeft(); }

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIterator.h (282660 => 282661)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIterator.h	2021-09-17 13:41:07 UTC (rev 282660)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIterator.h	2021-09-17 15:01:00 UTC (rev 282661)
@@ -86,8 +86,10 @@
     const RenderStyle& style() const;
 
     // For intermediate porting steps only.
-    LegacyInlineBox* legacyInlineBox() const;
-
+    const LegacyInlineBox* legacyInlineBox() const;
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+    const Layout::Run* inlineBox() const;
+#endif
     RunIterator nextOnLine() const;
     RunIterator previousOnLine() const;
     RunIterator nextOnLineIgnoringLineBreak() const;
@@ -125,8 +127,10 @@
     TextBoxSelectableRange selectableRange() const;
     LayoutRect selectionRect(unsigned start, unsigned end) const;
 
+    TextRun createTextRun() const;
+
     const RenderText& renderer() const { return downcast<RenderText>(PathRun::renderer()); }
-    LegacyInlineTextBox* legacyInlineBox() const { return downcast<LegacyInlineTextBox>(PathRun::legacyInlineBox()); }
+    const LegacyInlineTextBox* legacyInlineBox() const { return downcast<LegacyInlineTextBox>(PathRun::legacyInlineBox()); }
 
     TextRunIterator nextTextRun() const;
     TextRunIterator nextTextRunInTextOrder() const;
@@ -285,13 +289,22 @@
     });
 }
 
-inline LegacyInlineBox* PathRun::legacyInlineBox() const
+inline const LegacyInlineBox* PathRun::legacyInlineBox() const
 {
-    return WTF::switchOn(m_pathVariant, [](auto& path) {
-        return path.legacyInlineBox();
-    });
+    if (!WTF::holds_alternative<RunIteratorLegacyPath>(m_pathVariant))
+        return nullptr;
+    return WTF::get<RunIteratorLegacyPath>(m_pathVariant).legacyInlineBox();
 }
 
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+inline const Layout::Run* PathRun::inlineBox() const
+{
+    if (!WTF::holds_alternative<RunIteratorModernPath>(m_pathVariant))
+        return nullptr;
+    return &WTF::get<RunIteratorModernPath>(m_pathVariant).run();
+}
+#endif
+
 inline bool PathTextRun::hasHyphen() const
 {
     return WTF::switchOn(m_pathVariant, [](auto& path) {
@@ -360,8 +373,15 @@
     });
 }
 
+inline TextRun PathTextRun::createTextRun() const
+{
+    return WTF::switchOn(m_pathVariant, [&](auto& path) {
+        return path.createTextRun();
+    });
 }
+
 }
+}
 
 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::LayoutIntegration::PathTextRun)
 static bool isType(const WebCore::LayoutIntegration::PathRun& run) { return run.isText(); }

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorLegacyPath.h (282660 => 282661)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorLegacyPath.h	2021-09-17 13:41:07 UTC (rev 282660)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorLegacyPath.h	2021-09-17 15:01:00 UTC (rev 282661)
@@ -78,6 +78,8 @@
     TextBoxSelectableRange selectableRange() const { return inlineTextBox()->selectableRange(); }
     LayoutRect selectionRect(unsigned start, unsigned end) const { return inlineTextBox()->localSelectionRect(start, end); }
 
+    TextRun createTextRun() const { return inlineTextBox()->createTextRun(); }
+
     const RenderObject& renderer() const
     {
         return m_inlineBox->renderer();

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorModernPath.h (282660 => 282661)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorModernPath.h	2021-09-17 13:41:07 UTC (rev 282660)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorModernPath.h	2021-09-17 15:01:00 UTC (rev 282661)
@@ -134,6 +134,11 @@
         return snappedSelectionRect(selectionRect, logicalRight, selectionTop, selectionHeight, isHorizontal());
     }
 
+    TextRun createTextRun() const
+    {
+        return createTextRun(HyphenMode::Include);
+    };
+
     const RenderObject& renderer() const
     {
         return m_inlineContent->rendererForLayoutBox(run().layoutBox());
@@ -197,12 +202,8 @@
     bool operator==(const RunIteratorModernPath& other) const { return m_inlineContent == other.m_inlineContent && m_runIndex == other.m_runIndex; }
 
     bool atEnd() const { return m_runIndex == runs().size(); }
+    const Layout::Run& run() const { return runs()[m_runIndex]; }
 
-    LegacyInlineBox* legacyInlineBox() const
-    {
-        return nullptr;
-    }
-
 private:
     friend class LineIteratorModernPath;
     friend class PathRun;
@@ -224,6 +225,11 @@
         } while (!atEnd() && run().isInlineBox());
     }
 
+    void setAtEnd() { m_runIndex = runs().size(); }
+
+    const InlineContent::Runs& runs() const { return m_inlineContent->runs; }
+    const Line& line() const { return m_inlineContent->lineForRun(run()); }
+
     enum class HyphenMode { Include, Ignore };
     TextRun createTextRun(HyphenMode hyphenMode) const
     {
@@ -244,12 +250,6 @@
         return textRun;
     };
 
-    void setAtEnd() { m_runIndex = runs().size(); }
-
-    const InlineContent::Runs& runs() const { return m_inlineContent->runs; }
-    const Layout::Run& run() const { return runs()[m_runIndex]; }
-    const Line& line() const { return m_inlineContent->lineForRun(run()); }
-
     RefPtr<const InlineContent> m_inlineContent;
     size_t m_runIndex { 0 };
 };

Modified: trunk/Source/WebCore/rendering/LegacyInlineTextBox.h (282660 => 282661)


--- trunk/Source/WebCore/rendering/LegacyInlineTextBox.h	2021-09-17 13:41:07 UTC (rev 282660)
+++ trunk/Source/WebCore/rendering/LegacyInlineTextBox.h	2021-09-17 15:01:00 UTC (rev 282661)
@@ -31,6 +31,10 @@
 
 class RenderCombineText;
 
+namespace LayoutIntegration {
+class RunIteratorLegacyPath;
+}
+
 class LegacyInlineTextBox : public LegacyInlineBox {
     WTF_MAKE_ISO_ALLOCATED(LegacyInlineTextBox);
 public:
@@ -150,6 +154,7 @@
     bool hasMarkers() const;
 
 private:
+    friend class LayoutIntegration::RunIteratorLegacyPath;
     friend class TextBoxPainter;
 
     FloatPoint textOriginFromBoxRect(const FloatRect&) const;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to