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
This commit is contained in:
Fred Chasen 2023-02-16 21:29:07 +00:00 committed by Martin Robinson
parent 93326b2d2b
commit 9d41dd1ad9
8 changed files with 44 additions and 3 deletions

View file

@ -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 :)

View file

@ -480,6 +480,7 @@ class Longhand(Property):
"PageOrientation",
"Percentage",
"PrintColorAdjust",
"ForcedColorAdjust",
"Resize",
"RubyPosition",
"SVGOpacity",

View file

@ -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",
)}

View file

@ -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):

View file

@ -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;

View file

@ -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;

View file

@ -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,
}

View file

@ -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;