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
This commit is contained in:
Oriol Brufau 2023-05-16 10:16:12 +02:00
parent ed19da405f
commit b0a1eaebaa
2 changed files with 13 additions and 1 deletions

View file

@ -416,6 +416,10 @@ 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.
if color.is_system() {
return;
}
// For background-color, we revert or initial-with-preserved-alpha // For background-color, we revert or initial-with-preserved-alpha
// otherwise, this is needed to preserve semi-transparent // otherwise, this is needed to preserve semi-transparent
// backgrounds. // backgrounds.
@ -433,7 +437,10 @@ fn tweak_when_ignoring_colors(
} }
}, },
PropertyDeclaration::Color(ref color) => { 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 { if alpha_channel(&color.0, context) == 0 {
return; return;
} }

View file

@ -561,6 +561,11 @@ fn parse_hash_color(value: &[u8]) -> Result<RGBA, ()> {
} }
impl Color { impl Color {
/// Returns whether this color is a system color.
pub fn is_system(&self) -> bool {
matches!(self, Color::System(..))
}
/// Returns currentcolor value. /// Returns currentcolor value.
#[inline] #[inline]
pub fn currentcolor() -> Color { pub fn currentcolor() -> Color {