Bug 1344910, part 1 - Add a '-moz-win-accentcolor' color keyword to expose the Win10 accent color. r=jimm
☠☠ backed out by 8282a7374309 ☠ ☠
authorJonathan Watt <jwatt@jwatt.org>
Mon, 05 Jun 2017 12:19:51 +0100
changeset 365324 31a3362f641c45953dc820e2c8cadd42ca3cc51e
parent 365323 7e2c76c9f6d268549e8d5cd52ee6e41f5943d613
child 365325 94f08c38200bafa9c76234494f6a0b858f3e82eb
push id32068
push userkwierso@gmail.com
push dateThu, 22 Jun 2017 00:58:38 +0000
treeherdermozilla-central@f8bb96fb5c4f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1344910
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1344910, part 1 - Add a '-moz-win-accentcolor' color keyword to expose the Win10 accent color. r=jimm MozReview-Commit-ID: DtRcuizKRH2
layout/style/nsCSSKeywordList.h
layout/style/nsCSSProps.cpp
widget/LookAndFeel.h
widget/nsXPLookAndFeel.cpp
widget/windows/nsLookAndFeel.cpp
widget/windows/nsLookAndFeel.h
widget/windows/nsWindow.cpp
--- a/layout/style/nsCSSKeywordList.h
+++ b/layout/style/nsCSSKeywordList.h
@@ -742,16 +742,17 @@ CSS_KEY(groupbox, groupbox)
 CSS_KEY(checkbox-container, checkbox_container)
 CSS_KEY(radio-container, radio_container)
 CSS_KEY(checkbox-label, checkbox_label)
 CSS_KEY(radio-label, radio_label)
 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-mediatext, _moz_win_mediatext)
 CSS_KEY(-moz-win-communicationstext, _moz_win_communicationstext)
 CSS_KEY(-moz-win-glass, _moz_win_glass)
 CSS_KEY(-moz-win-borderless-glass, _moz_win_borderless_glass)
 CSS_KEY(-moz-window-titlebar, _moz_window_titlebar)
 CSS_KEY(-moz-window-titlebar-maximized, _moz_window_titlebar_maximized)
 CSS_KEY(-moz-window-frame-left, _moz_window_frame_left)
 CSS_KEY(-moz-window-frame-right, _moz_window_frame_right)
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -1132,16 +1132,17 @@ const KTableEntry nsCSSProps::kColorKTab
   { eCSSKeyword__moz_mac_secondaryhighlight, LookAndFeel::eColorID__moz_mac_secondaryhighlight },
   { eCSSKeyword__moz_menuhover, LookAndFeel::eColorID__moz_menuhover },
   { eCSSKeyword__moz_menuhovertext, LookAndFeel::eColorID__moz_menuhovertext },
   { eCSSKeyword__moz_menubartext, LookAndFeel::eColorID__moz_menubartext },
   { eCSSKeyword__moz_menubarhovertext, LookAndFeel::eColorID__moz_menubarhovertext },
   { 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_mediatext, LookAndFeel::eColorID__moz_win_mediatext },
   { eCSSKeyword__moz_win_communicationstext, LookAndFeel::eColorID__moz_win_communicationstext },
   { eCSSKeyword__moz_nativehyperlinktext, LookAndFeel::eColorID__moz_nativehyperlinktext },
   { eCSSKeyword__moz_comboboxtext, LookAndFeel::eColorID__moz_comboboxtext },
   { eCSSKeyword__moz_combobox, LookAndFeel::eColorID__moz_combobox },
   { eCSSKeyword_UNKNOWN, -1 }
 };
 
--- a/widget/LookAndFeel.h
+++ b/widget/LookAndFeel.h
@@ -153,16 +153,18 @@ public:
     eColorID__moz_mac_menutextselect,
     // text color of disabled text on toolbars
     eColorID__moz_mac_disabledtoolbartext,
     //inactive light hightlight
     eColorID__moz_mac_secondaryhighlight,
 
     // vista rebars
 
+    // accent color for title bar
+    eColorID__moz_win_accentcolor,
     // media rebar text
     eColorID__moz_win_mediatext,
     // communications rebar text
     eColorID__moz_win_communicationstext,
 
     // Hyperlink color extracted from the system, not affected by the
     // browser.anchor_color user pref.
     // There is no OS-specified safe background color for this text,
--- a/widget/nsXPLookAndFeel.cpp
+++ b/widget/nsXPLookAndFeel.cpp
@@ -653,16 +653,19 @@ nsXPLookAndFeel::GetStandinForNativeColo
     case eColorID__moz_mac_menutextdisable:
       result = NS_RGB(0x88, 0x88, 0x88); break;
     case eColorID__moz_mac_menutextselect:
       result = NS_RGB(0xFF, 0xFF, 0xFF); break;
     case eColorID__moz_mac_disabledtoolbartext:
       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_mediatext:
       result = NS_RGB(0xFF, 0xFF, 0xFF); break;
     case eColorID__moz_win_communicationstext:
       result = NS_RGB(0xFF, 0xFF, 0xFF); break;
     case eColorID__moz_nativehyperlinktext:
       result = NS_RGB(0x00, 0x66, 0xCC); break;
     case eColorID__moz_comboboxtext:
       result = NS_RGB(0x00, 0x00, 0x00); break;
--- a/widget/windows/nsLookAndFeel.cpp
+++ b/widget/windows/nsLookAndFeel.cpp
@@ -257,16 +257,26 @@ nsLookAndFeel::NativeGetColor(ColorID aI
     case eColorID__moz_fieldtext:
     case eColorID__moz_comboboxtext:
       idx = COLOR_WINDOWTEXT;
       break;
     case eColorID__moz_dialog:
     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_mediatext:
       if (IsAppThemed()) {
         res = ::GetColorFromTheme(eUXMediaToolbar,
                                   TP_BUTTON, TS_NORMAL, TMT_TEXTCOLOR, aColor);
         if (NS_SUCCEEDED(res))
           return res;
       }
       // if we've gotten here just return -moz-dialogtext instead
@@ -742,8 +752,47 @@ nsLookAndFeel::SetIntCacheImpl(const nsT
       break;
       case eIntID_WindowsThemeIdentifier:
       mNativeThemeId = entry.value;
       break;
     }
   }
 }
 
+/* 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;
+}
--- a/widget/windows/nsLookAndFeel.h
+++ b/widget/windows/nsLookAndFeel.h
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef __nsLookAndFeel
 #define __nsLookAndFeel
 
 #include "nsXPLookAndFeel.h"
 #include "gfxFont.h"
 #include "mozilla/RangedArray.h"
+#include "nsIWindowsRegKey.h"
 
 /*
  * Gesture System Metrics
  */
 #ifndef SM_DIGITIZER
 #define SM_DIGITIZER         94
 #define TABLET_CONFIG_NONE   0x00000000
 #define NID_INTEGRATED_TOUCH 0x00000001
@@ -46,16 +47,23 @@ public:
                    float aDevPixPerCSSPixel) override;
   void RefreshImpl() override;
   char16_t GetPasswordCharacterImpl() override;
 
   nsTArray<LookAndFeelInt> GetIntCacheImpl() override;
   void SetIntCacheImpl(const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache) override;
 
 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);
+
   // Content process cached values that get shipped over from the browser
   // process.
   int32_t mUseAccessibilityTheme;
   int32_t mUseDefaultTheme; // is the current theme a known default?
   int32_t mNativeThemeId; // see LookAndFeel enum 'WindowsTheme'
 
   struct CachedSystemFont {
     CachedSystemFont()
@@ -66,11 +74,13 @@ private:
     bool mHaveFont;
     nsString mFontName;
     gfxFontStyle mFontStyle;
   };
 
   mozilla::RangedArray<CachedSystemFont,
                        FontID_MINIMUM,
                        FontID_MAXIMUM + 1 - FontID_MINIMUM> mSystemFontCache;
+
+  nsCOMPtr<nsIWindowsRegKey> mDwmKey;
 };
 
 #endif
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -5192,22 +5192,29 @@ nsWindow::ProcessMessage(UINT msg, WPARA
         fontEnum->UpdateFontList(&didChange);
         ForceFontUpdate();
       } //if (NS_SUCCEEDED(rv))
     }
     break;
 
     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();
+            }
           }
         }
       }
     }
     break;
 
     case WM_NCCALCSIZE:
     {