Commit c5b5500d authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Commit Bot

Apply override for prefers-reduced-motion media query.

Bug: 1004647
Change-Id: Ic78a40f06ba80aa90a62a85641ecb6468ac2abb6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1821080
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699365}
parent de840ea1
......@@ -197,7 +197,7 @@ PreferredColorScheme MediaValues::CalculatePreferredColorScheme(
DCHECK(frame->GetSettings());
DCHECK(frame->GetDocument());
DCHECK(frame->GetPage());
if (auto* overrides = frame->GetPage()->GetMediaFeatureOverrides()) {
if (const auto* overrides = frame->GetPage()->GetMediaFeatureOverrides()) {
MediaQueryExpValue value = overrides->GetOverride("prefers-color-scheme");
if (value.IsValid())
return CSSValueIDToPreferredColorScheme(value.id);
......@@ -208,6 +208,11 @@ PreferredColorScheme MediaValues::CalculatePreferredColorScheme(
bool MediaValues::CalculatePrefersReducedMotion(LocalFrame* frame) {
DCHECK(frame);
DCHECK(frame->GetSettings());
if (const auto* overrides = frame->GetPage()->GetMediaFeatureOverrides()) {
MediaQueryExpValue value = overrides->GetOverride("prefers-reduced-motion");
if (value.IsValid())
return value.id == CSSValueID::kReduce;
}
return frame->GetSettings()->GetPrefersReducedMotion();
}
......
......@@ -1865,7 +1865,8 @@ void StyleEngine::UpdateColorScheme() {
PreferredColorScheme old_preferred_color_scheme = preferred_color_scheme_;
preferred_color_scheme_ = settings->GetPreferredColorScheme();
if (auto* overrides = GetDocument().GetPage()->GetMediaFeatureOverrides()) {
if (const auto* overrides =
GetDocument().GetPage()->GetMediaFeatureOverrides()) {
MediaQueryExpValue value = overrides->GetOverride("prefers-color-scheme");
if (value.IsValid())
preferred_color_scheme_ = CSSValueIDToPreferredColorScheme(value.id);
......
......@@ -1691,6 +1691,38 @@ TEST_F(StyleEngineTest, MediaQueriesColorSchemeOverride) {
GetCSSPropertyColor()));
}
TEST_F(StyleEngineTest, MediaQueriesReducedMotionOverride) {
EXPECT_FALSE(GetDocument().GetSettings()->GetPrefersReducedMotion());
GetDocument().body()->SetInnerHTMLFromString(R"HTML(
<style>
body { color: red }
@media (prefers-reduced-motion: reduce) {
body { color: green }
}
</style>
<body></body>
)HTML");
UpdateAllLifecyclePhases();
EXPECT_EQ(MakeRGB(255, 0, 0),
GetDocument().body()->GetComputedStyle()->VisitedDependentColor(
GetCSSPropertyColor()));
GetDocument().GetPage()->SetMediaFeatureOverride("prefers-reduced-motion",
"reduce");
UpdateAllLifecyclePhases();
EXPECT_EQ(MakeRGB(0, 128, 0),
GetDocument().body()->GetComputedStyle()->VisitedDependentColor(
GetCSSPropertyColor()));
GetDocument().GetPage()->ClearMediaFeatureOverrides();
UpdateAllLifecyclePhases();
EXPECT_EQ(MakeRGB(255, 0, 0),
GetDocument().body()->GetComputedStyle()->VisitedDependentColor(
GetCSSPropertyColor()));
}
TEST_F(StyleEngineTest, ShadowRootStyleRecalcCrash) {
GetDocument().body()->SetInnerHTMLFromString("<div id=host></div>");
auto* host = To<HTMLElement>(GetDocument().getElementById("host"));
......
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