Title: [269639] trunk/Source/WebCore
Revision
269639
Author
[email protected]
Date
2020-11-10 11:40:50 -0800 (Tue, 10 Nov 2020)

Log Message

[LFC][Integration] Move caret rect computation out of iterator
https://bugs.webkit.org/show_bug.cgi?id=218747

Reviewed by Zalan Bujtas.

Move it to RenderBlockFlow which it mostly deals with.

* layout/integration/LayoutIntegrationLineIterator.cpp:
(WebCore::LayoutIntegration::PathLine::computeCaretRect const): Deleted.
* layout/integration/LayoutIntegrationLineIterator.h:
(WebCore::LayoutIntegration::PathLine::selectionRect const):
* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::computeCaretRect const):
* rendering/RenderBlockFlow.h:
* rendering/RenderLineBreak.cpp:
(WebCore::RenderLineBreak::localCaretRect const):
* rendering/RenderText.cpp:
(WebCore::RenderText::localCaretRect const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (269638 => 269639)


--- trunk/Source/WebCore/ChangeLog	2020-11-10 19:38:28 UTC (rev 269638)
+++ trunk/Source/WebCore/ChangeLog	2020-11-10 19:40:50 UTC (rev 269639)
@@ -1,3 +1,24 @@
+2020-11-10  Antti Koivisto  <[email protected]>
+
+        [LFC][Integration] Move caret rect computation out of iterator
+        https://bugs.webkit.org/show_bug.cgi?id=218747
+
+        Reviewed by Zalan Bujtas.
+
+        Move it to RenderBlockFlow which it mostly deals with.
+
+        * layout/integration/LayoutIntegrationLineIterator.cpp:
+        (WebCore::LayoutIntegration::PathLine::computeCaretRect const): Deleted.
+        * layout/integration/LayoutIntegrationLineIterator.h:
+        (WebCore::LayoutIntegration::PathLine::selectionRect const):
+        * rendering/RenderBlockFlow.cpp:
+        (WebCore::RenderBlockFlow::computeCaretRect const):
+        * rendering/RenderBlockFlow.h:
+        * rendering/RenderLineBreak.cpp:
+        (WebCore::RenderLineBreak::localCaretRect const):
+        * rendering/RenderText.cpp:
+        (WebCore::RenderText::localCaretRect const):
+
 2020-11-10  Andres Gonzalez  <[email protected]>
 
         Fix for LayoutTests/accessibility/mac/search-predicate.html in isolated tree mode.

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.cpp (269638 => 269639)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.cpp	2020-11-10 19:38:28 UTC (rev 269638)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.cpp	2020-11-10 19:40:50 UTC (rev 269639)
@@ -179,59 +179,6 @@
     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 (269638 => 269639)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.h	2020-11-10 19:38:28 UTC (rev 269638)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIterator.h	2020-11-10 19:40:50 UTC (rev 269639)
@@ -58,6 +58,8 @@
     LayoutUnit lineBoxTop() const;
     LayoutUnit lineBoxBottom() const;
 
+    LayoutRect selectionRect() const;
+
     float y() const;
     float logicalLeft() const;
     float logicalRight() const;
@@ -64,7 +66,6 @@
     float logicalHeight() const;
 
     int blockDirectionPointInLine() const;
-    IntRect computeCaretRect(float logicalLeftPosition, unsigned caretWidth, LayoutUnit* extraWidthToEndOfLine) const;
 
     bool isHorizontal() const;
 
@@ -173,6 +174,11 @@
     });
 }
 
+inline LayoutRect PathLine::selectionRect() const
+{
+    return { LayoutPoint { logicalLeft(), selectionTop() }, LayoutPoint { logicalRight(), selectionBottom() } };
+}
+
 inline float PathLine::y() const
 {
     return WTF::switchOn(m_pathVariant, [](const auto& path) {

Modified: trunk/Source/WebCore/rendering/RenderBlockFlow.cpp (269638 => 269639)


--- trunk/Source/WebCore/rendering/RenderBlockFlow.cpp	2020-11-10 19:38:28 UTC (rev 269638)
+++ trunk/Source/WebCore/rendering/RenderBlockFlow.cpp	2020-11-10 19:40:50 UTC (rev 269639)
@@ -4438,5 +4438,56 @@
     maxLogicalWidth = preferredWidth(maxLogicalWidth, inlineMax);
 }
 
+IntRect RenderBlockFlow::computeCaretRect(const LayoutRect& lineSelectionRect, float logicalLeftPosition, unsigned caretWidth, LayoutUnit* extraWidthToEndOfLine) const
+{
+    int height = lineSelectionRect.height();
+    int top = lineSelectionRect.y();
+
+    // 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 = lineSelectionRect.x();
+    float lineRight = lineSelectionRect.maxX();
+
+    if (extraWidthToEndOfLine)
+        *extraWidthToEndOfLine = lineRight - (left + caretWidth);
+
+    bool rightAligned = false;
+    switch (style().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 = !style().isLeftToRightDirection();
+        break;
+    case TextAlignMode::End:
+        rightAligned = style().isLeftToRightDirection();
+        break;
+    }
+
+    float leftEdge = std::min<float>(0, lineLeft);
+    float rightEdge = std::max<float>(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 style().isHorizontalWritingMode() ? IntRect(left, top, caretWidth, height) : IntRect(top, left, height, caretWidth);
 }
+
+}
 // namespace WebCore

Modified: trunk/Source/WebCore/rendering/RenderBlockFlow.h (269638 => 269639)


--- trunk/Source/WebCore/rendering/RenderBlockFlow.h	2020-11-10 19:38:28 UTC (rev 269638)
+++ trunk/Source/WebCore/rendering/RenderBlockFlow.h	2020-11-10 19:40:50 UTC (rev 269639)
@@ -398,6 +398,7 @@
     void addFloatsToNewParent(RenderBlockFlow& toBlockFlow) const;
     
     LayoutUnit endPaddingWidthForCaret() const;
+    IntRect computeCaretRect(const LayoutRect& lineSelectionRect, float logicalLeftPosition, unsigned caretWidth, LayoutUnit* extraWidthToEndOfLine) const;
 
 protected:
     bool shouldResetLogicalHeightBeforeLayout() const override { return true; }

Modified: trunk/Source/WebCore/rendering/RenderLineBreak.cpp (269638 => 269639)


--- trunk/Source/WebCore/rendering/RenderLineBreak.cpp	2020-11-10 19:38:28 UTC (rev 269638)
+++ trunk/Source/WebCore/rendering/RenderLineBreak.cpp	2020-11-10 19:40:50 UTC (rev 269639)
@@ -167,7 +167,7 @@
         return LayoutRect();
 
     auto line = runAndOffset.run.line();
-    return line->computeCaretRect(line->logicalLeft(), caretWidth, extraWidthToEndOfLine);
+    return line->containingBlock().computeCaretRect(line->selectionRect(), line->logicalLeft(), caretWidth, extraWidthToEndOfLine);
 }
 
 IntRect RenderLineBreak::linesBoundingBox() const
@@ -213,7 +213,8 @@
         return;
     const RootInlineBox& rootBox = box->root();
 
-    LayoutRect rect = LayoutIntegration::LineIterator(&rootBox)->computeCaretRect(box->logicalLeft(), 0, nullptr);
+    auto line = LayoutIntegration::LineIterator(&rootBox);
+    LayoutRect rect = rootBox.blockFlow().computeCaretRect(line->selectionRect(), line->logicalLeft(), 0, nullptr);
 
     if (rootBox.isFirstAfterPageBreak()) {
         if (box->isHorizontal())

Modified: trunk/Source/WebCore/rendering/RenderText.cpp (269638 => 269639)


--- trunk/Source/WebCore/rendering/RenderText.cpp	2020-11-10 19:38:28 UTC (rev 269638)
+++ trunk/Source/WebCore/rendering/RenderText.cpp	2020-11-10 19:40:50 UTC (rev 269639)
@@ -715,9 +715,10 @@
         return LayoutRect();
 
     auto& textRun = downcast<LayoutIntegration::TextRunIterator>(runAndOffset.run);
+    auto line = textRun.line();
 
-    float left = textRun->positionForOffset(runAndOffset.offset);
-    return textRun.line()->computeCaretRect(left, caretWidth, extraWidthToEndOfLine);
+    float position = textRun->positionForOffset(runAndOffset.offset);
+    return line->containingBlock().computeCaretRect(line->selectionRect(), position, 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
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to