From 34373c2ac81131ec9aa8681adc7d546d9e3efc0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 20 Jun 2022 14:07:12 +0000 Subject: [PATCH] style: Check for allowed colors recursively in forced-colors mode Differential Revision: https://phabricator.services.mozilla.com/D149733 --- components/style/properties/cascade.rs | 21 +++++++++------------ components/style/values/specified/color.rs | 21 +++++++++++---------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/components/style/properties/cascade.rs b/components/style/properties/cascade.rs index 3d3c6b833b8..a85d507bd18 100644 --- a/components/style/properties/cascade.rs +++ b/components/style/properties/cascade.rs @@ -425,13 +425,7 @@ 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. + // We honor system colors and transparent colors unconditionally. // // NOTE(emilio): We honor transparent unconditionally, like we do // for color, even though it causes issues like bug 1625036. The @@ -440,6 +434,12 @@ fn tweak_when_ignoring_colors( // broken in other applications as well, and not honoring // transparent makes stuff uglier or break unconditionally // (bug 1666059, bug 1755713). + if color.honored_in_forced_colors_mode(/* allow_transparent = */ true) { + return; + } + // For background-color, we revert or initial-with-preserved-alpha + // otherwise, this is needed to preserve semi-transparent + // backgrounds. let alpha = alpha_channel(color, context); if alpha == 0 { return; @@ -451,10 +451,7 @@ fn tweak_when_ignoring_colors( }, PropertyDeclaration::Color(ref color) => { // We honor color: transparent and system colors. - if color.0.is_system() { - return; - } - if alpha_channel(&color.0, context) == 0 { + if color.0.honored_in_forced_colors_mode(/* allow_transparent = */ true) { return; } // If the inherited color would be transparent, but we would @@ -491,7 +488,7 @@ fn tweak_when_ignoring_colors( // caret-color doesn't make sense (using currentColor is fine), and // we ignore accent-color in high-contrast-mode anyways. if let Some(color) = declaration.color_value() { - if color.is_system() { + if color.honored_in_forced_colors_mode(/* allow_transparent = */ false) { return; } } diff --git a/components/style/values/specified/color.rs b/components/style/values/specified/color.rs index 6a285a265d5..e29f3558e6a 100644 --- a/components/style/values/specified/color.rs +++ b/components/style/values/specified/color.rs @@ -515,16 +515,17 @@ fn parse_hash_color(value: &[u8]) -> Result { } impl Color { - /// Returns whether this color is a system color. - #[cfg(feature = "gecko")] - pub fn is_system(&self) -> bool { - matches!(self, Color::System(..)) - } - - /// Returns whether this color is a system color. - #[cfg(feature = "servo")] - pub fn is_system(&self) -> bool { - false + /// Returns whether this color is allowed in forced-colors mode. + pub fn honored_in_forced_colors_mode(&self, allow_transparent: bool) -> bool { + match *self { + Color::InheritFromBodyQuirk | Color::CurrentColor => false, + Color::System(..) => true, + Color::Numeric { ref parsed, .. } => allow_transparent && parsed.alpha == 0, + Color::ColorMix(ref mix) => { + mix.left.honored_in_forced_colors_mode(allow_transparent) && + mix.right.honored_in_forced_colors_mode(allow_transparent) + }, + } } /// Returns currentcolor value.