Title: [193891] trunk/Source/WebCore
Revision
193891
Author
za...@apple.com
Date
2015-12-09 20:59:56 -0800 (Wed, 09 Dec 2015)

Log Message

TextPainter: Make before and after selection painting more explicit.
https://bugs.webkit.org/show_bug.cgi?id=152104

Reviewed by Myles C. Maxfield.

Instead of swapping start end end positions and expecting TextPainter::drawTextOrEmphasisMarks()
to recognize it, we call painting with 0 - startPosition and endPosition - length.

No change in functionality.

* rendering/TextPainter.cpp:
(WebCore::TextPainter::drawTextOrEmphasisMarks):
(WebCore::TextPainter::paintTextAndEmphasisMarksIfNeeded):
(WebCore::TextPainter::paintText):
(WebCore::TextPainter::paintEmphasisMarksIfNeeded): Deleted.
(WebCore::TextPainter::paintTextWithStyle): Deleted.
* rendering/TextPainter.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (193890 => 193891)


--- trunk/Source/WebCore/ChangeLog	2015-12-10 03:50:07 UTC (rev 193890)
+++ trunk/Source/WebCore/ChangeLog	2015-12-10 04:59:56 UTC (rev 193891)
@@ -1,3 +1,23 @@
+2015-12-09  Zalan Bujtas  <za...@apple.com>
+
+        TextPainter: Make before and after selection painting more explicit.
+        https://bugs.webkit.org/show_bug.cgi?id=152104
+
+        Reviewed by Myles C. Maxfield.
+
+        Instead of swapping start end end positions and expecting TextPainter::drawTextOrEmphasisMarks()
+        to recognize it, we call painting with 0 - startPosition and endPosition - length.
+
+        No change in functionality.
+
+        * rendering/TextPainter.cpp:
+        (WebCore::TextPainter::drawTextOrEmphasisMarks):
+        (WebCore::TextPainter::paintTextAndEmphasisMarksIfNeeded):
+        (WebCore::TextPainter::paintText):
+        (WebCore::TextPainter::paintEmphasisMarksIfNeeded): Deleted.
+        (WebCore::TextPainter::paintTextWithStyle): Deleted.
+        * rendering/TextPainter.h:
+
 2015-12-09  Daniel Bates  <daba...@apple.com>
 
         [iOS] Suspend and resume device motion and device orientation updates when page is hidden and visible, respectively

Modified: trunk/Source/WebCore/rendering/TextPainter.cpp (193890 => 193891)


--- trunk/Source/WebCore/rendering/TextPainter.cpp	2015-12-10 03:50:07 UTC (rev 193890)
+++ trunk/Source/WebCore/rendering/TextPainter.cpp	2015-12-10 04:59:56 UTC (rev 193891)
@@ -107,23 +107,11 @@
 void TextPainter::drawTextOrEmphasisMarks(const FontCascade& font, const TextRun& textRun, const AtomicString& emphasisMark,
     int emphasisMarkOffset, const FloatPoint& textOrigin, int startOffset, int endOffset)
 {
-    auto drawText = [&](int from, int to)
-    {
-        if (emphasisMark.isEmpty())
-            m_context.drawText(font, textRun, textOrigin, from, to);
-        else
-            m_context.drawEmphasisMarks(font, textRun, emphasisMark, textOrigin + IntSize(0, emphasisMarkOffset), from, to);
-    };
-
-    if (startOffset <= endOffset) {
-        drawText(startOffset, endOffset);
-        return;
-    }
-    
-    if (endOffset > 0)
-        drawText(0, endOffset);
-    if (startOffset < m_length)
-        drawText(startOffset, m_length);
+    ASSERT(startOffset < endOffset);
+    if (emphasisMark.isEmpty())
+        m_context.drawText(font, textRun, textOrigin, startOffset, endOffset);
+    else
+        m_context.drawEmphasisMarks(font, textRun, emphasisMark, textOrigin + IntSize(0, emphasisMarkOffset), startOffset, endOffset);
 }
 
 void TextPainter::paintTextWithShadows(const ShadowData* shadow, const FontCascade& font, const TextRun& textRun, const AtomicString& emphasisMark,
@@ -153,8 +141,11 @@
     }
 }
 
-void TextPainter::paintEmphasisMarksIfNeeded(int startOffset, int endOffset, const TextPaintStyle& paintStyle, const ShadowData* shadow)
+void TextPainter::paintTextAndEmphasisMarksIfNeeded(int startOffset, int endOffset, const TextPaintStyle& paintStyle, const ShadowData* shadow)
 {
+    // FIXME: Truncate right-to-left text correctly.
+    paintTextWithShadows(shadow, m_font, m_textRun, nullAtom, 0, startOffset, endOffset, m_textOrigin, paintStyle.strokeWidth > 0);
+
     if (m_emphasisMark.isEmpty())
         return;
 
@@ -172,29 +163,30 @@
     if (m_combinedText)
         m_context.concatCTM(rotation(m_boxRect, Counterclockwise));
 }
-
-void TextPainter::paintTextWithStyle(const TextPaintStyle& paintStyle, int startOffset, int endOffset, const ShadowData* shadow)
-{
-    GraphicsContextStateSaver stateSaver(m_context, paintStyle.strokeWidth > 0);
-    updateGraphicsContext(m_context, paintStyle);
-    // FIXME: Truncate right-to-left text correctly.
-    paintTextWithShadows(shadow, m_font, m_textRun, nullAtom, 0, startOffset, endOffset, m_textOrigin, paintStyle.strokeWidth > 0);
-    paintEmphasisMarksIfNeeded(startOffset, endOffset, paintStyle, shadow);
-}
     
 void TextPainter::paintText()
 {
     if (!m_paintSelectedTextOnly) {
         // For stroked painting, we have to change the text drawing mode. It's probably dangerous to leave that mutated as a side
         // effect, so only when we know we're stroking, do a save/restore.
-        int startPosition = m_paintSelectedTextSeparately ? m_selectionEnd : 0;
-        int endPosition = m_paintSelectedTextSeparately ? m_selectionStart : m_length;
-        paintTextWithStyle(m_textPaintStyle, startPosition, endPosition, m_textShadow);
+        GraphicsContextStateSaver stateSaver(m_context, m_textPaintStyle.strokeWidth > 0);
+        updateGraphicsContext(m_context, m_textPaintStyle);
+        if (m_paintSelectedTextSeparately) {
+            // Paint the before and after selection parts.
+            if (m_selectionStart > 0)
+                paintTextAndEmphasisMarksIfNeeded(0, m_selectionStart, m_textPaintStyle, m_textShadow);
+            if (m_selectionEnd < m_length)
+                paintTextAndEmphasisMarksIfNeeded(m_selectionEnd, m_length, m_textPaintStyle, m_textShadow);
+        } else
+            paintTextAndEmphasisMarksIfNeeded(0, m_length, m_textPaintStyle, m_textShadow);
     }
 
-    // paint only the text that is selected
-    if ((m_paintSelectedTextOnly || m_paintSelectedTextSeparately) && m_selectionStart < m_selectionEnd)
-        paintTextWithStyle(m_selectionPaintStyle, m_selectionStart, m_selectionEnd, m_selectionShadow);
+    // Paint only the text that is selected.
+    if ((m_paintSelectedTextOnly || m_paintSelectedTextSeparately) && m_selectionStart < m_selectionEnd) {
+        GraphicsContextStateSaver stateSaver(m_context, m_selectionPaintStyle.strokeWidth > 0);
+        updateGraphicsContext(m_context, m_selectionPaintStyle);
+        paintTextAndEmphasisMarksIfNeeded(m_selectionStart, m_selectionEnd, m_selectionPaintStyle, m_selectionShadow);
+    }
 }
 
 #if ENABLE(CSS3_TEXT_DECORATION_SKIP_INK)

Modified: trunk/Source/WebCore/rendering/TextPainter.h (193890 => 193891)


--- trunk/Source/WebCore/rendering/TextPainter.h	2015-12-10 03:50:07 UTC (rev 193890)
+++ trunk/Source/WebCore/rendering/TextPainter.h	2015-12-10 04:59:56 UTC (rev 193891)
@@ -59,8 +59,7 @@
         const FloatPoint& textOrigin, int startOffset, int endOffset);
     void paintTextWithShadows(const ShadowData*, const FontCascade&, const TextRun&, const AtomicString& emphasisMark, int emphasisMarkOffset,
         int startOffset, int endOffset, const FloatPoint& textOrigin, bool stroked);
-    void paintTextWithStyle(const TextPaintStyle&, int startOffset, int endOffset, const ShadowData*);
-    void paintEmphasisMarksIfNeeded(int startOffset, int endOffset, const TextPaintStyle&, const ShadowData*);
+    void paintTextAndEmphasisMarksIfNeeded(int startOffset, int endOffset, const TextPaintStyle&, const ShadowData*);
 
     GraphicsContext& m_context;
     TextPaintStyle& m_textPaintStyle;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to