Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Unified Diff: Source/core/animation/css/CSSAnimations.cpp

Issue 814083003: Update animation when changes in animation keyframes are detected. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address comments Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/animation/css/CSSAnimations.cpp
diff --git a/Source/core/animation/css/CSSAnimations.cpp b/Source/core/animation/css/CSSAnimations.cpp
index 2172e4d6df67e988f93a8ef73debbc6cbd72dbfe..11a0d7a8e110fccb90a73ee5fb03183ba9e9e9ea 100644
--- a/Source/core/animation/css/CSSAnimations.cpp
+++ b/Source/core/animation/css/CSSAnimations.cpp
@@ -227,7 +227,7 @@ CSSAnimations::CSSAnimations()
const AtomicString CSSAnimations::getAnimationNameForInspector(const AnimationPlayer& player)
{
for (const auto& it : m_animations) {
- if (it.value->sequenceNumber() == player.sequenceNumber())
+ if (it.value.player->sequenceNumber() == player.sequenceNumber())
return it.key;
}
return nullAtom;
@@ -256,6 +256,7 @@ void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate* update, const E
const CSSAnimationData* animationData = style.animations();
const CSSAnimations* cssAnimations = activeAnimations ? &activeAnimations->cssAnimations() : nullptr;
+ const Element* elementForScoping = animatingElement ? animatingElement : &element;
HashSet<AtomicString> inactive;
if (cssAnimations) {
@@ -272,25 +273,26 @@ void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate* update, const E
const bool isPaused = CSSTimingData::getRepeated(animationData->playStateList(), i) == AnimPlayStatePaused;
Timing timing = animationData->convertToTiming(i);
+ Timing newTiming = timing;
RefPtr<TimingFunction> keyframeTimingFunction = timing.timingFunction;
timing.timingFunction = Timing::defaults().timingFunction;
+ const StyleRuleKeyframes* keyframesRule = CSSAnimations::matchScopedKeyframesRule(resolver, elementForScoping, animationName.impl());
if (cssAnimations) {
AnimationMap::const_iterator existing(cssAnimations->m_animations.find(animationName));
if (existing != cssAnimations->m_animations.end()) {
inactive.remove(animationName);
- AnimationPlayer* player = existing->value.get();
-
- // FIXME: Should handle changes in the timing function.
- if (timing != player->source()->specifiedTiming()) {
- ASSERT(!activeAnimations || !activeAnimations->isAnimationStyleChange());
+ const RunningAnimation& runningAnimation = existing->value;
+ AnimationPlayer* player = runningAnimation.player.get();
+ ASSERT(keyframesRule);
+ if (keyframesRule->styleChangeCounter() != runningAnimation.styleChangeCounter || runningAnimation.specifiedTiming != newTiming) {
AnimatableValueKeyframeVector resolvedKeyframes;
resolveKeyframes(resolver, animatingElement, element, style, parentStyle, animationName, keyframeTimingFunction.get(), resolvedKeyframes);
- update->updateAnimationTiming(player, InertAnimation::create(AnimatableValueKeyframeEffectModel::create(resolvedKeyframes),
- timing, isPaused, player->currentTimeInternal()), timing);
+ update->updateAnimation(animationName, player, InertAnimation::create(AnimatableValueKeyframeEffectModel::create(resolvedKeyframes),
+ timing, isPaused, player->currentTimeInternal()), newTiming, keyframesRule->styleChangeCounter());
}
if (isPaused != player->paused()) {
@@ -306,7 +308,8 @@ void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate* update, const E
resolveKeyframes(resolver, animatingElement, element, style, parentStyle, animationName, keyframeTimingFunction.get(), resolvedKeyframes);
if (!resolvedKeyframes.isEmpty()) {
ASSERT(!activeAnimations || !activeAnimations->isAnimationStyleChange());
- update->startAnimation(animationName, InertAnimation::create(AnimatableValueKeyframeEffectModel::create(resolvedKeyframes), timing, isPaused, 0));
+ unsigned styleChangeCounter = keyframesRule ? keyframesRule->styleChangeCounter() : 0;
+ update->startAnimation(animationName, InertAnimation::create(AnimatableValueKeyframeEffectModel::create(resolvedKeyframes), timing, isPaused, 0), newTiming, styleChangeCounter);
}
}
}
@@ -314,7 +317,7 @@ void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate* update, const E
ASSERT(inactive.isEmpty() || cssAnimations);
for (const AtomicString& animationName : inactive) {
ASSERT(!activeAnimations || !activeAnimations->isAnimationStyleChange());
- update->cancelAnimation(animationName, *cssAnimations->m_animations.get(animationName));
+ update->cancelAnimation(animationName, *cssAnimations->m_animations.get(animationName).player);
}
}
@@ -335,13 +338,13 @@ void CSSAnimations::maybeApplyPendingUpdate(Element* element)
DisableCompositingQueryAsserts disabler;
for (const AtomicString& animationName : update->cancelledAnimationNames()) {
- RefPtrWillBeRawPtr<AnimationPlayer> player = m_animations.take(animationName);
+ RefPtrWillBeRawPtr<AnimationPlayer> player = m_animations.take(animationName).player;
player->cancel();
player->update(TimingUpdateOnDemand);
}
for (const AtomicString& animationName : update->animationsWithPauseToggled()) {
- AnimationPlayer* player = m_animations.get(animationName);
+ AnimationPlayer* player = m_animations.get(animationName).player.get();
if (player->paused())
player->unpause();
else
@@ -350,9 +353,16 @@ void CSSAnimations::maybeApplyPendingUpdate(Element* element)
player->update(TimingUpdateOnDemand);
}
- for (const auto& timingUpdate : update->animationsWithTimingUpdates()) {
- timingUpdate.player->source()->updateSpecifiedTiming(timingUpdate.newTiming);
- timingUpdate.player->update(TimingUpdateOnDemand);
+ for (const auto& entry : update->animationsWithUpdates()) {
+ ASSERT(entry.player->source()->isAnimation());
+ Animation* animation = static_cast<Animation*>(entry.player->source());
dstockwell 2014/12/30 00:59:12 use toAnimation() and drop the assert
shend 2015/01/02 01:58:29 Done.
+
+ animation->setEffect(entry.animation->effect());
+ animation->updateSpecifiedTiming(entry.animation->specifiedTiming());
+
+ auto& runningAnimation = m_animations.find(entry.name)->value;
+ runningAnimation.styleChangeCounter = entry.styleChangeCounter;
+ runningAnimation.specifiedTiming = entry.newTiming;
}
for (const auto& entry : update->newAnimations()) {
@@ -364,7 +374,13 @@ void CSSAnimations::maybeApplyPendingUpdate(Element* element)
if (inertAnimation->paused())
player->pause();
player->update(TimingUpdateOnDemand);
- m_animations.set(entry.name, player.get());
+
+ RunningAnimation runningAnimation;
+ runningAnimation.player = player;
+ runningAnimation.specifiedTiming = entry.timing;
+ runningAnimation.styleChangeCounter = entry.styleChangeCounter;
+
+ m_animations.set(entry.name, runningAnimation);
}
// Transitions that are run on the compositor only update main-thread state
@@ -554,8 +570,8 @@ void CSSAnimations::calculateTransitionUpdate(CSSAnimationUpdate* update, const
void CSSAnimations::cancel()
{
for (const auto& entry : m_animations) {
- entry.value->cancel();
- entry.value->update(TimingUpdateOnDemand);
+ entry.value.player->cancel();
+ entry.value.player->update(TimingUpdateOnDemand);
}
for (const auto& entry : m_transitions) {
@@ -582,8 +598,8 @@ void CSSAnimations::calculateAnimationActiveInterpolations(CSSAnimationUpdate* u
WillBeHeapVector<RawPtrWillBeMember<InertAnimation>> newAnimations;
for (const auto& newAnimation : update->newAnimations())
newAnimations.append(newAnimation.animation.get());
- for (const auto& updatedAnimation : update->animationsWithTimingUpdates())
- newAnimations.append(updatedAnimation.animation.get()); // Animations with timing updates use a temporary InertAnimation for the current frame.
+ for (const auto& updatedAnimation : update->animationsWithUpdates())
+ newAnimations.append(updatedAnimation.animation.get()); // Animations with updates use a temporary InertAnimation for the current frame.
WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>> activeInterpolationsForAnimations(AnimationStack::activeInterpolations(animationStack, &newAnimations, &update->suppressedAnimationAnimationPlayers(), Animation::DefaultPriority, timelineCurrentTime));
update->adoptActiveInterpolationsForAnimations(activeInterpolationsForAnimations);
@@ -769,7 +785,7 @@ void CSSAnimationUpdate::trace(Visitor* visitor)
visitor->trace(m_activeInterpolationsForTransitions);
visitor->trace(m_newAnimations);
visitor->trace(m_suppressedAnimationPlayers);
- visitor->trace(m_animationsWithTimingUpdates);
+ visitor->trace(m_animationsWithUpdates);
#endif
}

Powered by Google App Engine
This is Rietveld 408576698