Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[web-animations] keyframes should be recomputed if used CSS variable …
…changes https://bugs.webkit.org/show_bug.cgi?id=248145 Reviewed by Antti Koivisto. When the value for a CSS variable changes, we must ensure that any set of keyframes that use that CSS variable are recomputed, whether the animation is a CSS Animation of a script-originated animation. This does not apply to CSS Transitions which would operate on resolved values in RenderStyle. To do this we add a StyleRuleKeyframe::containsCSSVariableReferences() method which indicates whether a keyframe rule contains CSS variables. Then, we add a similar method on KeyframeEffect returning the boolean flag computed resolving keyframes in KeyframeEffect::computeCSSAnimationBlendingKeyframes(), for the CSS Animations case, and KeyframeEffect::updateBlendingKeyframes(), for the script-originated animation case. Then in KeyframeEffectStack::applyKeyframeEffects(), much like we do for detecting changes made to font-size, we check whether any CSS variable (or custom property in WebCore parlance) has changed and recompute keyframes if that is the case. We now pass the final two subtests in web-animations/animation-model/keyframe-effects/effect-value-context-filling.html and since those tests only test the script-originated animation case, we also add a new test in css/css-animations to test the CSS Animations case. * LayoutTests/imported/w3c/web-platform-tests/css/css-animations/animation-css-variable-in-keyframe-adjusted-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-animations/animation-css-variable-in-keyframe-adjusted.html: Added. * LayoutTests/imported/w3c/web-platform-tests/web-animations/animation-model/keyframe-effects/effect-value-context-filling-expected.txt: * Source/WebCore/animation/KeyframeEffect.cpp: (WebCore::KeyframeEffect::updateBlendingKeyframes): (WebCore::KeyframeEffect::computeCSSAnimationBlendingKeyframes): * Source/WebCore/animation/KeyframeEffect.h: (WebCore::KeyframeEffect::containsCSSVariableReferences const): * Source/WebCore/animation/KeyframeEffectStack.cpp: (WebCore::KeyframeEffectStack::applyKeyframeEffects): * Source/WebCore/css/CSSKeyframeRule.cpp: (WebCore::StyleRuleKeyframe::containsCSSVariableReferences const): * Source/WebCore/css/CSSKeyframeRule.h: * Source/WebCore/style/StyleResolver.cpp: (WebCore::Style::Resolver::keyframeStylesForAnimation): * Source/WebCore/style/StyleResolver.h: Canonical link: https://commits.webkit.org/256893@main
- Loading branch information
Showing
10 changed files
with
114 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
PASS Animations reflect changes to variables on element | ||
PASS Animations reflect changes to variables on parent element | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>CSS Animations: adjust value of CSS variable used in keyframes</title> | ||
<link rel="help" href="https://drafts.csswg.org/css-animations/"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="support/testcommon.js"></script> | ||
<style> | ||
|
||
@keyframes anim { | ||
from { margin-left: var(--margin-left) } | ||
to { margin-left: calc(var(--margin-left) * 2) } | ||
} | ||
|
||
</style> | ||
<div id="log"></div> | ||
<script> | ||
|
||
test(t => { | ||
const div = addDiv(t); | ||
div.style.setProperty('--margin-left', '100px'); | ||
|
||
div.style.animation = 'anim 1s linear'; | ||
const animation = div.getAnimations()[0]; | ||
animation.currentTime = 500; | ||
|
||
assert_equals( | ||
getComputedStyle(div).marginLeft, | ||
'150px', | ||
'Animated value before updating variable' | ||
); | ||
|
||
div.style.setProperty('--margin-left', '200px'); | ||
|
||
assert_equals( | ||
getComputedStyle(div).marginLeft, | ||
'300px', | ||
'Animated value after updating variable' | ||
); | ||
}, 'Animations reflect changes to variables on element'); | ||
|
||
test(t => { | ||
const parentDiv = addDiv(t); | ||
const div = addDiv(t); | ||
parentDiv.appendChild(div); | ||
parentDiv.style.setProperty('--margin-left', '100px'); | ||
|
||
div.style.animation = 'anim 1s linear'; | ||
const animation = div.getAnimations()[0]; | ||
animation.currentTime = 500; | ||
|
||
assert_equals( | ||
getComputedStyle(div).marginLeft, | ||
'150px', | ||
'Animated value before updating variable' | ||
); | ||
|
||
parentDiv.style.setProperty('--margin-left', '200px'); | ||
|
||
assert_equals( | ||
getComputedStyle(div).marginLeft, | ||
'300px', | ||
'Animated value after updating variable' | ||
); | ||
}, 'Animations reflect changes to variables on parent element'); | ||
|
||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters