diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index a84146192c3e..6fc9cd00cb8a 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -614,6 +614,14 @@ nsPresContext::GetDocumentColorPreferences() int32_t useAccessibilityTheme = 0; bool usePrefColors = true; bool isChromeDocShell = false; + static int32_t sDocumentColorsSetting; + static bool sDocumentColorsSettingPrefCached = false; + if (!sDocumentColorsSettingPrefCached) { + sDocumentColorsSettingPrefCached = true; + Preferences::AddIntVarCache(&sDocumentColorsSetting, + "browser.display.document_color_use", + 0); + } nsIDocument* doc = mDocument->GetDisplayDocument(); if (doc && doc->GetDocShell()) { @@ -669,9 +677,21 @@ nsPresContext::GetDocumentColorPreferences() mBackgroundColor = NS_ComposeColors(NS_RGB(0xFF, 0xFF, 0xFF), mBackgroundColor); - mUseDocumentColors = !useAccessibilityTheme && - Preferences::GetBool("browser.display.use_document_colors", - mUseDocumentColors); + + // Now deal with the pref: + // 0 = default: always, except in high contrast mode + // 1 = always + // 2 = never + if (sDocumentColorsSetting == 1) { + mUseDocumentColors = true; + } else if (sDocumentColorsSetting == 2) { + mUseDocumentColors = isChromeDocShell || mIsChromeOriginImage; + } else { + MOZ_ASSERT(!useAccessibilityTheme || + !(isChromeDocShell || mIsChromeOriginImage), + "The accessibility theme should only be on for non-chrome"); + mUseDocumentColors = !useAccessibilityTheme; + } } void diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index ba273372fa28..eb3e29925b74 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -80,8 +80,7 @@ class ContainerLayer; // supported values for cached bool types enum nsPresContext_CachedBoolPrefType { - kPresContext_UseDocumentColors = 1, - kPresContext_UseDocumentFonts, + kPresContext_UseDocumentFonts = 1, kPresContext_UnderlineLinks }; @@ -378,8 +377,6 @@ public: switch (aPrefType) { case kPresContext_UseDocumentFonts: return mUseDocumentFonts; - case kPresContext_UseDocumentColors: - return mUseDocumentColors; case kPresContext_UnderlineLinks: return mUnderlineLinks; default: @@ -846,7 +843,9 @@ public: // Is it OK to let the page specify colors and backgrounds? bool UseDocumentColors() const { - return GetCachedBoolPref(kPresContext_UseDocumentColors) || IsChrome() || IsChromeOriginImage(); + MOZ_ASSERT(mUseDocumentColors || !(IsChrome() || IsChromeOriginImage()), + "We should never have a chrome doc or image that can't use its colors."); + return mUseDocumentColors; } // Explicitly enable and disable paint flashing. diff --git a/layout/style/test/test_dont_use_document_colors.html b/layout/style/test/test_dont_use_document_colors.html index 99fc9d6e8aaa..ea637a631db1 100644 --- a/layout/style/test/test_dont_use_document_colors.html +++ b/layout/style/test/test_dont_use_document_colors.html @@ -50,7 +50,7 @@ var cs5 = getComputedStyle(document.getElementById("five"), ""); var cs6 = getComputedStyle(document.getElementById("six"), ""); var cs7 = getComputedStyle(document.getElementById("seven"), ""); -SpecialPowers.pushPrefEnv({'set': [['browser.display.use_document_colors', true]]}, part1); +SpecialPowers.pushPrefEnv({'set': [['browser.display.document_color_use', 1]]}, part1); var transparentBackgroundColor; var inputBackgroundColor, inputColor, inputBorderTopColor; @@ -121,7 +121,7 @@ function part1() inputBorderRightColor = cs4.borderRightColor; inputBorderLeftColor = cs4.borderLeftColor; inputBorderBottomColor = cs4.borderBottomColor; - SpecialPowers.pushPrefEnv({'set': [['browser.display.use_document_colors', false]]}, part2); + SpecialPowers.pushPrefEnv({'set': [['browser.display.document_color_use', 2]]}, part2); } function part2() diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index e31d32399abc..bd13ce09b288 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -177,7 +177,10 @@ pref("browser.sessionhistory.max_total_viewers", -1); pref("ui.use_native_colors", true); pref("ui.click_hold_context_menus", false); pref("browser.display.use_document_fonts", 1); // 0 = never, 1 = quick, 2 = always -pref("browser.display.use_document_colors", true); +// 0 = default: always, except in high contrast mode +// 1 = always +// 2 = never +pref("browser.display.document_color_use", 0); pref("browser.display.use_system_colors", false); pref("browser.display.foreground_color", "#000000"); pref("browser.display.background_color", "#FFFFFF");