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

Visited background-color alpha channel in Forced Colors Mode

Handle :visited background-colors in a similar way to the normal
background-color property in Forced Colors Mode.

Bug: 970285
Change-Id: I1dd0ac2530f3dec7de4b79de459d34e1d2ae193b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2393299Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Alison Maher <almaher@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#805825}
parent 4bd5c962
...@@ -550,6 +550,8 @@ void StyleCascade::ForceColors() { ...@@ -550,6 +550,8 @@ void StyleCascade::ForceColors() {
int bg_color_alpha = int bg_color_alpha =
style->VisitedDependentColor(GetCSSPropertyBackgroundColor()).Alpha(); style->VisitedDependentColor(GetCSSPropertyBackgroundColor()).Alpha();
int visited_bg_color_alpha =
style->ResolvedColor(style->InternalVisitedBackgroundColor()).Alpha();
const SVGComputedStyle& svg_style = style->SvgStyle(); const SVGComputedStyle& svg_style = style->SvgStyle();
MaybeForceColor(GetCSSPropertyColor(), style->GetColor()); MaybeForceColor(GetCSSPropertyColor(), style->GetColor());
...@@ -604,6 +606,10 @@ void StyleCascade::ForceColors() { ...@@ -604,6 +606,10 @@ void StyleCascade::ForceColors() {
style->SetBackgroundColor( style->SetBackgroundColor(
StyleColor(style->BackgroundColor().ResolveWithAlpha( StyleColor(style->BackgroundColor().ResolveWithAlpha(
style->GetCurrentColor(), WebColorScheme::kLight, bg_color_alpha))); style->GetCurrentColor(), WebColorScheme::kLight, bg_color_alpha)));
style->SetInternalVisitedBackgroundColor(
StyleColor(style->InternalVisitedBackgroundColor().ResolveWithAlpha(
style->GetCurrentColor(), WebColorScheme::kLight,
visited_bg_color_alpha)));
} }
void StyleCascade::MaybeForceColor(const CSSProperty& property, void StyleCascade::MaybeForceColor(const CSSProperty& property,
...@@ -626,8 +632,10 @@ const CSSValue* StyleCascade::GetForcedColorValue(CSSPropertyName name) { ...@@ -626,8 +632,10 @@ const CSSValue* StyleCascade::GetForcedColorValue(CSSPropertyName name) {
CascadePriority* p = map_.Find(name, CascadeOrigin::kUserAgent); CascadePriority* p = map_.Find(name, CascadeOrigin::kUserAgent);
if (p) if (p)
return ValueAt(match_result_, p->GetPosition()); return ValueAt(match_result_, p->GetPosition());
if (name.Id() == CSSPropertyID::kBackgroundColor) if (name.Id() == CSSPropertyID::kBackgroundColor ||
name.Id() == CSSPropertyID::kInternalVisitedBackgroundColor) {
return CSSIdentifierValue::Create(CSSValueID::kCanvas); return CSSIdentifierValue::Create(CSSValueID::kCanvas);
}
return cssvalue::CSSUnsetValue::Create(); return cssvalue::CSSUnsetValue::Create();
} }
......
...@@ -3530,4 +3530,29 @@ TEST_F(StyleCascadeTest, GetCascadedValuesInterpolated) { ...@@ -3530,4 +3530,29 @@ TEST_F(StyleCascadeTest, GetCascadedValuesInterpolated) {
EXPECT_EQ("-5s", CssTextAt(map, "animation-delay")); EXPECT_EQ("-5s", CssTextAt(map, "animation-delay"));
} }
TEST_F(StyleCascadeTest, ForcedVisitedBackgroundColor) {
ScopedForcedColorsForTest scoped_feature(true);
ColorSchemeHelper color_scheme_helper(GetDocument());
color_scheme_helper.SetForcedColors(GetDocument(), ForcedColors::kActive);
UpdateAllLifecyclePhasesForTest();
TestCascade cascade(GetDocument());
cascade.State().Style()->SetInsideLink(EInsideLink::kInsideVisitedLink);
cascade.Add(ParseDeclarationBlock("background-color:#aabbccdd"),
CascadeOrigin::kAuthor, CSSSelector::kMatchVisited);
cascade.Apply();
Color forced_bg_color =
StyleColor(CSSValueID::kCanvas).Resolve(Color(), WebColorScheme::kLight);
Color expected_bg_color =
Color(forced_bg_color.Red(), forced_bg_color.Green(),
forced_bg_color.Blue(), 0xdd);
// Verify that the visited background color alpha channel is preserved in
// Forced Colors Mode.
EXPECT_EQ(
expected_bg_color,
cascade.State().Style()->InternalVisitedBackgroundColor().GetColor());
}
} // namespace blink } // namespace blink
...@@ -2937,6 +2937,7 @@ class ComputedStyle : public ComputedStyleBase, ...@@ -2937,6 +2937,7 @@ class ComputedStyle : public ComputedStyleBase,
FRIEND_TEST_ALL_PREFIXES(ComputedStyleTest, InitialVariableNames); FRIEND_TEST_ALL_PREFIXES(ComputedStyleTest, InitialVariableNames);
FRIEND_TEST_ALL_PREFIXES(ComputedStyleTest, FRIEND_TEST_ALL_PREFIXES(ComputedStyleTest,
InitialAndInheritedAndNonInheritedVariableNames); InitialAndInheritedAndNonInheritedVariableNames);
FRIEND_TEST_ALL_PREFIXES(StyleCascadeTest, ForcedVisitedBackgroundColor);
}; };
inline bool ComputedStyle::HasAnyPseudoElementStyles() const { inline bool ComputedStyle::HasAnyPseudoElementStyles() const {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>Forced colors mode - pseudo elements.</title> <title>Forced colors mode - pseudo elements.</title>
<link rel="help" href="https://www.w3.org/TR/css-color-adjust-1/#forced-colors-properties"> <link rel="help" href="https://www.w3.org/TR/css-color-adjust-1/#forced-colors-properties">
<link rel=match href="forced-colors-mode-40-ref.html"> <link rel=match href="forced-colors-mode-39-ref.html">
<style> <style>
p::before { p::before {
background: blue; background: blue;
......
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