Bug 1591210 - Add forced-color-adjust property r=emilio

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
parent 4d4df405e6
commit cb0a8abc0b
51 changed files with 94 additions and 131 deletions

View File

@ -76,6 +76,7 @@ exports.ANIMATION_TYPE_FOR_LONGHANDS = [
"font-variant-numeric",
"font-variant-position",
"-moz-force-broken-image-icon",
"forced-color-adjust",
"grid-auto-columns",
"grid-auto-flow",
"grid-auto-rows",

View File

@ -3128,6 +3128,7 @@ exports.CSS_PROPERTIES = {
"text-underline-position",
"text-decoration-skip-ink",
"hyphenate-character",
"forced-color-adjust",
"cursor",
"pointer-events",
"-moz-user-input",

View File

@ -2395,18 +2395,27 @@ already_AddRefed<ComputedStyle> nsIFrame::ComputeSelectionStyle(
aSelectionStatus != nsISelectionController::SELECTION_DISABLED) {
return nullptr;
}
// When in high-contrast mode, the style system ends up ignoring the color
// declarations, which means that the ::selection style becomes the inherited
// color, and default background. That's no good.
if (PresContext()->ForcingColors()) {
return nullptr;
}
Element* element = FindElementAncestorForMozSelection(GetContent());
if (!element) {
return nullptr;
}
return PresContext()->StyleSet()->ProbePseudoElementStyle(
*element, PseudoStyleType::selection, Style());
RefPtr<ComputedStyle> pseudoStyle =
PresContext()->StyleSet()->ProbePseudoElementStyle(
*element, PseudoStyleType::selection, Style());
if (!pseudoStyle) {
return nullptr;
}
// When in high-contrast mode, the style system ends up ignoring the color
// declarations, which means that the ::selection style becomes the inherited
// color, and default background. That's no good.
// When force-color-adjust is set to none allow using the color styles,
// as they will not be replaced.
if (PresContext()->ForcingColors() &&
pseudoStyle->StyleText()->mForcedColorAdjust !=
StyleForcedColorAdjust::None) {
return nullptr;
}
return do_AddRef(pseudoStyle);
}
already_AddRefed<ComputedStyle> nsIFrame::ComputeHighlightSelectionStyle(

View File

@ -629,6 +629,7 @@ cbindgen-types = [
{ gecko = "StyleDProperty", servo = "crate::values::specified::svg::DProperty" },
{ gecko = "StyleImageRendering", servo = "crate::values::computed::ImageRendering" },
{ gecko = "StylePrintColorAdjust", servo = "crate::values::computed::PrintColorAdjust" },
{ gecko = "StyleForcedColorAdjust", servo = "crate::values::computed::ForcedColorAdjust" },
{ gecko = "StyleScrollbarGutter", servo = "crate::values::computed::ScrollbarGutter" },
{ gecko = "StyleHyphenateCharacter", servo = "crate::values::computed::HyphenateCharacter" },
{ gecko = "StyleContentVisibility", servo = "crate::values::computed::ContentVisibility" },

View File

@ -2937,6 +2937,7 @@ static StyleRGBA DefaultColor(const Document& aDocument) {
nsStyleText::nsStyleText(const Document& aDocument)
: mColor(DefaultColor(aDocument)),
mForcedColorAdjust(StyleForcedColorAdjust::Auto),
mTextTransform(StyleTextTransform::None()),
mTextAlign(StyleTextAlign::Start),
mTextAlignLast(StyleTextAlignLast::Auto),
@ -2975,6 +2976,7 @@ nsStyleText::nsStyleText(const Document& aDocument)
nsStyleText::nsStyleText(const nsStyleText& aSource)
: mColor(aSource.mColor),
mForcedColorAdjust(aSource.mForcedColorAdjust),
mTextTransform(aSource.mTextTransform),
mTextAlign(aSource.mTextAlign),
mTextAlignLast(aSource.mTextAlignLast),
@ -3086,7 +3088,8 @@ nsChangeHint nsStyleText::CalcDifference(const nsStyleText& aNewData) const {
return hint;
}
if (mTextEmphasisPosition != aNewData.mTextEmphasisPosition) {
if (mTextEmphasisPosition != aNewData.mTextEmphasisPosition ||
mForcedColorAdjust != aNewData.mForcedColorAdjust) {
return nsChangeHint_NeutralChange;
}

View File

@ -941,6 +941,7 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleText {
nsChangeHint CalcDifference(const nsStyleText& aNewData) const;
mozilla::StyleRGBA mColor;
mozilla::StyleForcedColorAdjust mForcedColorAdjust;
mozilla::StyleTextTransform mTextTransform;
mozilla::StyleTextAlign mTextAlign;
mozilla::StyleTextAlignLast mTextAlignLast;

View File

@ -13629,6 +13629,17 @@ if (IsCSSPropertyPrefEnabled("layout.css.color-scheme.enabled")) {
};
}
if (IsCSSPropertyPrefEnabled("layout.css.forced-color-adjust.enabled")) {
gCSSProperties["forced-color-adjust"] = {
domProp: "forcedColorAdjust",
inherited: true,
type: CSS_TYPE_LONGHAND,
initial_values: ["auto"],
other_values: ["none"],
invalid_values: [],
};
}
if (IsCSSPropertyPrefEnabled("layout.css.animation-composition.enabled")) {
gCSSProperties["animation-composition"] = {
domProp: "animationComposition",

View File

@ -8742,6 +8742,13 @@
mirror: always
rust: true
# Is support for forced-color-adjust properties enabled?
- name: layout.css.forced-color-adjust.enabled
type: RelaxedAtomicBool
value: false
mirror: always
rust: true
# Is support for -moz-prefixed animation properties enabled?
- name: layout.css.prefixes.animations
type: bool

View File

@ -425,6 +425,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

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

View File

@ -387,3 +387,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

@ -936,6 +936,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

@ -1054,3 +1054,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;

View File

@ -257,6 +257,7 @@ include = [
"DProperty",
"ImageRendering",
"PrintColorAdjust",
"ForcedColorAdjust",
"ScrollbarGutter",
"ScrollDirection",
"HyphenateCharacter",

View File

@ -1 +1 @@
prefs: [layout.css.color-scheme.enabled:true]
prefs: [layout.css.color-scheme.enabled:true,layout.css.forced-color-adjust.enabled:true]

View File

@ -1,6 +1,3 @@
[inheritance.html]
[Property forced-color-adjust has initial value auto]
expected: FAIL
[Property forced-color-adjust inherits]
expected: FAIL

View File

@ -0,0 +1 @@
prefs: [layout.css.forced-color-adjust.enabled:true]

View File

@ -1,7 +0,0 @@
[inheritance.html]
[Property forced-color-adjust inherits]
expected: FAIL
[Property forced-color-adjust has initial value auto]
expected: FAIL

View File

@ -1,9 +1,3 @@
[forced-color-adjust-computed.html]
[Property forced-color-adjust value 'auto']
expected: FAIL
[Property forced-color-adjust value 'none']
expected: FAIL
[Property forced-color-adjust value 'preserve-parent-color']
expected: FAIL

View File

@ -1,9 +1,3 @@
[forced-color-adjust-valid.html]
[e.style['forced-color-adjust'\] = "auto" should set the property value]
expected: FAIL
[e.style['forced-color-adjust'\] = "none" should set the property value]
expected: FAIL
[e.style['forced-color-adjust'\] = "preserve-parent-color" should set the property value]
expected: FAIL

View File

@ -1 +1,2 @@
leak-threshold: [default:51200]
prefs: [browser.display.document_color_use:2,layout.css.forced-color-adjust.enabled:true]

View File

@ -1,2 +0,0 @@
[forced-colors-mode-backplate-01.html]
expected: FAIL

View File

@ -1,2 +0,0 @@
[forced-colors-mode-backplate-02.html]
expected: FAIL

View File

@ -1,2 +0,0 @@
[forced-colors-mode-backplate-03.html]
expected: FAIL

View File

@ -1,2 +0,0 @@
[forced-colors-mode-backplate-04.html]
expected: FAIL

View File

@ -1,2 +0,0 @@
[forced-colors-mode-backplate-05.html]
expected: FAIL

View File

@ -1,2 +0,0 @@
[forced-colors-mode-backplate-06.html]
expected: FAIL

View File

@ -1,2 +0,0 @@
[forced-colors-mode-backplate-08.html]
expected: FAIL

View File

@ -1,2 +0,0 @@
[forced-colors-mode-backplate-09.html]
expected: FAIL

View File

@ -1,2 +0,0 @@
[forced-colors-mode-backplate-10.html]
expected: FAIL

View File

@ -1,2 +0,0 @@
[forced-colors-mode-01.html]
expected: FAIL

View File

@ -1,2 +0,0 @@
[forced-colors-mode-02.html]
expected: FAIL

View File

@ -1,2 +0,0 @@
[forced-colors-mode-05.html]
expected: FAIL

View File

@ -1,3 +0,0 @@
[forced-colors-mode-06.html]
expected:
FAIL

View File

@ -1,2 +0,0 @@
[forced-colors-mode-08.html]
expected: FAIL

View File

@ -1,4 +0,0 @@
[forced-colors-mode-09.html]
[Checks that styles defined inside/outside forced-colors are overridden in forced colors mode.]
expected: FAIL

View File

@ -1,4 +0,0 @@
[forced-colors-mode-10.html]
[Checks that styles defined inside/outside forced-colors are preserved in forced colors mode if forced-color-ajust is none.]
expected: FAIL

View File

@ -1,4 +0,0 @@
[forced-colors-mode-11.html]
[Checks that styles defined in forced-colors are preserved in forced colors mode.]
expected: FAIL

View File

@ -1,2 +1,4 @@
[forced-colors-mode-14.html]
expected: FAIL
expected:
if (os == "linux"): PASS
FAIL

View File

@ -1,2 +0,0 @@
[forced-colors-mode-17.html]
expected: FAIL

View File

@ -1,2 +0,0 @@
[forced-colors-mode-18.html]
expected: FAIL

View File

@ -1,5 +0,0 @@
[forced-colors-mode-20.html]
expected:
if (os == "android") and fission: [OK, TIMEOUT]
[Checks that background color alpha channels are preserved in forced colors mode.]
expected: FAIL

View File

@ -1,5 +0,0 @@
[forced-colors-mode-21.html]
expected:
if (os == "android") and fission: [TIMEOUT, OK]
[Checks that background color alpha channels are preserved in forced colors mode at the root node.]
expected: FAIL

View File

@ -1,5 +0,0 @@
[forced-colors-mode-27.html]
expected:
if (os == "android") and fission: [OK, TIMEOUT]
[Checks that html/head color is overridden to CanvasText.]
expected: FAIL

View File

@ -1,2 +0,0 @@
[forced-colors-mode-28.html]
expected: FAIL

View File

@ -1,2 +0,0 @@
[forced-colors-mode-39.html]
expected: FAIL

View File

@ -1,29 +0,0 @@
[forced-colors-mode-41.html]
expected:
if (os == "android") and fission: [OK, TIMEOUT]
[Forced colors affects the resolved value of border-left-color]
expected: FAIL
[Forced colors affects the resolved value of background-color]
expected: FAIL
[Forced colors affects the resolved value of outline-color]
expected: FAIL
[Forced colors affects the resolved value of border-top-color]
expected: FAIL
[Forced colors affects the resolved value of border-right-color]
expected: FAIL
[Forced colors affects the resolved value of color]
expected: FAIL
[Forced colors affects the resolved value of border-bottom-color]
expected: FAIL
[Forced colors affects the resolved value of caret-color]
expected: FAIL
[Forced colors affects the resolved value of accent-color]
expected: FAIL

View File

@ -1,2 +0,0 @@
[forced-colors-mode-52.html]
expected: FAIL