From 58f73ae29a7559c351622ae8e68e58903debad5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 28 Jul 2023 14:43:42 +0000 Subject: [PATCH] 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 --- widget/nsXPLookAndFeel.cpp | 10 +++++ widget/windows/nsLookAndFeel.cpp | 63 ++++++++++++++++++++------------ 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/widget/nsXPLookAndFeel.cpp b/widget/nsXPLookAndFeel.cpp index a2bc17ac56ac..53f72ffebfdf 100644 --- a/widget/nsXPLookAndFeel.cpp +++ b/widget/nsXPLookAndFeel.cpp @@ -751,6 +751,7 @@ Maybe 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 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 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(); } diff --git a/widget/windows/nsLookAndFeel.cpp b/widget/windows/nsLookAndFeel.cpp index 8671dd387a1a..d955f2a637c8 100644 --- a/widget/windows/nsLookAndFeel.cpp +++ b/widget/windows/nsLookAndFeel.cpp @@ -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 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(); }