Changeset 220988 in webkit
- Timestamp:
- Aug 21, 2017 4:21:15 PM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r220986 r220988 1 2017-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 1 40 2017-08-21 Myles C. Maxfield <mmaxfield@apple.com> 2 41 -
trunk/Source/WebCore/rendering/InlineTextBox.cpp
r220639 r220988 548 548 TextPainter textPainter(context); 549 549 textPainter.setFont(font); 550 textPainter.set TextPaintStyle(textPaintStyle);551 textPainter.setSelection PaintStyle(selectionPaintStyle);550 textPainter.setStyle(textPaintStyle); 551 textPainter.setSelectionStyle(selectionPaintStyle); 552 552 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); 555 556 556 557 auto draggedContentRanges = renderer().draggedContentRangesBetweenOffsets(m_start, m_start + m_len); … … 565 566 566 567 if (previousEnd < currentStart) 567 textPainter.paint TextInRange(textRun, boxRect, textOrigin, previousEnd, currentStart);568 textPainter.paintRange(textRun, boxRect, textOrigin, previousEnd, currentStart); 568 569 569 570 if (currentStart < currentEnd) { 570 571 context.save(); 571 572 context.setAlpha(0.25); 572 textPainter.paint TextInRange(textRun, boxRect, textOrigin, currentStart, currentEnd);573 textPainter.paintRange(textRun, boxRect, textOrigin, currentStart, currentEnd); 573 574 context.restore(); 574 575 } 575 576 } 576 577 if (currentEnd < length) 577 textPainter.paint TextInRange(textRun, boxRect, textOrigin, currentEnd, length);578 textPainter.paintRange(textRun, boxRect, textOrigin, currentEnd, length); 578 579 } else 579 textPainter.paint Text(textRun, length, boxRect, textOrigin, selectionStart, selectionEnd, paintSelectedTextOnly, paintSelectedTextSeparately, paintNonSelectedTextOnly);580 textPainter.paint(textRun, length, boxRect, textOrigin, selectionStart, selectionEnd, paintSelectedTextOnly, paintSelectedTextSeparately, paintNonSelectedTextOnly); 580 581 581 582 // Paint decorations -
trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp
r220503 r220988 82 82 TextPainter textPainter(paintInfo.context()); 83 83 textPainter.setFont(style.fontCascade()); 84 textPainter.set TextPaintStyle(computeTextPaintStyle(flow.frame(), style, paintInfo));84 textPainter.setStyle(computeTextPaintStyle(flow.frame(), style, paintInfo)); 85 85 86 86 std::unique_ptr<ShadowData> debugShadow = nullptr; 87 87 if (flow.settings().simpleLineLayoutDebugBordersEnabled()) { 88 88 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()); 90 90 } 91 91 … … 121 121 textRun.setTabSize(!style.collapseWhiteSpace(), style.tabSize()); 122 122 FloatPoint textOrigin = FloatPoint(rect.x() + paintOffset.x(), roundToDevicePixel(run.baselinePosition() + paintOffset.y(), deviceScaleFactor)); 123 textPainter.paint Text(textRun, textRun.length(), rect, textOrigin);123 textPainter.paint(textRun, textRun.length(), rect, textOrigin); 124 124 if (textDecorationPainter) { 125 125 textDecorationPainter->setWidth(rect.width()); -
trunk/Source/WebCore/rendering/TextPainter.cpp
r219237 r220988 2 2 * (C) 1999 Lars Knoll (knoll@kde.org) 3 3 * (C) 2000 Dirk Mueller (mueller@kde.org) 4 * Copyright (C) 2004 , 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013Apple Inc. All rights reserved.4 * Copyright (C) 2004-2017 Apple Inc. All rights reserved. 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 27 27 #include "InlineTextBox.h" 28 28 #include "RenderCombineText.h" 29 #include "ShadowData.h" 29 30 #include <wtf/NeverDestroyed.h> 30 31 … … 32 33 33 34 ShadowApplier::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 } 40 41 { 41 42 if (!shadow || m_nothingToDraw) { … … 69 70 } 70 71 72 inline bool ShadowApplier::isLastShadowIteration() 73 { 74 return m_shadow && !m_shadow->next(); 75 } 76 77 inline bool ShadowApplier::shadowIsCompletelyCoveredByText(bool textIsOpaque) 78 { 79 return textIsOpaque && m_shadow && m_shadow->location().isZero() && !m_shadow->radius(); 80 } 81 71 82 ShadowApplier::~ShadowApplier() 72 83 { … … 84 95 } 85 96 86 void TextPainter:: drawTextOrEmphasisMarks(const FontCascade& font, const TextRun& textRun, const AtomicString& emphasisMark,97 void TextPainter::paintTextOrEmphasisMarks(const FontCascade& font, const TextRun& textRun, const AtomicString& emphasisMark, 87 98 float emphasisMarkOffset, const FloatPoint& textOrigin, unsigned startOffset, unsigned endOffset) 88 99 { … … 98 109 { 99 110 if (!shadow) { 100 drawTextOrEmphasisMarks(font, textRun, emphasisMark, emphasisMarkOffset, textOrigin, startOffset, endOffset);111 paintTextOrEmphasisMarks(font, textRun, emphasisMark, emphasisMarkOffset, textOrigin, startOffset, endOffset); 101 112 return; 102 113 } … … 110 121 ShadowApplier shadowApplier(m_context, shadow, boxRect, lastShadowIterationShouldDrawText, opaque, m_textBoxIsHorizontal ? Horizontal : Vertical); 111 122 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); 113 124 shadow = shadow->next(); 114 125 } … … 117 128 if (!opaque) 118 129 m_context.setFillColor(fillColor); 119 drawTextOrEmphasisMarks(font, textRun, emphasisMark, emphasisMarkOffset, textOrigin, startOffset, endOffset);130 paintTextOrEmphasisMarks(font, textRun, emphasisMark, emphasisMarkOffset, textOrigin, startOffset, endOffset); 120 131 } 121 132 } … … 170 181 } 171 182 172 void TextPainter::paint TextInRange(const TextRun& textRun, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned start, unsigned end)183 void TextPainter::paintRange(const TextRun& textRun, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned start, unsigned end) 173 184 { 174 185 ASSERT(m_font); 175 186 ASSERT(start < end); 176 187 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); 180 191 } 181 192 182 void TextPainter::paint Text(const TextRun& textRun, unsigned length, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned selectionStart, unsigned selectionEnd,193 void TextPainter::paint(const TextRun& textRun, unsigned length, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned selectionStart, unsigned selectionEnd, 183 194 bool paintSelectedTextOnly, bool paintSelectedTextSeparately, bool paintNonSelectedTextOnly) 184 195 { … … 187 198 // For stroked painting, we have to change the text drawing mode. It's probably dangerous to leave that mutated as a side 188 199 // 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); 191 202 bool fullPaint = !paintSelectedTextSeparately || selectionEnd <= selectionStart; 192 203 if (fullPaint) 193 paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, 0, length, m_ textPaintStyle, m_textShadow);204 paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, 0, length, m_style, m_shadow); 194 205 else { 195 206 // Paint the before and after selection parts. 196 207 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); 198 209 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); 200 211 } 201 212 } … … 206 217 // Paint only the text that is selected. 207 218 if ((paintSelectedTextOnly || paintSelectedTextSeparately) && selectionStart < selectionEnd) { 208 GraphicsContextStateSaver stateSaver(m_context, m_selection PaintStyle.strokeWidth > 0);209 updateGraphicsContext(m_context, m_selection PaintStyle);210 paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, selectionStart, selectionEnd, m_selection PaintStyle, 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); 211 222 } 212 223 } -
trunk/Source/WebCore/rendering/TextPainter.h
r216212 r220988 2 2 * (C) 1999 Lars Knoll (knoll@kde.org) 3 3 * (C) 2000 Dirk Mueller (mueller@kde.org) 4 * Copyright (C) 2004 , 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013Apple Inc. All rights reserved.4 * Copyright (C) 2004-2017 Apple Inc. All rights reserved. 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 25 25 #include "AffineTransform.h" 26 26 #include "FloatRect.h" 27 #include "ShadowData.h"28 27 #include "TextFlags.h" 29 28 #include "TextPaintStyle.h" … … 34 33 class FontCascade; 35 34 class RenderCombineText; 35 class ShadowData; 36 36 class TextRun; 37 37 … … 50 50 TextPainter(GraphicsContext&); 51 51 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 54 60 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);58 61 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, 61 66 unsigned selectionStart = 0, unsigned selectionEnd = 0, bool paintSelectedTextOnly = false, bool paintSelectedTextSeparately = false, bool paintNonSelectedTextOnly = false); 62 67 63 68 private: 64 void drawTextOrEmphasisMarks(const FontCascade&, const TextRun&, const AtomicString& emphasisMark, float emphasisMarkOffset,69 void paintTextOrEmphasisMarks(const FontCascade&, const TextRun&, const AtomicString& emphasisMark, float emphasisMarkOffset, 65 70 const FloatPoint& textOrigin, unsigned startOffset, unsigned endOffset); 66 71 void paintTextWithShadows(const ShadowData*, const FontCascade&, const TextRun&, const FloatRect& boxRect, const FloatPoint& textOrigin, … … 71 76 GraphicsContext& m_context; 72 77 const FontCascade* m_font { nullptr }; 73 TextPaintStyle m_ textPaintStyle;74 TextPaintStyle m_selection PaintStyle;75 const ShadowData* m_ textShadow { nullptr };78 TextPaintStyle m_style; 79 TextPaintStyle m_selectionStyle; 80 const ShadowData* m_shadow { nullptr }; 76 81 const ShadowData* m_selectionShadow { nullptr }; 77 82 AtomicString m_emphasisMark; … … 81 86 }; 82 87 83 inline void TextPainter:: addEmphasis(const AtomicString& emphasisMark, float emphasisMarkOffset, RenderCombineText* combinedText)88 inline void TextPainter::setEmphasisMark(const AtomicString& mark, float offset, RenderCombineText* combinedText) 84 89 { 85 m_emphasisMark = emphasisMark;86 m_emphasisMarkOffset = emphasisMarkOffset;90 m_emphasisMark = mark; 91 m_emphasisMarkOffset = offset; 87 92 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;94 93 } 95 94 … … 115 114 }; 116 115 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 127 116 } // namespace WebCore
Note: See TracChangeset
for help on using the changeset viewer.