Re: [csswg-drafts] [css-ui-4] choosing background colors for accent-color for contrast (#6159)

Responding to @emilio's comments from my [intent to ship](https://groups.google.com/a/chromium.org/g/blink-dev/c/WwYkLjbGhoA):

> So the way form controls are drawn on Firefox requires two colors, a
"background" color (the accent color), and a "foreground" color (a color
that has sufficient contrast with the accent color). All other
decorative colors are derived from the accent color, by tweaking the
luminance.
> 
> For native form controls, the foreground and background colors are
provided by the OS (the macOS accent color, the Linux theme accent
color, etc). On Windows and Android it's hard-coded to white-on-blue,
though you can use the OS accent color if you change
`widget.non-native-theme.use-theme-accent` to true).
> 
> For the accent-color property, as specified it only requires one color
(the accent color), so we just choose a white or black foreground
depending on whether the color is "dark enough":
> 
> 
> https://searchfox.org/mozilla-central/rev/2c991232499e826e46f9d976eb653817340ba389/widget/nsNativeBasicTheme.cpp#192-197
> 
> Note that we always blend the accent color with white to make sure it's
opaque.
> 
> Anyhow, I think the current approach is not great, but is as good as it
can get with only one color. I think it's slightly unfortunate as some
accent colors would still look better with white, and the authors could
want e.g., a checkmark that isn't white or black. That's why I think the
option of providing two colors (background and foreground) to the
property is best.

I see why specifying a foreground and background color makes sense for firefox, but in chromium we have a bunch of hard coded [light scheme colors](https://source.chromium.org/chromium/chromium/src/+/main:ui/native_theme/native_theme_base.cc;l=1335-1415;drc=b7ed0ab024e0ebb4d23cdad80339890417bd48da) and [dark scheme colors](https://source.chromium.org/chromium/chromium/src/+/main:ui/native_theme/native_theme_base.cc;l=1417-1492;drc=b7ed0ab024e0ebb4d23cdad80339890417bd48da). I presume that all of these were hand picked by UX people as opposed to being generated based on relative luminance... I suppose if the relative luminance foreground/background thing is something we should be doing instead when accent-color is present, then we could back-calculate the relative luminance of these dozens of colors to try to make something that resembles firefox, but it sounds rather complicated and I wonder if it would end up better than my current forced-color-scheme-when-needed implementation.

-- 
GitHub Notification of comment by josepharhar
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/6159#issuecomment-858737718 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 10 June 2021 16:10:30 UTC