From ac663083950b2e00573395d68348302df94e3ac1 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Wed, 19 Jul 2017 13:11:28 +0200 Subject: Add `@media(-moz-windows-accent-color-applies)` #31 point 3 --- dom/base/nsGkAtomList.h | 2 ++ layout/style/nsCSSRuleProcessor.cpp | 5 +++++ layout/style/nsMediaFeatures.cpp | 8 ++++++++ layout/style/test/test_media_queries.html | 5 +++++ widget/LookAndFeel.h | 9 +++++++++ widget/windows/nsLookAndFeel.cpp | 6 ++++++ 6 files changed, 35 insertions(+) diff --git a/dom/base/nsGkAtomList.h b/dom/base/nsGkAtomList.h index 7827ad66b..f6b097a73 100644 --- a/dom/base/nsGkAtomList.h +++ b/dom/base/nsGkAtomList.h @@ -2230,6 +2230,7 @@ GK_ATOM(scrollbar_end_backward, "scrollbar-end-backward") GK_ATOM(scrollbar_end_forward, "scrollbar-end-forward") GK_ATOM(scrollbar_thumb_proportional, "scrollbar-thumb-proportional") GK_ATOM(overlay_scrollbars, "overlay-scrollbars") +GK_ATOM(windows_accent_color_applies, "windows-accent-color-applies") GK_ATOM(windows_default_theme, "windows-default-theme") GK_ATOM(mac_graphite_theme, "mac-graphite-theme") GK_ATOM(mac_yosemite_theme, "mac-yosemite-theme") @@ -2259,6 +2260,7 @@ GK_ATOM(_moz_scrollbar_end_backward, "-moz-scrollbar-end-backward") GK_ATOM(_moz_scrollbar_end_forward, "-moz-scrollbar-end-forward") GK_ATOM(_moz_scrollbar_thumb_proportional, "-moz-scrollbar-thumb-proportional") GK_ATOM(_moz_overlay_scrollbars, "-moz-overlay-scrollbars") +GK_ATOM(_moz_windows_accent_color_applies, "-moz-windows-accent-color-applies") GK_ATOM(_moz_windows_default_theme, "-moz-windows-default-theme") GK_ATOM(_moz_mac_graphite_theme, "-moz-mac-graphite-theme") GK_ATOM(_moz_mac_yosemite_theme, "-moz-mac-yosemite-theme") diff --git a/layout/style/nsCSSRuleProcessor.cpp b/layout/style/nsCSSRuleProcessor.cpp index 07a4ef57b..4dc7ea1c8 100644 --- a/layout/style/nsCSSRuleProcessor.cpp +++ b/layout/style/nsCSSRuleProcessor.cpp @@ -1127,6 +1127,11 @@ InitSystemMetrics() sSystemMetrics->AppendElement(nsGkAtoms::mac_yosemite_theme); } + rv = LookAndFeel::GetInt(LookAndFeel::eIntID_WindowsAccentColorApplies, &metricResult); + if (NS_SUCCEEDED(rv) && metricResult) { + sSystemMetrics->AppendElement(nsGkAtoms::windows_accent_color_applies); + } + rv = LookAndFeel::GetInt(LookAndFeel::eIntID_DWMCompositor, &metricResult); if (NS_SUCCEEDED(rv) && metricResult) { sSystemMetrics->AppendElement(nsGkAtoms::windows_compositor); diff --git a/layout/style/nsMediaFeatures.cpp b/layout/style/nsMediaFeatures.cpp index c07a4123e..f314835a4 100644 --- a/layout/style/nsMediaFeatures.cpp +++ b/layout/style/nsMediaFeatures.cpp @@ -715,6 +715,14 @@ nsMediaFeatures::features[] = { { &nsGkAtoms::mac_yosemite_theme }, GetSystemMetric }, + { + &nsGkAtoms::_moz_windows_accent_color_applies, + nsMediaFeature::eMinMaxNotAllowed, + nsMediaFeature::eBoolInteger, + nsMediaFeature::eNoRequirements, + { &nsGkAtoms::windows_accent_color_applies }, + GetSystemMetric + }, { &nsGkAtoms::_moz_windows_compositor, nsMediaFeature::eMinMaxNotAllowed, diff --git a/layout/style/test/test_media_queries.html b/layout/style/test/test_media_queries.html index 1edac15ae..479306a55 100644 --- a/layout/style/test/test_media_queries.html +++ b/layout/style/test/test_media_queries.html @@ -628,6 +628,7 @@ function run() { expression_should_be_parseable("-moz-windows-default-theme"); expression_should_be_parseable("-moz-mac-graphite-theme"); expression_should_be_parseable("-moz-mac-yosemite-theme"); + expression_should_be_parseable("-moz-windows-accent-color-applies"); expression_should_be_parseable("-moz-windows-compositor"); expression_should_be_parseable("-moz-windows-classic"); expression_should_be_parseable("-moz-windows-glass"); @@ -643,6 +644,7 @@ function run() { expression_should_be_parseable("-moz-windows-default-theme: 0"); expression_should_be_parseable("-moz-mac-graphite-theme: 0"); expression_should_be_parseable("-moz-mac-yosemite-theme: 0"); + expression_should_be_parseable("-moz-windows-accent-color-applies: 0"); expression_should_be_parseable("-moz-windows-compositor: 0"); expression_should_be_parseable("-moz-windows-classic: 0"); expression_should_be_parseable("-moz-windows-glass: 0"); @@ -658,6 +660,7 @@ function run() { expression_should_be_parseable("-moz-windows-default-theme: 1"); expression_should_be_parseable("-moz-mac-graphite-theme: 1"); expression_should_be_parseable("-moz-mac-yosemite-theme: 1"); + expression_should_be_parseable("-moz-windows-accent-color-applies: 1"); expression_should_be_parseable("-moz-windows-compositor: 1"); expression_should_be_parseable("-moz-windows-classic: 1"); expression_should_be_parseable("-moz-windows-glass: 1"); @@ -673,6 +676,7 @@ function run() { expression_should_not_be_parseable("-moz-windows-default-theme: -1"); expression_should_not_be_parseable("-moz-mac-graphite-theme: -1"); expression_should_not_be_parseable("-moz-mac-yosemite-theme: -1"); + expression_should_not_be_parseable("-moz-windows-accent-color-applies: -1"); expression_should_not_be_parseable("-moz-windows-compositor: -1"); expression_should_not_be_parseable("-moz-windows-classic: -1"); expression_should_not_be_parseable("-moz-windows-glass: -1"); @@ -688,6 +692,7 @@ function run() { expression_should_not_be_parseable("-moz-windows-default-theme: true"); expression_should_not_be_parseable("-moz-mac-graphite-theme: true"); expression_should_not_be_parseable("-moz-mac-yosemite-theme: true"); + expression_should_not_be_parseable("-moz-windows-accent-color-applies: true"); expression_should_not_be_parseable("-moz-windows-compositor: true"); expression_should_not_be_parseable("-moz-windows-classic: true"); expression_should_not_be_parseable("-moz-windows-glass: true"); diff --git a/widget/LookAndFeel.h b/widget/LookAndFeel.h index 3a4929c9f..b7a05748e 100644 --- a/widget/LookAndFeel.h +++ b/widget/LookAndFeel.h @@ -238,6 +238,15 @@ public: // Should menu items blink when they're chosen? eIntID_ChosenMenuItemsShouldBlink, + /* + * A Boolean value to determine whether the Windows accent color + * should be applied to the title bar. + * + * The value of this metric is not used on other platforms. These platforms + * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric. + */ + eIntID_WindowsAccentColorApplies, + /* * A Boolean value to determine whether the Windows default theme is * being used. diff --git a/widget/windows/nsLookAndFeel.cpp b/widget/windows/nsLookAndFeel.cpp index 7c427ac9f..60e351323 100644 --- a/widget/windows/nsLookAndFeel.cpp +++ b/widget/windows/nsLookAndFeel.cpp @@ -419,6 +419,12 @@ nsLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult) case eIntID_DWMCompositor: aResult = nsUXThemeData::CheckForCompositor(); break; + case eIntID_WindowsAccentColorApplies: + { + nscolor unused; + aResult = NS_SUCCEEDED(GetAccentColor(unused)) ? 1 : 0; + } + break; case eIntID_WindowsGlass: // Aero Glass is only available prior to Windows 8 when DWM is used. aResult = (nsUXThemeData::CheckForCompositor() && !IsWin8OrLater()); -- cgit v1.2.3 From f843f02860d8acd709fe89bfa891892d907de81a Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Wed, 19 Jul 2017 13:24:55 +0200 Subject: Add -moz-win-accentcolor(text) #31 points 1 and 2 --- layout/style/nsCSSKeywordList.h | 2 + layout/style/nsCSSProps.cpp | 2 + widget/LookAndFeel.h | 4 ++ widget/nsXPLookAndFeel.cpp | 5 +++ widget/windows/nsLookAndFeel.cpp | 82 ++++++++++++++++++++++++++++++++++++++++ widget/windows/nsLookAndFeel.h | 19 ++++++++++ widget/windows/nsWindow.cpp | 17 ++++++--- 7 files changed, 126 insertions(+), 5 deletions(-) diff --git a/layout/style/nsCSSKeywordList.h b/layout/style/nsCSSKeywordList.h index febdd32c6..933ff6e7b 100644 --- a/layout/style/nsCSSKeywordList.h +++ b/layout/style/nsCSSKeywordList.h @@ -742,6 +742,8 @@ CSS_KEY(button-focus, button_focus) CSS_KEY(-moz-win-media-toolbox, _moz_win_media_toolbox) CSS_KEY(-moz-win-communications-toolbox, _moz_win_communications_toolbox) CSS_KEY(-moz-win-browsertabbar-toolbox, _moz_win_browsertabbar_toolbox) +CSS_KEY(-moz-win-accentcolor, _moz_win_accentcolor) +CSS_KEY(-moz-win-accentcolortext, _moz_win_accentcolortext) CSS_KEY(-moz-win-mediatext, _moz_win_mediatext) CSS_KEY(-moz-win-communicationstext, _moz_win_communicationstext) CSS_KEY(-moz-win-glass, _moz_win_glass) diff --git a/layout/style/nsCSSProps.cpp b/layout/style/nsCSSProps.cpp index ec28d06f8..f3a7f898d 100644 --- a/layout/style/nsCSSProps.cpp +++ b/layout/style/nsCSSProps.cpp @@ -1174,6 +1174,8 @@ const KTableEntry nsCSSProps::kColorKTable[] = { { eCSSKeyword__moz_oddtreerow, LookAndFeel::eColorID__moz_oddtreerow }, { eCSSKeyword__moz_visitedhyperlinktext, NS_COLOR_MOZ_VISITEDHYPERLINKTEXT }, { eCSSKeyword_currentcolor, NS_COLOR_CURRENTCOLOR }, + { eCSSKeyword__moz_win_accentcolor, LookAndFeel::eColorID__moz_win_accentcolor }, + { eCSSKeyword__moz_win_accentcolortext, LookAndFeel::eColorID__moz_win_accentcolortext }, { eCSSKeyword__moz_win_mediatext, LookAndFeel::eColorID__moz_win_mediatext }, { eCSSKeyword__moz_win_communicationstext, LookAndFeel::eColorID__moz_win_communicationstext }, { eCSSKeyword__moz_nativehyperlinktext, LookAndFeel::eColorID__moz_nativehyperlinktext }, diff --git a/widget/LookAndFeel.h b/widget/LookAndFeel.h index b7a05748e..8d510f69f 100644 --- a/widget/LookAndFeel.h +++ b/widget/LookAndFeel.h @@ -158,6 +158,10 @@ public: // vista rebars + // accent color for title bar + eColorID__moz_win_accentcolor, + // color from drawing text over the accent color + eColorID__moz_win_accentcolortext, // media rebar text eColorID__moz_win_mediatext, // communications rebar text diff --git a/widget/nsXPLookAndFeel.cpp b/widget/nsXPLookAndFeel.cpp index 54c619829..28e1c2c5a 100644 --- a/widget/nsXPLookAndFeel.cpp +++ b/widget/nsXPLookAndFeel.cpp @@ -647,6 +647,11 @@ nsXPLookAndFeel::GetStandinForNativeColor(ColorID aID) result = NS_RGB(0x3F, 0x3F, 0x3F); break; case eColorID__moz_mac_secondaryhighlight: result = NS_RGB(0xD4, 0xD4, 0xD4); break; + case eColorID__moz_win_accentcolor: + // Seems to be the default color (hardcoded because of bug 1065998) + result = NS_RGB(0x9E, 0x9E, 0x9E); break; + case eColorID__moz_win_accentcolortext: + result = NS_RGB(0x00, 0x00, 0x00); break; case eColorID__moz_win_mediatext: result = NS_RGB(0xFF, 0xFF, 0xFF); break; case eColorID__moz_win_communicationstext: diff --git a/widget/windows/nsLookAndFeel.cpp b/widget/windows/nsLookAndFeel.cpp index 60e351323..63af65306 100644 --- a/widget/windows/nsLookAndFeel.cpp +++ b/widget/windows/nsLookAndFeel.cpp @@ -267,6 +267,23 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor) case eColorID__moz_cellhighlight: idx = COLOR_3DFACE; break; + case eColorID__moz_win_accentcolor: + res = GetAccentColor(aColor); + if (NS_SUCCEEDED(res)) { + return res; + } + NS_WARNING("Using fallback for accent color - UI code failed to use the " + "-moz-windows-accent-color-applies media query properly"); + // Seems to be the default color (hardcoded because of bug 1065998) + aColor = NS_RGB(158, 158, 158); + return NS_OK; + case eColorID__moz_win_accentcolortext: + res = GetAccentColorText(aColor); + if (NS_SUCCEEDED(res)) { + return res; + } + aColor = NS_RGB(0, 0, 0); + return NS_OK; case eColorID__moz_win_mediatext: if (IsVistaOrLater() && IsAppThemed()) { res = ::GetColorFromTheme(eUXMediaToolbar, @@ -705,3 +722,68 @@ nsLookAndFeel::SetIntCacheImpl(const nsTArray& aLookAndFeelIntCa } } +/* static */ nsresult +nsLookAndFeel::GetAccentColor(nscolor& aColor) +{ + nsresult rv; + + if (!mDwmKey) { + mDwmKey = do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + } + + rv = mDwmKey->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER, + NS_LITERAL_STRING("SOFTWARE\\Microsoft\\Windows\\DWM"), + nsIWindowsRegKey::ACCESS_QUERY_VALUE); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + + // The ColorPrevalence value is set to 1 when the "Show color on title bar" + // setting in the Color section of Window's Personalization settings is + // turned on. + uint32_t accentColor, colorPrevalence; + if (NS_SUCCEEDED(mDwmKey->ReadIntValue(NS_LITERAL_STRING("AccentColor"), &accentColor)) && + NS_SUCCEEDED(mDwmKey->ReadIntValue(NS_LITERAL_STRING("ColorPrevalence"), &colorPrevalence)) && + colorPrevalence == 1) { + // The order of the color components in the DWORD stored in the registry + // happens to be the same order as we store the components in nscolor + // so we can just assign directly here. + aColor = accentColor; + rv = NS_OK; + } else { + rv = NS_ERROR_NOT_AVAILABLE; + } + + mDwmKey->Close(); + + return rv; +} + +/* static */ nsresult +nsLookAndFeel::GetAccentColorText(nscolor& aColor) +{ + nscolor accentColor; + nsresult rv = GetAccentColor(accentColor); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + + // We want the color that we return for text that will be drawn over + // a background that has the accent color to have good contrast with + // the accent color. Windows itself uses either white or black text + // depending on how light or dark the accent color is. We do the same + // here based on the luminance of the accent color with a threshhold + // value and formula that are specified in the UWP guidelines. + // See: https://docs.microsoft.com/en-us/windows/uwp/style/color + + float luminance = (NS_GET_R(accentColor) * 2 + + NS_GET_G(accentColor) * 5 + + NS_GET_B(accentColor)) / 8; + + aColor = (luminance <= 128) ? NS_RGB(255, 255, 255) : NS_RGB(0, 0, 0); + + return NS_OK; +} diff --git a/widget/windows/nsLookAndFeel.h b/widget/windows/nsLookAndFeel.h index bc2d158b6..29b6f4b78 100644 --- a/widget/windows/nsLookAndFeel.h +++ b/widget/windows/nsLookAndFeel.h @@ -6,6 +6,7 @@ #ifndef __nsLookAndFeel #define __nsLookAndFeel #include "nsXPLookAndFeel.h" +#include "nsIWindowsRegKey.h" /* * Gesture System Metrics @@ -59,7 +60,25 @@ public: virtual void SetIntCacheImpl(const nsTArray& aLookAndFeelIntCache); private: + /** + * Fetches the Windows accent color from the Windows settings if + * the accent color is set to apply to the title bar, otherwise + * returns an error code. + */ + nsresult GetAccentColor(nscolor& aColor); + + /** + * If the Windows accent color from the Windows settings is set + * to apply to the title bar, this computes the color that should + * be used for text that is to be written over a background that has + * the accent color. Otherwise, (if the accent color should not + * apply to the title bar) this returns an error code. + */ + nsresult GetAccentColorText(nscolor& aColor); + int32_t mUseAccessibilityTheme; + + nsCOMPtr mDwmKey; }; #endif diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index 2172f2aa0..dd4f359f7 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -5084,12 +5084,19 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, case WM_SETTINGCHANGE: { - if (IsWin10OrLater() && mWindowType == eWindowType_invisible && lParam) { + if (lParam) { auto lParamString = reinterpret_cast(lParam); - if (!wcscmp(lParamString, L"UserInteractionMode")) { - nsCOMPtr uiUtils(do_GetService("@mozilla.org/windows-ui-utils;1")); - if (uiUtils) { - uiUtils->UpdateTabletModeState(); + if (!wcscmp(lParamString, L"ImmersiveColorSet")) { + // WM_SYSCOLORCHANGE is not dispatched for accent color changes + OnSysColorChanged(); + break; + } + if (IsWin10OrLater() && mWindowType == eWindowType_invisible) { + if (!wcscmp(lParamString, L"UserInteractionMode")) { + nsCOMPtr uiUtils(do_GetService("@mozilla.org/windows-ui-utils;1")); + if (uiUtils) { + uiUtils->UpdateTabletModeState(); + } } } } -- cgit v1.2.3 From 3af2c1c8795312d6cbb947b50bc1912df0589e0e Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Wed, 19 Jul 2017 13:33:17 +0200 Subject: Make the '-moz-windows-accent-color-applies' media query live to Windows 10 settings changes. --- layout/base/nsPresContext.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index b27e6d0e3..d9f7b368c 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -1696,6 +1696,9 @@ nsPresContext::SysColorChangedInternal() sLookAndFeelChanged = false; } + // Invalidate cached '-moz-windows-accent-color-applies' media query: + nsCSSRuleProcessor::FreeSystemMetrics(); + // Reset default background and foreground colors for the document since // they may be using system colors GetDocumentColorPreferences(); -- cgit v1.2.3 From 3019e0ff28bfd2d2a65b59501e582bb26356c6d7 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Wed, 19 Jul 2017 16:24:08 +0200 Subject: Split out the check for accent color luminance. --- widget/windows/nsLookAndFeel.cpp | 20 ++++++++++++-------- widget/windows/nsLookAndFeel.h | 8 ++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/widget/windows/nsLookAndFeel.cpp b/widget/windows/nsLookAndFeel.cpp index 63af65306..5c0358bd9 100644 --- a/widget/windows/nsLookAndFeel.cpp +++ b/widget/windows/nsLookAndFeel.cpp @@ -762,6 +762,16 @@ nsLookAndFeel::GetAccentColor(nscolor& aColor) return rv; } +bool +nsLookAndFeel::AccentColorIsDark(nscolor aColor) +{ + float luminance = (NS_GET_R(aColor) * 2 + + NS_GET_G(aColor) * 5 + + NS_GET_B(aColor)) / 8; + + return luminance <= 128; +} + /* static */ nsresult nsLookAndFeel::GetAccentColorText(nscolor& aColor) { @@ -775,15 +785,9 @@ nsLookAndFeel::GetAccentColorText(nscolor& aColor) // a background that has the accent color to have good contrast with // the accent color. Windows itself uses either white or black text // depending on how light or dark the accent color is. We do the same - // here based on the luminance of the accent color with a threshhold - // value and formula that are specified in the UWP guidelines. - // See: https://docs.microsoft.com/en-us/windows/uwp/style/color - - float luminance = (NS_GET_R(accentColor) * 2 + - NS_GET_G(accentColor) * 5 + - NS_GET_B(accentColor)) / 8; + // here based on the luminance of the accent color. - aColor = (luminance <= 128) ? NS_RGB(255, 255, 255) : NS_RGB(0, 0, 0); + aColor = AccentColorIsDark(accentColor) ? NS_RGB(255, 255, 255) : NS_RGB(0, 0, 0); return NS_OK; } diff --git a/widget/windows/nsLookAndFeel.h b/widget/windows/nsLookAndFeel.h index 29b6f4b78..6200541f5 100644 --- a/widget/windows/nsLookAndFeel.h +++ b/widget/windows/nsLookAndFeel.h @@ -67,6 +67,14 @@ private: */ nsresult GetAccentColor(nscolor& aColor); + /** + * Determines whether the Windows accent color is considered dark + * with a threshhold value and formula that are specified in the + * UWP guidelines. + * See: https://docs.microsoft.com/en-us/windows/uwp/style/color + */ + bool AccentColorIsDark(nscolor aColor); + /** * If the Windows accent color from the Windows settings is set * to apply to the title bar, this computes the color that should -- cgit v1.2.3 From 0f285318cdf3336aabda0cfa6bc306b2274f14e8 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Wed, 19 Jul 2017 16:34:50 +0200 Subject: Add -moz-windows-accent-color-is-dark #31 point 4 --- dom/base/nsGkAtomList.h | 2 ++ layout/style/nsCSSRuleProcessor.cpp | 5 +++++ layout/style/nsMediaFeatures.cpp | 8 ++++++++ widget/LookAndFeel.h | 9 +++++++++ widget/windows/nsLookAndFeel.cpp | 8 ++++++++ widget/windows/nsWindow.cpp | 5 +++++ 6 files changed, 37 insertions(+) diff --git a/dom/base/nsGkAtomList.h b/dom/base/nsGkAtomList.h index f6b097a73..0b76b2bea 100644 --- a/dom/base/nsGkAtomList.h +++ b/dom/base/nsGkAtomList.h @@ -2231,6 +2231,7 @@ GK_ATOM(scrollbar_end_forward, "scrollbar-end-forward") GK_ATOM(scrollbar_thumb_proportional, "scrollbar-thumb-proportional") GK_ATOM(overlay_scrollbars, "overlay-scrollbars") GK_ATOM(windows_accent_color_applies, "windows-accent-color-applies") +GK_ATOM(windows_accent_color_is_dark, "windows-accent-color-is-dark") GK_ATOM(windows_default_theme, "windows-default-theme") GK_ATOM(mac_graphite_theme, "mac-graphite-theme") GK_ATOM(mac_yosemite_theme, "mac-yosemite-theme") @@ -2261,6 +2262,7 @@ GK_ATOM(_moz_scrollbar_end_forward, "-moz-scrollbar-end-forward") GK_ATOM(_moz_scrollbar_thumb_proportional, "-moz-scrollbar-thumb-proportional") GK_ATOM(_moz_overlay_scrollbars, "-moz-overlay-scrollbars") GK_ATOM(_moz_windows_accent_color_applies, "-moz-windows-accent-color-applies") +GK_ATOM(_moz_windows_accent_color_is_dark, "-moz-windows-accent-color-is-dark") GK_ATOM(_moz_windows_default_theme, "-moz-windows-default-theme") GK_ATOM(_moz_mac_graphite_theme, "-moz-mac-graphite-theme") GK_ATOM(_moz_mac_yosemite_theme, "-moz-mac-yosemite-theme") diff --git a/layout/style/nsCSSRuleProcessor.cpp b/layout/style/nsCSSRuleProcessor.cpp index 4dc7ea1c8..8760a330e 100644 --- a/layout/style/nsCSSRuleProcessor.cpp +++ b/layout/style/nsCSSRuleProcessor.cpp @@ -1132,6 +1132,11 @@ InitSystemMetrics() sSystemMetrics->AppendElement(nsGkAtoms::windows_accent_color_applies); } + rv = LookAndFeel::GetInt(LookAndFeel::eIntID_WindowsAccentColorIsDark, &metricResult); + if (NS_SUCCEEDED(rv) && metricResult) { + sSystemMetrics->AppendElement(nsGkAtoms::windows_accent_color_is_dark); + } + rv = LookAndFeel::GetInt(LookAndFeel::eIntID_DWMCompositor, &metricResult); if (NS_SUCCEEDED(rv) && metricResult) { sSystemMetrics->AppendElement(nsGkAtoms::windows_compositor); diff --git a/layout/style/nsMediaFeatures.cpp b/layout/style/nsMediaFeatures.cpp index f314835a4..052ce58e8 100644 --- a/layout/style/nsMediaFeatures.cpp +++ b/layout/style/nsMediaFeatures.cpp @@ -723,6 +723,14 @@ nsMediaFeatures::features[] = { { &nsGkAtoms::windows_accent_color_applies }, GetSystemMetric }, + { + &nsGkAtoms::_moz_windows_accent_color_is_dark, + nsMediaFeature::eMinMaxNotAllowed, + nsMediaFeature::eBoolInteger, + nsMediaFeature::eNoRequirements, + { &nsGkAtoms::windows_accent_color_is_dark }, + GetSystemMetric + }, { &nsGkAtoms::_moz_windows_compositor, nsMediaFeature::eMinMaxNotAllowed, diff --git a/widget/LookAndFeel.h b/widget/LookAndFeel.h index 8d510f69f..e2502c559 100644 --- a/widget/LookAndFeel.h +++ b/widget/LookAndFeel.h @@ -250,6 +250,15 @@ public: * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric. */ eIntID_WindowsAccentColorApplies, + + /* + * A Boolean value to determine whether the Windows accent color + * is considered dark and should get bright text/controls. + * + * The value of this metric is not used on other platforms. These platforms + * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric. + */ + eIntID_WindowsAccentColorIsDark, /* * A Boolean value to determine whether the Windows default theme is diff --git a/widget/windows/nsLookAndFeel.cpp b/widget/windows/nsLookAndFeel.cpp index 5c0358bd9..e649802b1 100644 --- a/widget/windows/nsLookAndFeel.cpp +++ b/widget/windows/nsLookAndFeel.cpp @@ -442,6 +442,14 @@ nsLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult) aResult = NS_SUCCEEDED(GetAccentColor(unused)) ? 1 : 0; } break; + case eIntID_WindowsAccentColorIsDark: + { + nscolor accentColor; + if (NS_SUCCEEDED(GetAccentColor(accentColor))) { + aResult = AccentColorIsDark(accentColor) ? 1 : 0; + } + } + break; case eIntID_WindowsGlass: // Aero Glass is only available prior to Windows 8 when DWM is used. aResult = (nsUXThemeData::CheckForCompositor() && !IsWin8OrLater()); diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index dd4f359f7..85321a189 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -7138,6 +7138,11 @@ nsWindow::OnSysColorChanged() // so all presentations get notified properly. // See nsWindow::GlobalMsgWindowProc. NotifySysColorChanged(); + // On Windows 10 only, we trigger a theme change to pick up changed media + // queries that are needed for accent color changes. + if (IsWin10OrLater()) { + NotifyThemeChanged(); + } } } -- cgit v1.2.3 From 998542d94d86d2bf1f0ac247fcf478c31dcdafec Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Wed, 19 Jul 2017 21:31:28 +0200 Subject: Change "darkwindowframe" calculation on Win 8 to UWP formula. #31 point 6 --- browser/base/content/browser.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 7b05e1da7..7aaaa09aa 100755 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -1055,8 +1055,10 @@ var gBrowserInit = { window.matchMedia("(-moz-windows-default-theme)").matches) { let windowFrameColor = new Color(...Cu.import("resource:///modules/Windows8WindowFrameColor.jsm", {}) .Windows8WindowFrameColor.get()); - // Default to black for foreground text. - if (!windowFrameColor.isContrastRatioAcceptable(new Color(0, 0, 0))) { + // Check if window frame color is dark. + if ((windowFrameColor.r * 2 + + windowFrameColor.g * 5 + + windowFrameColor.b) <= 128 * 8) { document.documentElement.setAttribute("darkwindowframe", "true"); } } -- cgit v1.2.3