| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/paint/TextPainter.h" | 5 #include "core/paint/TextPainter.h" |
| 6 | 6 |
| 7 #include "core/CSSPropertyNames.h" | 7 #include "core/CSSPropertyNames.h" |
| 8 #include "core/frame/Settings.h" | 8 #include "core/frame/Settings.h" |
| 9 #include "core/layout/LayoutObject.h" | 9 #include "core/layout/LayoutObject.h" |
| 10 #include "core/layout/LayoutTextCombine.h" | 10 #include "core/layout/LayoutTextCombine.h" |
| 11 #include "core/layout/api/LineLayoutAPIShim.h" |
| 12 #include "core/layout/api/LineLayoutItem.h" |
| 11 #include "core/layout/line/InlineTextBox.h" | 13 #include "core/layout/line/InlineTextBox.h" |
| 12 #include "core/paint/BoxPainter.h" | 14 #include "core/paint/BoxPainter.h" |
| 13 #include "core/paint/PaintInfo.h" | 15 #include "core/paint/PaintInfo.h" |
| 14 #include "core/style/ComputedStyle.h" | 16 #include "core/style/ComputedStyle.h" |
| 15 #include "core/style/ShadowList.h" | 17 #include "core/style/ShadowList.h" |
| 16 #include "platform/fonts/Font.h" | 18 #include "platform/fonts/Font.h" |
| 17 #include "platform/graphics/GraphicsContext.h" | 19 #include "platform/graphics/GraphicsContext.h" |
| 18 #include "platform/graphics/GraphicsContextStateSaver.h" | 20 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 19 #include "platform/text/TextRun.h" | 21 #include "platform/text/TextRun.h" |
| 20 #include "wtf/Assertions.h" | 22 #include "wtf/Assertions.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 } | 110 } |
| 109 | 111 |
| 110 static Color textColorForWhiteBackground(Color textColor) | 112 static Color textColorForWhiteBackground(Color textColor) |
| 111 { | 113 { |
| 112 int distanceFromWhite = differenceSquared(textColor, Color::white); | 114 int distanceFromWhite = differenceSquared(textColor, Color::white); |
| 113 // semi-arbitrarily chose 65025 (255^2) value here after a few tests; | 115 // semi-arbitrarily chose 65025 (255^2) value here after a few tests; |
| 114 return distanceFromWhite > 65025 ? textColor : textColor.dark(); | 116 return distanceFromWhite > 65025 ? textColor : textColor.dark(); |
| 115 } | 117 } |
| 116 | 118 |
| 117 // static | 119 // static |
| 118 TextPainter::Style TextPainter::textPaintingStyle(const LayoutObject& layoutObje
ct, const ComputedStyle& style, const PaintInfo& paintInfo) | 120 TextPainter::Style TextPainter::textPaintingStyle(LineLayoutItem lineLayoutItem,
const ComputedStyle& style, const PaintInfo& paintInfo) |
| 119 { | 121 { |
| 120 TextPainter::Style textStyle; | 122 TextPainter::Style textStyle; |
| 121 bool isPrinting = paintInfo.isPrinting(); | 123 bool isPrinting = paintInfo.isPrinting(); |
| 122 | 124 |
| 123 if (paintInfo.phase == PaintPhaseTextClip) { | 125 if (paintInfo.phase == PaintPhaseTextClip) { |
| 124 // When we use the text as a clip, we only care about the alpha, thus we
make all the colors black. | 126 // When we use the text as a clip, we only care about the alpha, thus we
make all the colors black. |
| 125 textStyle.currentColor = Color::black; | 127 textStyle.currentColor = Color::black; |
| 126 textStyle.fillColor = Color::black; | 128 textStyle.fillColor = Color::black; |
| 127 textStyle.strokeColor = Color::black; | 129 textStyle.strokeColor = Color::black; |
| 128 textStyle.emphasisMarkColor = Color::black; | 130 textStyle.emphasisMarkColor = Color::black; |
| 129 textStyle.strokeWidth = style.textStrokeWidth(); | 131 textStyle.strokeWidth = style.textStrokeWidth(); |
| 130 textStyle.shadow = 0; | 132 textStyle.shadow = 0; |
| 131 } else { | 133 } else { |
| 132 textStyle.currentColor = style.visitedDependentColor(CSSPropertyColor); | 134 textStyle.currentColor = style.visitedDependentColor(CSSPropertyColor); |
| 133 textStyle.fillColor = layoutObject.resolveColor(style, CSSPropertyWebkit
TextFillColor); | 135 textStyle.fillColor = lineLayoutItem.resolveColor(style, CSSPropertyWebk
itTextFillColor); |
| 134 textStyle.strokeColor = layoutObject.resolveColor(style, CSSPropertyWebk
itTextStrokeColor); | 136 textStyle.strokeColor = lineLayoutItem.resolveColor(style, CSSPropertyWe
bkitTextStrokeColor); |
| 135 textStyle.emphasisMarkColor = layoutObject.resolveColor(style, CSSProper
tyWebkitTextEmphasisColor); | 137 textStyle.emphasisMarkColor = lineLayoutItem.resolveColor(style, CSSProp
ertyWebkitTextEmphasisColor); |
| 136 textStyle.strokeWidth = style.textStrokeWidth(); | 138 textStyle.strokeWidth = style.textStrokeWidth(); |
| 137 textStyle.shadow = style.textShadow(); | 139 textStyle.shadow = style.textShadow(); |
| 138 | 140 |
| 139 // Adjust text color when printing with a white background. | 141 // Adjust text color when printing with a white background. |
| 140 ASSERT(layoutObject.document().printing() == isPrinting); | 142 ASSERT(lineLayoutItem.document().printing() == isPrinting); |
| 141 bool forceBackgroundToWhite = BoxPainter::shouldForceWhiteBackgroundForP
rintEconomy(style, layoutObject.document()); | 143 bool forceBackgroundToWhite = BoxPainter::shouldForceWhiteBackgroundForP
rintEconomy(style, lineLayoutItem.document()); |
| 142 if (forceBackgroundToWhite) { | 144 if (forceBackgroundToWhite) { |
| 143 textStyle.fillColor = textColorForWhiteBackground(textStyle.fillColo
r); | 145 textStyle.fillColor = textColorForWhiteBackground(textStyle.fillColo
r); |
| 144 textStyle.strokeColor = textColorForWhiteBackground(textStyle.stroke
Color); | 146 textStyle.strokeColor = textColorForWhiteBackground(textStyle.stroke
Color); |
| 145 textStyle.emphasisMarkColor = textColorForWhiteBackground(textStyle.
emphasisMarkColor); | 147 textStyle.emphasisMarkColor = textColorForWhiteBackground(textStyle.
emphasisMarkColor); |
| 146 } | 148 } |
| 147 | 149 |
| 148 // Text shadows are disabled when printing. http://crbug.com/258321 | 150 // Text shadows are disabled when printing. http://crbug.com/258321 |
| 149 if (isPrinting) | 151 if (isPrinting) |
| 150 textStyle.shadow = 0; | 152 textStyle.shadow = 0; |
| 151 } | 153 } |
| 152 | 154 |
| 153 return textStyle; | 155 return textStyle; |
| 154 } | 156 } |
| 155 | 157 |
| 156 TextPainter::Style TextPainter::selectionPaintingStyle(const LayoutObject& layou
tObject, bool haveSelection, const PaintInfo& paintInfo, const TextPainter::Styl
e& textStyle) | 158 TextPainter::Style TextPainter::selectionPaintingStyle(LineLayoutItem lineLayout
Item, bool haveSelection, const PaintInfo& paintInfo, const TextPainter::Style&
textStyle) |
| 157 { | 159 { |
| 160 const LayoutObject& layoutObject = *LineLayoutAPIShim::constLayoutObjectFrom
(lineLayoutItem); |
| 158 TextPainter::Style selectionStyle = textStyle; | 161 TextPainter::Style selectionStyle = textStyle; |
| 159 bool usesTextAsClip = paintInfo.phase == PaintPhaseTextClip; | 162 bool usesTextAsClip = paintInfo.phase == PaintPhaseTextClip; |
| 160 bool isPrinting = paintInfo.isPrinting(); | 163 bool isPrinting = paintInfo.isPrinting(); |
| 161 | 164 |
| 162 if (haveSelection) { | 165 if (haveSelection) { |
| 163 if (!usesTextAsClip) { | 166 if (!usesTextAsClip) { |
| 164 selectionStyle.fillColor = layoutObject.selectionForegroundColor(pai
ntInfo.globalPaintFlags()); | 167 selectionStyle.fillColor = layoutObject.selectionForegroundColor(pai
ntInfo.globalPaintFlags()); |
| 165 selectionStyle.emphasisMarkColor = layoutObject.selectionEmphasisMar
kColor(paintInfo.globalPaintFlags()); | 168 selectionStyle.emphasisMarkColor = layoutObject.selectionEmphasisMar
kColor(paintInfo.globalPaintFlags()); |
| 166 } | 169 } |
| 167 | 170 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 TextRun placeholderTextRun(&ideographicFullStopCharacter, 1); | 223 TextRun placeholderTextRun(&ideographicFullStopCharacter, 1); |
| 221 FloatPoint emphasisMarkTextOrigin(m_textBounds.x().toFloat(), m_textBounds.y
().toFloat() + m_font.fontMetrics().ascent() + m_emphasisMarkOffset); | 224 FloatPoint emphasisMarkTextOrigin(m_textBounds.x().toFloat(), m_textBounds.y
().toFloat() + m_font.fontMetrics().ascent() + m_emphasisMarkOffset); |
| 222 TextRunPaintInfo textRunPaintInfo(placeholderTextRun); | 225 TextRunPaintInfo textRunPaintInfo(placeholderTextRun); |
| 223 textRunPaintInfo.bounds = FloatRect(m_textBounds); | 226 textRunPaintInfo.bounds = FloatRect(m_textBounds); |
| 224 m_graphicsContext.concatCTM(rotation(m_textBounds, Clockwise)); | 227 m_graphicsContext.concatCTM(rotation(m_textBounds, Clockwise)); |
| 225 m_graphicsContext.drawEmphasisMarks(m_combinedText->originalFont(), textRunP
aintInfo, m_emphasisMark, emphasisMarkTextOrigin); | 228 m_graphicsContext.drawEmphasisMarks(m_combinedText->originalFont(), textRunP
aintInfo, m_emphasisMark, emphasisMarkTextOrigin); |
| 226 m_graphicsContext.concatCTM(rotation(m_textBounds, Counterclockwise)); | 229 m_graphicsContext.concatCTM(rotation(m_textBounds, Counterclockwise)); |
| 227 } | 230 } |
| 228 | 231 |
| 229 } // namespace blink | 232 } // namespace blink |
| OLD | NEW |