Commit 8c7161dc authored by Alison Maher's avatar Alison Maher Committed by Commit Bot

Don't adjust SVG text in forced colors mode

As per the following spec resolution, SVG text no longer should be
adjusted in forced colors mode by default.
https://github.com/w3c/csswg-drafts/issues/3855

Bug: 970285
Change-Id: I11a785f64ca6f7e7840b17d6b59d4ce9b9f8b4e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2055431Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Commit-Queue: Alison Maher <almaher@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#743163}
parent 634cde89
......@@ -1632,7 +1632,9 @@ void StyleResolver::ApplyForcedColors(StyleResolverState& state,
ApplyProperty(GetCSSPropertyBorderTopColor(), state, *unset, apply_mask);
ApplyProperty(GetCSSPropertyBoxShadow(), state, *unset, apply_mask);
ApplyProperty(GetCSSPropertyColumnRuleColor(), state, *unset, apply_mask);
ApplyProperty(GetCSSPropertyFill(), state, *unset, apply_mask);
ApplyProperty(GetCSSPropertyOutlineColor(), state, *unset, apply_mask);
ApplyProperty(GetCSSPropertyStroke(), state, *unset, apply_mask);
ApplyProperty(GetCSSPropertyTextDecorationColor(), state, *unset,
apply_mask);
ApplyProperty(GetCSSPropertyTextShadow(), state, *unset, apply_mask);
......@@ -1641,13 +1643,6 @@ void StyleResolver::ApplyForcedColors(StyleResolverState& state,
ApplyProperty(GetCSSPropertyWebkitTextEmphasisColor(), state, *unset,
apply_mask);
// Only revert fill and stroke for elements that handle fill and stroke
// forced colors in the UA stylesheet.
if (state.GetElement().IsSVGElement()) {
ApplyProperty(GetCSSPropertyFill(), state, *unset, apply_mask);
ApplyProperty(GetCSSPropertyStroke(), state, *unset, apply_mask);
}
// Background colors compute to the Canvas system color for all values
// except for the alpha channel.
RGBA32 prev_bg_color = state.Style()->BackgroundColor().GetColor().Rgb();
......@@ -2134,20 +2129,14 @@ void StyleResolver::CascadeAndApplyForcedColors(StyleResolverState& state,
set->SetProperty(CSSPropertyID::kBoxShadow, *unset);
set->SetProperty(CSSPropertyID::kColor, *unset);
set->SetProperty(CSSPropertyID::kColumnRuleColor, *unset);
set->SetProperty(CSSPropertyID::kFill, *unset);
set->SetProperty(CSSPropertyID::kOutlineColor, *unset);
set->SetProperty(CSSPropertyID::kOutlineColor, *unset);
set->SetProperty(CSSPropertyID::kStroke, *unset);
set->SetProperty(CSSPropertyID::kTextDecorationColor, *unset);
set->SetProperty(CSSPropertyID::kTextShadow, *unset);
set->SetProperty(CSSPropertyID::kWebkitTapHighlightColor, *unset);
set->SetProperty(CSSPropertyID::kWebkitTextEmphasisColor, *unset);
// Only revert fill and stroke for elements that handle fill and stroke
// forced colors in the UA stylesheet.
if (state.GetElement().IsSVGElement()) {
set->SetProperty(CSSPropertyID::kFill, *unset);
set->SetProperty(CSSPropertyID::kStroke, *unset);
}
amended_result.AddMatchedProperties(set);
for (const auto& matched_properties : result.UaRules()) {
......
......@@ -95,13 +95,15 @@ foreignObject {
https://drafts.csswg.org/css-color-adjust-1/#forced-colors-properties
*/
@media forced-colors {
svg {
svg:root {
color: CanvasText;
}
svg {
forced-color-adjust: none;
}
text, foreignObject {
fill: CanvasText;
foreignObject {
forced-color-adjust: auto;
}
}
......@@ -12,6 +12,7 @@
body {
background-color: Canvas;
color: CanvasText;
fill: currentColor;
}
:focus {
......
<!DOCTYPE html>
<meta charset="utf-8">
<title>Forced colors mode - fill and stroke reference.
Only text and foreignObject svg elements should have fill and stroke
<title>Forced colors mode - svg.
Only foreignObject svg elements should have styles
overridden in forced colors mode.
</title>
<style>
......@@ -11,18 +11,26 @@
</style>
<body>
<svg height="600" width="600">
<text x="0" y="15" fill="WindowText">
This text should have a WindowText fill and transparent stroke color in
<text x="0" y="15" fill="red" stroke="blue">
This text should have a red fill and blue stroke color in
forced colors mode.
</text>
<rect x="0" height="60" y="30" width="180" style="fill: red; stroke: blue;"/>
<foreignObject x="20" y="100" width="160" height="160">
<div xmlns="http://www.w3.org/1999/xhtml" style="color: WindowText;">
This text should be WindowText color in forced colors mode.
<div xmlns="http://www.w3.org/1999/xhtml" style="color: orange;">
This text should be orange in forced colors mode due to inheritance.
</div>
<svg height="20" width="20">
<rect x="0" height="20" y="0" width="20" style="fill: green; stroke: purple;"/>
</svg>
</foreignObject>
</svg>
<svg height="600" width="600">
<foreignObject x="20" y="100" width="160" height="160" style="color: CanvasText;">
<div xmlns="http://www.w3.org/1999/xhtml">
This text should be CanvasText in forced colors mode.
</div>
</foreignObject>
</svg>
</body>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Forced colors mode - fill and stroke.
Only text and foreignObject svg elements should have fill and stroke
<title>Forced colors mode - svg.
Only foreignObject svg elements should have styles
overridden in forced colors mode.
</title>
<link rel="help" href="https://www.w3.org/TR/css-color-adjust-1/#forced-colors-properties">
<link rel=match href="forced-colors-mode-18.tentative-ref.html">
<link rel=match href="forced-colors-mode-18-ref.html">
<body>
<!-- Discussions on SVG styles in forced colors mode are ongoing:
https://github.com/w3c/csswg-drafts/issues/3855 -->
<svg height="600" width="600">
<svg height="600" width="600" style="color: orange">
<text x="0" y="15" fill="red" stroke="blue">
This text should have a WindowText fill and transparent stroke color in
This text should have a red fill and blue stroke color in
forced colors mode.
</text>
<rect x="0" height="60" y="30" width="180" style="fill: red; stroke: blue;"/>
<foreignObject x="20" y="100" width="160" height="160">
<div xmlns="http://www.w3.org/1999/xhtml" style="color: blue;">
This text should be WindowText color in forced colors mode.
<foreignObject x="20" y="100" width="160" height="160" style="color: blue;">
<div xmlns="http://www.w3.org/1999/xhtml">
This text should be orange in forced colors mode due to inheritance.
</div>
<svg height="20" width="20">
<rect x="0" height="20" y="0" width="20" style="fill: green; stroke: purple;"/>
</svg>
</foreignObject>
</svg>
<svg height="600" width="600">
<foreignObject x="20" y="100" width="160" height="160" style="color: blue;">
<div xmlns="http://www.w3.org/1999/xhtml">
This text should be CanvasText in forced colors mode.
</div>
</foreignObject>
</svg>
</body>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Forced colors mode - fill/stroke inheritance.
Tests that fill and stroke colors are properly inherited from parent elements.
<title>Forced colors mode - fill/stroke.
</title>
<style>
body {
......@@ -9,8 +8,8 @@
}
</style>
<body>
The triangle below should be red when forced colors mode is enabled and disabled.
The triangle below should be currentColor when forced colors mode.
<svg height="600" width="600">
<path fill="red" stroke="blue" d="M150 0 L75 200 L225 200 Z" />
<path fill="currentColor" d="M150 0 L75 200 L225 200 Z" />
</svg>
</body>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Forced colors mode - fill/stroke inheritance.
Tests that fill and stroke colors are properly inherited from parent elements.
<title>Forced colors mode - fill/stroke.
</title>
<link rel="help" href="https://www.w3.org/TR/css-color-adjust-1/#forced-colors-properties">
<link rel=match href="forced-colors-mode-26.tentative-ref.html">
<link rel=match href="forced-colors-mode-26-ref.html">
<style>
div {
fill: red;
......@@ -13,9 +12,7 @@
</style>
<body>
<div>
The triangle below should be red when forced colors mode is enabled and disabled.
<!-- Discussions on SVG styles in forced colors mode are ongoing:
https://github.com/w3c/csswg-drafts/issues/3855 -->
The triangle below should be currentColor when forced colors mode.
<svg height="600" width="600">
<path d="M150 0 L75 200 L225 200 Z" />
</svg>
......
......@@ -2,7 +2,7 @@
<meta charset="utf-8">
<title>
Forced colors mode - backplate.
Tests backplate is drawn behind SVG text.
Tests backplate is NOT drawn behind SVG text.
</title>
<link rel="help" href="https://www.w3.org/TR/css-color-adjust-1/#forced">
<style>
......@@ -15,7 +15,7 @@
<div>
<svg>
<text x="50" y="50" width="226" height="11" font-family="Ahem">
This text should have a backplate in <tspan>forced colors mode.</tspan>
This text should NOT have a backplate in <tspan>forced colors mode.</tspan>
</text>
</svg>
</div>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment