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.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@220988
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2017-08-21 Daniel Bates <dabates@apple.com>
+
+ 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.
+
2017-08-21 Myles C. Maxfield <mmaxfield@apple.com>
Addressing post-review comments after r220725
TextPainter textPainter(context);
textPainter.setFont(font);
- textPainter.setTextPaintStyle(textPaintStyle);
- textPainter.setSelectionPaintStyle(selectionPaintStyle);
+ textPainter.setStyle(textPaintStyle);
+ textPainter.setSelectionStyle(selectionPaintStyle);
textPainter.setIsHorizontal(isHorizontal());
- textPainter.addTextShadow(textShadow, selectionShadow);
- textPainter.addEmphasis(emphasisMark, emphasisMarkOffset, combinedText);
+ textPainter.setShadow(textShadow);
+ textPainter.setSelectionShadow(selectionShadow);
+ textPainter.setEmphasisMark(emphasisMark, emphasisMarkOffset, combinedText);
auto draggedContentRanges = renderer().draggedContentRangesBetweenOffsets(m_start, m_start + m_len);
if (!draggedContentRanges.isEmpty() && !paintSelectedTextOnly && !paintNonSelectedTextOnly) {
currentEnd = std::min(draggedContentRanges[index].second - m_start, length);
if (previousEnd < currentStart)
- textPainter.paintTextInRange(textRun, boxRect, textOrigin, previousEnd, currentStart);
+ textPainter.paintRange(textRun, boxRect, textOrigin, previousEnd, currentStart);
if (currentStart < currentEnd) {
context.save();
context.setAlpha(0.25);
- textPainter.paintTextInRange(textRun, boxRect, textOrigin, currentStart, currentEnd);
+ textPainter.paintRange(textRun, boxRect, textOrigin, currentStart, currentEnd);
context.restore();
}
}
if (currentEnd < length)
- textPainter.paintTextInRange(textRun, boxRect, textOrigin, currentEnd, length);
+ textPainter.paintRange(textRun, boxRect, textOrigin, currentEnd, length);
} else
- textPainter.paintText(textRun, length, boxRect, textOrigin, selectionStart, selectionEnd, paintSelectedTextOnly, paintSelectedTextSeparately, paintNonSelectedTextOnly);
+ textPainter.paint(textRun, length, boxRect, textOrigin, selectionStart, selectionEnd, paintSelectedTextOnly, paintSelectedTextSeparately, paintNonSelectedTextOnly);
// Paint decorations
TextDecoration textDecorations = lineStyle.textDecorationsInEffect();
TextPainter textPainter(paintInfo.context());
textPainter.setFont(style.fontCascade());
- textPainter.setTextPaintStyle(computeTextPaintStyle(flow.frame(), style, paintInfo));
+ textPainter.setStyle(computeTextPaintStyle(flow.frame(), style, paintInfo));
std::unique_ptr<ShadowData> debugShadow = nullptr;
if (flow.settings().simpleLineLayoutDebugBordersEnabled()) {
debugShadow = std::make_unique<ShadowData>(IntPoint(0, 0), 10, 20, ShadowStyle::Normal, true, Color(0, 255, 0, 200));
- textPainter.addTextShadow(debugShadow.get(), nullptr);
+ textPainter.setShadow(debugShadow.get());
}
std::optional<TextDecorationPainter> textDecorationPainter;
TextRun textRun(run.hasHyphen() ? textWithHyphen : run.text(), 0, run.expansion(), run.expansionBehavior());
textRun.setTabSize(!style.collapseWhiteSpace(), style.tabSize());
FloatPoint textOrigin = FloatPoint(rect.x() + paintOffset.x(), roundToDevicePixel(run.baselinePosition() + paintOffset.y(), deviceScaleFactor));
- textPainter.paintText(textRun, textRun.length(), rect, textOrigin);
+ textPainter.paint(textRun, textRun.length(), rect, textOrigin);
if (textDecorationPainter) {
textDecorationPainter->setWidth(rect.width());
textDecorationPainter->paintTextDecoration(textRun, textOrigin, rect.location() + paintOffset);
/*
* (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 2000 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2004-2017 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
#include "GraphicsContext.h"
#include "InlineTextBox.h"
#include "RenderCombineText.h"
+#include "ShadowData.h"
#include <wtf/NeverDestroyed.h>
namespace WebCore {
ShadowApplier::ShadowApplier(GraphicsContext& context, const ShadowData* shadow, const FloatRect& textRect, bool lastShadowIterationShouldDrawText, bool opaque, FontOrientation orientation)
- : m_context(context)
- , m_shadow(shadow)
- , m_onlyDrawsShadow(!isLastShadowIteration() || !lastShadowIterationShouldDrawText)
- , m_avoidDrawingShadow(shadowIsCompletelyCoveredByText(opaque))
- , m_nothingToDraw(shadow && m_avoidDrawingShadow && m_onlyDrawsShadow)
- , m_didSaveContext(false)
+ : m_context { context }
+ , m_shadow { shadow }
+ , m_onlyDrawsShadow { !isLastShadowIteration() || !lastShadowIterationShouldDrawText }
+ , m_avoidDrawingShadow { shadowIsCompletelyCoveredByText(opaque) }
+ , m_nothingToDraw { shadow && m_avoidDrawingShadow && m_onlyDrawsShadow }
+ , m_didSaveContext { false }
{
if (!shadow || m_nothingToDraw) {
m_shadow = nullptr;
context.setShadow(shadowOffset, shadowRadius, shadowColor);
}
+inline bool ShadowApplier::isLastShadowIteration()
+{
+ return m_shadow && !m_shadow->next();
+}
+
+inline bool ShadowApplier::shadowIsCompletelyCoveredByText(bool textIsOpaque)
+{
+ return textIsOpaque && m_shadow && m_shadow->location().isZero() && !m_shadow->radius();
+}
+
ShadowApplier::~ShadowApplier()
{
if (!m_shadow)
{
}
-void TextPainter::drawTextOrEmphasisMarks(const FontCascade& font, const TextRun& textRun, const AtomicString& emphasisMark,
+void TextPainter::paintTextOrEmphasisMarks(const FontCascade& font, const TextRun& textRun, const AtomicString& emphasisMark,
float emphasisMarkOffset, const FloatPoint& textOrigin, unsigned startOffset, unsigned endOffset)
{
ASSERT(startOffset < endOffset);
unsigned startOffset, unsigned endOffset, const AtomicString& emphasisMark, float emphasisMarkOffset, bool stroked)
{
if (!shadow) {
- drawTextOrEmphasisMarks(font, textRun, emphasisMark, emphasisMarkOffset, textOrigin, startOffset, endOffset);
+ paintTextOrEmphasisMarks(font, textRun, emphasisMark, emphasisMarkOffset, textOrigin, startOffset, endOffset);
return;
}
while (shadow) {
ShadowApplier shadowApplier(m_context, shadow, boxRect, lastShadowIterationShouldDrawText, opaque, m_textBoxIsHorizontal ? Horizontal : Vertical);
if (!shadowApplier.nothingToDraw())
- drawTextOrEmphasisMarks(font, textRun, emphasisMark, emphasisMarkOffset, textOrigin + shadowApplier.extraOffset(), startOffset, endOffset);
+ paintTextOrEmphasisMarks(font, textRun, emphasisMark, emphasisMarkOffset, textOrigin + shadowApplier.extraOffset(), startOffset, endOffset);
shadow = shadow->next();
}
if (!lastShadowIterationShouldDrawText) {
if (!opaque)
m_context.setFillColor(fillColor);
- drawTextOrEmphasisMarks(font, textRun, emphasisMark, emphasisMarkOffset, textOrigin, startOffset, endOffset);
+ paintTextOrEmphasisMarks(font, textRun, emphasisMark, emphasisMarkOffset, textOrigin, startOffset, endOffset);
}
}
m_context.concatCTM(rotation(boxRect, Counterclockwise));
}
-void TextPainter::paintTextInRange(const TextRun& textRun, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned start, unsigned end)
+void TextPainter::paintRange(const TextRun& textRun, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned start, unsigned end)
{
ASSERT(m_font);
ASSERT(start < end);
- GraphicsContextStateSaver stateSaver(m_context, m_textPaintStyle.strokeWidth > 0);
- updateGraphicsContext(m_context, m_textPaintStyle);
- paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, start, end, m_textPaintStyle, m_textShadow);
+ GraphicsContextStateSaver stateSaver(m_context, m_style.strokeWidth > 0);
+ updateGraphicsContext(m_context, m_style);
+ paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, start, end, m_style, m_shadow);
}
-void TextPainter::paintText(const TextRun& textRun, unsigned length, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned selectionStart, unsigned selectionEnd,
+void TextPainter::paint(const TextRun& textRun, unsigned length, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned selectionStart, unsigned selectionEnd,
bool paintSelectedTextOnly, bool paintSelectedTextSeparately, bool paintNonSelectedTextOnly)
{
ASSERT(m_font);
if (!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.
- GraphicsContextStateSaver stateSaver(m_context, m_textPaintStyle.strokeWidth > 0);
- updateGraphicsContext(m_context, m_textPaintStyle);
+ GraphicsContextStateSaver stateSaver(m_context, m_style.strokeWidth > 0);
+ updateGraphicsContext(m_context, m_style);
bool fullPaint = !paintSelectedTextSeparately || selectionEnd <= selectionStart;
if (fullPaint)
- paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, 0, length, m_textPaintStyle, m_textShadow);
+ paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, 0, length, m_style, m_shadow);
else {
// Paint the before and after selection parts.
if (selectionStart > 0)
- paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, 0, selectionStart, m_textPaintStyle, m_textShadow);
+ paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, 0, selectionStart, m_style, m_shadow);
if (selectionEnd < length)
- paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, selectionEnd, length, m_textPaintStyle, m_textShadow);
+ paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, selectionEnd, length, m_style, m_shadow);
}
}
// Paint only the text that is selected.
if ((paintSelectedTextOnly || paintSelectedTextSeparately) && selectionStart < selectionEnd) {
- GraphicsContextStateSaver stateSaver(m_context, m_selectionPaintStyle.strokeWidth > 0);
- updateGraphicsContext(m_context, m_selectionPaintStyle);
- paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, selectionStart, selectionEnd, m_selectionPaintStyle, m_selectionShadow);
+ GraphicsContextStateSaver stateSaver(m_context, m_selectionStyle.strokeWidth > 0);
+ updateGraphicsContext(m_context, m_selectionStyle);
+ paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, selectionStart, selectionEnd, m_selectionStyle, m_selectionShadow);
}
}
/*
* (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 2000 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2004-2017 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
#include "AffineTransform.h"
#include "FloatRect.h"
-#include "ShadowData.h"
#include "TextFlags.h"
#include "TextPaintStyle.h"
#include <wtf/text/AtomicString.h>
class FontCascade;
class RenderCombineText;
+class ShadowData;
class TextRun;
struct TextPaintStyle;
public:
TextPainter(GraphicsContext&);
- void setTextPaintStyle(const TextPaintStyle& textPaintStyle) { m_textPaintStyle = textPaintStyle; }
- void setSelectionPaintStyle(const TextPaintStyle& selectionPaintStyle) { m_selectionPaintStyle = selectionPaintStyle; }
- void setIsHorizontal(bool isHorizontal) { m_textBoxIsHorizontal = isHorizontal; }
+ void setStyle(const TextPaintStyle& textPaintStyle) { m_style = textPaintStyle; }
+ void setSelectionStyle(const TextPaintStyle& selectionPaintStyle) { m_selectionStyle = selectionPaintStyle; }
+
+ void setShadow(const ShadowData* shadow) { m_shadow = shadow; }
+ void setSelectionShadow(const ShadowData* selectionShadow) { m_selectionShadow = selectionShadow; }
+
void setFont(const FontCascade& font) { m_font = &font; }
- void addEmphasis(const AtomicString& emphasisMark, float emphasisMarkOffset, RenderCombineText*);
- void addTextShadow(const ShadowData* textShadow, const ShadowData* selectionShadow);
- void paintTextInRange(const TextRun&, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned start, unsigned end);
- void paintText(const TextRun&, unsigned length, const FloatRect& boxRect, const FloatPoint& textOrigin,
+ void setIsHorizontal(bool isHorizontal) { m_textBoxIsHorizontal = isHorizontal; }
+
+ void setEmphasisMark(const AtomicString& mark, float offset, RenderCombineText*);
+
+ void paintRange(const TextRun&, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned start, unsigned end);
+ void paint(const TextRun&, unsigned length, const FloatRect& boxRect, const FloatPoint& textOrigin,
unsigned selectionStart = 0, unsigned selectionEnd = 0, bool paintSelectedTextOnly = false, bool paintSelectedTextSeparately = false, bool paintNonSelectedTextOnly = false);
private:
- void drawTextOrEmphasisMarks(const FontCascade&, const TextRun&, const AtomicString& emphasisMark, float emphasisMarkOffset,
+ void paintTextOrEmphasisMarks(const FontCascade&, const TextRun&, const AtomicString& emphasisMark, float emphasisMarkOffset,
const FloatPoint& textOrigin, unsigned startOffset, unsigned endOffset);
void paintTextWithShadows(const ShadowData*, const FontCascade&, const TextRun&, const FloatRect& boxRect, const FloatPoint& textOrigin,
unsigned startOffset, unsigned endOffset, const AtomicString& emphasisMark, float emphasisMarkOffset, bool stroked);
GraphicsContext& m_context;
const FontCascade* m_font { nullptr };
- TextPaintStyle m_textPaintStyle;
- TextPaintStyle m_selectionPaintStyle;
- const ShadowData* m_textShadow { nullptr };
+ TextPaintStyle m_style;
+ TextPaintStyle m_selectionStyle;
+ const ShadowData* m_shadow { nullptr };
const ShadowData* m_selectionShadow { nullptr };
AtomicString m_emphasisMark;
RenderCombineText* m_combinedText { nullptr };
bool m_textBoxIsHorizontal { true };
};
-inline void TextPainter::addEmphasis(const AtomicString& emphasisMark, float emphasisMarkOffset, RenderCombineText* combinedText)
+inline void TextPainter::setEmphasisMark(const AtomicString& mark, float offset, RenderCombineText* combinedText)
{
- m_emphasisMark = emphasisMark;
- m_emphasisMarkOffset = emphasisMarkOffset;
+ m_emphasisMark = mark;
+ m_emphasisMarkOffset = offset;
m_combinedText = combinedText;
}
-inline void TextPainter::addTextShadow(const ShadowData* textShadow, const ShadowData* selectionShadow)
-{
- m_textShadow = textShadow;
- m_selectionShadow = selectionShadow;
-}
-
class ShadowApplier {
public:
ShadowApplier(GraphicsContext&, const ShadowData*, const FloatRect& textRect, bool lastShadowIterationShouldDrawText = true, bool opaque = false, FontOrientation = Horizontal);
bool m_didSaveContext : 1;
};
-inline bool ShadowApplier::isLastShadowIteration()
-{
- return m_shadow && !m_shadow->next();
-}
-
-inline bool ShadowApplier::shadowIsCompletelyCoveredByText(bool textIsOpaque)
-{
- return textIsOpaque && m_shadow && m_shadow->location() == IntPoint() && !m_shadow->radius();
-}
-
} // namespace WebCore