From 9d41dd1ad9c0dafd9378d3b2cb387021cca207b9 Mon Sep 17 00:00:00 2001 From: Fred Chasen Date: Thu, 16 Feb 2023 21:29:07 +0000 Subject: [PATCH] style: Add forced-color-adjust property Adds the forced-color-adjust property and ForcedColorAdjust keywords. Updates tweak_when_ignoring_colors to check for `none` value of that property when determining if a color adjustment in needed. Adds a check for `none` when styling selections to make sure they can be styled in forced color modes. Differential Revision: https://phabricator.services.mozilla.com/D169000 --- components/style/properties/cascade.rs | 6 +++++ components/style/properties/data.py | 1 + .../longhands/inherited_text.mako.rs | 11 ++++++++++ .../style/properties/properties.mako.rs | 1 + components/style/values/computed/color.rs | 2 +- components/style/values/computed/mod.rs | 2 +- components/style/values/specified/color.rs | 22 +++++++++++++++++++ components/style/values/specified/mod.rs | 2 +- 8 files changed, 44 insertions(+), 3 deletions(-) diff --git a/components/style/properties/cascade.rs b/components/style/properties/cascade.rs index 7de0d61a252..be0a24e92e5 100644 --- a/components/style/properties/cascade.rs +++ b/components/style/properties/cascade.rs @@ -424,6 +424,12 @@ fn tweak_when_ignoring_colors( return; } + // Always honor colors if forced-color-adjust is set to none. + let forced = context.builder.get_inherited_text().clone_forced_color_adjust(); + if forced == computed::ForcedColorAdjust::None { + return; + } + // Don't override background-color on ::-moz-color-swatch. It is set as an // author style (via the style attribute), but it's pretty important for it // to show up for obvious reasons :) diff --git a/components/style/properties/data.py b/components/style/properties/data.py index 0a30b4152d9..109689fb5de 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -480,6 +480,7 @@ class Longhand(Property): "PageOrientation", "Percentage", "PrintColorAdjust", + "ForcedColorAdjust", "Resize", "RubyPosition", "SVGOpacity", diff --git a/components/style/properties/longhands/inherited_text.mako.rs b/components/style/properties/longhands/inherited_text.mako.rs index 9a6eb4f410e..0fc77e0cae9 100644 --- a/components/style/properties/longhands/inherited_text.mako.rs +++ b/components/style/properties/longhands/inherited_text.mako.rs @@ -388,3 +388,14 @@ ${helpers.predefined_type( animation_value_type="discrete", spec="https://www.w3.org/TR/css-text-4/#hyphenate-character", )} + +${helpers.predefined_type( + "forced-color-adjust", + "ForcedColorAdjust", + "computed::ForcedColorAdjust::Auto", + engines="gecko", + gecko_pref="layout.css.forced-color-adjust.enabled", + has_effect_on_gecko_scrollbars=False, + animation_value_type="discrete", + spec="https://drafts.csswg.org/css-color-adjust-1/#forced-color-adjust-prop", +)} diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 5aabb5c5367..840d4e5be6c 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -935,6 +935,7 @@ CASCADE_GROUPS = { "font-family", # color-scheme affects how system colors resolve. "color-scheme", + "forced-color-adjust", ], } def in_late_group(p): diff --git a/components/style/values/computed/color.rs b/components/style/values/computed/color.rs index 89266f3c6e3..96e1aae8d32 100644 --- a/components/style/values/computed/color.rs +++ b/components/style/values/computed/color.rs @@ -12,7 +12,7 @@ use cssparser::{Color as CSSParserColor, RGBA}; use std::fmt; use style_traits::{CssWriter, ToCss}; -pub use crate::values::specified::color::{ColorScheme, PrintColorAdjust}; +pub use crate::values::specified::color::{ColorScheme, PrintColorAdjust, ForcedColorAdjust}; /// The computed value of the `color` property. pub type ColorPropertyValue = RGBA; diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 2a36232656e..49048711643 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -59,7 +59,7 @@ pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize, S pub use self::box_::{ScrollAxis, ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStop}; pub use self::box_::{ScrollSnapStrictness, ScrollSnapType, ScrollTimelineName}; pub use self::box_::{TouchAction, VerticalAlign, WillChange}; -pub use self::color::{Color, ColorOrAuto, ColorPropertyValue, ColorScheme, PrintColorAdjust}; +pub use self::color::{Color, ColorOrAuto, ColorPropertyValue, ColorScheme, PrintColorAdjust, ForcedColorAdjust}; pub use self::column::ColumnCount; pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset, CounterSet}; pub use self::easing::TimingFunction; diff --git a/components/style/values/specified/color.rs b/components/style/values/specified/color.rs index 8d03e523a78..9fa04150d0b 100644 --- a/components/style/values/specified/color.rs +++ b/components/style/values/specified/color.rs @@ -1073,3 +1073,25 @@ pub enum PrintColorAdjust { /// Respect specified colors. Exact, } + +/// https://drafts.csswg.org/css-color-adjust-1/#forced-color-adjust-prop +#[derive( + Clone, + Copy, + Debug, + MallocSizeOf, + Parse, + PartialEq, + SpecifiedValueInfo, + ToCss, + ToComputedValue, + ToResolvedValue, + ToShmem, +)] +#[repr(u8)] +pub enum ForcedColorAdjust { + /// Adjust colors if needed. + Auto, + /// Respect specified colors. + None, +} diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index a566a3fdf89..3dedfa221ca 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -45,7 +45,7 @@ pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize, S pub use self::box_::{ScrollAxis, ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStop}; pub use self::box_::{ScrollSnapStrictness, ScrollSnapType, ScrollTimelineName}; pub use self::box_::{TouchAction, TransitionProperty, VerticalAlign, WillChange}; -pub use self::color::{Color, ColorOrAuto, ColorPropertyValue, ColorScheme, PrintColorAdjust}; +pub use self::color::{Color, ColorOrAuto, ColorPropertyValue, ColorScheme, PrintColorAdjust, ForcedColorAdjust}; pub use self::column::ColumnCount; pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset, CounterSet}; pub use self::easing::TimingFunction;