Bug 1843044 - Make windows titlebar system colors return our theme's colors for the default theme. r=mhowell

This doesn't change behavior yet because the front-end doesn't use them for the
cases where we're changing behavior, but this is in preparation to use them
unconditionally in the front-end and simplify a bit the code there.

Since we need generic colors, and the default theme light colors are not
particularly useful (they are windows-xp-like titlebar colors), I think this
makes sense.

Differential Revision: https://phabricator.services.mozilla.com/D184707
This commit is contained in:
Emilio Cobos Álvarez 2023-07-28 14:43:42 +00:00
Родитель 81a713b20a
Коммит 58f73ae29a
2 изменённых файлов: 49 добавлений и 24 удалений

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

@ -751,6 +751,7 @@ Maybe<nscolor> nsXPLookAndFeel::GenericDarkColor(ColorID aID) {
case ColorID::MozComboboxtext:
case ColorID::MozButtonhovertext:
case ColorID::MozButtonactivetext:
case ColorID::Captiontext:
color = kWindowText;
break;
case ColorID::Buttonshadow:
@ -762,6 +763,7 @@ Maybe<nscolor> nsXPLookAndFeel::GenericDarkColor(ColorID aID) {
case ColorID::Graytext: // opacity: 0.4 of kWindowText blended over the
// "Window" background color, which happens to be
// the same :-)
case ColorID::Inactivecaptiontext:
color = NS_ComposeColors(kWindowBackground, NS_RGBA(251, 251, 254, 102));
break;
case ColorID::MozCellhighlight:
@ -813,6 +815,14 @@ Maybe<nscolor> nsXPLookAndFeel::GenericDarkColor(ColorID aID) {
// other options too.
color = NS_RGB(0xff, 0x66, 0x66);
break;
case ColorID::Activeborder:
case ColorID::Inactiveborder:
color = NS_RGB(57, 57, 57);
break;
case ColorID::Activecaption:
case ColorID::Inactivecaption:
color = NS_RGB(28, 27, 34);
break;
default:
return Nothing();
}

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

@ -184,6 +184,30 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
return NS_OK;
}
// Titlebar colors are color-scheme aware.
switch (aID) {
case ColorID::Activecaption:
aColor = mTitlebarColors.Get(aScheme, true).mBg;
return NS_OK;
case ColorID::Captiontext:
aColor = mTitlebarColors.Get(aScheme, true).mFg;
return NS_OK;
case ColorID::Activeborder:
aColor = mTitlebarColors.Get(aScheme, true).mBorder;
return NS_OK;
case ColorID::Inactivecaption:
aColor = mTitlebarColors.Get(aScheme, false).mBg;
return NS_OK;
case ColorID::Inactivecaptiontext:
aColor = mTitlebarColors.Get(aScheme, false).mFg;
return NS_OK;
case ColorID::Inactiveborder:
aColor = mTitlebarColors.Get(aScheme, false).mBorder;
return NS_OK;
default:
break;
}
if (aScheme == ColorScheme::Dark) {
if (auto color = GenericDarkColor(aID)) {
aColor = *color;
@ -273,24 +297,6 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
}
aColor = NS_TRANSPARENT;
return NS_OK;
case ColorID::Activecaption:
aColor = mTitlebarColors.Get(aScheme, true).mBg;
return NS_OK;
case ColorID::Captiontext:
aColor = mTitlebarColors.Get(aScheme, true).mFg;
return NS_OK;
case ColorID::Activeborder:
aColor = mTitlebarColors.Get(aScheme, true).mBorder;
return NS_OK;
case ColorID::Inactivecaption:
aColor = mTitlebarColors.Get(aScheme, false).mBg;
return NS_OK;
case ColorID::Inactivecaptiontext:
aColor = mTitlebarColors.Get(aScheme, false).mFg;
return NS_OK;
case ColorID::Inactiveborder:
aColor = mTitlebarColors.Get(aScheme, false).mBorder;
return NS_OK;
case ColorID::Infobackground:
idx = COLOR_INFOBK;
break;
@ -782,11 +788,21 @@ auto nsLookAndFeel::ComputeTitlebarColors() -> TitlebarColors {
GetColorForSysColorIndex(COLOR_INACTIVECAPTIONTEXT),
GetColorForSysColorIndex(COLOR_INACTIVEBORDER)};
// Foreground and background taken from Windows Mica material theme colors.
result.mActiveDark = {NS_RGB(0x2e, 0x2e, 0x2e), NS_RGB(0xff, 0xff, 0xff),
NS_RGB(57, 57, 57)};
result.mInactiveDark = {NS_RGB(0x33, 0x33, 0x33), NS_RGB(0xff, 0xff, 0xff),
NS_RGB(57, 57, 57)};
if (!nsUXThemeData::IsHighContrastOn()) {
// This is our current default light theme behavior.
result.mActiveLight =
result.mInactiveLight = {GetColorForSysColorIndex(COLOR_3DFACE),
GetColorForSysColorIndex(COLOR_WINDOWTEXT),
GetColorForSysColorIndex(COLOR_ACTIVEBORDER)};
}
// Foreground and background taken from our dark theme.
result.mActiveDark = {*GenericDarkColor(ColorID::Activecaption),
*GenericDarkColor(ColorID::Captiontext),
*GenericDarkColor(ColorID::Activeborder)};
result.mInactiveDark = {*GenericDarkColor(ColorID::Inactivecaption),
*GenericDarkColor(ColorID::Inactivecaptiontext),
*GenericDarkColor(ColorID::Inactiveborder)};
nsCOMPtr<nsIWindowsRegKey> dwmKey =
do_CreateInstance("@mozilla.org/windows-registry-key;1");
@ -899,6 +915,5 @@ void nsLookAndFeel::EnsureInit() {
return NS_RGB(0, 120, 215);
}();
mColorAccentText = GetAccentColorText(mColorAccent);
RecordTelemetry();
}