diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-02-04 23:58:08 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-02-04 23:58:08 +0100 |
commit | a9a672fd681acca009741acf24b5e2076843394d (patch) | |
tree | fda76eb6688358f101fc9ac4f4d99b0cc0abab26 | |
parent | 7edd685eee95759d66a457cf428f42e0dda94671 (diff) | |
parent | 998542d94d86d2bf1f0ac247fcf478c31dcdafec (diff) | |
download | UXP-a9a672fd681acca009741acf24b5e2076843394d.tar UXP-a9a672fd681acca009741acf24b5e2076843394d.tar.gz UXP-a9a672fd681acca009741acf24b5e2076843394d.tar.lz UXP-a9a672fd681acca009741acf24b5e2076843394d.tar.xz UXP-a9a672fd681acca009741acf24b5e2076843394d.zip |
Merge branch 'ported-moebius'
-rwxr-xr-x | browser/base/content/browser.js | 6 | ||||
-rw-r--r-- | dom/base/nsGkAtomList.h | 4 | ||||
-rw-r--r-- | layout/base/nsPresContext.cpp | 3 | ||||
-rw-r--r-- | layout/style/nsCSSKeywordList.h | 2 | ||||
-rw-r--r-- | layout/style/nsCSSProps.cpp | 2 | ||||
-rw-r--r-- | layout/style/nsCSSRuleProcessor.cpp | 10 | ||||
-rw-r--r-- | layout/style/nsMediaFeatures.cpp | 16 | ||||
-rw-r--r-- | layout/style/test/test_media_queries.html | 5 | ||||
-rw-r--r-- | widget/LookAndFeel.h | 22 | ||||
-rw-r--r-- | widget/nsXPLookAndFeel.cpp | 5 | ||||
-rw-r--r-- | widget/windows/nsLookAndFeel.cpp | 100 | ||||
-rw-r--r-- | widget/windows/nsLookAndFeel.h | 27 | ||||
-rw-r--r-- | widget/windows/nsWindow.cpp | 22 |
13 files changed, 217 insertions, 7 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"); } } diff --git a/dom/base/nsGkAtomList.h b/dom/base/nsGkAtomList.h index 7827ad66b..0b76b2bea 100644 --- a/dom/base/nsGkAtomList.h +++ b/dom/base/nsGkAtomList.h @@ -2230,6 +2230,8 @@ 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_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") @@ -2259,6 +2261,8 @@ 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_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/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(); 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/layout/style/nsCSSRuleProcessor.cpp b/layout/style/nsCSSRuleProcessor.cpp index 07a4ef57b..8760a330e 100644 --- a/layout/style/nsCSSRuleProcessor.cpp +++ b/layout/style/nsCSSRuleProcessor.cpp @@ -1127,6 +1127,16 @@ 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_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 c07a4123e..052ce58e8 100644 --- a/layout/style/nsMediaFeatures.cpp +++ b/layout/style/nsMediaFeatures.cpp @@ -716,6 +716,22 @@ nsMediaFeatures::features[] = { GetSystemMetric }, { + &nsGkAtoms::_moz_windows_accent_color_applies, + nsMediaFeature::eMinMaxNotAllowed, + nsMediaFeature::eBoolInteger, + nsMediaFeature::eNoRequirements, + { &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, nsMediaFeature::eBoolInteger, 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..e2502c559 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 @@ -239,6 +243,24 @@ public: 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 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 * being used. * 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 7c427ac9f..e649802b1 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, @@ -419,6 +436,20 @@ 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_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()); @@ -699,3 +730,72 @@ nsLookAndFeel::SetIntCacheImpl(const nsTArray<LookAndFeelInt>& 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; +} + +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) +{ + 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. + + 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 bc2d158b6..6200541f5 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,33 @@ public: virtual void SetIntCacheImpl(const nsTArray<LookAndFeelInt>& 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); + + /** + * 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 + * 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<nsIWindowsRegKey> mDwmKey; }; #endif diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index 2172f2aa0..85321a189 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<const wchar_t*>(lParam); - if (!wcscmp(lParamString, L"UserInteractionMode")) { - nsCOMPtr<nsIWindowsUIUtils> 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<nsIWindowsUIUtils> uiUtils(do_GetService("@mozilla.org/windows-ui-utils;1")); + if (uiUtils) { + uiUtils->UpdateTabletModeState(); + } } } } @@ -7131,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(); + } } } |