From b0a1eaebaacaf3ed60ec89a9062c77bb8cc00527 Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Tue, 16 May 2023 10:16:12 +0200 Subject: [PATCH] style: Respect system colors in the color and background-color properties The reason why this doesn't work is because these styles come from datetimebox.css, which is really an author style. We could special-case these elements, but the approach that the CSSWG resolved on for the new forced-colors spec is to respect system colors specified by authors, see: https://drafts.csswg.org/css-color-adjust-1/#forced-colors-properties So this moves us towards that, and fixes the issue nicely. Differential Revision: https://phabricator.services.mozilla.com/D108321 --- components/style/properties/cascade.rs | 9 ++++++++- components/style/values/specified/color.rs | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/components/style/properties/cascade.rs b/components/style/properties/cascade.rs index 275ed7afc38..9c3e6ebd85e 100644 --- a/components/style/properties/cascade.rs +++ b/components/style/properties/cascade.rs @@ -416,6 +416,10 @@ fn tweak_when_ignoring_colors( // A few special-cases ahead. match **declaration { PropertyDeclaration::BackgroundColor(ref color) => { + // We honor system colors. + if color.is_system() { + return; + } // For background-color, we revert or initial-with-preserved-alpha // otherwise, this is needed to preserve semi-transparent // backgrounds. @@ -433,7 +437,10 @@ fn tweak_when_ignoring_colors( } }, PropertyDeclaration::Color(ref color) => { - // We honor color: transparent, and "revert-or-initial" otherwise. + // We honor color: transparent and system colors. + if color.0.is_system() { + return; + } if alpha_channel(&color.0, context) == 0 { return; } diff --git a/components/style/values/specified/color.rs b/components/style/values/specified/color.rs index 486d22fa101..c70d69e01b8 100644 --- a/components/style/values/specified/color.rs +++ b/components/style/values/specified/color.rs @@ -561,6 +561,11 @@ fn parse_hash_color(value: &[u8]) -> Result { } impl Color { + /// Returns whether this color is a system color. + pub fn is_system(&self) -> bool { + matches!(self, Color::System(..)) + } + /// Returns currentcolor value. #[inline] pub fn currentcolor() -> Color {