Title: [234533] branches/safari-606-branch/Source/WebCore
Revision
234533
Author
[email protected]
Date
2018-08-02 18:16:49 -0700 (Thu, 02 Aug 2018)

Log Message

Cherry-pick r234512. rdar://problem/42882298

    Text selection color is hard to see in dark mode web views.
    https://bugs.webkit.org/show_bug.cgi?id=188260
    rdar://problem/42721294

    Reviewed by Simon Fraser.

    Stop using blendWithWhite() to transform the AppKit selection color in dark mode.
    Using an alpha of 80% gives good contrast, and still works good for selections over images.

    * platform/graphics/Color.cpp:
    (WebCore::Color::blendWithWhite const): Mark new colors as semantic if the original is.
    (WebCore::Color::colorWithAlpha const): Ditto.
    * rendering/RenderElement.cpp:
    (WebCore::RenderElement::selectionBackgroundColor const): Use transformSelectionBackgroundColor.
    * rendering/RenderTheme.cpp:
    (WebCore::RenderTheme::activeSelectionBackgroundColor const): Use transformSelectionBackgroundColor.
    (WebCore::RenderTheme::inactiveSelectionBackgroundColor const): Ditto.
    (WebCore::RenderTheme::transformSelectionBackgroundColor const): Added. Just blend with white.
    * rendering/RenderTheme.h:
    * rendering/RenderThemeMac.h:
    * rendering/RenderThemeMac.mm:
    (WebCore::RenderThemeMac::transformSelectionBackgroundColor const): Added. Use an alpha with the color
    in dark mode, otherwise fallback to RenderTheme.
    (WebCore::RenderThemeMac::systemColor const): Use activeListBoxSelectionBackgroundColor()
    and activeSelectionBackgroundColor() instead of caching the colors again. Update hardcoded color.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234512 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-606-branch/Source/WebCore/ChangeLog (234532 => 234533)


--- branches/safari-606-branch/Source/WebCore/ChangeLog	2018-08-03 01:16:46 UTC (rev 234532)
+++ branches/safari-606-branch/Source/WebCore/ChangeLog	2018-08-03 01:16:49 UTC (rev 234533)
@@ -1,5 +1,66 @@
 2018-08-02  Babak Shafiei  <[email protected]>
 
+        Cherry-pick r234512. rdar://problem/42882298
+
+    Text selection color is hard to see in dark mode web views.
+    https://bugs.webkit.org/show_bug.cgi?id=188260
+    rdar://problem/42721294
+    
+    Reviewed by Simon Fraser.
+    
+    Stop using blendWithWhite() to transform the AppKit selection color in dark mode.
+    Using an alpha of 80% gives good contrast, and still works good for selections over images.
+    
+    * platform/graphics/Color.cpp:
+    (WebCore::Color::blendWithWhite const): Mark new colors as semantic if the original is.
+    (WebCore::Color::colorWithAlpha const): Ditto.
+    * rendering/RenderElement.cpp:
+    (WebCore::RenderElement::selectionBackgroundColor const): Use transformSelectionBackgroundColor.
+    * rendering/RenderTheme.cpp:
+    (WebCore::RenderTheme::activeSelectionBackgroundColor const): Use transformSelectionBackgroundColor.
+    (WebCore::RenderTheme::inactiveSelectionBackgroundColor const): Ditto.
+    (WebCore::RenderTheme::transformSelectionBackgroundColor const): Added. Just blend with white.
+    * rendering/RenderTheme.h:
+    * rendering/RenderThemeMac.h:
+    * rendering/RenderThemeMac.mm:
+    (WebCore::RenderThemeMac::transformSelectionBackgroundColor const): Added. Use an alpha with the color
+    in dark mode, otherwise fallback to RenderTheme.
+    (WebCore::RenderThemeMac::systemColor const): Use activeListBoxSelectionBackgroundColor()
+    and activeSelectionBackgroundColor() instead of caching the colors again. Update hardcoded color.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234512 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2018-08-02  Timothy Hatcher  <[email protected]>
+
+            Text selection color is hard to see in dark mode web views.
+            https://bugs.webkit.org/show_bug.cgi?id=188260
+            rdar://problem/42721294
+
+            Reviewed by Simon Fraser.
+
+            Stop using blendWithWhite() to transform the AppKit selection color in dark mode.
+            Using an alpha of 80% gives good contrast, and still works good for selections over images.
+
+            * platform/graphics/Color.cpp:
+            (WebCore::Color::blendWithWhite const): Mark new colors as semantic if the original is.
+            (WebCore::Color::colorWithAlpha const): Ditto.
+            * rendering/RenderElement.cpp:
+            (WebCore::RenderElement::selectionBackgroundColor const): Use transformSelectionBackgroundColor.
+            * rendering/RenderTheme.cpp:
+            (WebCore::RenderTheme::activeSelectionBackgroundColor const): Use transformSelectionBackgroundColor.
+            (WebCore::RenderTheme::inactiveSelectionBackgroundColor const): Ditto.
+            (WebCore::RenderTheme::transformSelectionBackgroundColor const): Added. Just blend with white.
+            * rendering/RenderTheme.h:
+            * rendering/RenderThemeMac.h:
+            * rendering/RenderThemeMac.mm:
+            (WebCore::RenderThemeMac::transformSelectionBackgroundColor const): Added. Use an alpha with the color
+            in dark mode, otherwise fallback to RenderTheme.
+            (WebCore::RenderThemeMac::systemColor const): Use activeListBoxSelectionBackgroundColor()
+            and activeSelectionBackgroundColor() instead of caching the colors again. Update hardcoded color.
+
+2018-08-02  Babak Shafiei  <[email protected]>
+
         Cherry-pick r234469. rdar://problem/42882308
 
     Always use MediaPlayback audio category when playing to AppleTV

Modified: branches/safari-606-branch/Source/WebCore/platform/graphics/Color.cpp (234532 => 234533)


--- branches/safari-606-branch/Source/WebCore/platform/graphics/Color.cpp	2018-08-03 01:16:46 UTC (rev 234532)
+++ branches/safari-606-branch/Source/WebCore/platform/graphics/Color.cpp	2018-08-03 01:16:49 UTC (rev 234533)
@@ -500,6 +500,9 @@
         if (r >= 0 && g >= 0 && b >= 0)
             break;
     }
+
+    if (isSemantic())
+        newColor.setIsSemantic();
     return newColor;
 }
 
@@ -515,7 +518,11 @@
         return Color { m_colorData.extendedColor->red(), m_colorData.extendedColor->green(), m_colorData.extendedColor->blue(), alpha, m_colorData.extendedColor->colorSpace() };
 
     int newAlpha = alpha * 255;
-    return Color { red(), green(), blue(), newAlpha };
+
+    Color result = { red(), green(), blue(), newAlpha };
+    if (isSemantic())
+        result.setIsSemantic();
+    return result;
 }
 
 void Color::getRGBA(float& r, float& g, float& b, float& a) const

Modified: branches/safari-606-branch/Source/WebCore/rendering/RenderElement.cpp (234532 => 234533)


--- branches/safari-606-branch/Source/WebCore/rendering/RenderElement.cpp	2018-08-03 01:16:46 UTC (rev 234532)
+++ branches/safari-606-branch/Source/WebCore/rendering/RenderElement.cpp	2018-08-03 01:16:49 UTC (rev 234533)
@@ -1407,11 +1407,11 @@
         return Color();
 
     if (frame().selection().shouldShowBlockCursor() && frame().selection().isCaret())
-        return style().visitedDependentColorWithColorFilter(CSSPropertyColor).blendWithWhite();
+        return theme().transformSelectionBackgroundColor(style().visitedDependentColorWithColorFilter(CSSPropertyColor), document().styleColorOptions());
 
     std::unique_ptr<RenderStyle> pseudoStyle = selectionPseudoStyle();
     if (pseudoStyle && pseudoStyle->visitedDependentColorWithColorFilter(CSSPropertyBackgroundColor).isValid())
-        return pseudoStyle->visitedDependentColorWithColorFilter(CSSPropertyBackgroundColor).blendWithWhite();
+        return theme().transformSelectionBackgroundColor(pseudoStyle->visitedDependentColorWithColorFilter(CSSPropertyBackgroundColor), document().styleColorOptions());
 
     if (frame().selection().isFocusedAndActive())
         return theme().activeSelectionBackgroundColor(document().styleColorOptions());

Modified: branches/safari-606-branch/Source/WebCore/rendering/RenderTheme.cpp (234532 => 234533)


--- branches/safari-606-branch/Source/WebCore/rendering/RenderTheme.cpp	2018-08-03 01:16:46 UTC (rev 234532)
+++ branches/safari-606-branch/Source/WebCore/rendering/RenderTheme.cpp	2018-08-03 01:16:49 UTC (rev 234533)
@@ -584,7 +584,7 @@
 {
     auto& cache = colorCache(options);
     if (!cache.activeSelectionBackgroundColor.isValid())
-        cache.activeSelectionBackgroundColor = platformActiveSelectionBackgroundColor(options).blendWithWhite();
+        cache.activeSelectionBackgroundColor = transformSelectionBackgroundColor(platformActiveSelectionBackgroundColor(options), options);
     return cache.activeSelectionBackgroundColor;
 }
 
@@ -592,10 +592,15 @@
 {
     auto& cache = colorCache(options);
     if (!cache.inactiveSelectionBackgroundColor.isValid())
-        cache.inactiveSelectionBackgroundColor = platformInactiveSelectionBackgroundColor(options).blendWithWhite();
+        cache.inactiveSelectionBackgroundColor = transformSelectionBackgroundColor(platformInactiveSelectionBackgroundColor(options), options);
     return cache.inactiveSelectionBackgroundColor;
 }
 
+Color RenderTheme::transformSelectionBackgroundColor(const Color& color, OptionSet<StyleColor::Options>) const
+{
+    return color.blendWithWhite();
+}
+
 Color RenderTheme::activeSelectionForegroundColor(OptionSet<StyleColor::Options> options) const
 {
     auto& cache = colorCache(options);

Modified: branches/safari-606-branch/Source/WebCore/rendering/RenderTheme.h (234532 => 234533)


--- branches/safari-606-branch/Source/WebCore/rendering/RenderTheme.h	2018-08-03 01:16:46 UTC (rev 234532)
+++ branches/safari-606-branch/Source/WebCore/rendering/RenderTheme.h	2018-08-03 01:16:49 UTC (rev 234533)
@@ -139,6 +139,7 @@
     // Text selection colors.
     Color activeSelectionBackgroundColor(OptionSet<StyleColor::Options>) const;
     Color inactiveSelectionBackgroundColor(OptionSet<StyleColor::Options>) const;
+    virtual Color transformSelectionBackgroundColor(const Color&, OptionSet<StyleColor::Options>) const;
     Color activeSelectionForegroundColor(OptionSet<StyleColor::Options>) const;
     Color inactiveSelectionForegroundColor(OptionSet<StyleColor::Options>) const;
 
@@ -415,8 +416,6 @@
         Color systemVisitedLinkColor;
         Color systemFocusRingColor;
         Color systemControlAccentColor;
-        Color systemSelectedTextBackgroundColor;
-        Color systemSelectedContentBackgroundColor;
 
         Color activeSelectionBackgroundColor;
         Color inactiveSelectionBackgroundColor;

Modified: branches/safari-606-branch/Source/WebCore/rendering/RenderThemeMac.h (234532 => 234533)


--- branches/safari-606-branch/Source/WebCore/rendering/RenderThemeMac.h	2018-08-03 01:16:46 UTC (rev 234532)
+++ branches/safari-606-branch/Source/WebCore/rendering/RenderThemeMac.h	2018-08-03 01:16:49 UTC (rev 234533)
@@ -55,6 +55,7 @@
 
     Color platformActiveSelectionBackgroundColor(OptionSet<StyleColor::Options>) const final;
     Color platformActiveSelectionForegroundColor(OptionSet<StyleColor::Options>) const final;
+    Color transformSelectionBackgroundColor(const Color&, OptionSet<StyleColor::Options>) const final;
     Color platformInactiveSelectionBackgroundColor(OptionSet<StyleColor::Options>) const final;
     Color platformInactiveSelectionForegroundColor(OptionSet<StyleColor::Options>) const final;
     Color platformActiveListBoxSelectionBackgroundColor(OptionSet<StyleColor::Options>) const final;

Modified: branches/safari-606-branch/Source/WebCore/rendering/RenderThemeMac.mm (234532 => 234533)


--- branches/safari-606-branch/Source/WebCore/rendering/RenderThemeMac.mm	2018-08-03 01:16:46 UTC (rev 234532)
+++ branches/safari-606-branch/Source/WebCore/rendering/RenderThemeMac.mm	2018-08-03 01:16:49 UTC (rev 234533)
@@ -338,6 +338,18 @@
 #endif
 }
 
+Color RenderThemeMac::transformSelectionBackgroundColor(const Color& color, OptionSet<StyleColor::Options> options) const
+{
+    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseSystemAppearance), options.contains(StyleColor::Options::UseDarkAppearance));
+    if (localAppearance.usingDarkAppearance()) {
+        // Use an alpha value that is similar to results from blendWithWhite() on light colors.
+        static const float darkAppearanceAlpha = 0.8;
+        return !color.isOpaque() ? color : color.colorWithAlpha(darkAppearanceAlpha);
+    }
+
+    return RenderTheme::transformSelectionBackgroundColor(color, options);
+}
+
 bool RenderThemeMac::supportsSelectionForegroundColors(OptionSet<StyleColor::Options> options) const
 {
     LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseSystemAppearance), options.contains(StyleColor::Options::UseDarkAppearance));
@@ -585,22 +597,12 @@
 #endif
 
         case CSSValueAppleSystemSelectedContentBackground:
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
-            return systemAppearanceColor(cache.systemSelectedContentBackgroundColor, @selector(selectedContentBackgroundColor));
-#else
-            return systemAppearanceColor(cache.systemSelectedContentBackgroundColor, @selector(alternateSelectedControlColor));
-#endif
+            return activeListBoxSelectionBackgroundColor(options);
 
         case CSSValueAppleSystemSelectedTextBackground:
         case CSSValueHighlight:
-            // Can't use systemAppearanceColor() since blendWithWhite() needs called before caching as a semantic color.
-            if (!cache.systemSelectedTextBackgroundColor.isValid()) {
-                Color systemColor = semanticColorFromNSColor([NSColor selectedTextBackgroundColor]);
-                cache.systemSelectedTextBackgroundColor = Color(systemColor.blendWithWhite().rgb(), Color::Semantic);
-            }
+            return activeSelectionBackgroundColor(options);
 
-            return cache.systemSelectedTextBackgroundColor;
-
         default:
             // Handle other system colors below, that don't need special system appearance handling.
             break;
@@ -783,7 +785,7 @@
         case CSSValueAppleSystemSelectedTextBackground:
             // Hardcoded to avoid exposing a user appearance preference to the web for fingerprinting.
             if (localAppearance.usingDarkAppearance())
-                return Color(0xCC0F3C6E, Color::Semantic);
+                return Color(0xCC3F638B, Color::Semantic);
             return Color(0x9980BCFE, Color::Semantic);
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to