Bug 1816336 - Use consistent menu colors with color-scheme: dark and HCM. r=dao

When we get to NativeGetColor with ColorScheme::Dark and some of the
menu colors, we end up in a somewhat weird state, where most of the
colors come from GenericDarkColor, but some of the colors would use the
IsHighlightColor/IsHighlightTextColor code-path.

Use the non-native menu colors with the dark color-scheme consistently,
to guarantee we get matching color pairs. Note that for native menus
(i.e., Win7/Win8, we can't get here because of [1]).

The behavior when the user selects a light theme is a bit inconsistent
with this (because we'd still use the HCM colors in that case), but
that's both pre-existing and probably not a big deal.

To fix that properly we'd need to either introduce a third
`color-scheme`, which doesn't seem too appealing, or do something like
`color-scheme: light !important` on menus as well with `not
(-moz-windows-default-theme)` (which is fine but not sure it's desired).

[1]: https://searchfox.org/mozilla-central/rev/5ccb73c0217d1710b10d6e6e297cf3396d10ec23/toolkit/themes/windows/global/popup.css#32

Differential Revision: https://phabricator.services.mozilla.com/D169803
This commit is contained in:
Emilio Cobos Álvarez 2023-02-14 16:07:39 +00:00
Родитель 7d8d07561f
Коммит 1249da2f38
1 изменённых файлов: 12 добавлений и 11 удалений

Просмотреть файл

@ -85,11 +85,12 @@ void nsLookAndFeel::RefreshImpl() {
nsXPLookAndFeel::RefreshImpl();
}
static bool UseNonNativeMenuColors() {
static bool UseNonNativeMenuColors(ColorScheme aScheme) {
if (!LookAndFeel::WindowsNonNativeMenusEnabled()) {
return false;
}
return LookAndFeel::GetInt(LookAndFeel::IntID::WindowsDefaultTheme);
return LookAndFeel::GetInt(LookAndFeel::IntID::WindowsDefaultTheme) ||
aScheme == ColorScheme::Dark;
}
nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
@ -99,7 +100,7 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
auto IsHighlightColor = [&] {
switch (aID) {
case ColorID::MozMenuhover:
return !UseNonNativeMenuColors();
return !UseNonNativeMenuColors(aScheme);
case ColorID::Highlight:
case ColorID::Selecteditem:
// We prefer the generic dark selection color if we don't have an
@ -116,7 +117,7 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
auto IsHighlightTextColor = [&] {
switch (aID) {
case ColorID::MozMenubarhovertext:
if (UseNonNativeMenuColors()) {
if (UseNonNativeMenuColors(aScheme)) {
return false;
}
if (!nsUXThemeData::IsAppThemed()) {
@ -124,7 +125,7 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
}
[[fallthrough]];
case ColorID::MozMenuhovertext:
if (UseNonNativeMenuColors()) {
if (UseNonNativeMenuColors(aScheme)) {
return false;
}
return !mColorMenuHoverText;
@ -231,7 +232,7 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
idx = COLOR_GRAYTEXT;
break;
case ColorID::MozMenubarhovertext:
if (UseNonNativeMenuColors()) {
if (UseNonNativeMenuColors(aScheme)) {
aColor = kNonNativeMenuText;
return NS_OK;
}
@ -241,7 +242,7 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
}
[[fallthrough]];
case ColorID::MozMenuhovertext:
if (UseNonNativeMenuColors()) {
if (UseNonNativeMenuColors(aScheme)) {
aColor = kNonNativeMenuText;
return NS_OK;
}
@ -252,11 +253,11 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
idx = COLOR_HIGHLIGHTTEXT;
break;
case ColorID::MozMenuhover:
MOZ_ASSERT(UseNonNativeMenuColors());
MOZ_ASSERT(UseNonNativeMenuColors(aScheme));
aColor = NS_RGB(0xe0, 0xe0, 0xe6);
return NS_OK;
case ColorID::MozMenuhoverdisabled:
if (UseNonNativeMenuColors()) {
if (UseNonNativeMenuColors(aScheme)) {
aColor = NS_RGB(0xf0, 0xf0, 0xf3);
return NS_OK;
}
@ -278,7 +279,7 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
idx = COLOR_INFOTEXT;
break;
case ColorID::Menu:
if (UseNonNativeMenuColors()) {
if (UseNonNativeMenuColors(aScheme)) {
aColor = NS_RGB(0xf9, 0xf9, 0xfb);
return NS_OK;
}
@ -286,7 +287,7 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
break;
case ColorID::Menutext:
case ColorID::MozMenubartext:
if (UseNonNativeMenuColors()) {
if (UseNonNativeMenuColors(aScheme)) {
aColor = kNonNativeMenuText;
return NS_OK;
}