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
This commit is contained in:
Emilio Cobos Alvarez 2021-06-22 10:43:17 +00:00
parent 556f23b5a4
commit ec3cfdc989
3 changed files with 10 additions and 8 deletions

View File

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

View File

@ -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 <typename PaintBackendData>
@ -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);

View File

@ -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<sRGBColor, sRGBColor> ComputeCheckboxColors(const EventStates&,
StyleAppearance,