void CompositeAnimation::updateKeyframeAnimations(RenderObject* renderer, RenderStyle* currentStyle, RenderStyle* targetStyle) { // Nothing to do if we don't have any animations, and didn't have any before if (m_keyframeAnimations.isEmpty() && !targetStyle->hasAnimations()) return; m_keyframeAnimations.checkConsistency(); AnimationNameMap::const_iterator kfend = m_keyframeAnimations.end(); if (currentStyle && currentStyle->hasAnimations() && targetStyle->hasAnimations() && *(currentStyle->animations()) == *(targetStyle->animations())) { // The current and target animations are the same so we just need to toss any // animation which is finished (postActive). for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != kfend; ++it) { if (it->second->postActive()) it->second->setIndex(-1); } } else { // Mark all existing animations as no longer active. for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != kfend; ++it) it->second->setIndex(-1); // Toss the animation order map. m_keyframeAnimationOrderMap.clear(); // Now mark any still active animations as active and add any new animations. if (targetStyle->animations()) { int numAnims = targetStyle->animations()->size(); for (int i = 0; i < numAnims; ++i) { const Animation* anim = targetStyle->animations()->animation(i); AtomicString animationName(anim->name()); if (!anim->isValidAnimation()) continue; // See if there is a current animation for this name. RefPtr<KeyframeAnimation> keyframeAnim = m_keyframeAnimations.get(animationName.impl()); if (keyframeAnim) { // If this animation is postActive, skip it so it gets removed at the end of this function. if (keyframeAnim->postActive()) continue; // This one is still active. // Animations match, but play states may differ. Update if needed. keyframeAnim->updatePlayState(anim->playState() == AnimPlayStatePlaying); // Set the saved animation to this new one, just in case the play state has changed. keyframeAnim->setAnimation(anim); keyframeAnim->setIndex(i); } else if ((anim->duration() || anim->delay()) && anim->iterationCount()) { keyframeAnim = KeyframeAnimation::create(const_cast<Animation*>(anim), renderer, i, this, targetStyle); m_keyframeAnimations.set(keyframeAnim->name().impl(), keyframeAnim); } // Add this to the animation order map. if (keyframeAnim) m_keyframeAnimationOrderMap.append(keyframeAnim->name().impl()); } } } // Make a list of animations to be removed. Vector<AtomicStringImpl*> animsToBeRemoved; kfend = m_keyframeAnimations.end(); for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != kfend; ++it) { KeyframeAnimation* keyframeAnim = it->second.get(); if (keyframeAnim->index() < 0) animsToBeRemoved.append(keyframeAnim->name().impl()); } // Now remove the animations from the list. for (size_t j = 0; j < animsToBeRemoved.size(); ++j) m_keyframeAnimations.remove(animsToBeRemoved[j]); }
void CompositeAnimation::updateKeyframeAnimations(RenderElement* renderer, RenderStyle* currentStyle, RenderStyle* targetStyle) { // Nothing to do if we don't have any animations, and didn't have any before if (m_keyframeAnimations.isEmpty() && !targetStyle->hasAnimations()) return; m_keyframeAnimations.checkConsistency(); AnimationNameMap::const_iterator kfend = m_keyframeAnimations.end(); if (currentStyle && currentStyle->hasAnimations() && targetStyle->hasAnimations() && *(currentStyle->animations()) == *(targetStyle->animations())) { // The current and target animations are the same so we just need to toss any // animation which is finished (postActive). for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != kfend; ++it) { if (it->value->postActive()) it->value->setIndex(-1); } } else { // Mark all existing animations as no longer active. for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != kfend; ++it) it->value->setIndex(-1); // Toss the animation order map. m_keyframeAnimationOrderMap.clear(); DEFINE_STATIC_LOCAL(const AtomicString, none, ("none", AtomicString::ConstructFromLiteral)); // Now mark any still active animations as active and add any new animations. if (targetStyle->animations()) { int numAnims = targetStyle->animations()->size(); for (int i = 0; i < numAnims; ++i) { const Animation& animation = targetStyle->animations()->animation(i); AtomicString animationName(animation.name()); if (!animation.isValidAnimation()) continue; // See if there is a current animation for this name. RefPtr<KeyframeAnimation> keyframeAnim = m_keyframeAnimations.get(animationName.impl()); if (keyframeAnim) { // If this animation is postActive, skip it so it gets removed at the end of this function. if (keyframeAnim->postActive()) continue; // This one is still active. // Animations match, but play states may differ. Update if needed. keyframeAnim->updatePlayState(animation.playState()); // Set the saved animation to this new one, just in case the play state has changed. keyframeAnim->setAnimation(animation); keyframeAnim->setIndex(i); } else if ((animation.duration() || animation.delay()) && animation.iterationCount() && animationName != none) { keyframeAnim = KeyframeAnimation::create(animation, renderer, i, this, targetStyle); LOG(Animations, "Creating KeyframeAnimation %p with keyframes %s, duration %.2f, delay %.2f, iterations %.2f", keyframeAnim.get(), animation.name().utf8().data(), animation.duration(), animation.delay(), animation.iterationCount()); if (m_suspended) { keyframeAnim->updatePlayState(AnimPlayStatePaused); LOG(Animations, " (created in suspended/paused state)"); } #if !LOG_DISABLED for (auto it = keyframeAnim->keyframes().beginProperties(), end = keyframeAnim->keyframes().endProperties(); it != end; ++it) LOG(Animations, " property %s", getPropertyName(*it)); #endif m_keyframeAnimations.set(keyframeAnim->name().impl(), keyframeAnim); } // Add this to the animation order map. if (keyframeAnim) m_keyframeAnimationOrderMap.append(keyframeAnim->name().impl()); } } } // Make a list of animations to be removed. Vector<AtomicStringImpl*> animsToBeRemoved; kfend = m_keyframeAnimations.end(); for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != kfend; ++it) { KeyframeAnimation* keyframeAnim = it->value.get(); if (keyframeAnim->index() < 0) { animsToBeRemoved.append(keyframeAnim->name().impl()); animationController()->animationWillBeRemoved(keyframeAnim); keyframeAnim->clear(); LOG(Animations, "Removing KeyframeAnimation %p", keyframeAnim); } } // Now remove the animations from the list. for (size_t j = 0; j < animsToBeRemoved.size(); ++j) m_keyframeAnimations.remove(animsToBeRemoved[j]); }