diff --git a/widget/ThemeColors.cpp b/widget/ThemeColors.cpp index 9c7b66784c7f..98279b017a0b 100644 --- a/widget/ThemeColors.cpp +++ b/widget/ThemeColors.cpp @@ -157,10 +157,10 @@ sRGBColor ThemeAccentColor::GetDarker() const { return sRGBColor::FromABGR(ColorPalette::GetDarker(*mAccentColor)); } -auto ThemeColors::ShouldBeHighContrast(const nsPresContext& aPc, - bool aCustomAccentColor) +auto ThemeColors::ShouldBeHighContrast(const nsIFrame* aFrame) -> HighContrastInfo { - if (!aPc.GetBackgroundColorDraw()) { + auto* pc = aFrame->PresContext(); + if (!pc->GetBackgroundColorDraw()) { // 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. @@ -177,18 +177,18 @@ auto ThemeColors::ShouldBeHighContrast(const nsPresContext& aPc, // or in "requested" mode (chrome-only) with no custom accent color. // Otherwise it causes issues when pages only override some of the system // colors, specially in dark themes. - switch (aPc.ForcedColors()) { + switch (pc->ForcedColors()) { case StyleForcedColors::None: break; case StyleForcedColors::Requested: - return !aCustomAccentColor; + return aFrame->StyleUI()->mAccentColor.IsAuto(); case StyleForcedColors::Active: return true; } return false; }(); const bool mustUseLight = - PreferenceSheet::PrefsFor(*aPc.Document()).mMustUseLightSystemColors; + PreferenceSheet::PrefsFor(*pc->Document()).mMustUseLightSystemColors; return {highContrast, mustUseLight}; } diff --git a/widget/ThemeColors.h b/widget/ThemeColors.h index 12d9b12521be..982e02396dc0 100644 --- a/widget/ThemeColors.h +++ b/widget/ThemeColors.h @@ -55,18 +55,17 @@ class ThemeColors { }; const Document& mDoc; + const HighContrastInfo mHighContrastInfo; const ColorScheme mColorScheme; const AccentColor mAccentColor; - const HighContrastInfo mHighContrastInfo; public: explicit ThemeColors(const nsIFrame* aFrame, StyleAppearance aAppearance) : mDoc(*aFrame->PresContext()->Document()), + mHighContrastInfo(ShouldBeHighContrast(aFrame)), mColorScheme( ColorSchemeForWidget(aFrame, aAppearance, mHighContrastInfo)), - mAccentColor(*aFrame->Style(), mColorScheme), - mHighContrastInfo(ShouldBeHighContrast(*aFrame->PresContext(), - mAccentColor.IsCustom())) {} + mAccentColor(*aFrame->Style(), mColorScheme) {} virtual ~ThemeColors() = default; [[nodiscard]] static float ScaleLuminanceBy(float aLuminance, float aFactor) { @@ -102,8 +101,8 @@ class ThemeColors { } // Whether we should use system colors (for high contrast mode). - static HighContrastInfo ShouldBeHighContrast(const nsPresContext&, - bool aCustomAccentColor); + static HighContrastInfo ShouldBeHighContrast(const nsIFrame*); + static ColorScheme ColorSchemeForWidget(const nsIFrame*, StyleAppearance, const HighContrastInfo&);