Bug 1596050 - Centralize logic to ignore document colors. r=jfkthame
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 15 Nov 2019 13:39:08 +0000
changeset 502175 2a60597c297223332fe440c4c6337a5b1a6edcc7
parent 502174 0860d7cbadd429f0bee361d5e389dd61ef5e54ad
child 502176 58474f8ce95afd72d34a3ea0a82c2e99411f9800
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1596050
milestone72.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 1596050 - Centralize logic to ignore document colors. r=jfkthame This was a follow-up from the backplate stuff which I requested but didn't happen. Differential Revision: https://phabricator.services.mozilla.com/D53170
layout/generic/nsBlockFrame.cpp
layout/style/PreferenceSheet.cpp
layout/style/PreferenceSheet.h
servo/components/style/gecko/media_queries.rs
--- a/layout/generic/nsBlockFrame.cpp
+++ b/layout/generic/nsBlockFrame.cpp
@@ -6837,28 +6837,21 @@ void nsBlockFrame::BuildDisplayList(nsDi
            (ForceDescendIntoIfVisible() &&
             aLineArea.Intersects(aBuilder->GetVisibleRect()));
   };
 
   // We'll try to draw an accessibility backplate behind text
   // (to ensure it's readable over any possible background-images),
   // if all of the following hold:
   //    (A) the backplate feature is preffed on
-  //    (B) we are in high-contrast mode [by browser setting or
-  //        windows setting]
-  //    (C) this is web content (not chrome) -- mUseAccessibilityTheme
-  //        already checks this, so we check IsChrome() explicitly
-  //        in the browser_display_document_color_use == 2 case.
+  //    (B) we are not honoring the document colors
   const bool shouldDrawBackplate =
       StaticPrefs::browser_display_permit_backplate() &&
-      (((PresContext()->PrefSheetPrefs().mUseAccessibilityTheme &&
-         StaticPrefs::browser_display_document_color_use() == 0) ||
-        (StaticPrefs::browser_display_document_color_use() == 2 &&
-         !PresContext()->IsChrome())) &&
-       !IsComboboxControlFrame());
+      !PresContext()->PrefSheetPrefs().mUseDocumentColors &&
+      !IsComboboxControlFrame();
 
   // Don't use the line cursor if we might have a descendant placeholder ...
   // it might skip lines that contain placeholders but don't themselves
   // intersect with the dirty area.
   // In particular, we really want to check ShouldDescendIntoFrame()
   // on all our child frames, but that might be expensive.  So we
   // approximate it by checking it on |this|; if it's true for any
   // frame in our child list, it's also true for |this|.
--- a/layout/style/PreferenceSheet.cpp
+++ b/layout/style/PreferenceSheet.cpp
@@ -58,16 +58,27 @@ bool PreferenceSheet::ShouldUseChromePre
   return false;
 }
 
 static bool UseAccessibilityTheme(bool aIsChrome) {
   return !aIsChrome &&
          !!LookAndFeel::GetInt(LookAndFeel::eIntID_UseAccessibilityTheme, 0);
 }
 
+static bool UseDocumentColors(bool aIsChrome, bool aUseAcccessibilityTheme) {
+  switch (StaticPrefs::browser_display_document_color_use()) {
+    case 1:
+      return true;
+    case 2:
+      return aIsChrome;
+    default:
+      return !aUseAcccessibilityTheme;
+  }
+}
+
 void PreferenceSheet::Prefs::Load(bool aIsChrome) {
   *this = {};
 
   mIsChrome = aIsChrome;
   mUseAccessibilityTheme = UseAccessibilityTheme(aIsChrome);
   mUnderlineLinks = StaticPrefs::browser_underline_anchors();
 
   mUseFocusColors = StaticPrefs::browser_display_use_focus_colors();
@@ -114,16 +125,17 @@ void PreferenceSheet::Prefs::Load(bool a
 
   GetColor("browser.display.focus_text_color", mFocusTextColor);
   GetColor("browser.display.focus_background_color", mFocusBackgroundColor);
 
   // Wherever we got the default background color from, ensure it is
   // opaque.
   mDefaultBackgroundColor =
       NS_ComposeColors(NS_RGB(0xFF, 0xFF, 0xFF), mDefaultBackgroundColor);
+  mUseDocumentColors = UseDocumentColors(aIsChrome, mUseAccessibilityTheme);
 }
 
 void PreferenceSheet::Initialize() {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(!sInitialized);
 
   sInitialized = true;
 
--- a/layout/style/PreferenceSheet.h
+++ b/layout/style/PreferenceSheet.h
@@ -31,16 +31,17 @@ struct PreferenceSheet {
     nscolor mFocusTextColor = mDefaultColor;
     nscolor mFocusBackgroundColor = mDefaultBackgroundColor;
 
     bool mIsChrome = false;
     bool mUseAccessibilityTheme = false;
 
     bool mUnderlineLinks = true;
     bool mUseFocusColors = false;
+    bool mUseDocumentColors = true;
     uint8_t mFocusRingWidth = 1;
     uint8_t mFocusRingStyle = 1;
     bool mFocusRingOnAnything = false;
 
     void Load(bool aIsChrome);
   };
 
   static void EnsureInitialized() {
--- a/servo/components/style/gecko/media_queries.rs
+++ b/servo/components/style/gecko/media_queries.rs
@@ -269,23 +269,17 @@ impl Device {
 
     /// Returns whether document colors are enabled.
     #[inline]
     pub fn use_document_colors(&self) -> bool {
         let doc = self.document();
         if doc.mIsBeingUsedAsImage() {
             return true;
         }
-        let document_color_use = static_prefs::pref!("browser.display.document_color_use");
-        let prefs = self.pref_sheet_prefs();
-        match document_color_use {
-            1 => true,
-            2 => prefs.mIsChrome,
-            _ => !prefs.mUseAccessibilityTheme,
-        }
+        self.pref_sheet_prefs().mUseDocumentColors
     }
 
     /// Returns the default background color.
     pub fn default_background_color(&self) -> RGBA {
         convert_nscolor_to_rgba(self.pref_sheet_prefs().mDefaultBackgroundColor)
     }
 
     /// Returns the current effective text zoom.