style: Check for allowed colors recursively in forced-colors mode

Differential Revision: https://phabricator.services.mozilla.com/D149733
This commit is contained in:
Emilio Cobos Álvarez 2022-06-20 14:07:12 +00:00 committed by Martin Robinson
parent f0b7f3aca2
commit 34373c2ac8
2 changed files with 20 additions and 22 deletions

View file

@ -425,13 +425,7 @@ fn tweak_when_ignoring_colors(
// A few special-cases ahead. // A few special-cases ahead.
match **declaration { match **declaration {
PropertyDeclaration::BackgroundColor(ref color) => { PropertyDeclaration::BackgroundColor(ref color) => {
// We honor system colors. // We honor system colors and transparent colors unconditionally.
if color.is_system() {
return;
}
// For background-color, we revert or initial-with-preserved-alpha
// otherwise, this is needed to preserve semi-transparent
// backgrounds.
// //
// NOTE(emilio): We honor transparent unconditionally, like we do // NOTE(emilio): We honor transparent unconditionally, like we do
// for color, even though it causes issues like bug 1625036. The // 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 // broken in other applications as well, and not honoring
// transparent makes stuff uglier or break unconditionally // transparent makes stuff uglier or break unconditionally
// (bug 1666059, bug 1755713). // (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); let alpha = alpha_channel(color, context);
if alpha == 0 { if alpha == 0 {
return; return;
@ -451,10 +451,7 @@ fn tweak_when_ignoring_colors(
}, },
PropertyDeclaration::Color(ref color) => { PropertyDeclaration::Color(ref color) => {
// We honor color: transparent and system colors. // We honor color: transparent and system colors.
if color.0.is_system() { if color.0.honored_in_forced_colors_mode(/* allow_transparent = */ true) {
return;
}
if alpha_channel(&color.0, context) == 0 {
return; return;
} }
// If the inherited color would be transparent, but we would // 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 // caret-color doesn't make sense (using currentColor is fine), and
// we ignore accent-color in high-contrast-mode anyways. // we ignore accent-color in high-contrast-mode anyways.
if let Some(color) = declaration.color_value() { if let Some(color) = declaration.color_value() {
if color.is_system() { if color.honored_in_forced_colors_mode(/* allow_transparent = */ false) {
return; return;
} }
} }

View file

@ -515,16 +515,17 @@ fn parse_hash_color(value: &[u8]) -> Result<RGBA, ()> {
} }
impl Color { impl Color {
/// Returns whether this color is a system color. /// Returns whether this color is allowed in forced-colors mode.
#[cfg(feature = "gecko")] pub fn honored_in_forced_colors_mode(&self, allow_transparent: bool) -> bool {
pub fn is_system(&self) -> bool { match *self {
matches!(self, Color::System(..)) Color::InheritFromBodyQuirk | Color::CurrentColor => false,
} Color::System(..) => true,
Color::Numeric { ref parsed, .. } => allow_transparent && parsed.alpha == 0,
/// Returns whether this color is a system color. Color::ColorMix(ref mix) => {
#[cfg(feature = "servo")] mix.left.honored_in_forced_colors_mode(allow_transparent) &&
pub fn is_system(&self) -> bool { mix.right.honored_in_forced_colors_mode(allow_transparent)
false },
}
} }
/// Returns currentcolor value. /// Returns currentcolor value.