Changeset 220988 in webkit


Ignore:
Timestamp:
Aug 21, 2017 4:21:15 PM (7 years ago)
Author:
dbates@webkit.org
Message:

Cleanup TextPainter
https://bugs.webkit.org/show_bug.cgi?id=175782

Reviewed by Myles C. Maxfield.

Remove redundant mention of "text" in the name of TextPainter member functions, add separate
setters for selection and non-selection shadows, and do some other minor cleanups.

  • rendering/InlineTextBox.cpp:

(WebCore::InlineTextBox::paint): Update code for renamed functions.

  • rendering/SimpleLineLayoutFunctions.cpp:

(WebCore::SimpleLineLayout::paintFlow): Ditto.

  • rendering/TextPainter.cpp: Include ShadowData.h.

(WebCore::ShadowApplier::ShadowApplier): Use C++11 brace-initialization syntax.
(WebCore::ShadowApplier::isLastShadowIteration): Moved from TextPainter.h.
(WebCore::ShadowApplier::shadowIsCompletelyCoveredByText): Ditto.
(WebCore::TextPainter::paintTextOrEmphasisMarks): Renamed; formerly named drawTextOrEmphasisMarks.
(WebCore::TextPainter::paintTextWithShadows): Update code for renamed functions.
(WebCore::TextPainter::paintRange): Renamed; formerly named paintTextInRange.
(WebCore::TextPainter::paint): Renamed; formerly named paintText.
(WebCore::TextPainter::drawTextOrEmphasisMarks): Renamed to paintTextOrEmphasisMarks() to match
the naming convention of all the other paint functions in this class.
(WebCore::TextPainter::paintTextInRange): Renamed to paintRange.
(WebCore::TextPainter::paintText): Renamed to paint.

  • rendering/TextPainter.h: Forward declare ShadowData.

(WebCore::TextPainter::setStyle): Renamed; formerly named setTextPaintStyle.
(WebCore::TextPainter::setSelectionStyle): Renamed; formerly named setSelectionPaintStyle.
(WebCore::TextPainter::setShadow): Added.
(WebCore::TextPainter::setSelectionShadow): Added.
(WebCore::TextPainter::setEmphasisMark): Renamed; formerly named addEmphasis.
(WebCore::TextPainter::setTextPaintStyle): Renamed to setStyle.
(WebCore::TextPainter::setSelectionPaintStyle): Renamed to setSelectionStyle.
(WebCore::TextPainter::addEmphasis): Renamed to setEmphasisMark.
(WebCore::TextPainter::addTextShadow): Split functionality into setShadow and setSelectionShadow.
(WebCore::ShadowApplier::isLastShadowIteration): Moved to TextPainter.cpp.
(WebCore::ShadowApplier::shadowIsCompletelyCoveredByText): Ditto.

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r220986 r220988  
     12017-08-21  Daniel Bates  <dabates@apple.com>
     2
     3        Cleanup TextPainter
     4        https://bugs.webkit.org/show_bug.cgi?id=175782
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        Remove redundant mention of "text" in the name of TextPainter member functions, add separate
     9        setters for selection and non-selection shadows, and do some other minor cleanups.
     10
     11        * rendering/InlineTextBox.cpp:
     12        (WebCore::InlineTextBox::paint): Update code for renamed functions.
     13        * rendering/SimpleLineLayoutFunctions.cpp:
     14        (WebCore::SimpleLineLayout::paintFlow): Ditto.
     15        * rendering/TextPainter.cpp: Include ShadowData.h.
     16        (WebCore::ShadowApplier::ShadowApplier): Use C++11 brace-initialization syntax.
     17        (WebCore::ShadowApplier::isLastShadowIteration): Moved from TextPainter.h.
     18        (WebCore::ShadowApplier::shadowIsCompletelyCoveredByText): Ditto.
     19        (WebCore::TextPainter::paintTextOrEmphasisMarks): Renamed; formerly named drawTextOrEmphasisMarks.
     20        (WebCore::TextPainter::paintTextWithShadows): Update code for renamed functions.
     21        (WebCore::TextPainter::paintRange): Renamed; formerly named paintTextInRange.
     22        (WebCore::TextPainter::paint): Renamed; formerly named paintText.
     23        (WebCore::TextPainter::drawTextOrEmphasisMarks): Renamed to paintTextOrEmphasisMarks() to match
     24        the naming convention of all the other paint functions in this class.
     25        (WebCore::TextPainter::paintTextInRange): Renamed to paintRange.
     26        (WebCore::TextPainter::paintText): Renamed to paint.
     27        * rendering/TextPainter.h: Forward declare ShadowData.
     28        (WebCore::TextPainter::setStyle): Renamed; formerly named setTextPaintStyle.
     29        (WebCore::TextPainter::setSelectionStyle): Renamed; formerly named setSelectionPaintStyle.
     30        (WebCore::TextPainter::setShadow): Added.
     31        (WebCore::TextPainter::setSelectionShadow): Added.
     32        (WebCore::TextPainter::setEmphasisMark): Renamed; formerly named addEmphasis.
     33        (WebCore::TextPainter::setTextPaintStyle): Renamed to setStyle.
     34        (WebCore::TextPainter::setSelectionPaintStyle): Renamed to setSelectionStyle.
     35        (WebCore::TextPainter::addEmphasis): Renamed to setEmphasisMark.
     36        (WebCore::TextPainter::addTextShadow): Split functionality into setShadow and setSelectionShadow.
     37        (WebCore::ShadowApplier::isLastShadowIteration): Moved to TextPainter.cpp.
     38        (WebCore::ShadowApplier::shadowIsCompletelyCoveredByText): Ditto.
     39
    1402017-08-21  Myles C. Maxfield  <mmaxfield@apple.com>
    241
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r220639 r220988  
    548548    TextPainter textPainter(context);
    549549    textPainter.setFont(font);
    550     textPainter.setTextPaintStyle(textPaintStyle);
    551     textPainter.setSelectionPaintStyle(selectionPaintStyle);
     550    textPainter.setStyle(textPaintStyle);
     551    textPainter.setSelectionStyle(selectionPaintStyle);
    552552    textPainter.setIsHorizontal(isHorizontal());
    553     textPainter.addTextShadow(textShadow, selectionShadow);
    554     textPainter.addEmphasis(emphasisMark, emphasisMarkOffset, combinedText);
     553    textPainter.setShadow(textShadow);
     554    textPainter.setSelectionShadow(selectionShadow);
     555    textPainter.setEmphasisMark(emphasisMark, emphasisMarkOffset, combinedText);
    555556
    556557    auto draggedContentRanges = renderer().draggedContentRangesBetweenOffsets(m_start, m_start + m_len);
     
    565566
    566567            if (previousEnd < currentStart)
    567                 textPainter.paintTextInRange(textRun, boxRect, textOrigin, previousEnd, currentStart);
     568                textPainter.paintRange(textRun, boxRect, textOrigin, previousEnd, currentStart);
    568569
    569570            if (currentStart < currentEnd) {
    570571                context.save();
    571572                context.setAlpha(0.25);
    572                 textPainter.paintTextInRange(textRun, boxRect, textOrigin, currentStart, currentEnd);
     573                textPainter.paintRange(textRun, boxRect, textOrigin, currentStart, currentEnd);
    573574                context.restore();
    574575            }
    575576        }
    576577        if (currentEnd < length)
    577             textPainter.paintTextInRange(textRun, boxRect, textOrigin, currentEnd, length);
     578            textPainter.paintRange(textRun, boxRect, textOrigin, currentEnd, length);
    578579    } else
    579         textPainter.paintText(textRun, length, boxRect, textOrigin, selectionStart, selectionEnd, paintSelectedTextOnly, paintSelectedTextSeparately, paintNonSelectedTextOnly);
     580        textPainter.paint(textRun, length, boxRect, textOrigin, selectionStart, selectionEnd, paintSelectedTextOnly, paintSelectedTextSeparately, paintNonSelectedTextOnly);
    580581
    581582    // Paint decorations
  • trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp

    r220503 r220988  
    8282    TextPainter textPainter(paintInfo.context());
    8383    textPainter.setFont(style.fontCascade());
    84     textPainter.setTextPaintStyle(computeTextPaintStyle(flow.frame(), style, paintInfo));
     84    textPainter.setStyle(computeTextPaintStyle(flow.frame(), style, paintInfo));
    8585
    8686    std::unique_ptr<ShadowData> debugShadow = nullptr;
    8787    if (flow.settings().simpleLineLayoutDebugBordersEnabled()) {
    8888        debugShadow = std::make_unique<ShadowData>(IntPoint(0, 0), 10, 20, ShadowStyle::Normal, true, Color(0, 255, 0, 200));
    89         textPainter.addTextShadow(debugShadow.get(), nullptr);
     89        textPainter.setShadow(debugShadow.get());
    9090    }
    9191
     
    121121        textRun.setTabSize(!style.collapseWhiteSpace(), style.tabSize());
    122122        FloatPoint textOrigin = FloatPoint(rect.x() + paintOffset.x(), roundToDevicePixel(run.baselinePosition() + paintOffset.y(), deviceScaleFactor));
    123         textPainter.paintText(textRun, textRun.length(), rect, textOrigin);
     123        textPainter.paint(textRun, textRun.length(), rect, textOrigin);
    124124        if (textDecorationPainter) {
    125125            textDecorationPainter->setWidth(rect.width());
  • trunk/Source/WebCore/rendering/TextPainter.cpp

    r219237 r220988  
    22 * (C) 1999 Lars Knoll (knoll@kde.org)
    33 * (C) 2000 Dirk Mueller (mueller@kde.org)
    4  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
     4 * Copyright (C) 2004-2017 Apple Inc. All rights reserved.
    55 *
    66 * This library is free software; you can redistribute it and/or
     
    2727#include "InlineTextBox.h"
    2828#include "RenderCombineText.h"
     29#include "ShadowData.h"
    2930#include <wtf/NeverDestroyed.h>
    3031
     
    3233
    3334ShadowApplier::ShadowApplier(GraphicsContext& context, const ShadowData* shadow, const FloatRect& textRect, bool lastShadowIterationShouldDrawText, bool opaque, FontOrientation orientation)
    34     : m_context(context)
    35     , m_shadow(shadow)
    36     , m_onlyDrawsShadow(!isLastShadowIteration() || !lastShadowIterationShouldDrawText)
    37     , m_avoidDrawingShadow(shadowIsCompletelyCoveredByText(opaque))
    38     , m_nothingToDraw(shadow && m_avoidDrawingShadow && m_onlyDrawsShadow)
    39     , m_didSaveContext(false)
     35    : m_context { context }
     36    , m_shadow { shadow }
     37    , m_onlyDrawsShadow { !isLastShadowIteration() || !lastShadowIterationShouldDrawText }
     38    , m_avoidDrawingShadow { shadowIsCompletelyCoveredByText(opaque) }
     39    , m_nothingToDraw { shadow && m_avoidDrawingShadow && m_onlyDrawsShadow }
     40    , m_didSaveContext { false }
    4041{
    4142    if (!shadow || m_nothingToDraw) {
     
    6970}
    7071
     72inline bool ShadowApplier::isLastShadowIteration()
     73{
     74    return m_shadow && !m_shadow->next();
     75}
     76
     77inline bool ShadowApplier::shadowIsCompletelyCoveredByText(bool textIsOpaque)
     78{
     79    return textIsOpaque && m_shadow && m_shadow->location().isZero() && !m_shadow->radius();
     80}
     81
    7182ShadowApplier::~ShadowApplier()
    7283{
     
    8495}
    8596
    86 void TextPainter::drawTextOrEmphasisMarks(const FontCascade& font, const TextRun& textRun, const AtomicString& emphasisMark,
     97void TextPainter::paintTextOrEmphasisMarks(const FontCascade& font, const TextRun& textRun, const AtomicString& emphasisMark,
    8798    float emphasisMarkOffset, const FloatPoint& textOrigin, unsigned startOffset, unsigned endOffset)
    8899{
     
    98109{
    99110    if (!shadow) {
    100         drawTextOrEmphasisMarks(font, textRun, emphasisMark, emphasisMarkOffset, textOrigin, startOffset, endOffset);
     111        paintTextOrEmphasisMarks(font, textRun, emphasisMark, emphasisMarkOffset, textOrigin, startOffset, endOffset);
    101112        return;
    102113    }
     
    110121        ShadowApplier shadowApplier(m_context, shadow, boxRect, lastShadowIterationShouldDrawText, opaque, m_textBoxIsHorizontal ? Horizontal : Vertical);
    111122        if (!shadowApplier.nothingToDraw())
    112             drawTextOrEmphasisMarks(font, textRun, emphasisMark, emphasisMarkOffset, textOrigin + shadowApplier.extraOffset(), startOffset, endOffset);
     123            paintTextOrEmphasisMarks(font, textRun, emphasisMark, emphasisMarkOffset, textOrigin + shadowApplier.extraOffset(), startOffset, endOffset);
    113124        shadow = shadow->next();
    114125    }
     
    117128        if (!opaque)
    118129            m_context.setFillColor(fillColor);
    119         drawTextOrEmphasisMarks(font, textRun, emphasisMark, emphasisMarkOffset, textOrigin, startOffset, endOffset);
     130        paintTextOrEmphasisMarks(font, textRun, emphasisMark, emphasisMarkOffset, textOrigin, startOffset, endOffset);
    120131    }
    121132}
     
    170181}
    171182
    172 void TextPainter::paintTextInRange(const TextRun& textRun, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned start, unsigned end)
     183void TextPainter::paintRange(const TextRun& textRun, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned start, unsigned end)
    173184{
    174185    ASSERT(m_font);
    175186    ASSERT(start < end);
    176187
    177     GraphicsContextStateSaver stateSaver(m_context, m_textPaintStyle.strokeWidth > 0);
    178     updateGraphicsContext(m_context, m_textPaintStyle);
    179     paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, start, end, m_textPaintStyle, m_textShadow);
     188    GraphicsContextStateSaver stateSaver(m_context, m_style.strokeWidth > 0);
     189    updateGraphicsContext(m_context, m_style);
     190    paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, start, end, m_style, m_shadow);
    180191}
    181192   
    182 void TextPainter::paintText(const TextRun& textRun, unsigned length, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned selectionStart, unsigned selectionEnd,
     193void TextPainter::paint(const TextRun& textRun, unsigned length, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned selectionStart, unsigned selectionEnd,
    183194    bool paintSelectedTextOnly, bool paintSelectedTextSeparately, bool paintNonSelectedTextOnly)
    184195{
     
    187198        // For stroked painting, we have to change the text drawing mode. It's probably dangerous to leave that mutated as a side
    188199        // effect, so only when we know we're stroking, do a save/restore.
    189         GraphicsContextStateSaver stateSaver(m_context, m_textPaintStyle.strokeWidth > 0);
    190         updateGraphicsContext(m_context, m_textPaintStyle);
     200        GraphicsContextStateSaver stateSaver(m_context, m_style.strokeWidth > 0);
     201        updateGraphicsContext(m_context, m_style);
    191202        bool fullPaint = !paintSelectedTextSeparately || selectionEnd <= selectionStart;
    192203        if (fullPaint)
    193             paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, 0, length, m_textPaintStyle, m_textShadow);
     204            paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, 0, length, m_style, m_shadow);
    194205        else {
    195206            // Paint the before and after selection parts.
    196207            if (selectionStart > 0)
    197                 paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, 0, selectionStart, m_textPaintStyle, m_textShadow);
     208                paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, 0, selectionStart, m_style, m_shadow);
    198209            if (selectionEnd < length)
    199                 paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, selectionEnd, length, m_textPaintStyle, m_textShadow);
     210                paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, selectionEnd, length, m_style, m_shadow);
    200211        }
    201212    }
     
    206217    // Paint only the text that is selected.
    207218    if ((paintSelectedTextOnly || paintSelectedTextSeparately) && selectionStart < selectionEnd) {
    208         GraphicsContextStateSaver stateSaver(m_context, m_selectionPaintStyle.strokeWidth > 0);
    209         updateGraphicsContext(m_context, m_selectionPaintStyle);
    210         paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, selectionStart, selectionEnd, m_selectionPaintStyle, m_selectionShadow);
     219        GraphicsContextStateSaver stateSaver(m_context, m_selectionStyle.strokeWidth > 0);
     220        updateGraphicsContext(m_context, m_selectionStyle);
     221        paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, selectionStart, selectionEnd, m_selectionStyle, m_selectionShadow);
    211222    }
    212223}
  • trunk/Source/WebCore/rendering/TextPainter.h

    r216212 r220988  
    22 * (C) 1999 Lars Knoll (knoll@kde.org)
    33 * (C) 2000 Dirk Mueller (mueller@kde.org)
    4  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
     4 * Copyright (C) 2004-2017 Apple Inc. All rights reserved.
    55 *
    66 * This library is free software; you can redistribute it and/or
     
    2525#include "AffineTransform.h"
    2626#include "FloatRect.h"
    27 #include "ShadowData.h"
    2827#include "TextFlags.h"
    2928#include "TextPaintStyle.h"
     
    3433class FontCascade;
    3534class RenderCombineText;
     35class ShadowData;
    3636class TextRun;
    3737
     
    5050    TextPainter(GraphicsContext&);
    5151   
    52     void setTextPaintStyle(const TextPaintStyle& textPaintStyle) { m_textPaintStyle = textPaintStyle; }
    53     void setSelectionPaintStyle(const TextPaintStyle& selectionPaintStyle) { m_selectionPaintStyle = selectionPaintStyle; }
     52    void setStyle(const TextPaintStyle& textPaintStyle) { m_style = textPaintStyle; }
     53    void setSelectionStyle(const TextPaintStyle& selectionPaintStyle) { m_selectionStyle = selectionPaintStyle; }
     54
     55    void setShadow(const ShadowData* shadow) { m_shadow = shadow; }
     56    void setSelectionShadow(const ShadowData* selectionShadow) { m_selectionShadow = selectionShadow; }
     57
     58    void setFont(const FontCascade& font) { m_font = &font; }
     59
    5460    void setIsHorizontal(bool isHorizontal) { m_textBoxIsHorizontal = isHorizontal; }
    55     void setFont(const FontCascade& font) { m_font = &font; }
    56     void addEmphasis(const AtomicString& emphasisMark, float emphasisMarkOffset, RenderCombineText*);
    57     void addTextShadow(const ShadowData* textShadow, const ShadowData* selectionShadow);
    5861
    59     void paintTextInRange(const TextRun&, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned start, unsigned end);
    60     void paintText(const TextRun&, unsigned length, const FloatRect& boxRect, const FloatPoint& textOrigin,
     62    void setEmphasisMark(const AtomicString& mark, float offset, RenderCombineText*);
     63
     64    void paintRange(const TextRun&, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned start, unsigned end);
     65    void paint(const TextRun&, unsigned length, const FloatRect& boxRect, const FloatPoint& textOrigin,
    6166        unsigned selectionStart = 0, unsigned selectionEnd = 0, bool paintSelectedTextOnly = false, bool paintSelectedTextSeparately = false, bool paintNonSelectedTextOnly = false);
    6267
    6368private:
    64     void drawTextOrEmphasisMarks(const FontCascade&, const TextRun&, const AtomicString& emphasisMark, float emphasisMarkOffset,
     69    void paintTextOrEmphasisMarks(const FontCascade&, const TextRun&, const AtomicString& emphasisMark, float emphasisMarkOffset,
    6570        const FloatPoint& textOrigin, unsigned startOffset, unsigned endOffset);
    6671    void paintTextWithShadows(const ShadowData*, const FontCascade&, const TextRun&, const FloatRect& boxRect, const FloatPoint& textOrigin,
     
    7176    GraphicsContext& m_context;
    7277    const FontCascade* m_font { nullptr };
    73     TextPaintStyle m_textPaintStyle;
    74     TextPaintStyle m_selectionPaintStyle;
    75     const ShadowData* m_textShadow { nullptr };
     78    TextPaintStyle m_style;
     79    TextPaintStyle m_selectionStyle;
     80    const ShadowData* m_shadow { nullptr };
    7681    const ShadowData* m_selectionShadow { nullptr };
    7782    AtomicString m_emphasisMark;
     
    8186};
    8287
    83 inline void TextPainter::addEmphasis(const AtomicString& emphasisMark, float emphasisMarkOffset, RenderCombineText* combinedText)
     88inline void TextPainter::setEmphasisMark(const AtomicString& mark, float offset, RenderCombineText* combinedText)
    8489{
    85     m_emphasisMark = emphasisMark;
    86     m_emphasisMarkOffset = emphasisMarkOffset;
     90    m_emphasisMark = mark;
     91    m_emphasisMarkOffset = offset;
    8792    m_combinedText = combinedText;
    88 }
    89 
    90 inline void TextPainter::addTextShadow(const ShadowData* textShadow, const ShadowData* selectionShadow)
    91 {
    92     m_textShadow = textShadow;
    93     m_selectionShadow = selectionShadow;
    9493}
    9594
     
    115114};
    116115
    117 inline bool ShadowApplier::isLastShadowIteration()
    118 {
    119     return m_shadow && !m_shadow->next();
    120 }
    121 
    122 inline bool ShadowApplier::shadowIsCompletelyCoveredByText(bool textIsOpaque)
    123 {
    124     return textIsOpaque && m_shadow && m_shadow->location() == IntPoint() && !m_shadow->radius();
    125 }
    126 
    127116} // namespace WebCore
Note: See TracChangeset for help on using the changeset viewer.