diff --git a/components/style/properties/cascade.rs b/components/style/properties/cascade.rs index 822a7c52053..e3f919cc56e 100644 --- a/components/style/properties/cascade.rs +++ b/components/style/properties/cascade.rs @@ -464,7 +464,22 @@ fn tweak_when_ignoring_colors( } } }, - _ => {}, + _ => { + // We honor transparent and system colors more generally for all + // colors. + // + // NOTE(emilio): This doesn't handle caret-color and + // accent-color because those use a slightly different syntax + // ( | auto for example). That's probably fine though, as + // using a system color for 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() || alpha_channel(color, context) == 0 { + return; + } + } + }, } *declaration.to_mut() = diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index fff28e4bfab..67183062e2f 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -232,7 +232,7 @@ pub mod shorthands { // which don't exist in `LonghandId`. <% - extra = [ + extra_variants = [ { "name": "CSSWideKeyword", "type": "WideKeywordDeclaration", @@ -252,7 +252,7 @@ pub mod shorthands { "copy": False, }, ] - for v in extra: + for v in extra_variants: variants.append(v) groups[v["type"]] = [v] %> @@ -394,6 +394,17 @@ impl MallocSizeOf for PropertyDeclaration { impl PropertyDeclaration { + /// Returns whether this is a variant of the Longhand(Value) type, rather + /// than one of the special variants in extra_variants. + fn is_longhand_value(&self) -> bool { + match *self { + % for v in extra_variants: + PropertyDeclaration::${v["name"]}(..) => false, + % endfor + _ => true, + } + } + /// Like the method on ToCss, but without the type parameter to avoid /// accidentally monomorphizing this large function multiple times for /// different writers. @@ -409,6 +420,24 @@ impl PropertyDeclaration { % endfor } } + + /// Returns the color value of a given property, for high-contrast-mode + /// tweaks. + pub(crate) fn color_value(&self) -> Option<<&crate::values::specified::Color> { + ${static_longhand_id_set("COLOR_PROPERTIES", lambda p: p.predefined_type == "Color")} + <% + # sanity check + assert data.longhands_by_name["background-color"].predefined_type == "Color" + + color_specified_type = data.longhands_by_name["background-color"].specified_type() + %> + let id = self.id().as_longhand()?; + if !COLOR_PROPERTIES.contains(id) || !self.is_longhand_value() { + return None; + } + let repr = self as *const _ as *const PropertyDeclarationVariantRepr<${color_specified_type}>; + Some(unsafe { &(*repr).value }) + } } /// A module with all the code related to animated properties.