diff --git a/layout/style/PreferenceSheet.cpp b/layout/style/PreferenceSheet.cpp index 8a847faf3aa5..209d03f4d5f5 100644 --- a/layout/style/PreferenceSheet.cpp +++ b/layout/style/PreferenceSheet.cpp @@ -27,6 +27,7 @@ using dom::Document; bool PreferenceSheet::sInitialized; PreferenceSheet::Prefs PreferenceSheet::sContentPrefs; PreferenceSheet::Prefs PreferenceSheet::sChromePrefs; +PreferenceSheet::Prefs PreferenceSheet::sPrintPrefs; static void GetColor(const char* aPrefName, nscolor& aColor) { nsAutoCString value; @@ -41,24 +42,28 @@ static void GetColor(const char* aPrefName, nscolor& aColor) { aColor = result; } -bool PreferenceSheet::ShouldUseChromePrefs(const Document& aDoc) { +auto PreferenceSheet::PrefsKindFor(const Document& aDoc) -> PrefsKind { // DevTools documents run in a content frame but should temporarily use // chrome preferences, in particular to avoid applying High Contrast mode // colors. See Bug 1575766. if (aDoc.IsDevToolsDocument() && StaticPrefs::devtools_toolbox_force_chrome_prefs()) { - return true; + return PrefsKind::Chrome; } if (aDoc.IsInChromeDocShell()) { - return true; + return PrefsKind::Chrome; } if (aDoc.IsBeingUsedAsImage() && aDoc.IsDocumentURISchemeChrome()) { - return true; + return PrefsKind::Chrome; } - return false; + if (aDoc.IsStaticDocument()) { + return PrefsKind::Print; + } + + return PrefsKind::Content; } static bool UseAccessibilityTheme(bool aIsChrome) { @@ -142,6 +147,10 @@ void PreferenceSheet::Initialize() { sContentPrefs.Load(false); sChromePrefs.Load(true); + sPrintPrefs = sContentPrefs; + if (!sPrintPrefs.mUseDocumentColors) { + sPrintPrefs.mColors = Prefs().mColors; + } nsAutoString useDocumentColorPref; switch (StaticPrefs::browser_display_document_color_use()) { diff --git a/layout/style/PreferenceSheet.h b/layout/style/PreferenceSheet.h index a394212ee37a..00ea0f534053 100644 --- a/layout/style/PreferenceSheet.h +++ b/layout/style/PreferenceSheet.h @@ -69,15 +69,40 @@ struct PreferenceSheet { return sChromePrefs; } - static bool ShouldUseChromePrefs(const dom::Document&); + static Prefs& PrintPrefs() { + MOZ_ASSERT(sInitialized); + return sPrintPrefs; + } + + enum class PrefsKind { + Chrome, + Print, + Content, + }; + + static PrefsKind PrefsKindFor(const dom::Document&); + + static bool ShouldUseChromePrefs(const dom::Document& aDocument) { + return PrefsKindFor(aDocument) == PrefsKind::Chrome; + } + static const Prefs& PrefsFor(const dom::Document& aDocument) { - return ShouldUseChromePrefs(aDocument) ? ChromePrefs() : ContentPrefs(); + switch (PrefsKindFor(aDocument)) { + case PrefsKind::Chrome: + return ChromePrefs(); + case PrefsKind::Print: + return PrintPrefs(); + case PrefsKind::Content: + break; + } + return ContentPrefs(); } private: static bool sInitialized; - static Prefs sContentPrefs; static Prefs sChromePrefs; + static Prefs sPrintPrefs; + static Prefs sContentPrefs; static void Initialize(); }; diff --git a/widget/nsXPLookAndFeel.cpp b/widget/nsXPLookAndFeel.cpp index f7a0d1915608..b2c3b396c1ec 100644 --- a/widget/nsXPLookAndFeel.cpp +++ b/widget/nsXPLookAndFeel.cpp @@ -1043,10 +1043,18 @@ static bool ColorIsCSSAccessible(LookAndFeel::ColorID aId) { LookAndFeel::UseStandins LookAndFeel::ShouldUseStandins( const dom::Document& aDoc, ColorID aId) { - return UseStandins( - ShouldUseStandinsForNativeColorForNonNativeTheme(aDoc, aId) || - (nsContentUtils::UseStandinsForNativeColors() && - !nsContentUtils::IsChromeDoc(&aDoc) && ColorIsCSSAccessible(aId))); + if (ShouldUseStandinsForNativeColorForNonNativeTheme(aDoc, aId)) { + return UseStandins::Yes; + } + if (nsContentUtils::UseStandinsForNativeColors() && + !nsContentUtils::IsChromeDoc(&aDoc) && ColorIsCSSAccessible(aId)) { + return UseStandins::Yes; + } + if (aDoc.IsStaticDocument() && + !PreferenceSheet::ContentPrefs().mUseDocumentColors) { + return UseStandins::Yes; + } + return UseStandins::No; } Maybe LookAndFeel::GetColor(ColorID aId, const dom::Document& aDoc) {