Commit e4b4bc16 authored by Alison Maher's avatar Alison Maher Committed by Commit Bot

Force fill/stroke color at used value time

Forced colors should now happen at used value time. This change adjusts
the used value of fill, stroke, -internal-visited-fill, and
-internal-visited-stroke to take forced colors into account. No internal
properties were needed since we only ever force fill and stroke to one
value in forced colors mode.

The other forced color properties will be moved in follow up changes.

Note: This change will result in some functional differences with the
current fill/stroke behavior in forced colors mode. SVG elements have
"forced-color-adjust:none" set. Previously, SVG elements could inherit
forced colors from their ancestors. Now, since we force at used value
time, the used value of fill/stroke for SVG elements can no longer
inherit forced colors (unless "forced-color-adjust:auto" is set by
the author).

The related web tests have been updated to reflect this change in
behavior.

Bug: 970285
Change-Id: I5bcc498a67dbd49d7b319f7f079d062d73586013
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2515228
Commit-Queue: Alison Maher <almaher@microsoft.com>
Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#829948}
parent 0cb0baf1
...@@ -2605,6 +2605,8 @@ const blink::Color Fill::ColorIncludingFallback( ...@@ -2605,6 +2605,8 @@ const blink::Color Fill::ColorIncludingFallback(
DCHECK(!visited_link); DCHECK(!visited_link);
DCHECK(style.SvgStyle().FillPaint().HasColor()); DCHECK(style.SvgStyle().FillPaint().HasColor());
StyleColor fill_color = style.SvgStyle().FillPaint().GetColor(); StyleColor fill_color = style.SvgStyle().FillPaint().GetColor();
if (style.ShouldForceColor(fill_color))
return style.GetCurrentColor();
return fill_color.Resolve(style.GetCurrentColor(), style.UsedColorScheme()); return fill_color.Resolve(style.GetCurrentColor(), style.UsedColorScheme());
} }
...@@ -3720,6 +3722,8 @@ const blink::Color InternalVisitedFill::ColorIncludingFallback( ...@@ -3720,6 +3722,8 @@ const blink::Color InternalVisitedFill::ColorIncludingFallback(
.ColorIncludingFallback(false, style); .ColorIncludingFallback(false, style);
} }
StyleColor visited_fill_color = paint.GetColor(); StyleColor visited_fill_color = paint.GetColor();
if (style.ShouldForceColor(visited_fill_color))
return style.GetInternalVisitedCurrentColor();
return visited_fill_color.Resolve(style.GetInternalVisitedCurrentColor(), return visited_fill_color.Resolve(style.GetInternalVisitedCurrentColor(),
style.UsedColorScheme()); style.UsedColorScheme());
} }
...@@ -3775,6 +3779,8 @@ const blink::Color InternalVisitedStroke::ColorIncludingFallback( ...@@ -3775,6 +3779,8 @@ const blink::Color InternalVisitedStroke::ColorIncludingFallback(
.ColorIncludingFallback(false, style); .ColorIncludingFallback(false, style);
} }
StyleColor visited_stroke_color = paint.GetColor(); StyleColor visited_stroke_color = paint.GetColor();
if (style.ShouldForceColor(visited_stroke_color))
return style.GetInternalVisitedCurrentColor();
return visited_stroke_color.Resolve(style.GetInternalVisitedCurrentColor(), return visited_stroke_color.Resolve(style.GetInternalVisitedCurrentColor(),
style.UsedColorScheme()); style.UsedColorScheme());
} }
...@@ -6283,6 +6289,8 @@ const blink::Color Stroke::ColorIncludingFallback( ...@@ -6283,6 +6289,8 @@ const blink::Color Stroke::ColorIncludingFallback(
DCHECK(!visited_link); DCHECK(!visited_link);
DCHECK(style.SvgStyle().StrokePaint().HasColor()); DCHECK(style.SvgStyle().StrokePaint().HasColor());
StyleColor stroke_color = style.SvgStyle().StrokePaint().GetColor(); StyleColor stroke_color = style.SvgStyle().StrokePaint().GetColor();
if (style.ShouldForceColor(stroke_color))
return style.GetCurrentColor();
return stroke_color.Resolve(style.GetCurrentColor(), style.UsedColorScheme()); return stroke_color.Resolve(style.GetCurrentColor(), style.UsedColorScheme());
} }
......
...@@ -574,12 +574,8 @@ void StyleCascade::ForceColors() { ...@@ -574,12 +574,8 @@ void StyleCascade::ForceColors() {
style->ForcedColorAdjust() == EForcedColorAdjust::kNone) style->ForcedColorAdjust() == EForcedColorAdjust::kNone)
return; return;
const SVGComputedStyle& svg_style = style->SvgStyle();
MaybeForceColor(GetCSSPropertyColor(), style->GetColor()); MaybeForceColor(GetCSSPropertyColor(), style->GetColor());
MaybeForceColor(GetCSSPropertyFill(), svg_style.FillPaint().GetColor());
MaybeForceColor(GetCSSPropertyOutlineColor(), style->OutlineColor()); MaybeForceColor(GetCSSPropertyOutlineColor(), style->OutlineColor());
MaybeForceColor(GetCSSPropertyStroke(), svg_style.StrokePaint().GetColor());
MaybeForceColor(GetCSSPropertyTextDecorationColor(), MaybeForceColor(GetCSSPropertyTextDecorationColor(),
style->TextDecorationColor()); style->TextDecorationColor());
MaybeForceColor(GetCSSPropertyColumnRuleColor(), style->ColumnRuleColor()); MaybeForceColor(GetCSSPropertyColumnRuleColor(), style->ColumnRuleColor());
...@@ -589,12 +585,8 @@ void StyleCascade::ForceColors() { ...@@ -589,12 +585,8 @@ void StyleCascade::ForceColors() {
style->TextEmphasisColor()); style->TextEmphasisColor());
MaybeForceColor(GetCSSPropertyInternalVisitedColor(), MaybeForceColor(GetCSSPropertyInternalVisitedColor(),
style->InternalVisitedColor()); style->InternalVisitedColor());
MaybeForceColor(GetCSSPropertyInternalVisitedFill(),
svg_style.InternalVisitedFillPaint().GetColor());
MaybeForceColor(GetCSSPropertyInternalVisitedOutlineColor(), MaybeForceColor(GetCSSPropertyInternalVisitedOutlineColor(),
style->InternalVisitedOutlineColor()); style->InternalVisitedOutlineColor());
MaybeForceColor(GetCSSPropertyInternalVisitedStroke(),
svg_style.InternalVisitedStrokePaint().GetColor());
MaybeForceColor(GetCSSPropertyInternalVisitedTextDecorationColor(), MaybeForceColor(GetCSSPropertyInternalVisitedTextDecorationColor(),
style->InternalVisitedTextDecorationColor()); style->InternalVisitedTextDecorationColor());
MaybeForceColor(GetCSSPropertyInternalVisitedColumnRuleColor(), MaybeForceColor(GetCSSPropertyInternalVisitedColumnRuleColor(),
......
...@@ -90,10 +90,6 @@ tspan, textPath { ...@@ -90,10 +90,6 @@ tspan, textPath {
https://drafts.csswg.org/css-color-adjust-1/#forced-colors-properties https://drafts.csswg.org/css-color-adjust-1/#forced-colors-properties
*/ */
@media ua-forced-colors { @media ua-forced-colors {
svg:root {
color: CanvasText;
}
svg { svg {
forced-color-adjust: none; forced-color-adjust: none;
} }
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
@media ua-forced-colors { @media ua-forced-colors {
html { html {
color: CanvasText; color: CanvasText;
fill: currentColor;
} }
:focus { :focus {
......
...@@ -8,8 +8,12 @@ ...@@ -8,8 +8,12 @@
} }
</style> </style>
<body> <body>
The triangle below should be currentColor when forced colors mode. The triangle below should NOT get overridden in forced colors mode.
<svg height="600" width="600"> <svg height="200" width="350">
<path fill="currentColor" d="M150 0 L75 200 L225 200 Z" /> <path fill="red" stroke="blue" d="M150 0 L75 200 L225 200 Z" />
</svg>
The triangle below should be currentColor in forced colors mode.
<svg height="200" width="350">
<path fill="currentColor" stroke="currentColor" d="M150 0 L75 200 L225 200 Z" />
</svg> </svg>
</body> </body>
...@@ -12,8 +12,12 @@ ...@@ -12,8 +12,12 @@
</style> </style>
<body> <body>
<div> <div>
The triangle below should be currentColor when forced colors mode. The triangle below should NOT get overridden in forced colors mode.
<svg height="600" width="600"> <svg height="200" width="350">
<path d="M150 0 L75 200 L225 200 Z" />
</svg>
The triangle below should be currentColor in forced colors mode.
<svg height="200" width="350" style="forced-color-adjust: auto;">
<path d="M150 0 L75 200 L225 200 Z" /> <path d="M150 0 L75 200 L225 200 Z" />
</svg> </svg>
</div> </div>
......
...@@ -4,14 +4,17 @@ ...@@ -4,14 +4,17 @@
</title> </title>
<style> <style>
a { a {
fill: VisitedText; color: VisitedText;
forced-color-adjust: none; forced-color-adjust: none;
} }
</style> </style>
<a href=""> <a href="">
The triangle below should not preserve the blue/green fill/stroke colors The triangle below should NOT get overridden in forced colors mode.
in forced colors mode. <svg height="200" width="350">
<svg height="600" width="600"> <path fill="blue" stroke="green" d="M150 0 L75 200 L225 200 Z" />
<path d="M150 0 L75 200 L225 200 Z" /> </svg>
The triangle below should be currentColor in forced colors mode.
<svg height="200" width="350">
<path fill="currentColor" stroke="currentColor" d="M150 0 L75 200 L225 200 Z" />
</svg> </svg>
</a> </a>
\ No newline at end of file
...@@ -15,9 +15,12 @@ ...@@ -15,9 +15,12 @@
} }
</style> </style>
<a href=""> <a href="">
The triangle below should not preserve the blue/green fill/stroke colors The triangle below should NOT get overridden in forced colors mode.
in forced colors mode. <svg height="200" width="350">
<svg height="600" width="600"> <path d="M150 0 L75 200 L225 200 Z" />
</svg>
The triangle below should be currentColor in forced colors mode.
<svg height="200" width="350" style="forced-color-adjust: auto;">
<path d="M150 0 L75 200 L225 200 Z" /> <path d="M150 0 L75 200 L225 200 Z" />
</svg> </svg>
</a> </a>
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
div { div {
background-color: green; background-color: green;
border-color: green; border-color: green;
fill: green;
stroke: green;
} }
</style> </style>
<div id="div"> <div id="div">
...@@ -23,6 +25,8 @@ ...@@ -23,6 +25,8 @@
"border-left-color", "border-left-color",
"border-right-color", "border-right-color",
"border-top-color", "border-top-color",
"fill",
"stroke"
]; ];
for (let property of properties_to_test) { for (let property of properties_to_test) {
test(function() { test(function() {
......
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