Title: [277067] trunk/Source/WebCore
Revision
277067
Author
akeer...@apple.com
Date
2021-05-05 19:34:28 -0700 (Wed, 05 May 2021)

Log Message

[macOS] Use system colors for ActiveButtonText
https://bugs.webkit.org/show_bug.cgi?id=225375
<rdar://problem/75863443>

Reviewed by Tim Horton.

Currently, the ActiveButtonText color keyword returns a hardcoded value
on macOS. This behavior is problematic since AppKit can make changes to
the button style, leaving us with illegible text when a button is
pressed.

To fix, return a system color for ActiveButtonText, so that our pressed
buttons are consistent with the rest of the system.

* rendering/RenderThemeMac.mm:
(WebCore::activeButtonTextColor):

AppKit determines the pressed (active) text color using the cell's
interiorBackgroundStyle. There is not a single system color exposed for
the pressed text color, so it must be determined dynamically.

Unfortunately, this requires us to create an NSButtonCell to determine
the appropriate color. However, this logic is relatively inexpensive,
since we cache exposed system colors.

(WebCore::RenderThemeMac::systemColor const):

Remove the hardcoded value.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (277066 => 277067)


--- trunk/Source/WebCore/ChangeLog	2021-05-06 02:01:06 UTC (rev 277066)
+++ trunk/Source/WebCore/ChangeLog	2021-05-06 02:34:28 UTC (rev 277067)
@@ -1,3 +1,34 @@
+2021-05-05  Aditya Keerthi  <akeer...@apple.com>
+
+        [macOS] Use system colors for ActiveButtonText
+        https://bugs.webkit.org/show_bug.cgi?id=225375
+        <rdar://problem/75863443>
+
+        Reviewed by Tim Horton.
+
+        Currently, the ActiveButtonText color keyword returns a hardcoded value
+        on macOS. This behavior is problematic since AppKit can make changes to
+        the button style, leaving us with illegible text when a button is
+        pressed.
+
+        To fix, return a system color for ActiveButtonText, so that our pressed
+        buttons are consistent with the rest of the system.
+
+        * rendering/RenderThemeMac.mm:
+        (WebCore::activeButtonTextColor):
+
+        AppKit determines the pressed (active) text color using the cell's
+        interiorBackgroundStyle. There is not a single system color exposed for
+        the pressed text color, so it must be determined dynamically.
+
+        Unfortunately, this requires us to create an NSButtonCell to determine
+        the appropriate color. However, this logic is relatively inexpensive,
+        since we cache exposed system colors.
+
+        (WebCore::RenderThemeMac::systemColor const):
+
+        Remove the hardcoded value.
+
 2021-05-05  Cameron McCormack  <hey...@apple.com>
 
         Remove unused DisplayList::Recorder::ContextState::wasUsedForDrawing

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (277066 => 277067)


--- trunk/Source/WebCore/rendering/RenderThemeMac.mm	2021-05-06 02:01:06 UTC (rev 277066)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm	2021-05-06 02:34:28 UTC (rev 277067)
@@ -404,6 +404,25 @@
 }
 #endif
 
+static Color activeButtonTextColor()
+{
+    // FIXME: <rdar://problem/77572622> There is no single corresponding NSColor for ActiveButtonText.
+    // Instead, the NSColor used is dependent on NSButtonCell's interiorBackgroundStyle. Consequently,
+    // we need to create an NSButtonCell just to determine the correct color.
+
+    auto cell = adoptNS([[NSButtonCell alloc] init]);
+    [cell setBezelStyle:NSBezelStyleRounded];
+    [cell setHighlighted:YES];
+
+    NSColor *activeButtonTextColor;
+    if ([cell interiorBackgroundStyle] == NSBackgroundStyleEmphasized)
+        activeButtonTextColor = [NSColor alternateSelectedControlTextColor];
+    else
+        activeButtonTextColor = [NSColor controlTextColor];
+
+    return semanticColorFromNSColor(activeButtonTextColor);
+}
+
 static SRGBA<uint8_t> menuBackgroundColor()
 {
     RetainPtr<NSBitmapImageRep> offscreenRep = adoptNS([[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil pixelsWide:1 pixelsHigh:1
@@ -642,8 +661,7 @@
 
         switch (cssValueID) {
         case CSSValueActivebuttontext:
-            // No corresponding NSColor for this so we use a hard coded value.
-            return Color::white;
+            return activeButtonTextColor();
 
         case CSSValueButtonface:
         case CSSValueThreedface:
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to