compositeanimation.cpp

来自「linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自Web」· C++ 代码 · 共 736 行 · 第 1/2 页

CPP
736
字号
        for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != animationsEnd; ++it) {            KeyframeAnimation* animation = it->second.get();            double t = animation ? animation->willNeedService() : -1;            if (t < minT || minT == -1)                minT = t;            if (minT == 0)                return 0;        }    }    return minT;}PassRefPtr<KeyframeAnimation> CompositeAnimationPrivate::getAnimationForProperty(int property){    RefPtr<KeyframeAnimation> retval;        // We want to send back the last animation with the property if there are multiples.    // So we need to iterate through all animations    if (!m_keyframeAnimations.isEmpty()) {        AnimationNameMap::const_iterator animationsEnd = m_keyframeAnimations.end();        for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != animationsEnd; ++it) {            RefPtr<KeyframeAnimation> anim = it->second;            if (anim->hasAnimationForProperty(property))                retval = anim;        }    }        return retval;}void CompositeAnimationPrivate::cleanupFinishedAnimations(RenderObject*){    if (isSuspended())        return;    // Make a list of transitions to be deleted    Vector<int> finishedTransitions;    if (!m_transitions.isEmpty()) {        CSSPropertyTransitionsMap::const_iterator transitionsEnd = m_transitions.end();        for (CSSPropertyTransitionsMap::const_iterator it = m_transitions.begin(); it != transitionsEnd; ++it) {            ImplicitAnimation* anim = it->second.get();            if (!anim)                continue;            if (anim->postActive())                finishedTransitions.append(anim->animatingProperty());        }                // Delete them        size_t finishedTransitionCount = finishedTransitions.size();        for (size_t i = 0; i < finishedTransitionCount; ++i)            m_transitions.remove(finishedTransitions[i]);    }    // Make a list of animations to be deleted    Vector<AtomicStringImpl*> finishedAnimations;    if (!m_keyframeAnimations.isEmpty()) {        AnimationNameMap::const_iterator animationsEnd = m_keyframeAnimations.end();        for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != animationsEnd; ++it) {            KeyframeAnimation* anim = it->second.get();            if (!anim)                continue;            if (anim->postActive())                finishedAnimations.append(anim->name().impl());        }        // Delete them        size_t finishedAnimationCount = finishedAnimations.size();        for (size_t i = 0; i < finishedAnimationCount; ++i)            m_keyframeAnimations.remove(finishedAnimations[i]);    }}void CompositeAnimationPrivate::suspendAnimations(){    if (m_isSuspended)        return;    m_isSuspended = true;    if (!m_keyframeAnimations.isEmpty()) {        AnimationNameMap::const_iterator animationsEnd = m_keyframeAnimations.end();        for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != animationsEnd; ++it) {            if (KeyframeAnimation* anim = it->second.get())                anim->updatePlayState(false);        }    }    if (!m_transitions.isEmpty()) {        CSSPropertyTransitionsMap::const_iterator transitionsEnd = m_transitions.end();        for (CSSPropertyTransitionsMap::const_iterator it = m_transitions.begin(); it != transitionsEnd; ++it) {            ImplicitAnimation* anim = it->second.get();            if (anim && anim->hasStyle())                anim->updatePlayState(false);        }    }}void CompositeAnimationPrivate::resumeAnimations(){    if (!m_isSuspended)        return;    m_isSuspended = false;    if (!m_keyframeAnimations.isEmpty()) {        AnimationNameMap::const_iterator animationsEnd = m_keyframeAnimations.end();        for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != animationsEnd; ++it) {            KeyframeAnimation* anim = it->second.get();            if (anim && anim->playStatePlaying())                anim->updatePlayState(true);        }    }    if (!m_transitions.isEmpty()) {        CSSPropertyTransitionsMap::const_iterator transitionsEnd = m_transitions.end();        for (CSSPropertyTransitionsMap::const_iterator it = m_transitions.begin(); it != transitionsEnd; ++it) {            ImplicitAnimation* anim = it->second.get();            if (anim && anim->hasStyle())                anim->updatePlayState(true);        }    }}void CompositeAnimationPrivate::overrideImplicitAnimations(int property){    CSSPropertyTransitionsMap::const_iterator end = m_transitions.end();    if (!m_transitions.isEmpty()) {        for (CSSPropertyTransitionsMap::const_iterator it = m_transitions.begin(); it != end; ++it) {            ImplicitAnimation* anim = it->second.get();            if (anim && anim->animatingProperty() == property)                anim->setOverridden(true);        }    }}void CompositeAnimationPrivate::resumeOverriddenImplicitAnimations(int property){    if (!m_transitions.isEmpty()) {        CSSPropertyTransitionsMap::const_iterator end = m_transitions.end();        for (CSSPropertyTransitionsMap::const_iterator it = m_transitions.begin(); it != end; ++it) {            ImplicitAnimation* anim = it->second.get();            if (anim && anim->animatingProperty() == property)                anim->setOverridden(false);        }    }}bool CompositeAnimationPrivate::isAnimatingProperty(int property, bool isRunningNow) const{    if (!m_keyframeAnimations.isEmpty()) {        AnimationNameMap::const_iterator animationsEnd = m_keyframeAnimations.end();        for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != animationsEnd; ++it) {            KeyframeAnimation* anim = it->second.get();            if (anim && anim->isAnimatingProperty(property, isRunningNow))                return true;        }    }    if (!m_transitions.isEmpty()) {        CSSPropertyTransitionsMap::const_iterator transitionsEnd = m_transitions.end();        for (CSSPropertyTransitionsMap::const_iterator it = m_transitions.begin(); it != transitionsEnd; ++it) {            ImplicitAnimation* anim = it->second.get();            if (anim && anim->isAnimatingProperty(property, isRunningNow))                return true;        }    }    return false;}void CompositeAnimationPrivate::addToStyleAvailableWaitList(AnimationBase* animation){    m_animationController->addToStyleAvailableWaitList(animation);}void CompositeAnimationPrivate::removeFromStyleAvailableWaitList(AnimationBase* animation){    m_animationController->removeFromStyleAvailableWaitList(animation);}void CompositeAnimationPrivate::addToStartTimeResponseWaitList(AnimationBase* animation, bool willGetResponse){    m_animationController->addToStartTimeResponseWaitList(animation, willGetResponse);}void CompositeAnimationPrivate::removeFromStartTimeResponseWaitList(AnimationBase* animation){    m_animationController->removeFromStartTimeResponseWaitList(animation);}bool CompositeAnimationPrivate::pauseAnimationAtTime(const AtomicString& name, double t){    if (!name)        return false;    RefPtr<KeyframeAnimation> keyframeAnim = m_keyframeAnimations.get(name.impl());    if (!keyframeAnim || !keyframeAnim->running())        return false;    int count = keyframeAnim->m_animation->iterationCount();    if ((t >= 0.0) && (!count || (t <= count * keyframeAnim->duration()))) {        keyframeAnim->pauseAtTime(t);        return true;    }    return false;}bool CompositeAnimationPrivate::pauseTransitionAtTime(int property, double t){    if ((property < firstCSSProperty) || (property >= firstCSSProperty + numCSSProperties))        return false;    ImplicitAnimation* implAnim = m_transitions.get(property).get();    if (!implAnim || !implAnim->running())        return false;    if ((t >= 0.0) && (t <= implAnim->duration())) {        implAnim->pauseAtTime(t);        return true;    }    return false;}unsigned CompositeAnimationPrivate::numberOfActiveAnimations() const{    unsigned count = 0;        if (!m_keyframeAnimations.isEmpty()) {        AnimationNameMap::const_iterator animationsEnd = m_keyframeAnimations.end();        for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != animationsEnd; ++it) {            KeyframeAnimation* anim = it->second.get();            if (anim->running())                ++count;        }    }    if (!m_transitions.isEmpty()) {        CSSPropertyTransitionsMap::const_iterator transitionsEnd = m_transitions.end();        for (CSSPropertyTransitionsMap::const_iterator it = m_transitions.begin(); it != transitionsEnd; ++it) {            ImplicitAnimation* anim = it->second.get();            if (anim->running())                ++count;        }    }        return count;}CompositeAnimation::CompositeAnimation(AnimationControllerPrivate* animationController)    : m_data(new CompositeAnimationPrivate(animationController, this)){}CompositeAnimation::~CompositeAnimation(){    delete m_data;}AnimationControllerPrivate* CompositeAnimation::animationControllerPriv() const{    return m_data->animationControllerPriv(); }void CompositeAnimation::clearRenderer(){    m_data->clearRenderer();}PassRefPtr<RenderStyle> CompositeAnimation::animate(RenderObject* renderer, RenderStyle* currentStyle, RenderStyle* targetStyle){    return m_data->animate(renderer, currentStyle, targetStyle);}PassRefPtr<RenderStyle> CompositeAnimation::getAnimatedStyle(){    return m_data->getAnimatedStyle();}double CompositeAnimation::willNeedService() const{    return m_data->willNeedService();}void CompositeAnimation::addToStyleAvailableWaitList(AnimationBase* animation){    m_data->addToStyleAvailableWaitList(animation);}void CompositeAnimation::removeFromStyleAvailableWaitList(AnimationBase* animation){    m_data->removeFromStyleAvailableWaitList(animation);}void CompositeAnimation::addToStartTimeResponseWaitList(AnimationBase* animation, bool willGetResponse){    m_data->addToStartTimeResponseWaitList(animation, willGetResponse);}void CompositeAnimation::removeFromStartTimeResponseWaitList(AnimationBase* animation){    m_data->removeFromStartTimeResponseWaitList(animation);}void CompositeAnimation::suspendAnimations(){    m_data->suspendAnimations();}void CompositeAnimation::resumeAnimations(){    m_data->resumeAnimations();}bool CompositeAnimation::isSuspended() const{    return m_data->isSuspended();}bool CompositeAnimation::hasAnimations() const{    return m_data->hasAnimations();}void CompositeAnimation::setAnimating(bool b){    m_data->setAnimating(b);}bool CompositeAnimation::isAnimatingProperty(int property, bool isRunningNow) const{    return m_data->isAnimatingProperty(property, isRunningNow);}PassRefPtr<KeyframeAnimation> CompositeAnimation::getAnimationForProperty(int property){    return m_data->getAnimationForProperty(property);}void CompositeAnimation::overrideImplicitAnimations(int property){    m_data->overrideImplicitAnimations(property);}void CompositeAnimation::resumeOverriddenImplicitAnimations(int property){    m_data->resumeOverriddenImplicitAnimations(property);}bool CompositeAnimation::pauseAnimationAtTime(const AtomicString& name, double t){    return m_data->pauseAnimationAtTime(name, t);}bool CompositeAnimation::pauseTransitionAtTime(int property, double t){    return m_data->pauseTransitionAtTime(property, t);}unsigned CompositeAnimation::numberOfActiveAnimations() const{    return m_data->numberOfActiveAnimations();}} // namespace WebCore

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?