summaryrefslogtreecommitdiffstats
path: root/widget/windows/nsLookAndFeel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'widget/windows/nsLookAndFeel.cpp')
-rw-r--r--widget/windows/nsLookAndFeel.cpp117
1 files changed, 105 insertions, 12 deletions
diff --git a/widget/windows/nsLookAndFeel.cpp b/widget/windows/nsLookAndFeel.cpp
index 7c427ac9f..06eee3771 100644
--- a/widget/windows/nsLookAndFeel.cpp
+++ b/widget/windows/nsLookAndFeel.cpp
@@ -32,12 +32,8 @@ nsLookAndFeel::GetOperatingSystemVersion()
version = eOperatingSystemVersion_Windows10;
} else if (IsWin8OrLater()) {
version = eOperatingSystemVersion_Windows8;
- } else if (IsWin7OrLater()) {
- version = eOperatingSystemVersion_Windows7;
- } else if (IsVistaOrLater()) {
- version = eOperatingSystemVersion_WindowsVista;
} else {
- version = eOperatingSystemVersion_WindowsXP;
+ version = eOperatingSystemVersion_Windows7;
}
return version;
@@ -183,8 +179,7 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
idx = COLOR_HIGHLIGHT;
break;
case eColorID__moz_menubarhovertext:
- if (!IsVistaOrLater() || !IsAppThemed())
- {
+ if (!IsAppThemed()) {
idx = nsUXThemeData::sFlatMenus ?
COLOR_HIGHLIGHTTEXT :
COLOR_MENUTEXT;
@@ -192,8 +187,7 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
}
// Fall through
case eColorID__moz_menuhovertext:
- if (IsVistaOrLater() && IsAppThemed())
- {
+ if (IsAppThemed()) {
res = ::GetColorFromTheme(eUXMenu,
MENU_POPUPITEM, MPI_HOT, TMT_TEXTCOLOR, aColor);
if (NS_SUCCEEDED(res))
@@ -267,8 +261,25 @@ 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()) {
+ if (IsAppThemed()) {
res = ::GetColorFromTheme(eUXMediaToolbar,
TP_BUTTON, TS_NORMAL, TMT_TEXTCOLOR, aColor);
if (NS_SUCCEEDED(res))
@@ -278,8 +289,7 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
idx = COLOR_WINDOWTEXT;
break;
case eColorID__moz_win_communicationstext:
- if (IsVistaOrLater() && IsAppThemed())
- {
+ if (IsAppThemed()) {
res = ::GetColorFromTheme(eUXCommunicationsToolbar,
TP_BUTTON, TS_NORMAL, TMT_TEXTCOLOR, aColor);
if (NS_SUCCEEDED(res))
@@ -419,6 +429,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 +723,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;
+}