Extract logic to paint composition underlines to its own function
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Oct 2017 19:18:09 +0000 (19:18 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Oct 2017 19:18:09 +0000 (19:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=178038

Reviewed by Zalan Bujtas.

No functionality changed. So, no new tests.

* rendering/InlineTextBox.cpp:
(WebCore::InlineTextBox::paint): Modified to call paintCompositionUnderlines().
(WebCore::InlineTextBox::paintCompositionUnderlines const): Added; extract code
from InlineTextBox::paint() and modernized it.
(WebCore::InlineTextBox::paintCompositionUnderline const): Added.
(WebCore::InlineTextBox::paintCompositionUnderline): Deleted; made const.
* rendering/InlineTextBox.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@223198 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/InlineTextBox.cpp
Source/WebCore/rendering/InlineTextBox.h

index a32274c..be0edf5 100644 (file)
@@ -1,5 +1,22 @@
 2017-10-11  Daniel Bates  <dabates@apple.com>
 
+        Extract logic to paint composition underlines to its own function
+        https://bugs.webkit.org/show_bug.cgi?id=178038
+
+        Reviewed by Zalan Bujtas.
+
+        No functionality changed. So, no new tests.
+
+        * rendering/InlineTextBox.cpp:
+        (WebCore::InlineTextBox::paint): Modified to call paintCompositionUnderlines().
+        (WebCore::InlineTextBox::paintCompositionUnderlines const): Added; extract code
+        from InlineTextBox::paint() and modernized it.
+        (WebCore::InlineTextBox::paintCompositionUnderline const): Added.
+        (WebCore::InlineTextBox::paintCompositionUnderline): Deleted; made const.
+        * rendering/InlineTextBox.h:
+
+2017-10-11  Daniel Bates  <dabates@apple.com>
+
         InlineTextBox::isSelected() should only return true for a non-empty selection
         and remove incorrect FIXME from InlineTextBox::localSelectionRect()
         https://bugs.webkit.org/show_bug.cgi?id=160786
index da843a8..89c1e0d 100644 (file)
@@ -588,30 +588,8 @@ void InlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset,
     if (paintInfo.phase == PaintPhaseForeground) {
         paintDocumentMarkers(context, boxOrigin, false);
 
-        if (useCustomUnderlines) {
-            const Vector<CompositionUnderline>& underlines = renderer().frame().editor().customCompositionUnderlines();
-            size_t numUnderlines = underlines.size();
-
-            for (size_t index = 0; index < numUnderlines; ++index) {
-                const CompositionUnderline& underline = underlines[index];
-
-                if (underline.endOffset <= start())
-                    // underline is completely before this run.  This might be an underline that sits
-                    // before the first run we draw, or underlines that were within runs we skipped 
-                    // due to truncation.
-                    continue;
-                
-                if (underline.startOffset <= end()) {
-                    // underline intersects this run.  Paint it.
-                    paintCompositionUnderline(context, boxOrigin, underline);
-                    if (underline.endOffset > end() + 1)
-                        // underline also runs into the next run. Bail now, no more marker advancement.
-                        break;
-                } else
-                    // underline is completely after this run, bail.  A later run will paint it.
-                    break;
-            }
-        }
+        if (useCustomUnderlines)
+            paintCompositionUnderlines(context, boxOrigin);
     }
     
     if (shouldRotate)
@@ -963,7 +941,31 @@ void InlineTextBox::paintDocumentMarkers(GraphicsContext& context, const FloatPo
     }
 }
 
-void InlineTextBox::paintCompositionUnderline(GraphicsContext& context, const FloatPoint& boxOrigin, const CompositionUnderline& underline)
+void InlineTextBox::paintCompositionUnderlines(GraphicsContext& context, const FloatPoint& boxOrigin) const
+{
+    if (m_truncation == cFullTruncation)
+        return;
+
+    for (auto& underline : renderer().frame().editor().customCompositionUnderlines()) {
+        if (underline.endOffset <= m_start) {
+            // Underline is completely before this run. This might be an underline that sits
+            // before the first run we draw, or underlines that were within runs we skipped
+            // due to truncation.
+            continue;
+        }
+
+        if (underline.startOffset > end())
+            break; // Underline is completely after this run, bail. A later run will paint it.
+
+        // Underline intersects this run. Paint it.
+        paintCompositionUnderline(context, boxOrigin, underline);
+
+        if (underline.endOffset > end() + 1)
+            break; // Underline also runs into the next run. Bail now, no more marker advancement.
+    }
+}
+
+void InlineTextBox::paintCompositionUnderline(GraphicsContext& context, const FloatPoint& boxOrigin, const CompositionUnderline& underline) const
 {
     if (m_truncation == cFullTruncation)
         return;
index e7eb867..506367a 100644 (file)
@@ -159,7 +159,8 @@ private:
     void paintTextMatchMarker(GraphicsContext&, const FloatPoint& boxOrigin, const MarkerSubrange&, bool isActiveMatch);
 
     void paintCompositionBackground(GraphicsContext&, const FloatPoint& boxOrigin);
-    void paintCompositionUnderline(GraphicsContext&, const FloatPoint& boxOrigin, const CompositionUnderline&);
+    void paintCompositionUnderlines(GraphicsContext&, const FloatPoint& boxOrigin) const;
+    void paintCompositionUnderline(GraphicsContext&, const FloatPoint& boxOrigin, const CompositionUnderline&) const;
 
     void paintTextSubrangeBackground(GraphicsContext&, const FloatPoint& boxOrigin, const Color&, unsigned startOffset, unsigned endOffset);