[GTK] Menu list button doesn't use the text color from the theme
[WebKit-https.git] / Source / WebCore / rendering / TextPaintStyle.cpp
index 8b8f91b..e1debbb 100644 (file)
 #include "config.h"
 #include "TextPaintStyle.h"
 
+#include "FocusController.h"
 #include "Frame.h"
 #include "GraphicsContext.h"
+#include "Page.h"
 #include "PaintInfo.h"
 #include "RenderStyle.h"
 #include "RenderText.h"
+#include "RenderTheme.h"
 #include "RenderView.h"
 #include "Settings.h"
 
 namespace WebCore {
 
-TextPaintStyle::TextPaintStyle(ColorSpace colorSpace)
-    : colorSpace(colorSpace)
-    , strokeWidth(0)
-{
-}
-
-TextPaintStyle::TextPaintStyle(Color color, ColorSpace colorSpace)
-    : colorSpace(colorSpace)
-    , fillColor(color)
+TextPaintStyle::TextPaintStyle(const Color& color)
+    : fillColor(color)
     , strokeColor(color)
-    , strokeWidth(0)
 {
 }
 
-static Color adjustColorForVisibilityOnBackground(Color textColor, Color backgroundColor)
+static Color adjustColorForVisibilityOnBackground(const Color& textColor, const Color& backgroundColor)
 {
     int d = differenceSquared(textColor, backgroundColor);
     // Semi-arbitrarily chose 65025 (255^2) value here after a few tests.
@@ -65,25 +60,37 @@ static Color adjustColorForVisibilityOnBackground(Color textColor, Color backgro
     return textColor.light();
 }
 
-TextPaintStyle computeTextPaintStyle(const RenderText& renderer, const RenderStyle& lineStyle, const PaintInfo& paintInfo)
+TextPaintStyle computeTextPaintStyle(const Frame& frame, const RenderStyle& lineStyle, const PaintInfo& paintInfo)
 {
-    TextPaintStyle paintStyle(lineStyle.colorSpace());
+    TextPaintStyle paintStyle;
 
+#if ENABLE(LETTERPRESS)
+    paintStyle.useLetterpressEffect = lineStyle.textDecorationsInEffect() & TextDecorationLetterpress;
+#endif
     paintStyle.strokeWidth = lineStyle.textStrokeWidth();
 
-    if (paintInfo.forceBlackText()) {
-        paintStyle.fillColor = Color::black;
-        paintStyle.strokeColor = Color::black;
-        paintStyle.emphasisMarkColor = Color::black;
+    if (paintInfo.forceTextColor()) {
+        paintStyle.fillColor = paintInfo.forcedTextColor();
+        paintStyle.strokeColor = paintInfo.forcedTextColor();
+        paintStyle.emphasisMarkColor = paintInfo.forcedTextColor();
         return paintStyle;
     }
+
+    if (lineStyle.insideDefaultButton()) {
+        Page* page = frame.page();
+        if (page && page->focusController().isActive()) {
+            paintStyle.fillColor = page->theme().systemColor(CSSValueActivebuttontext);
+            return paintStyle;
+        }
+    }
+
     paintStyle.fillColor = lineStyle.visitedDependentColor(CSSPropertyWebkitTextFillColor);
 
     bool forceBackgroundToWhite = false;
-    if (renderer.document().printing()) {
+    if (frame.document() && frame.document()->printing()) {
         if (lineStyle.printColorAdjust() == PrintColorAdjustEconomy)
             forceBackgroundToWhite = true;
-        if (renderer.frame().settings().shouldPrintBackgrounds())
+        if (frame.settings().shouldPrintBackgrounds())
             forceBackgroundToWhite = false;
     }
 
@@ -110,19 +117,19 @@ TextPaintStyle computeTextSelectionPaintStyle(const TextPaintStyle& textPaintSty
 {
     paintSelectedTextOnly = (paintInfo.phase == PaintPhaseSelection);
     paintSelectedTextSeparately = false;
-    selectionShadow = paintInfo.forceBlackText() ? nullptr : lineStyle.textShadow();
+    selectionShadow = (paintInfo.forceTextColor()) ? nullptr : lineStyle.textShadow();
 
     TextPaintStyle selectionPaintStyle = textPaintStyle;
 
 #if ENABLE(TEXT_SELECTION)
-    Color foreground = paintInfo.forceBlackText() ? Color::black : renderer.selectionForegroundColor();
+    Color foreground = paintInfo.forceTextColor() ? paintInfo.forcedTextColor() : renderer.selectionForegroundColor();
     if (foreground.isValid() && foreground != selectionPaintStyle.fillColor) {
         if (!paintSelectedTextOnly)
             paintSelectedTextSeparately = true;
         selectionPaintStyle.fillColor = foreground;
     }
 
-    Color emphasisMarkForeground = paintInfo.forceBlackText() ? Color::black : renderer.selectionEmphasisMarkColor();
+    Color emphasisMarkForeground = paintInfo.forceTextColor() ? paintInfo.forcedTextColor() : renderer.selectionEmphasisMarkColor();
     if (emphasisMarkForeground.isValid() && emphasisMarkForeground != selectionPaintStyle.emphasisMarkColor) {
         if (!paintSelectedTextOnly)
             paintSelectedTextSeparately = true;
@@ -130,7 +137,7 @@ TextPaintStyle computeTextSelectionPaintStyle(const TextPaintStyle& textPaintSty
     }
 
     if (RenderStyle* pseudoStyle = renderer.getCachedPseudoStyle(SELECTION)) {
-        const ShadowData* shadow = paintInfo.forceBlackText() ? 0 : pseudoStyle->textShadow();
+        const ShadowData* shadow = paintInfo.forceTextColor() ? nullptr : pseudoStyle->textShadow();
         if (shadow != selectionShadow) {
             if (!paintSelectedTextOnly)
                 paintSelectedTextSeparately = true;
@@ -144,7 +151,7 @@ TextPaintStyle computeTextSelectionPaintStyle(const TextPaintStyle& textPaintSty
             selectionPaintStyle.strokeWidth = strokeWidth;
         }
 
-        Color stroke = paintInfo.forceBlackText() ? Color::black : pseudoStyle->visitedDependentColor(CSSPropertyWebkitTextStrokeColor);
+        Color stroke = paintInfo.forceTextColor() ? paintInfo.forcedTextColor() : pseudoStyle->visitedDependentColor(CSSPropertyWebkitTextStrokeColor);
         if (stroke != selectionPaintStyle.strokeColor) {
             if (!paintSelectedTextOnly)
                 paintSelectedTextSeparately = true;
@@ -162,21 +169,27 @@ TextPaintStyle computeTextSelectionPaintStyle(const TextPaintStyle& textPaintSty
 void updateGraphicsContext(GraphicsContext& context, const TextPaintStyle& paintStyle, FillColorType fillColorType)
 {
     TextDrawingModeFlags mode = context.textDrawingMode();
-    if (paintStyle.strokeWidth > 0) {
-        TextDrawingModeFlags newMode = mode | TextModeStroke;
-        if (mode != newMode) {
-            context.setTextDrawingMode(newMode);
-            mode = newMode;
-        }
+    TextDrawingModeFlags newMode = mode;
+#if ENABLE(LETTERPRESS)
+    if (paintStyle.useLetterpressEffect)
+        newMode |= TextModeLetterpress;
+    else
+        newMode &= ~TextModeLetterpress;
+#endif
+    if (paintStyle.strokeWidth > 0)
+        newMode |= TextModeStroke;
+    if (mode != newMode) {
+        context.setTextDrawingMode(newMode);
+        mode = newMode;
     }
-    
+
     Color fillColor = fillColorType == UseEmphasisMarkColor ? paintStyle.emphasisMarkColor : paintStyle.fillColor;
-    if (mode & TextModeFill && (fillColor != context.fillColor() || paintStyle.colorSpace != context.fillColorSpace()))
-        context.setFillColor(fillColor, paintStyle.colorSpace);
+    if (mode & TextModeFill && (fillColor != context.fillColor()))
+        context.setFillColor(fillColor);
 
     if (mode & TextModeStroke) {
         if (paintStyle.strokeColor != context.strokeColor())
-            context.setStrokeColor(paintStyle.strokeColor, paintStyle.colorSpace);
+            context.setStrokeColor(paintStyle.strokeColor);
         if (paintStyle.strokeWidth != context.strokeThickness())
             context.setStrokeThickness(paintStyle.strokeWidth);
     }