Bug 1330876 - Add a new variant of LookAndFeel::GetColor that uses stand-ins for native colors and accepts default value. r=heycam draft
authorChung-Sheng Fu <cfu@mozilla.com>
Mon, 12 Jun 2017 13:57:17 +0800
changeset 592383 3b857574add35f068a014a5575c6abaf769cf782
parent 590864 82e7d2e1e5724904a4c8e3834248b3ef619f7826
child 632795 13fde97cdefeaf71d43a8260e6a25cdcbbb253f6
push id63363
push userbmo:cfu@mozilla.com
push dateMon, 12 Jun 2017 06:27:51 +0000
reviewersheycam
bugs1330876
milestone55.0a1
Bug 1330876 - Add a new variant of LookAndFeel::GetColor that uses stand-ins for native colors and accepts default value. r=heycam MozReview-Commit-ID: 40tmdTJbLy1
layout/base/nsPresContext.cpp
widget/LookAndFeel.h
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -511,24 +511,20 @@ nsPresContext::GetDocumentColorPreferenc
   if (usePrefColors) {
     usePrefColors =
       !Preferences::GetBool("browser.display.use_system_colors", false);
   }
 
   if (sUseStandinsForNativeColors) {
     // Once the preference "ui.use_standins_for_native_colors" is enabled,
     // use fixed color values instead of prefered colors and system colors.
-    if (NS_FAILED(LookAndFeel::GetColor(
-        LookAndFeel::eColorID_windowtext, true, &mDefaultColor))) {
-      mDefaultColor = NS_RGB(0x00, 0x00, 0x00);
-    }
-    if (NS_FAILED(LookAndFeel::GetColor(
-        LookAndFeel::eColorID_window, true, &mBackgroundColor))) {
-      mBackgroundColor = NS_RGB(0xff, 0xff, 0xff);
-    }
+    mDefaultColor = LookAndFeel::GetColorUsingStandins(
+        LookAndFeel::eColorID_windowtext, NS_RGB(0x00, 0x00, 0x00));
+    mBackgroundColor = LookAndFeel::GetColorUsingStandins(
+        LookAndFeel::eColorID_window, NS_RGB(0xff, 0xff, 0xff));
   } else if (usePrefColors) {
     nsAdoptingString colorStr =
       Preferences::GetString("browser.display.foreground_color");
 
     if (!colorStr.IsEmpty()) {
       mDefaultColor = MakeColorPref(colorStr);
     }
 
--- a/widget/LookAndFeel.h
+++ b/widget/LookAndFeel.h
@@ -530,16 +530,28 @@ public:
   {
     nscolor result = NS_RGB(0, 0, 0);
     if (NS_FAILED(GetColor(aID, &result))) {
       return aDefault;
     }
     return result;
   }
 
+  static nscolor GetColorUsingStandins(ColorID aID,
+                                       nscolor aDefault = NS_RGB(0, 0, 0))
+  {
+    nscolor result = NS_RGB(0, 0, 0);
+    if (NS_FAILED(GetColor(aID,
+                           true, // aUseStandinsForNativeColors
+                           &result))) {
+      return aDefault;
+    }
+    return result;
+  }
+
   static int32_t GetInt(IntID aID, int32_t aDefault = 0)
   {
     int32_t result;
     if (NS_FAILED(GetInt(aID, &result))) {
       return aDefault;
     }
     return result;
   }