| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/paint/TextPainter.h" | 6 #include "core/paint/TextPainter.h" |
| 7 | 7 |
| 8 #include "core/CSSPropertyNames.h" | 8 #include "core/CSSPropertyNames.h" |
| 9 #include "core/frame/Settings.h" | 9 #include "core/frame/Settings.h" |
| 10 #include "core/rendering/InlineTextBox.h" | 10 #include "core/rendering/InlineTextBox.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 101 } |
| 102 | 102 |
| 103 static Color textColorForWhiteBackground(Color textColor) | 103 static Color textColorForWhiteBackground(Color textColor) |
| 104 { | 104 { |
| 105 int distanceFromWhite = differenceSquared(textColor, Color::white); | 105 int distanceFromWhite = differenceSquared(textColor, Color::white); |
| 106 // semi-arbitrarily chose 65025 (255^2) value here after a few tests; | 106 // semi-arbitrarily chose 65025 (255^2) value here after a few tests; |
| 107 return distanceFromWhite > 65025 ? textColor : textColor.dark(); | 107 return distanceFromWhite > 65025 ? textColor : textColor.dark(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 // static | 110 // static |
| 111 TextPainter::Style TextPainter::textPaintingStyle(RenderObject& renderer, Render
Style* style, bool forceBlackText, bool isPrinting) | 111 TextPainter::Style TextPainter::textPaintingStyle(RenderObject& renderer, const
RenderStyle* style, bool forceBlackText, bool isPrinting) |
| 112 { | 112 { |
| 113 TextPainter::Style textStyle; | 113 TextPainter::Style textStyle; |
| 114 | 114 |
| 115 if (forceBlackText) { | 115 if (forceBlackText) { |
| 116 textStyle.fillColor = Color::black; | 116 textStyle.fillColor = Color::black; |
| 117 textStyle.strokeColor = Color::black; | 117 textStyle.strokeColor = Color::black; |
| 118 textStyle.emphasisMarkColor = Color::black; | 118 textStyle.emphasisMarkColor = Color::black; |
| 119 textStyle.strokeWidth = style->textStrokeWidth(); | 119 textStyle.strokeWidth = style->textStrokeWidth(); |
| 120 textStyle.shadow = 0; | 120 textStyle.shadow = 0; |
| 121 } else { | 121 } else { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 150 TextPainter::Style TextPainter::selectionPaintingStyle(RenderObject& renderer, b
ool haveSelection, bool forceBlackText, bool isPrinting, const TextPainter::Styl
e& textStyle) | 150 TextPainter::Style TextPainter::selectionPaintingStyle(RenderObject& renderer, b
ool haveSelection, bool forceBlackText, bool isPrinting, const TextPainter::Styl
e& textStyle) |
| 151 { | 151 { |
| 152 TextPainter::Style selectionStyle = textStyle; | 152 TextPainter::Style selectionStyle = textStyle; |
| 153 | 153 |
| 154 if (haveSelection) { | 154 if (haveSelection) { |
| 155 if (!forceBlackText) { | 155 if (!forceBlackText) { |
| 156 selectionStyle.fillColor = renderer.selectionForegroundColor(); | 156 selectionStyle.fillColor = renderer.selectionForegroundColor(); |
| 157 selectionStyle.emphasisMarkColor = renderer.selectionEmphasisMarkCol
or(); | 157 selectionStyle.emphasisMarkColor = renderer.selectionEmphasisMarkCol
or(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 if (RenderStyle* pseudoStyle = renderer.getCachedPseudoStyle(SELECTION))
{ | 160 if (const RenderStyle* pseudoStyle = renderer.getCachedPseudoStyle(SELEC
TION)) { |
| 161 selectionStyle.strokeColor = forceBlackText ? Color::black : rendere
r.resolveColor(pseudoStyle, CSSPropertyWebkitTextStrokeColor); | 161 selectionStyle.strokeColor = forceBlackText ? Color::black : rendere
r.resolveColor(pseudoStyle, CSSPropertyWebkitTextStrokeColor); |
| 162 selectionStyle.strokeWidth = pseudoStyle->textStrokeWidth(); | 162 selectionStyle.strokeWidth = pseudoStyle->textStrokeWidth(); |
| 163 selectionStyle.shadow = forceBlackText ? 0 : pseudoStyle->textShadow
(); | 163 selectionStyle.shadow = forceBlackText ? 0 : pseudoStyle->textShadow
(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 // Text shadows are disabled when printing. http://crbug.com/258321 | 166 // Text shadows are disabled when printing. http://crbug.com/258321 |
| 167 if (isPrinting) | 167 if (isPrinting) |
| 168 selectionStyle.shadow = 0; | 168 selectionStyle.shadow = 0; |
| 169 } | 169 } |
| 170 | 170 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 DEFINE_STATIC_LOCAL(TextRun, placeholderTextRun, (&ideographicFullStop, 1)); | 212 DEFINE_STATIC_LOCAL(TextRun, placeholderTextRun, (&ideographicFullStop, 1)); |
| 213 FloatPoint emphasisMarkTextOrigin(m_textBounds.x(), m_textBounds.y() + m_fon
t.fontMetrics().ascent() + m_emphasisMarkOffset); | 213 FloatPoint emphasisMarkTextOrigin(m_textBounds.x(), m_textBounds.y() + m_fon
t.fontMetrics().ascent() + m_emphasisMarkOffset); |
| 214 TextRunPaintInfo textRunPaintInfo(placeholderTextRun); | 214 TextRunPaintInfo textRunPaintInfo(placeholderTextRun); |
| 215 textRunPaintInfo.bounds = m_textBounds; | 215 textRunPaintInfo.bounds = m_textBounds; |
| 216 m_graphicsContext->concatCTM(rotation(m_textBounds, Clockwise)); | 216 m_graphicsContext->concatCTM(rotation(m_textBounds, Clockwise)); |
| 217 m_graphicsContext->drawEmphasisMarks(m_combinedText->originalFont(), textRun
PaintInfo, m_emphasisMark, emphasisMarkTextOrigin); | 217 m_graphicsContext->drawEmphasisMarks(m_combinedText->originalFont(), textRun
PaintInfo, m_emphasisMark, emphasisMarkTextOrigin); |
| 218 m_graphicsContext->concatCTM(rotation(m_textBounds, Counterclockwise)); | 218 m_graphicsContext->concatCTM(rotation(m_textBounds, Counterclockwise)); |
| 219 } | 219 } |
| 220 | 220 |
| 221 } // namespace blink | 221 } // namespace blink |
| OLD | NEW |