Title: [269510] trunk/Source/WebCore
Revision
269510
Author
an...@apple.com
Date
2020-11-06 06:33:10 -0800 (Fri, 06 Nov 2020)

Log Message

[LFC][Integration] localCaretOffset should use iterator
https://bugs.webkit.org/show_bug.cgi?id=218620

Reviewed by Zalan Bujtas.

Convert all localCaretRect implementations to use the inline iterator.

* accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::localCaretRectForCharacterOffset):
* editing/RenderedPosition.cpp:
(WebCore::RenderedPosition::absoluteRect const):
* editing/VisiblePosition.cpp:
(WebCore::VisiblePosition::localCaretRect const):
* layout/integration/LayoutIntegrationLineIterator.cpp:
(WebCore::LayoutIntegration::PathLine::computeCaretRect const):
* layout/integration/LayoutIntegrationLineIterator.h:
(WebCore::LayoutIntegration::PathLine::logicalLeft const):
(WebCore::LayoutIntegration::PathLine::logicalRight const):
* layout/integration/LayoutIntegrationLineIteratorLegacyPath.h:
(WebCore::LayoutIntegration::LineIteratorLegacyPath::logicalLeft const):
(WebCore::LayoutIntegration::LineIteratorLegacyPath::logicalRight const):
* layout/integration/LayoutIntegrationLineIteratorModernPath.h:
(WebCore::LayoutIntegration::LineIteratorModernPath::logicalLeft const):
(WebCore::LayoutIntegration::LineIteratorModernPath::logicalRight const):
* layout/integration/LayoutIntegrationRunIterator.h:
(WebCore::LayoutIntegration::PathTextRun::positionForOffset const):
* layout/integration/LayoutIntegrationRunIteratorLegacyPath.h:
(WebCore::LayoutIntegration::RunIteratorLegacyPath::offsetForPosition const):
(WebCore::LayoutIntegration::RunIteratorLegacyPath::positionForOffset const):
* layout/integration/LayoutIntegrationRunIteratorModernPath.h:
(WebCore::LayoutIntegration::RunIteratorModernPath::positionForOffset const):
(WebCore::LayoutIntegration::RunIteratorModernPath::selectionRect const):
(WebCore::LayoutIntegration::RunIteratorModernPath::clampedOffset const):

Make clampedOffset return 0 based offset like it does in InlineTextBox to make porting easier.

* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::localCaretRect const):
(WebCore::RenderBlock::localCaretRect): Deleted.
* rendering/RenderBlock.h:
* rendering/RenderBox.cpp:
(WebCore::RenderBox::localCaretRect const):
(WebCore::RenderBox::localCaretRect): Deleted.
* rendering/RenderBox.h:
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::localCaretRectForEmptyElement const):
(WebCore::RenderBoxModelObject::localCaretRectForEmptyElement): Deleted.
* rendering/RenderBoxModelObject.h:
* rendering/RenderInline.cpp:
(WebCore::RenderInline::localCaretRect const):
(WebCore::RenderInline::localCaretRect): Deleted.
* rendering/RenderInline.h:
* rendering/RenderLineBreak.cpp:
(WebCore::RenderLineBreak::localCaretRect const):
(WebCore::RenderLineBreak::linesBoundingBox const):
(WebCore::RenderLineBreak::localCaretRect): Deleted.
* rendering/RenderLineBreak.h:
* rendering/RenderObject.cpp:
(WebCore::RenderObject::localCaretRect const):
(WebCore::RenderObject::localCaretRect): Deleted.
* rendering/RenderObject.h:
* rendering/RenderText.cpp:
(WebCore::RenderText::localCaretRect const):
(WebCore::RenderText::localCaretRect): Deleted.
* rendering/RenderText.h:
* rendering/svg/RenderSVGInlineText.cpp:
(WebCore::RenderSVGInlineText::createTextBox):
(WebCore::RenderSVGInlineText::localCaretRect const):
(WebCore::RenderSVGInlineText::localCaretRect): Deleted.
* rendering/svg/RenderSVGInlineText.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (269509 => 269510)


--- trunk/Source/WebCore/ChangeLog	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/ChangeLog	2020-11-06 14:33:10 UTC (rev 269510)
@@ -1,3 +1,76 @@
+2020-11-06  Antti Koivisto  <an...@apple.com>
+
+        [LFC][Integration] localCaretOffset should use iterator
+        https://bugs.webkit.org/show_bug.cgi?id=218620
+
+        Reviewed by Zalan Bujtas.
+
+        Convert all localCaretRect implementations to use the inline iterator.
+
+        * accessibility/AXObjectCache.cpp:
+        (WebCore::AXObjectCache::localCaretRectForCharacterOffset):
+        * editing/RenderedPosition.cpp:
+        (WebCore::RenderedPosition::absoluteRect const):
+        * editing/VisiblePosition.cpp:
+        (WebCore::VisiblePosition::localCaretRect const):
+        * layout/integration/LayoutIntegrationLineIterator.cpp:
+        (WebCore::LayoutIntegration::PathLine::computeCaretRect const):
+        * layout/integration/LayoutIntegrationLineIterator.h:
+        (WebCore::LayoutIntegration::PathLine::logicalLeft const):
+        (WebCore::LayoutIntegration::PathLine::logicalRight const):
+        * layout/integration/LayoutIntegrationLineIteratorLegacyPath.h:
+        (WebCore::LayoutIntegration::LineIteratorLegacyPath::logicalLeft const):
+        (WebCore::LayoutIntegration::LineIteratorLegacyPath::logicalRight const):
+        * layout/integration/LayoutIntegrationLineIteratorModernPath.h:
+        (WebCore::LayoutIntegration::LineIteratorModernPath::logicalLeft const):
+        (WebCore::LayoutIntegration::LineIteratorModernPath::logicalRight const):
+        * layout/integration/LayoutIntegrationRunIterator.h:
+        (WebCore::LayoutIntegration::PathTextRun::positionForOffset const):
+        * layout/integration/LayoutIntegrationRunIteratorLegacyPath.h:
+        (WebCore::LayoutIntegration::RunIteratorLegacyPath::offsetForPosition const):
+        (WebCore::LayoutIntegration::RunIteratorLegacyPath::positionForOffset const):
+        * layout/integration/LayoutIntegrationRunIteratorModernPath.h:
+        (WebCore::LayoutIntegration::RunIteratorModernPath::positionForOffset const):
+        (WebCore::LayoutIntegration::RunIteratorModernPath::selectionRect const):
+        (WebCore::LayoutIntegration::RunIteratorModernPath::clampedOffset const):
+
+        Make clampedOffset return 0 based offset like it does in InlineTextBox to make porting easier.
+
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::localCaretRect const):
+        (WebCore::RenderBlock::localCaretRect): Deleted.
+        * rendering/RenderBlock.h:
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::localCaretRect const):
+        (WebCore::RenderBox::localCaretRect): Deleted.
+        * rendering/RenderBox.h:
+        * rendering/RenderBoxModelObject.cpp:
+        (WebCore::RenderBoxModelObject::localCaretRectForEmptyElement const):
+        (WebCore::RenderBoxModelObject::localCaretRectForEmptyElement): Deleted.
+        * rendering/RenderBoxModelObject.h:
+        * rendering/RenderInline.cpp:
+        (WebCore::RenderInline::localCaretRect const):
+        (WebCore::RenderInline::localCaretRect): Deleted.
+        * rendering/RenderInline.h:
+        * rendering/RenderLineBreak.cpp:
+        (WebCore::RenderLineBreak::localCaretRect const):
+        (WebCore::RenderLineBreak::linesBoundingBox const):
+        (WebCore::RenderLineBreak::localCaretRect): Deleted.
+        * rendering/RenderLineBreak.h:
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::localCaretRect const):
+        (WebCore::RenderObject::localCaretRect): Deleted.
+        * rendering/RenderObject.h:
+        * rendering/RenderText.cpp:
+        (WebCore::RenderText::localCaretRect const):
+        (WebCore::RenderText::localCaretRect): Deleted.
+        * rendering/RenderText.h:
+        * rendering/svg/RenderSVGInlineText.cpp:
+        (WebCore::RenderSVGInlineText::createTextBox):
+        (WebCore::RenderSVGInlineText::localCaretRect const):
+        (WebCore::RenderSVGInlineText::localCaretRect): Deleted.
+        * rendering/svg/RenderSVGInlineText.h:
+
 2020-11-06  Oriol Brufau  <obru...@igalia.com>
 
         [css-grid] Prevent FindUsedFlexFraction from iterating items twice

Modified: trunk/Source/WebCore/accessibility/AXObjectCache.cpp (269509 => 269510)


--- trunk/Source/WebCore/accessibility/AXObjectCache.cpp	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/accessibility/AXObjectCache.cpp	2020-11-06 14:33:10 UTC (rev 269510)
@@ -84,6 +84,7 @@
 #include "HTMLSelectElement.h"
 #include "HTMLTextFormControlElement.h"
 #include "InlineElementBox.h"
+#include "InlineRunAndOffset.h"
 #include "MathMLElement.h"
 #include "Page.h"
 #include "Range.h"
@@ -2893,14 +2894,14 @@
     if (!range)
         return IntRect();
 
-    auto [inlineBox, caretOffset] = makeContainerOffsetPosition(range->start).inlineBoxAndOffset(Affinity::Downstream);
-    if (inlineBox)
-        renderer = &inlineBox->renderer();
+    auto runAndOffset = makeContainerOffsetPosition(range->start).inlineRunAndOffset(Affinity::Downstream);
+    if (runAndOffset.run)
+        renderer = const_cast<RenderObject*>(&runAndOffset.run->renderer());
 
-    if (is<RenderLineBreak>(renderer) && downcast<RenderLineBreak>(renderer)->inlineBoxWrapper() != inlineBox)
+    if (is<RenderLineBreak>(renderer) && LayoutIntegration::runFor(downcast<RenderLineBreak>(*renderer)) != runAndOffset.run)
         return IntRect();
 
-    return renderer->localCaretRect(inlineBox, caretOffset);
+    return renderer->localCaretRect(runAndOffset);
 }
 
 IntRect AXObjectCache::absoluteCaretBoundsForCharacterOffset(const CharacterOffset& characterOffset)

Modified: trunk/Source/WebCore/editing/RenderedPosition.cpp (269509 => 269510)


--- trunk/Source/WebCore/editing/RenderedPosition.cpp	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/editing/RenderedPosition.cpp	2020-11-06 14:33:10 UTC (rev 269510)
@@ -229,7 +229,7 @@
     if (isNull())
         return IntRect();
 
-    IntRect localRect = snappedIntRect(const_cast<RenderObject*>(m_renderer)->localCaretRect(m_run->legacyInlineBox(), m_offset, extraWidthToEndOfLine));
+    IntRect localRect = snappedIntRect(const_cast<RenderObject*>(m_renderer)->localCaretRect({ m_run, m_offset }, extraWidthToEndOfLine));
     return localRect == IntRect() ? IntRect() : m_renderer->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoundingBox();
 }
 

Modified: trunk/Source/WebCore/editing/VisiblePosition.cpp (269509 => 269510)


--- trunk/Source/WebCore/editing/VisiblePosition.cpp	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/editing/VisiblePosition.cpp	2020-11-06 14:33:10 UTC (rev 269510)
@@ -639,12 +639,12 @@
     if (!node)
         return { };
 
-    auto [inlineBox, caretOffset] = inlineBoxAndOffset();
-    auto renderer = inlineBox ? &inlineBox->renderer() : node->renderer();
+    auto runAndOffset = inlineRunAndOffset();
+    auto renderer = runAndOffset.run ? &runAndOffset.run->renderer() : node->renderer();
     if (!renderer)
         return { };
 
-    return { renderer->localCaretRect(inlineBox, caretOffset), renderer };
+    return { renderer->localCaretRect(runAndOffset), const_cast<RenderObject*>(renderer) };
 }
 
 IntRect VisiblePosition::absoluteCaretBounds(bool* insideFixed) const

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.cpp (269509 => 269510)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.cpp	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.cpp	2020-11-06 14:33:10 UTC (rev 269510)
@@ -179,6 +179,59 @@
     return !containingBlock().style().isFlippedBlocksWritingMode() ? std::max(top(), selectionTop()) : std::min(bottom(), selectionBottom());
 }
 
+IntRect PathLine::computeCaretRect(float logicalLeftPosition, unsigned caretWidth, LayoutUnit* extraWidthToEndOfLine) const
+{
+    int height = selectionBottom() - selectionTop();
+    int top = selectionTop();
+
+    // Distribute the caret's width to either side of the offset.
+    float left = logicalLeftPosition;
+    int caretWidthLeftOfOffset = caretWidth / 2;
+    left -= caretWidthLeftOfOffset;
+    int caretWidthRightOfOffset = caretWidth - caretWidthLeftOfOffset;
+    left = roundf(left);
+
+    float lineLeft = logicalLeft();
+    float lineRight = logicalRight();
+
+    if (extraWidthToEndOfLine)
+        *extraWidthToEndOfLine = lineRight - (left + caretWidth);
+
+    const RenderStyle& blockStyle = containingBlock().style();
+
+    bool rightAligned = false;
+    switch (blockStyle.textAlign()) {
+    case TextAlignMode::Right:
+    case TextAlignMode::WebKitRight:
+        rightAligned = true;
+        break;
+    case TextAlignMode::Left:
+    case TextAlignMode::WebKitLeft:
+    case TextAlignMode::Center:
+    case TextAlignMode::WebKitCenter:
+        break;
+    case TextAlignMode::Justify:
+    case TextAlignMode::Start:
+        rightAligned = !blockStyle.isLeftToRightDirection();
+        break;
+    case TextAlignMode::End:
+        rightAligned = blockStyle.isLeftToRightDirection();
+        break;
+    }
+
+    float leftEdge = std::min<float>(0, lineLeft);
+    float rightEdge = std::max<float>(containingBlock().logicalWidth(), lineRight);
+
+    if (rightAligned) {
+        left = std::max(left, leftEdge);
+        left = std::min(left, lineRight - caretWidth);
+    } else {
+        left = std::min(left, rightEdge - caretWidthRightOfOffset);
+        left = std::max(left, lineLeft);
+    }
+    return blockStyle.isHorizontalWritingMode() ? IntRect(left, top, caretWidth, height) : IntRect(top, left, height, caretWidth);
 }
+
 }
+}
 

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.h (269509 => 269510)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.h	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.h	2020-11-06 14:33:10 UTC (rev 269510)
@@ -59,9 +59,12 @@
     LayoutUnit lineBoxBottom() const;
 
     float y() const;
+    float logicalLeft() const;
+    float logicalRight() const;
     float logicalHeight() const;
 
     int blockDirectionPointInLine() const;
+    IntRect computeCaretRect(float logicalLeftPosition, unsigned caretWidth, LayoutUnit* extraWidthToEndOfLine) const;
 
     bool isHorizontal() const;
 
@@ -177,6 +180,20 @@
     });
 }
 
+inline float PathLine::logicalLeft() const
+{
+    return WTF::switchOn(m_pathVariant, [](const auto& path) {
+        return path.logicalLeft();
+    });
+}
+
+inline float PathLine::logicalRight() const
+{
+    return WTF::switchOn(m_pathVariant, [](const auto& path) {
+        return path.logicalRight();
+    });
+}
+
 inline float PathLine::logicalHeight() const
 {
     return WTF::switchOn(m_pathVariant, [](const auto& path) {

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIteratorLegacyPath.h (269509 => 269510)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIteratorLegacyPath.h	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIteratorLegacyPath.h	2020-11-06 14:33:10 UTC (rev 269510)
@@ -53,6 +53,8 @@
     LayoutUnit lineBoxBottom() const { return m_rootInlineBox->lineBoxBottom(); }
 
     float y() const { return m_rootInlineBox->y(); }
+    float logicalLeft() const { return m_rootInlineBox->logicalLeft(); }
+    float logicalRight() const { return m_rootInlineBox->logicalRight(); }
     float logicalHeight() const { return m_rootInlineBox->logicalHeight(); }
     bool isHorizontal() const { return m_rootInlineBox->isHorizontal(); }
 

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIteratorModernPath.h (269509 => 269510)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIteratorModernPath.h	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIteratorModernPath.h	2020-11-06 14:33:10 UTC (rev 269510)
@@ -51,13 +51,17 @@
 
     LayoutUnit top() const { return LayoutUnit::fromFloatRound(line().enclosingRect().y()); }
     LayoutUnit bottom() const { return LayoutUnit::fromFloatRound(line().enclosingRect().maxY()); }
+    LayoutUnit lineBoxTop() const { return LayoutUnit::fromFloatRound(line().rect().y()); }
+    LayoutUnit lineBoxBottom() const { return LayoutUnit::fromFloatRound(line().rect().maxY()); }
+
     // FIXME: What should these really be?
     LayoutUnit selectionTop() const { return top(); }
     LayoutUnit selectionTopForHitTesting() const { return top(); }
     LayoutUnit selectionBottom() const { return bottom(); }
-    LayoutUnit lineBoxTop() const { return LayoutUnit::fromFloatRound(line().rect().y()); }
-    LayoutUnit lineBoxBottom() const { return LayoutUnit::fromFloatRound(line().rect().maxY()); }
 
+    // FIXME: What should these be?
+    float logicalLeft() const { return line().scrollableOverflow().x(); }
+    float logicalRight() const { return line().scrollableOverflow().maxX(); }
     float y() const { return lineBoxTop(); }
     float logicalHeight() const { return line().rect().height(); }
     bool isHorizontal() const { return true; }

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIterator.h (269509 => 269510)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIterator.h	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIterator.h	2020-11-06 14:33:10 UTC (rev 269510)
@@ -108,6 +108,7 @@
     unsigned length() const;
 
     unsigned offsetForPosition(float x) const;
+    float positionForOffset(unsigned) const;
 
     bool isSelectable(unsigned start, unsigned end) const;
     LayoutRect selectionRect(unsigned start, unsigned end) const;
@@ -328,6 +329,13 @@
     });
 }
 
+inline float PathTextRun::positionForOffset(unsigned offset) const
+{
+    return WTF::switchOn(m_pathVariant, [&](auto& path) {
+        return path.positionForOffset(offset);
+    });
+}
+
 inline bool PathTextRun::isSelectable(unsigned start, unsigned end) const
 {
     return WTF::switchOn(m_pathVariant, [&](auto& path) {

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorLegacyPath.h (269509 => 269510)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorLegacyPath.h	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorLegacyPath.h	2020-11-06 14:33:10 UTC (rev 269510)
@@ -59,7 +59,8 @@
     unsigned end() const { return inlineTextBox()->end(); }
     unsigned length() const { return inlineTextBox()->len(); }
 
-    inline unsigned offsetForPosition(float x) const { return inlineTextBox()->offsetForPosition(x); }
+    unsigned offsetForPosition(float x) const { return inlineTextBox()->offsetForPosition(x); }
+    float positionForOffset(unsigned offset) const { return inlineTextBox()->positionForOffset(offset); }
 
     bool isSelectable(unsigned start, unsigned end) const { return inlineTextBox()->isSelected(start, end); }
     LayoutRect selectionRect(unsigned start, unsigned end) const { return inlineTextBox()->localSelectionRect(start, end); }

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorModernPath.h (269509 => 269510)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorModernPath.h	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorModernPath.h	2020-11-06 14:33:10 UTC (rev 269510)
@@ -66,6 +66,7 @@
     unsigned end() const { return run().textContent()->end(); }
     unsigned length() const { return run().textContent()->length(); }
 
+    // FIXME: Make a shared generic version of this.
     inline unsigned offsetForPosition(float x) const
     {
         if (isLineBreak())
@@ -81,6 +82,23 @@
         return run().style().fontCascade().offsetForPosition(createTextRun(HyphenMode::Ignore), localX, includePartialGlyphs);
     }
 
+    // FIXME: Make a shared generic version of this.
+    float positionForOffset(unsigned offset) const
+    {
+        ASSERT(offset >= start());
+        ASSERT(offset <= end());
+
+        if (isLineBreak())
+            return rect().x();
+
+        auto endOffset = clampedOffset(offset);
+
+        LayoutRect selectionRect = LayoutRect(rect().x(), 0, 0, 0);
+        TextRun textRun = createTextRun(HyphenMode::Ignore);
+        run().style().fontCascade().adjustSelectionRectForText(textRun, selectionRect, 0, endOffset);
+        return snapRectToDevicePixelsWithWritingDirection(selectionRect, renderer().document().deviceScaleFactor(), textRun.ltr()).maxX();
+    }
+
     bool isSelectable(unsigned start, unsigned end) const
     {
         return clampedOffset(start) < clampedOffset(end);
@@ -105,8 +123,8 @@
         LayoutRect selectionRect { logicalLeft, selectionTop, logicalWidth, selectionHeight };
 
         TextRun textRun = createTextRun(HyphenMode::Include);
-        if (clampedStart != start() || clampedEnd != textRun.length())
-            run().style().fontCascade().adjustSelectionRectForText(textRun, selectionRect, clampedStart - start(), clampedEnd - start());
+        if (clampedStart || clampedEnd != textRun.length())
+            run().style().fontCascade().adjustSelectionRectForText(textRun, selectionRect, clampedStart, clampedEnd);
 
         return snappedSelectionRect(selectionRect, logicalRight, selectionTop, selectionHeight, isHorizontal());
     }
@@ -198,9 +216,9 @@
 
     unsigned clampedOffset(unsigned offset) const
     {
-        auto clampedOffset = std::max(start(), std::min(offset, end()));
+        auto clampedOffset = std::max(start(), std::min(offset, end())) - start();
         // We treat the last codepoint in this run and the hyphen as a single unit.
-        if (hasHyphen() && clampedOffset == end())
+        if (hasHyphen() && clampedOffset == length())
             clampedOffset += run().style().hyphenString().length();
 
         return clampedOffset;

Modified: trunk/Source/WebCore/rendering/RenderBlock.cpp (269509 => 269510)


--- trunk/Source/WebCore/rendering/RenderBlock.cpp	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/rendering/RenderBlock.cpp	2020-11-06 14:33:10 UTC (rev 269510)
@@ -2841,11 +2841,11 @@
     }
 }
 
-LayoutRect RenderBlock::localCaretRect(InlineBox* inlineBox, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine)
+LayoutRect RenderBlock::localCaretRect(const InlineRunAndOffset& runAndOffset, LayoutUnit* extraWidthToEndOfLine) const
 {
     // Do the normal calculation in most cases.
     if (firstChild())
-        return RenderBox::localCaretRect(inlineBox, caretOffset, extraWidthToEndOfLine);
+        return RenderBox::localCaretRect(runAndOffset, extraWidthToEndOfLine);
 
     LayoutRect caretRect = localCaretRectForEmptyElement(width(), textIndentOffset());
 

Modified: trunk/Source/WebCore/rendering/RenderBlock.h (269509 => 269510)


--- trunk/Source/WebCore/rendering/RenderBlock.h	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/rendering/RenderBlock.h	2020-11-06 14:33:10 UTC (rev 269510)
@@ -484,7 +484,7 @@
 
     void paintContinuationOutlines(PaintInfo&, const LayoutPoint&);
 
-    LayoutRect localCaretRect(InlineBox*, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) final;
+    LayoutRect localCaretRect(const InlineRunAndOffset&, LayoutUnit* extraWidthToEndOfLine = nullptr) const final;
     
     // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
     virtual VisiblePosition positionForPointWithInlineChildren(const LayoutPoint&, const RenderFragmentContainer*);

Modified: trunk/Source/WebCore/rendering/RenderBox.cpp (269509 => 269510)


--- trunk/Source/WebCore/rendering/RenderBox.cpp	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/rendering/RenderBox.cpp	2020-11-06 14:33:10 UTC (rev 269510)
@@ -47,6 +47,7 @@
 #include "HTMLTextAreaElement.h"
 #include "HitTestResult.h"
 #include "InlineElementBox.h"
+#include "InlineRunAndOffset.h"
 #include "LayoutIntegrationLineLayout.h"
 #include "Page.h"
 #include "PaintInfo.h"
@@ -4429,7 +4430,7 @@
     computedValues.m_position = logicalTopPos;
 }
 
-LayoutRect RenderBox::localCaretRect(InlineBox* box, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine)
+LayoutRect RenderBox::localCaretRect(const InlineRunAndOffset& runAndOffset, LayoutUnit* extraWidthToEndOfLine) const
 {
     // VisiblePositions at offsets inside containers either a) refer to the positions before/after
     // those containers (tables and select elements) or b) refer to the position inside an empty block.
@@ -4437,16 +4438,16 @@
     // FIXME: Paint the carets inside empty blocks differently than the carets before/after elements.
 
     LayoutRect rect(location(), LayoutSize(caretWidth, height()));
-    bool ltr = box ? box->isLeftToRightDirection() : style().isLeftToRightDirection();
+    bool ltr = runAndOffset.run ? runAndOffset.run->isLeftToRightDirection() : style().isLeftToRightDirection();
 
-    if ((!caretOffset) ^ ltr)
+    if ((!runAndOffset.offset) ^ ltr)
         rect.move(LayoutSize(width() - caretWidth, 0_lu));
 
-    if (box) {
-        const RootInlineBox& rootBox = box->root();
-        LayoutUnit top = rootBox.lineTop();
+    if (runAndOffset.run) {
+        auto line = runAndOffset.run.line();
+        LayoutUnit top = line->top();
         rect.setY(top);
-        rect.setHeight(rootBox.lineBottom() - top);
+        rect.setHeight(line->bottom() - top);
     }
 
     // If height of box is smaller than font height, use the latter one,

Modified: trunk/Source/WebCore/rendering/RenderBox.h (269509 => 269510)


--- trunk/Source/WebCore/rendering/RenderBox.h	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/rendering/RenderBox.h	2020-11-06 14:33:10 UTC (rev 269510)
@@ -498,7 +498,7 @@
 
     bool shouldTreatChildAsReplacedInTableCells() const;
     
-    LayoutRect localCaretRect(InlineBox*, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine = nullptr) override;
+    LayoutRect localCaretRect(const InlineRunAndOffset&, LayoutUnit* extraWidthToEndOfLine = nullptr) const override;
 
     virtual LayoutRect overflowClipRect(const LayoutPoint& location, RenderFragmentContainer* = nullptr, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize, PaintPhase = PaintPhase::BlockBackground) const;
     virtual LayoutRect overflowClipRectForChildLayers(const LayoutPoint& location, RenderFragmentContainer* fragment, OverlayScrollbarSizeRelevancy relevancy) const { return overflowClipRect(location, fragment, relevancy); }

Modified: trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp (269509 => 269510)


--- trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp	2020-11-06 14:33:10 UTC (rev 269510)
@@ -2626,7 +2626,7 @@
     firstLetterRemainingTextMap().remove(this);
 }
 
-LayoutRect RenderBoxModelObject::localCaretRectForEmptyElement(LayoutUnit width, LayoutUnit textIndentOffset)
+LayoutRect RenderBoxModelObject::localCaretRectForEmptyElement(LayoutUnit width, LayoutUnit textIndentOffset) const
 {
     ASSERT(!firstChild());
 

Modified: trunk/Source/WebCore/rendering/RenderBoxModelObject.h (269509 => 269510)


--- trunk/Source/WebCore/rendering/RenderBoxModelObject.h	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/rendering/RenderBoxModelObject.h	2020-11-06 14:33:10 UTC (rev 269510)
@@ -260,7 +260,7 @@
 
     InterpolationQuality chooseInterpolationQuality(GraphicsContext&, Image&, const void*, const LayoutSize&);
 
-    LayoutRect localCaretRectForEmptyElement(LayoutUnit width, LayoutUnit textIndentOffset);
+    LayoutRect localCaretRectForEmptyElement(LayoutUnit width, LayoutUnit textIndentOffset) const;
 
     static bool shouldAntialiasLines(GraphicsContext&);
 

Modified: trunk/Source/WebCore/rendering/RenderInline.cpp (269509 => 269510)


--- trunk/Source/WebCore/rendering/RenderInline.cpp	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/rendering/RenderInline.cpp	2020-11-06 14:33:10 UTC (rev 269510)
@@ -228,7 +228,7 @@
     }
 }
 
-LayoutRect RenderInline::localCaretRect(InlineBox* inlineBox, unsigned, LayoutUnit* extraWidthToEndOfLine)
+LayoutRect RenderInline::localCaretRect(const InlineRunAndOffset&, LayoutUnit* extraWidthToEndOfLine) const
 {
     if (firstChild()) {
         // This condition is possible if the RenderInline is at an editing boundary,
@@ -239,8 +239,6 @@
         return LayoutRect();
     }
 
-    ASSERT_UNUSED(inlineBox, !inlineBox);
-
     if (extraWidthToEndOfLine)
         *extraWidthToEndOfLine = 0;
 

Modified: trunk/Source/WebCore/rendering/RenderInline.h (269509 => 269510)


--- trunk/Source/WebCore/rendering/RenderInline.h	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/rendering/RenderInline.h	2020-11-06 14:33:10 UTC (rev 269510)
@@ -86,7 +86,7 @@
     void setAlwaysCreateLineBoxes() { setRenderInlineAlwaysCreatesLineBoxes(true); }
     void updateAlwaysCreateLineBoxes(bool fullLayout);
 
-    LayoutRect localCaretRect(InlineBox*, unsigned, LayoutUnit* extraWidthToEndOfLine) final;
+    LayoutRect localCaretRect(const InlineRunAndOffset&, LayoutUnit* extraWidthToEndOfLine) const final;
 
     bool hitTestCulledInline(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset);
 

Modified: trunk/Source/WebCore/rendering/RenderLineBreak.cpp (269509 => 269510)


--- trunk/Source/WebCore/rendering/RenderLineBreak.cpp	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/rendering/RenderLineBreak.cpp	2020-11-06 14:33:10 UTC (rev 269510)
@@ -27,6 +27,8 @@
 #include "HTMLElement.h"
 #include "HTMLWBRElement.h"
 #include "InlineElementBox.h"
+#include "InlineRunAndOffset.h"
+#include "LayoutIntegrationLineIterator.h"
 #include "LayoutIntegrationRunIterator.h"
 #include "LogicalSelectionOffsetCaches.h"
 #include "RenderBlock.h"
@@ -156,24 +158,25 @@
     m_inlineBoxWrapper->root().setHasSelectedChildren(state != HighlightState::None);
 }
 
-LayoutRect RenderLineBreak::localCaretRect(InlineBox* inlineBox, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine)
+LayoutRect RenderLineBreak::localCaretRect(const InlineRunAndOffset& runAndOffset, LayoutUnit* extraWidthToEndOfLine) const
 {
-    ASSERT_UNUSED(caretOffset, !caretOffset);
-    ASSERT_UNUSED(inlineBox, inlineBox == m_inlineBoxWrapper);
-    if (!inlineBox)
+    ASSERT(!runAndOffset.offset);
+    ASSERT(runAndOffset.run == LayoutIntegration::runFor(*this));
+
+    if (!runAndOffset.run)
         return LayoutRect();
 
-    const RootInlineBox& rootBox = inlineBox->root();
-    return rootBox.computeCaretRect(inlineBox->logicalLeft(), caretWidth, extraWidthToEndOfLine);
+    auto line = runAndOffset.run.line();
+    return line->computeCaretRect(line->logicalLeft(), caretWidth, extraWidthToEndOfLine);
 }
 
 IntRect RenderLineBreak::linesBoundingBox() const
 {
-    auto box = LayoutIntegration::runFor(*this);
-    if (!box)
+    auto run = LayoutIntegration::runFor(*this);
+    if (!run)
         return { };
 
-    return enclosingIntRect(box->rect());
+    return enclosingIntRect(run->rect());
 }
 
 void RenderLineBreak::absoluteRects(Vector<IntRect>& rects, const LayoutPoint& accumulatedOffset) const
@@ -209,7 +212,9 @@
     if (!box)
         return;
     const RootInlineBox& rootBox = box->root();
-    LayoutRect rect = rootBox.computeCaretRect(box->logicalLeft(), 0, nullptr);
+
+    LayoutRect rect = LayoutIntegration::LineIterator(&rootBox)->computeCaretRect(box->logicalLeft(), 0, nullptr);
+
     if (rootBox.isFirstAfterPageBreak()) {
         if (box->isHorizontal())
             rect.shiftYEdgeTo(rootBox.lineBoxTop());

Modified: trunk/Source/WebCore/rendering/RenderLineBreak.h (269509 => 269510)


--- trunk/Source/WebCore/rendering/RenderLineBreak.h	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/rendering/RenderLineBreak.h	2020-11-06 14:33:10 UTC (rev 269510)
@@ -66,7 +66,7 @@
     int caretMinOffset() const final;
     int caretMaxOffset() const final;
     bool canBeSelectionLeaf() const final;
-    LayoutRect localCaretRect(InlineBox*, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine) final;
+    LayoutRect localCaretRect(const InlineRunAndOffset&, LayoutUnit* extraWidthToEndOfLine) const final;
     void setSelectionState(HighlightState) final;
 
     LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode) const final;

Modified: trunk/Source/WebCore/rendering/RenderObject.cpp (269509 => 269510)


--- trunk/Source/WebCore/rendering/RenderObject.cpp	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/rendering/RenderObject.cpp	2020-11-06 14:33:10 UTC (rev 269510)
@@ -1400,7 +1400,7 @@
     return offset;
 }
 
-LayoutRect RenderObject::localCaretRect(InlineBox*, unsigned, LayoutUnit* extraWidthToEndOfLine)
+LayoutRect RenderObject::localCaretRect(const InlineRunAndOffset&, LayoutUnit* extraWidthToEndOfLine) const
 {
     if (extraWidthToEndOfLine)
         *extraWidthToEndOfLine = 0;

Modified: trunk/Source/WebCore/rendering/RenderObject.h (269509 => 269510)


--- trunk/Source/WebCore/rendering/RenderObject.h	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/rendering/RenderObject.h	2020-11-06 14:33:10 UTC (rev 269510)
@@ -75,6 +75,7 @@
 class SelectionRect;
 #endif
 
+struct InlineRunAndOffset;
 struct PaintInfo;
 struct SimpleRange;
 
@@ -672,13 +673,8 @@
     // Whether or not a given block needs to paint selection gaps.
     virtual bool shouldPaintSelectionGaps() const { return false; }
 
-    /**
-     * Returns the local coordinates of the caret within this render object.
-     * @param caretOffset zero-based offset determining position within the render object.
-     * @param extraWidthToEndOfLine optional out arg to give extra width to end of line -
-     * useful for character range rect computations
-     */
-    virtual LayoutRect localCaretRect(InlineBox*, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine = nullptr);
+    // Returns the local coordinates of the caret within this render object.
+    virtual LayoutRect localCaretRect(const InlineRunAndOffset&, LayoutUnit* extraWidthToEndOfLine = nullptr) const;
 
     // When performing a global document tear-down, or when going into the back/forward cache, the renderer of the document is cleared.
     bool renderTreeBeingDestroyed() const;

Modified: trunk/Source/WebCore/rendering/RenderText.cpp (269509 => 269510)


--- trunk/Source/WebCore/rendering/RenderText.cpp	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/rendering/RenderText.cpp	2020-11-06 14:33:10 UTC (rev 269510)
@@ -36,6 +36,7 @@
 #include "FrameView.h"
 #include "HTMLParserIdioms.h"
 #include "Hyphenation.h"
+#include "InlineRunAndOffset.h"
 #include "InlineTextBox.h"
 #include "LayoutIntegrationLineIterator.h"
 #include "LayoutIntegrationLineLayout.h"
@@ -710,14 +711,15 @@
     return createVisiblePosition(0, Affinity::Downstream);
 }
 
-LayoutRect RenderText::localCaretRect(InlineBox* inlineBox, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine)
+LayoutRect RenderText::localCaretRect(const InlineRunAndOffset& runAndOffset, LayoutUnit* extraWidthToEndOfLine) const
 {
-    if (!inlineBox)
+    if (!runAndOffset.run)
         return LayoutRect();
 
-    auto& box = downcast<InlineTextBox>(*inlineBox);
-    float left = box.positionForOffset(caretOffset);
-    return box.root().computeCaretRect(left, caretWidth, extraWidthToEndOfLine);
+    auto& textRun = downcast<LayoutIntegration::TextRunIterator>(runAndOffset.run);
+
+    float left = textRun->positionForOffset(runAndOffset.offset);
+    return textRun.line()->computeCaretRect(left, caretWidth, extraWidthToEndOfLine);
 }
 
 ALWAYS_INLINE float RenderText::widthFromCache(const FontCascade& f, unsigned start, unsigned len, float xPos, HashSet<const Font*>* fallbackFonts, GlyphOverflow* glyphOverflow, const RenderStyle& style) const

Modified: trunk/Source/WebCore/rendering/RenderText.h (269509 => 269510)


--- trunk/Source/WebCore/rendering/RenderText.h	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/rendering/RenderText.h	2020-11-06 14:33:10 UTC (rev 269510)
@@ -205,7 +205,7 @@
 
     void setSelectionState(HighlightState) final;
     LayoutRect selectionRectForRepaint(const RenderLayerModelObject* repaintContainer, bool clipToVisibleContent = true) final;
-    LayoutRect localCaretRect(InlineBox*, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine = nullptr) override;
+    LayoutRect localCaretRect(const InlineRunAndOffset&, LayoutUnit* extraWidthToEndOfLine = nullptr) const override;
     LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const final;
 
     void computePreferredLogicalWidths(float leadWidth, HashSet<const Font*>& fallbackFonts, GlyphOverflow&);

Modified: trunk/Source/WebCore/rendering/RootInlineBox.cpp (269509 => 269510)


--- trunk/Source/WebCore/rendering/RootInlineBox.cpp	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/rendering/RootInlineBox.cpp	2020-11-06 14:33:10 UTC (rev 269510)
@@ -474,59 +474,6 @@
     return result;
 }
 
-IntRect RootInlineBox::computeCaretRect(float logicalLeftPosition, unsigned caretWidth, LayoutUnit* extraWidthToEndOfLine) const
-{
-    int height = selectionHeight();
-    int top = selectionTop();
-
-    // Distribute the caret's width to either side of the offset.
-    float left = logicalLeftPosition;
-    int caretWidthLeftOfOffset = caretWidth / 2;
-    left -= caretWidthLeftOfOffset;
-    int caretWidthRightOfOffset = caretWidth - caretWidthLeftOfOffset;
-    left = roundf(left);
-
-    float rootLeft = logicalLeft();
-    float rootRight = logicalRight();
-
-    if (extraWidthToEndOfLine)
-        *extraWidthToEndOfLine = (logicalWidth() + rootLeft) - (left + caretWidth);
-
-    const RenderStyle& blockStyle = blockFlow().style();
-
-    bool rightAligned = false;
-    switch (blockStyle.textAlign()) {
-    case TextAlignMode::Right:
-    case TextAlignMode::WebKitRight:
-        rightAligned = true;
-        break;
-    case TextAlignMode::Left:
-    case TextAlignMode::WebKitLeft:
-    case TextAlignMode::Center:
-    case TextAlignMode::WebKitCenter:
-        break;
-    case TextAlignMode::Justify:
-    case TextAlignMode::Start:
-        rightAligned = !blockStyle.isLeftToRightDirection();
-        break;
-    case TextAlignMode::End:
-        rightAligned = blockStyle.isLeftToRightDirection();
-        break;
-    }
-
-    float leftEdge = std::min<float>(0, rootLeft);
-    float rightEdge = std::max<float>(blockFlow().logicalWidth(), rootRight);
-
-    if (rightAligned) {
-        left = std::max(left, leftEdge);
-        left = std::min(left, rootRight - caretWidth);
-    } else {
-        left = std::min(left, rightEdge - caretWidthRightOfOffset);
-        left = std::max(left, rootLeft);
-    }
-    return blockStyle.isHorizontalWritingMode() ? IntRect(left, top, caretWidth, height) : IntRect(top, left, height, caretWidth);
-}
-
 RenderObject::HighlightState RootInlineBox::selectionState()
 {
     // Walk over all of the selected boxes.

Modified: trunk/Source/WebCore/rendering/RootInlineBox.h (269509 => 269510)


--- trunk/Source/WebCore/rendering/RootInlineBox.h	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/rendering/RootInlineBox.h	2020-11-06 14:33:10 UTC (rev 269510)
@@ -132,8 +132,6 @@
     GapRects lineSelectionGap(RenderBlock& rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
         LayoutUnit selTop, LayoutUnit selHeight, const LogicalSelectionOffsetCaches&, const PaintInfo*);
 
-    IntRect computeCaretRect(float logicalLeftPosition, unsigned caretWidth, LayoutUnit* extraWidthToEndOfLine) const;
-
     using CleanLineFloatList = Vector<WeakPtr<RenderBox>>;
     void appendFloat(RenderBox& floatingBox)
     {

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGInlineText.cpp (269509 => 269510)


--- trunk/Source/WebCore/rendering/svg/RenderSVGInlineText.cpp	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGInlineText.cpp	2020-11-06 14:33:10 UTC (rev 269510)
@@ -27,6 +27,7 @@
 #include "CSSFontSelector.h"
 #include "FloatConversion.h"
 #include "FloatQuad.h"
+#include "InlineRunAndOffset.h"
 #include "RenderBlock.h"
 #include "RenderSVGRoot.h"
 #include "RenderSVGText.h"
@@ -115,11 +116,14 @@
 {
     auto box = makeUnique<SVGInlineTextBox>(*this);
     box->setHasVirtualLogicalHeight();
-    return box;
+    return box; 
 }
 
-LayoutRect RenderSVGInlineText::localCaretRect(InlineBox* box, unsigned caretOffset, LayoutUnit*)
+LayoutRect RenderSVGInlineText::localCaretRect(const InlineRunAndOffset& runAndOffset, LayoutUnit*) const
 {
+    auto* box = runAndOffset.run ? runAndOffset.run->legacyInlineBox() : nullptr;
+    auto caretOffset = runAndOffset.offset;
+
     if (!is<InlineTextBox>(box))
         return LayoutRect();
 

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGInlineText.h (269509 => 269510)


--- trunk/Source/WebCore/rendering/svg/RenderSVGInlineText.h	2020-11-06 14:09:47 UTC (rev 269509)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGInlineText.h	2020-11-06 14:33:10 UTC (rev 269510)
@@ -62,7 +62,7 @@
     bool isSVGInlineText() const override { return true; }
 
     VisiblePosition positionForPoint(const LayoutPoint&, const RenderFragmentContainer*) override;
-    LayoutRect localCaretRect(InlineBox*, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) override;
+    LayoutRect localCaretRect(const InlineRunAndOffset&, LayoutUnit* extraWidthToEndOfLine = nullptr) const override;
     IntRect linesBoundingBox() const override;
     std::unique_ptr<InlineTextBox> createTextBox() override;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to