Title: [199307] trunk/Source/WebCore
Revision
199307
Author
[email protected]
Date
2016-04-11 12:52:35 -0700 (Mon, 11 Apr 2016)

Log Message

Simplify InlineTextBox::selectionStartEnd()
https://bugs.webkit.org/show_bug.cgi?id=156459

Reviewed by Darin Adler.

No change in functionality.

* rendering/InlineTextBox.cpp:
(WebCore::InlineTextBox::selectionState):
(WebCore::InlineTextBox::paint):
(WebCore::InlineTextBox::selectionStartEnd):
(WebCore::InlineTextBox::paintSelection):
(WebCore::InlineTextBox::paintCompositionBackground):
* rendering/InlineTextBox.h:
* rendering/svg/SVGInlineTextBox.cpp:
(WebCore::SVGInlineTextBox::paintSelectionBackground):
(WebCore::SVGInlineTextBox::paintText):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (199306 => 199307)


--- trunk/Source/WebCore/ChangeLog	2016-04-11 19:37:01 UTC (rev 199306)
+++ trunk/Source/WebCore/ChangeLog	2016-04-11 19:52:35 UTC (rev 199307)
@@ -1,5 +1,25 @@
 2016-04-11  Zalan Bujtas  <[email protected]>
 
+        Simplify InlineTextBox::selectionStartEnd()
+        https://bugs.webkit.org/show_bug.cgi?id=156459
+
+        Reviewed by Darin Adler.
+
+        No change in functionality.
+
+        * rendering/InlineTextBox.cpp:
+        (WebCore::InlineTextBox::selectionState):
+        (WebCore::InlineTextBox::paint):
+        (WebCore::InlineTextBox::selectionStartEnd):
+        (WebCore::InlineTextBox::paintSelection):
+        (WebCore::InlineTextBox::paintCompositionBackground):
+        * rendering/InlineTextBox.h:
+        * rendering/svg/SVGInlineTextBox.cpp:
+        (WebCore::SVGInlineTextBox::paintSelectionBackground):
+        (WebCore::SVGInlineTextBox::paintText):
+
+2016-04-11  Zalan Bujtas  <[email protected]>
+
         REGRESSION (r193857): Text selection causes text to disappear.
         https://bugs.webkit.org/show_bug.cgi?id=156448
         rdar://problem/25578952

Modified: trunk/Source/WebCore/rendering/InlineTextBox.cpp (199306 => 199307)


--- trunk/Source/WebCore/rendering/InlineTextBox.cpp	2016-04-11 19:37:01 UTC (rev 199306)
+++ trunk/Source/WebCore/rendering/InlineTextBox.cpp	2016-04-11 19:52:35 UTC (rev 199307)
@@ -165,13 +165,14 @@
     if (m_truncation != cNoTruncation && root().ellipsisBox()) {
         EllipsisBox* ellipsis = root().ellipsisBox();
         if (state != RenderObject::SelectionNone) {
-            int start, end;
-            selectionStartEnd(start, end);
+            int selectionStart;
+            int selectionEnd;
+            std::tie(selectionStart, selectionEnd) = selectionStartEnd();
             // The ellipsis should be considered to be selected if the end of
             // the selection is past the beginning of the truncation and the
             // beginning of the selection is before or at the beginning of the
             // truncation.
-            ellipsis->setSelectionState(end >= m_truncation && start <= m_truncation ?
+            ellipsis->setSelectionState(selectionEnd >= m_truncation && selectionStart <= m_truncation ?
                 RenderObject::SelectionInside : RenderObject::SelectionNone);
         } else
             ellipsis->setSelectionState(RenderObject::SelectionNone);
@@ -519,7 +520,7 @@
     int selectionStart = 0;
     int selectionEnd = 0;
     if (haveSelection && (paintSelectedTextOnly || paintSelectedTextSeparately))
-        selectionStartEnd(selectionStart, selectionEnd);
+        std::tie(selectionStart, selectionEnd) = selectionStartEnd();
 
     if (m_truncation != cNoTruncation) {
         selectionStart = std::min<int>(selectionStart, m_truncation);
@@ -595,22 +596,20 @@
         context.concatCTM(rotation(boxRect, Counterclockwise));
 }
 
-void InlineTextBox::selectionStartEnd(int& sPos, int& ePos)
+std::pair<int, int> InlineTextBox::selectionStartEnd() const
 {
-    int startPos, endPos;
-    if (renderer().selectionState() == RenderObject::SelectionInside) {
-        startPos = 0;
-        endPos = renderer().textLength();
-    } else {
-        renderer().selectionStartEnd(startPos, endPos);
-        if (renderer().selectionState() == RenderObject::SelectionStart)
-            endPos = renderer().textLength();
-        else if (renderer().selectionState() == RenderObject::SelectionEnd)
-            startPos = 0;
-    }
-
-    sPos = std::max(startPos - m_start, 0);
-    ePos = std::min(endPos - m_start, (int)m_len);
+    auto selectionState = renderer().selectionState();
+    if (selectionState == RenderObject::SelectionInside)
+        return {0, m_len};
+    
+    int start;
+    int end;
+    renderer().selectionStartEnd(start, end);
+    if (selectionState == RenderObject::SelectionStart)
+        end = renderer().textLength();
+    else if (selectionState == RenderObject::SelectionEnd)
+        start = 0;
+    return { std::max(start - m_start, 0), std::min<int>(end - m_start, m_len) };
 }
 
 void InlineTextBox::paintSelection(GraphicsContext& context, const FloatPoint& boxOrigin, const RenderStyle& style, const FontCascade& font, Color textColor)
@@ -620,9 +619,10 @@
         return;
 
     // See if we have a selection to paint at all.
-    int sPos, ePos;
-    selectionStartEnd(sPos, ePos);
-    if (sPos >= ePos)
+    int selectionStart;
+    int selectionEnd;
+    std::tie(selectionStart, selectionEnd) = selectionStartEnd();
+    if (selectionStart >= selectionEnd)
         return;
 
     Color c = renderer().selectionBackgroundColor();
@@ -648,10 +648,10 @@
     }
 
     String hyphenatedStringBuffer;
-    bool respectHyphen = ePos == length && hasHyphen();
+    bool respectHyphen = selectionEnd == length && hasHyphen();
     TextRun textRun = constructTextRun(style, string, renderer().textLength() - m_start, respectHyphen ? &hyphenatedStringBuffer : nullptr);
     if (respectHyphen)
-        ePos = textRun.length();
+        selectionEnd = textRun.length();
 
     const RootInlineBox& rootBox = root();
     LayoutUnit selectionBottom = rootBox.selectionBottom();
@@ -661,7 +661,7 @@
     LayoutUnit selectionHeight = std::max<LayoutUnit>(0, selectionBottom - selectionTop);
 
     LayoutRect selectionRect = LayoutRect(boxOrigin.x(), boxOrigin.y() - deltaY, m_logicalWidth, selectionHeight);
-    font.adjustSelectionRectForText(textRun, selectionRect, sPos, ePos);
+    font.adjustSelectionRectForText(textRun, selectionRect, selectionStart, selectionEnd);
     context.fillRect(snapRectToDevicePixelsWithWritingDirection(selectionRect, renderer().document().deviceScaleFactor(), textRun.ltr()), c);
 #else
     UNUSED_PARAM(context);
@@ -675,10 +675,9 @@
 void InlineTextBox::paintCompositionBackground(GraphicsContext& context, const FloatPoint& boxOrigin, const RenderStyle& style, const FontCascade& font, int startPos, int endPos)
 {
     int offset = m_start;
-    int sPos = std::max(startPos - offset, 0);
-    int ePos = std::min(endPos - offset, (int)m_len);
-
-    if (sPos >= ePos)
+    int selectionStart = std::max(startPos - offset, 0);
+    int selectionEnd = std::min<int>(endPos - offset, m_len);
+    if (selectionStart >= selectionEnd)
         return;
 
     GraphicsContextStateSaver stateSaver(context);
@@ -688,7 +687,7 @@
     LayoutUnit deltaY = renderer().style().isFlippedLinesWritingMode() ? selectionBottom() - logicalBottom() : logicalTop() - selectionTop();
     LayoutRect selectionRect = LayoutRect(boxOrigin.x(), boxOrigin.y() - deltaY, 0, selectionHeight());
     TextRun textRun = constructTextRun(style);
-    font.adjustSelectionRectForText(textRun, selectionRect, sPos, ePos);
+    font.adjustSelectionRectForText(textRun, selectionRect, selectionStart, selectionEnd);
     context.fillRect(snapRectToDevicePixelsWithWritingDirection(selectionRect, renderer().document().deviceScaleFactor(), textRun.ltr()), compositionColor);
 }
 

Modified: trunk/Source/WebCore/rendering/InlineTextBox.h (199306 => 199307)


--- trunk/Source/WebCore/rendering/InlineTextBox.h	2016-04-11 19:37:01 UTC (rev 199306)
+++ trunk/Source/WebCore/rendering/InlineTextBox.h	2016-04-11 19:52:35 UTC (rev 199307)
@@ -120,7 +120,7 @@
 
     virtual LayoutRect localSelectionRect(int startPos, int endPos) const;
     bool isSelected(int startPos, int endPos) const;
-    void selectionStartEnd(int& sPos, int& ePos);
+    std::pair<int, int> selectionStartEnd() const;
 
 protected:
     void paint(PaintInfo&, const LayoutPoint&, LayoutUnit lineTop, LayoutUnit lineBottom) override;

Modified: trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp (199306 => 199307)


--- trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp	2016-04-11 19:37:01 UTC (rev 199306)
+++ trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp	2016-04-11 19:52:35 UTC (rev 199307)
@@ -203,8 +203,9 @@
 
     RenderStyle& style = parentRenderer.style();
 
-    int startPosition, endPosition;
-    selectionStartEnd(startPosition, endPosition);
+    int startPosition;
+    int endPosition;
+    std::tie(startPosition, endPosition) = selectionStartEnd();
 
     int fragmentStartPosition = 0;
     int fragmentEndPosition = 0;
@@ -592,7 +593,7 @@
     int startPosition = 0;
     int endPosition = 0;
     if (hasSelection) {
-        selectionStartEnd(startPosition, endPosition);
+        std::tie(startPosition, endPosition) = selectionStartEnd();
         hasSelection = mapStartEndPositionsIntoFragmentCoordinates(fragment, startPosition, endPosition);
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to