Bug 1033881 part 1 - Don't generate animations when the animation-name doesn't match; r=dbaron

When animation-name does not match a keyframes rule, we should not dispatch
animation events as per:

  "Any animation for which both a valid keyframe rule and a non-zero duration
  are defined will run and generate events; this includes animations with empty
  keyframe rules."
  http://dev.w3.org/csswg/css-animations/#events

Since bug 1004377, however, we started dispatching events in this case because
we no longer ignore animations whose set of keyframes is empty.

This patch checks for a matching keyframes rule in BuildAnimations and if one is
not found, no corresponding animation is generated.
This commit is contained in:
Brian Birtles 2014-07-09 09:13:33 +09:00
parent 8a1d25238c
commit cd38f4d2f0
2 changed files with 32 additions and 13 deletions

View File

@ -395,11 +395,17 @@ nsAnimationManager::BuildAnimations(nsStyleContext* aStyleContext,
animIdx != animEnd; ++animIdx) { animIdx != animEnd; ++animIdx) {
const StyleAnimation& src = disp->mAnimations[animIdx]; const StyleAnimation& src = disp->mAnimations[animIdx];
// CSS Animations with an animation-name of "none" are represented // CSS Animations whose animation-name does not match a @keyframes rule do
// by StyleAnimations with an empty name. Unlike animations with an empty // not generate animation events. This includes when the animation-name is
// keyframes rule, these "none" animations should not generate events // "none" which is represented by an empty name in the StyleAnimation.
// at all so we drop them here. // Since such animations neither affect style nor dispatch events, we do
if (src.GetName().IsEmpty()) { // not generate a corresponding ElementAnimation for them.
nsCSSKeyframesRule* rule =
src.GetName().IsEmpty()
? nullptr
: mPresContext->StyleSet()->KeyframesRuleForName(mPresContext,
src.GetName());
if (!rule) {
continue; continue;
} }
@ -423,14 +429,6 @@ nsAnimationManager::BuildAnimations(nsStyleContext* aStyleContext,
dest->mPauseStart = TimeStamp(); dest->mPauseStart = TimeStamp();
} }
nsCSSKeyframesRule* rule =
mPresContext->StyleSet()->KeyframesRuleForName(mPresContext,
dest->mName);
if (!rule) {
// no segments
continue;
}
// While current drafts of css3-animations say that later keyframes // While current drafts of css3-animations say that later keyframes
// with the same key entirely replace earlier ones (no cascading), // with the same key entirely replace earlier ones (no cascading),
// this is a bad idea and contradictory to the rest of CSS. So // this is a bad idea and contradictory to the rest of CSS. So

View File

@ -1937,6 +1937,27 @@ check_events([{ type: 'animationstart', target: div,
"events for animation-name: a, none, a"); "events for animation-name: a, none, a");
done_div(); done_div();
/*
* Bug 1033881 - Non-matching animation-name
*
* The code under test here is run entirely on the main thread so there is no
* OMTA version of these tests in test_animations_omta.html.
*/
new_div("animation-name: non_existent, always_fifty; animation-duration: 1s");
listen();
advance_clock(0);
advance_clock(500);
advance_clock(500);
check_events([{ type: 'animationstart', target: div,
animationName: 'always_fifty', elapsedTime: 0,
pseudoElement: '' },
{ type: 'animationend', target: div,
animationName: 'always_fifty', elapsedTime: 1,
pseudoElement: '' }],
"events for animation-name: non_existent, always_fifty");
done_div();
SpecialPowers.DOMWindowUtils.restoreNormalRefresh(); SpecialPowers.DOMWindowUtils.restoreNormalRefresh();
</script> </script>