Bug 1717873 - Print documents shouldn't use system colors when in hcm. r=morgan

Instead, use default colors.

Testing this properly requires writing test infrastructure for paged tests with
"print backgrounds" settings turned off, not sure if worth it.

Depends on D120679

Differential Revision: https://phabricator.services.mozilla.com/D120680
This commit is contained in:
Emilio Cobos Álvarez 2021-07-24 21:10:44 +00:00
parent 4fe6efa8c9
commit 5512bfda91
3 changed files with 54 additions and 12 deletions

View File

@ -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()) {

View File

@ -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();
};

View File

@ -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<nscolor> LookAndFeel::GetColor(ColorID aId, const dom::Document& aDoc) {