Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(974)

Unified Diff: Source/core/rendering/InlineTextBox.cpp

Issue 367973003: Refactor color selection out of InlineTextBox::paint. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/rendering/InlineTextBox.cpp
diff --git a/Source/core/rendering/InlineTextBox.cpp b/Source/core/rendering/InlineTextBox.cpp
index 9c1874312ef4a693554b85868fb343c7adfa5af4..7cce10024d65b71a3d648d74b5dce9507ef06be4 100644
--- a/Source/core/rendering/InlineTextBox.cpp
+++ b/Source/core/rendering/InlineTextBox.cpp
@@ -474,6 +474,91 @@ bool InlineTextBox::getEmphasisMarkPosition(RenderStyle* style, TextEmphasisPosi
return !rubyText || !rubyText->firstLineBox();
}
+namespace {
+
+struct TextPaintingStyle {
+ Color fillColor;
+ Color strokeColor;
+ Color emphasisMarkColor;
+ float strokeWidth;
+ const ShadowList* shadow;
+
+ bool operator==(const TextPaintingStyle& other)
+ {
+ return fillColor == other.fillColor
+ && strokeColor == other.strokeColor
+ && emphasisMarkColor == other.emphasisMarkColor
+ && strokeWidth == other.strokeWidth
+ && shadow == other.shadow;
+ }
+ bool operator!=(const TextPaintingStyle& other) { return !(*this == other); }
+};
+
+TextPaintingStyle textPaintingStyle(RenderText& renderer, RenderStyle* style, bool forceBlackText, bool isPrinting)
+{
+ TextPaintingStyle textStyle;
+
+ if (forceBlackText) {
+ textStyle.fillColor = Color::black;
+ textStyle.strokeColor = Color::black;
+ textStyle.emphasisMarkColor = Color::black;
+ textStyle.strokeWidth = style->textStrokeWidth();
+ textStyle.shadow = 0;
+ } else {
+ textStyle.fillColor = renderer.resolveColor(style, CSSPropertyWebkitTextFillColor);
+ textStyle.strokeColor = renderer.resolveColor(style, CSSPropertyWebkitTextStrokeColor);
+ textStyle.emphasisMarkColor = renderer.resolveColor(style, CSSPropertyWebkitTextEmphasisColor);
+ textStyle.strokeWidth = style->textStrokeWidth();
+ textStyle.shadow = style->textShadow();
+
+ // Adjust text color when printing with a white background.
+ bool forceBackgroundToWhite = false;
+ if (isPrinting) {
+ if (style->printColorAdjust() == PrintColorAdjustEconomy)
+ forceBackgroundToWhite = true;
+ if (renderer.document().settings() && renderer.document().settings()->shouldPrintBackgrounds())
+ forceBackgroundToWhite = false;
+ }
+ if (forceBackgroundToWhite) {
+ textStyle.fillColor = correctedTextColor(textStyle.fillColor, Color::white);
+ textStyle.strokeColor = correctedTextColor(textStyle.strokeColor, Color::white);
+ textStyle.emphasisMarkColor = correctedTextColor(textStyle.emphasisMarkColor, Color::white);
+ }
+
+ // Text shadows are disabled when printing. http://crbug.com/258321
+ if (isPrinting)
+ textStyle.shadow = 0;
+ }
+
+ return textStyle;
+}
+
+TextPaintingStyle selectionPaintingStyle(RenderText& renderer, bool haveSelection, bool forceBlackText, bool isPrinting, const TextPaintingStyle& textStyle)
+{
+ TextPaintingStyle selectionStyle = textStyle;
+
+ if (haveSelection) {
+ if (!forceBlackText) {
+ selectionStyle.fillColor = renderer.selectionForegroundColor();
+ selectionStyle.emphasisMarkColor = renderer.selectionEmphasisMarkColor();
+ }
+
+ if (RenderStyle* pseudoStyle = renderer.getCachedPseudoStyle(SELECTION)) {
+ selectionStyle.strokeColor = forceBlackText ? Color::black : renderer.resolveColor(pseudoStyle, CSSPropertyWebkitTextStrokeColor);
+ selectionStyle.strokeWidth = pseudoStyle->textStrokeWidth();
+ selectionStyle.shadow = forceBlackText ? 0 : pseudoStyle->textShadow();
+ }
+
+ // Text shadows are disabled when printing. http://crbug.com/258321
+ if (isPrinting)
+ selectionStyle.shadow = 0;
+ }
+
+ return selectionStyle;
+}
+
+} // namespace
+
void InlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit /*lineTop*/, LayoutUnit /*lineBottom*/)
{
if (isLineBreak() || !paintInfo.shouldPaintWithinRoot(&renderer()) || renderer().style()->visibility() != VISIBLE
@@ -545,101 +630,16 @@ void InlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset,
bool containsComposition = renderer().node() && renderer().frame()->inputMethodController().compositionNode() == renderer().node();
bool useCustomUnderlines = containsComposition && renderer().frame()->inputMethodController().compositionUsesCustomUnderlines();
- // Determine the text colors and selection colors.
- Color textFillColor;
- Color textStrokeColor;
- Color emphasisMarkColor;
- float textStrokeWidth = styleToUse->textStrokeWidth();
-
- // Text shadows are disabled when printing. http://crbug.com/258321
- const ShadowList* textShadow = (context->printing() || paintInfo.forceBlackText()) ? 0 : styleToUse->textShadow();
-
- if (paintInfo.forceBlackText()) {
- textFillColor = Color::black;
- textStrokeColor = Color::black;
- emphasisMarkColor = Color::black;
- } else {
- textFillColor = renderer().resolveColor(styleToUse, CSSPropertyWebkitTextFillColor);
-
- bool forceBackgroundToWhite = false;
- if (isPrinting) {
- if (styleToUse->printColorAdjust() == PrintColorAdjustEconomy)
- forceBackgroundToWhite = true;
- if (textRenderer().document().settings() && textRenderer().document().settings()->shouldPrintBackgrounds())
- forceBackgroundToWhite = false;
- }
-
- // Make the text fill color legible against a white background
- if (forceBackgroundToWhite)
- textFillColor = correctedTextColor(textFillColor, Color::white);
-
- textStrokeColor = renderer().resolveColor(styleToUse, CSSPropertyWebkitTextStrokeColor);
-
- // Make the text stroke color legible against a white background
- if (forceBackgroundToWhite)
- textStrokeColor = correctedTextColor(textStrokeColor, Color::white);
-
- emphasisMarkColor = renderer().resolveColor(styleToUse, CSSPropertyWebkitTextEmphasisColor);
-
- // Make the text stroke color legible against a white background
- if (forceBackgroundToWhite)
- emphasisMarkColor = correctedTextColor(emphasisMarkColor, Color::white);
- }
-
+ // Determine text colors.
+ TextPaintingStyle textStyle = textPaintingStyle(textRenderer(), styleToUse, paintInfo.forceBlackText(), isPrinting);
+ TextPaintingStyle selectionStyle = selectionPaintingStyle(textRenderer(), haveSelection, paintInfo.forceBlackText(), isPrinting, textStyle);
bool paintSelectedTextOnly = (paintInfo.phase == PaintPhaseSelection);
- bool paintSelectedTextSeparately = false;
-
- Color selectionFillColor = textFillColor;
- Color selectionStrokeColor = textStrokeColor;
- Color selectionEmphasisMarkColor = emphasisMarkColor;
- float selectionStrokeWidth = textStrokeWidth;
- const ShadowList* selectionShadow = textShadow;
- if (haveSelection) {
- // Check foreground color first.
- Color foreground = paintInfo.forceBlackText() ? Color::black : renderer().selectionForegroundColor();
- if (foreground != selectionFillColor) {
- if (!paintSelectedTextOnly)
- paintSelectedTextSeparately = true;
- selectionFillColor = foreground;
- }
-
- Color emphasisMarkForeground = paintInfo.forceBlackText() ? Color::black : renderer().selectionEmphasisMarkColor();
- if (emphasisMarkForeground != selectionEmphasisMarkColor) {
- if (!paintSelectedTextOnly)
- paintSelectedTextSeparately = true;
- selectionEmphasisMarkColor = emphasisMarkForeground;
- }
-
- if (RenderStyle* pseudoStyle = renderer().getCachedPseudoStyle(SELECTION)) {
- // Text shadows are disabled when printing. http://crbug.com/258321
- const ShadowList* shadow = (context->printing() || paintInfo.forceBlackText()) ? 0 : pseudoStyle->textShadow();
- if (shadow != selectionShadow) {
- if (!paintSelectedTextOnly)
- paintSelectedTextSeparately = true;
- selectionShadow = shadow;
- }
-
- float strokeWidth = pseudoStyle->textStrokeWidth();
- if (strokeWidth != selectionStrokeWidth) {
- if (!paintSelectedTextOnly)
- paintSelectedTextSeparately = true;
- selectionStrokeWidth = strokeWidth;
- }
-
- Color stroke = paintInfo.forceBlackText() ? Color::black : renderer().resolveColor(pseudoStyle, CSSPropertyWebkitTextStrokeColor);
- if (stroke != selectionStrokeColor) {
- if (!paintSelectedTextOnly)
- paintSelectedTextSeparately = true;
- selectionStrokeColor = stroke;
- }
- }
- }
+ bool paintSelectedTextSeparately = !paintSelectedTextOnly && textStyle != selectionStyle;
// Set our font.
const Font& font = styleToUse->font();
FloatPoint textOrigin = FloatPoint(boxOrigin.x(), boxOrigin.y() + font.fontMetrics().ascent());
-
if (combinedText)
combinedText->adjustTextOrigin(textOrigin, boxRect);
@@ -653,7 +653,7 @@ void InlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset,
paintDocumentMarkers(context, boxOrigin, styleToUse, font, true);
if (haveSelection && !useCustomUnderlines)
- paintSelection(context, boxOrigin, styleToUse, font, selectionFillColor);
+ paintSelection(context, boxOrigin, styleToUse, font, selectionStyle.fillColor);
}
// 2. Now paint the foreground, including text and decorations like underline/overline (in quirks mode only).
@@ -704,33 +704,33 @@ void InlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset,
// 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(*context, textStrokeWidth > 0);
+ GraphicsContextStateSaver stateSaver(*context, textStyle.strokeWidth > 0);
- updateGraphicsContext(context, textFillColor, textStrokeColor, textStrokeWidth);
- paintTextWithShadows(context, font, textRun, nullAtom, 0, startOffset, endOffset, length, textOrigin, boxRect, textShadow, isHorizontal());
+ updateGraphicsContext(context, textStyle.fillColor, textStyle.strokeColor, textStyle.strokeWidth);
+ paintTextWithShadows(context, font, textRun, nullAtom, 0, startOffset, endOffset, length, textOrigin, boxRect, textStyle.shadow, isHorizontal());
if (!emphasisMark.isEmpty())
- paintEmphasisMark(context, emphasisMark, emphasisMarkOffset, startOffset, endOffset, length, font, emphasisMarkColor, textStrokeColor, textStrokeWidth, textShadow, combinedText, textRun, textOrigin, boxRect, isHorizontal());
+ paintEmphasisMark(context, emphasisMark, emphasisMarkOffset, startOffset, endOffset, length, font, textStyle.emphasisMarkColor, textStyle.strokeColor, textStyle.strokeWidth, textStyle.shadow, combinedText, textRun, textOrigin, boxRect, isHorizontal());
}
if ((paintSelectedTextOnly || paintSelectedTextSeparately) && sPos < ePos) {
// paint only the text that is selected
- GraphicsContextStateSaver stateSaver(*context, selectionStrokeWidth > 0);
+ GraphicsContextStateSaver stateSaver(*context, selectionStyle.strokeWidth > 0);
- updateGraphicsContext(context, selectionFillColor, selectionStrokeColor, selectionStrokeWidth);
- paintTextWithShadows(context, font, textRun, nullAtom, 0, sPos, ePos, length, textOrigin, boxRect, selectionShadow, isHorizontal());
+ updateGraphicsContext(context, selectionStyle.fillColor, selectionStyle.strokeColor, selectionStyle.strokeWidth);
+ paintTextWithShadows(context, font, textRun, nullAtom, 0, sPos, ePos, length, textOrigin, boxRect, selectionStyle.shadow, isHorizontal());
if (!emphasisMark.isEmpty())
- paintEmphasisMark(context, emphasisMark, emphasisMarkOffset, sPos, ePos, length, font, selectionEmphasisMarkColor, textStrokeColor, textStrokeWidth, selectionShadow, combinedText, textRun, textOrigin, boxRect, isHorizontal());
+ paintEmphasisMark(context, emphasisMark, emphasisMarkOffset, sPos, ePos, length, font, selectionStyle.emphasisMarkColor, selectionStyle.strokeColor, textStyle.strokeWidth, selectionStyle.shadow, combinedText, textRun, textOrigin, boxRect, isHorizontal());
}
// Paint decorations
TextDecoration textDecorations = styleToUse->textDecorationsInEffect();
if (textDecorations != TextDecorationNone && paintInfo.phase != PaintPhaseSelection) {
- updateGraphicsContext(context, textFillColor, textStrokeColor, textStrokeWidth);
+ updateGraphicsContext(context, textStyle.fillColor, textStyle.strokeColor, textStyle.strokeWidth);
if (combinedText)
context->concatCTM(rotation(boxRect, Clockwise));
- paintDecoration(context, boxOrigin, textDecorations, textShadow);
+ paintDecoration(context, boxOrigin, textDecorations, textStyle.shadow);
if (combinedText)
context->concatCTM(rotation(boxRect, Counterclockwise));
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698