From ec3cfdc9892ec0ae64d47ae7b3dcab3d1d1c0e2f Mon Sep 17 00:00:00 2001 From: Emilio Cobos Alvarez Date: Tue, 22 Jun 2021 10:43:17 +0000 Subject: [PATCH] Bug 1717245 - Don't use system colors in the non-native theme if we're not painting backgrounds. r=mstange (Like for printing with backgrounds disabled). Otherwise layout darkens our foreground colors etc, and that causes contrast to be poor. Since the point of not painting backgrounds is saving ink, using the regular colors seems fine. Differential Revision: https://phabricator.services.mozilla.com/D118276 --- widget/gtk/nsNativeBasicThemeGTK.cpp | 2 +- widget/nsNativeBasicTheme.cpp | 14 ++++++++------ widget/nsNativeBasicTheme.h | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/widget/gtk/nsNativeBasicThemeGTK.cpp b/widget/gtk/nsNativeBasicThemeGTK.cpp index 51297cf9fc64..f9ecb9e8c0d2 100644 --- a/widget/gtk/nsNativeBasicThemeGTK.cpp +++ b/widget/gtk/nsNativeBasicThemeGTK.cpp @@ -30,7 +30,7 @@ nsITheme::Transparency nsNativeBasicThemeGTK::GetWidgetTransparency( aAppearance == StyleAppearance::ScrollbarHorizontal) { nsPresContext* pc = aFrame->PresContext(); auto docState = pc->Document()->GetDocumentState(); - const auto useSystemColors = ShouldUseSystemColors(*pc->Document()); + const auto useSystemColors = ShouldUseSystemColors(*pc); const auto* style = nsLayoutUtils::StyleForScrollbar(aFrame); auto trackColor = ComputeScrollbarTrackColor(aFrame, *style, docState, useSystemColors); diff --git a/widget/nsNativeBasicTheme.cpp b/widget/nsNativeBasicTheme.cpp index 1e427294b9df..95f59f4b66b2 100644 --- a/widget/nsNativeBasicTheme.cpp +++ b/widget/nsNativeBasicTheme.cpp @@ -1776,12 +1776,14 @@ static LayoutDeviceRect ToSnappedRect( return LayoutDeviceRect::FromAppUnits(aRect, aTwipsPerPixel); } -auto nsNativeBasicTheme::ShouldUseSystemColors(const dom::Document& aDoc) +auto nsNativeBasicTheme::ShouldUseSystemColors(const nsPresContext& aPc) -> UseSystemColors { - // TODO: Do we really want to use system colors even when the page can - // override the high contrast theme? (mUseDocumentColors = true?). - return UseSystemColors( - PreferenceSheet::PrefsFor(aDoc).NonNativeThemeShouldUseSystemColors()); + // We make sure that we're drawing backgrounds, since otherwise layout will + // darken our used text colors etc anyways, and that can cause contrast issues + // with dark high-contrast themes. + return UseSystemColors(aPc.GetBackgroundColorDraw() && + PreferenceSheet::PrefsFor(*aPc.Document()) + .NonNativeThemeShouldUseSystemColors()); } template @@ -1798,7 +1800,7 @@ bool nsNativeBasicTheme::DoDrawWidgetBackground(PaintBackendData& aPaintData, const auto devPxRect = ToSnappedRect(aRect, twipsPerPixel, aPaintData); const EventStates docState = pc->Document()->GetDocumentState(); - const auto useSystemColors = ShouldUseSystemColors(*pc->Document()); + const auto useSystemColors = ShouldUseSystemColors(*pc); EventStates eventState = GetContentState(aFrame, aAppearance); if (aAppearance == StyleAppearance::MozMenulistArrowButton) { bool isHTML = IsHTMLContent(aFrame); diff --git a/widget/nsNativeBasicTheme.h b/widget/nsNativeBasicTheme.h index 09d8c1e4939e..3ac993331353 100644 --- a/widget/nsNativeBasicTheme.h +++ b/widget/nsNativeBasicTheme.h @@ -184,7 +184,7 @@ class nsNativeBasicTheme : protected nsNativeTheme, public nsITheme { // Whether we should use system colors (for high contrast mode). enum class UseSystemColors : bool { No, Yes }; - static UseSystemColors ShouldUseSystemColors(const mozilla::dom::Document&); + static UseSystemColors ShouldUseSystemColors(const nsPresContext&); std::pair ComputeCheckboxColors(const EventStates&, StyleAppearance,