Bug 946595 - High contrast themes on Windows 8 shouldn't be considered the default theme in CSS, r=jimm, a=sylvestre.
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 28 Mar 2014 22:13:10 +0000
changeset 183630 250d63775815
parent 183629 3e69377c027a
child 183631 aecbb562466a
push id3426
push usermdeboer@mozilla.com
push date2014-04-04 09:01 +0000
Treeherderresults
reviewersjimm, sylvestre
bugs946595
milestone29.0
Bug 946595 - High contrast themes on Windows 8 shouldn't be considered the default theme in CSS, r=jimm, a=sylvestre.
widget/windows/nsLookAndFeel.cpp
widget/windows/nsUXThemeData.cpp
widget/windows/nsUXThemeData.h
--- a/widget/windows/nsLookAndFeel.cpp
+++ b/widget/windows/nsLookAndFeel.cpp
@@ -370,21 +370,17 @@ nsLookAndFeel::GetIntImpl(IntID aID, int
         break;
     case eIntID_DragThresholdY:
         aResult = ::GetSystemMetrics(SM_CYDRAG) - 1;
         break;
     case eIntID_UseAccessibilityTheme:
         // High contrast is a misnomer under Win32 -- any theme can be used with it, 
         // e.g. normal contrast with large fonts, low contrast, etc.
         // The high contrast flag really means -- use this theme and don't override it.
-        HIGHCONTRAST contrastThemeInfo;
-        contrastThemeInfo.cbSize = sizeof(contrastThemeInfo);
-        ::SystemParametersInfo(SPI_GETHIGHCONTRAST, 0, &contrastThemeInfo, 0);
-
-        aResult = ((contrastThemeInfo.dwFlags & HCF_HIGHCONTRASTON) != 0);
+        aResult = nsUXThemeData::IsHighContrastOn();
         break;
     case eIntID_ScrollArrowStyle:
         aResult = eScrollArrowStyle_Single;
         break;
     case eIntID_ScrollSliderStyle:
         aResult = eScrollThumbStyle_Proportional;
         break;
     case eIntID_TreeOpenDelay:
--- a/widget/windows/nsUXThemeData.cpp
+++ b/widget/windows/nsUXThemeData.cpp
@@ -248,30 +248,37 @@ const THEMELIST knownColors[] = {
   { L"metallic",    WINTHEMECOLOR_METALLIC }
 };
 
 LookAndFeel::WindowsTheme
 nsUXThemeData::sThemeId = LookAndFeel::eWindowsTheme_Generic;
 
 bool
 nsUXThemeData::sIsDefaultWindowsTheme = false;
+bool
+nsUXThemeData::sIsHighContrastOn = false;
 
 // static
 LookAndFeel::WindowsTheme
 nsUXThemeData::GetNativeThemeId()
 {
   return sThemeId;
 }
 
 // static
 bool nsUXThemeData::IsDefaultWindowTheme()
 {
   return sIsDefaultWindowsTheme;
 }
 
+bool nsUXThemeData::IsHighContrastOn()
+{
+  return sIsHighContrastOn;
+}
+
 // static
 bool nsUXThemeData::CheckForCompositor(bool aUpdateCache)
 {
   static BOOL sCachedValue = FALSE;
   if (aUpdateCache && WinUtils::dwmIsCompositionEnabledPtr) {
     WinUtils::dwmIsCompositionEnabledPtr(&sCachedValue);
   }
   return sCachedValue;
@@ -287,16 +294,24 @@ nsUXThemeData::UpdateNativeThemeInfo()
   sIsDefaultWindowsTheme = false;
   sThemeId = LookAndFeel::eWindowsTheme_Generic;
 
   if (!IsAppThemed()) {
     sThemeId = LookAndFeel::eWindowsTheme_Classic;
     return;
   }
 
+  HIGHCONTRAST highContrastInfo;
+  highContrastInfo.cbSize = sizeof(HIGHCONTRAST);
+  if (SystemParametersInfo(SPI_GETHIGHCONTRAST, 0, &highContrastInfo, 0)) {
+    sIsHighContrastOn = ((highContrastInfo.dwFlags & HCF_HIGHCONTRASTON) != 0);
+  } else {
+    sIsHighContrastOn = false;
+  }
+
   WCHAR themeFileName[MAX_PATH + 1];
   WCHAR themeColor[MAX_PATH + 1];
   if (FAILED(GetCurrentThemeName(themeFileName,
                                  MAX_PATH,
                                  themeColor,
                                  MAX_PATH,
                                  nullptr, 0))) {
     sThemeId = LookAndFeel::eWindowsTheme_Classic;
@@ -312,19 +327,26 @@ nsUXThemeData::UpdateNativeThemeInfo()
       theme = (WindowsTheme)knownThemes[i].type;
       break;
     }
   }
 
   if (theme == WINTHEME_UNRECOGNIZED)
     return;
 
-  if (theme == WINTHEME_AERO || theme == WINTHEME_AERO_LITE || theme == WINTHEME_LUNA)
+  // We're using the default theme if we're using any of Aero, Aero Lite, or
+  // luna. However, on Win8, GetCurrentThemeName (see above) returns
+  // AeroLite.msstyles for the 4 builtin highcontrast themes as well. Those
+  // themes "don't count" as default themes, so we specifically check for high
+  // contrast mode in that situation.
+  if (!(IsWin8OrLater() && sIsHighContrastOn) &&
+      (theme == WINTHEME_AERO || theme == WINTHEME_AERO_LITE || theme == WINTHEME_LUNA)) {
     sIsDefaultWindowsTheme = true;
-  
+  }
+
   if (theme != WINTHEME_LUNA) {
     switch(theme) {
       case WINTHEME_AERO:
         sThemeId = LookAndFeel::eWindowsTheme_Aero;
         return;
       case WINTHEME_AERO_LITE:
         sThemeId = LookAndFeel::eWindowsTheme_AeroLite;
         return;
--- a/widget/windows/nsUXThemeData.h
+++ b/widget/windows/nsUXThemeData.h
@@ -87,30 +87,32 @@ class nsUXThemeData {
 public:
   static const wchar_t kThemeLibraryName[];
   static bool sFlatMenus;
   static bool sTitlebarInfoPopulatedAero;
   static bool sTitlebarInfoPopulatedThemed;
   static SIZE sCommandButtons[4];
   static mozilla::LookAndFeel::WindowsTheme sThemeId;
   static bool sIsDefaultWindowsTheme;
+  static bool sIsHighContrastOn;
 
   static void Initialize();
   static void Teardown();
   static void Invalidate();
   static HANDLE GetTheme(nsUXThemeClass cls);
   static HMODULE GetThemeDLL();
 
   // nsWindow calls this to update desktop settings info
   static void InitTitlebarInfo();
   static void UpdateTitlebarInfo(HWND aWnd);
 
   static void UpdateNativeThemeInfo();
   static mozilla::LookAndFeel::WindowsTheme GetNativeThemeId();
   static bool IsDefaultWindowTheme();
+  static bool IsHighContrastOn();
 
   // This method returns the cached compositor state. Most
   // callers should call without the argument. The cache
   // should be modified only when the application receives
   // WM_DWMCOMPOSITIONCHANGED. This rule prevents inconsistent
   // results for two or more calls which check the state during
   // composition transition.
   static bool CheckForCompositor(bool aUpdateCache = false);