animationcontroller.cpp

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

CPP
527
字号
}double AnimationControllerPrivate::beginAnimationUpdateTime(){    if (m_beginAnimationUpdateTime == cBeginAnimationUpdateTimeNotSet)        m_beginAnimationUpdateTime = currentTime();    return m_beginAnimationUpdateTime;}PassRefPtr<RenderStyle> AnimationControllerPrivate::getAnimatedStyleForRenderer(RenderObject* renderer){    if (!renderer)        return 0;    RefPtr<CompositeAnimation> rendererAnimations = m_compositeAnimations.get(renderer);    if (!rendererAnimations)        return renderer->style();        // Make sure animationUpdateTime is updated, so that it is current even if no    // styleChange has happened (e.g. accelerated animations).    setBeginAnimationUpdateTime(cBeginAnimationUpdateTimeNotSet);    return rendererAnimations->getAnimatedStyle();}unsigned AnimationControllerPrivate::numberOfActiveAnimations() const{    unsigned count = 0;        RenderObjectAnimationMap::const_iterator animationsEnd = m_compositeAnimations.end();    for (RenderObjectAnimationMap::const_iterator it = m_compositeAnimations.begin(); it != animationsEnd; ++it) {        CompositeAnimation* compAnim = it->second.get();        count += compAnim->numberOfActiveAnimations();    }        return count;}void AnimationControllerPrivate::addToStyleAvailableWaitList(AnimationBase* animation){    ASSERT(!animation->next());        if (m_styleAvailableWaiters)        m_lastStyleAvailableWaiter->setNext(animation);    else        m_styleAvailableWaiters = animation;            m_lastStyleAvailableWaiter = animation;    animation->setNext(0);}void AnimationControllerPrivate::removeFromStyleAvailableWaitList(AnimationBase* animationToRemove){    AnimationBase* prevAnimation = 0;    for (AnimationBase* animation = m_styleAvailableWaiters; animation; animation = animation->next()) {        if (animation == animationToRemove) {            if (prevAnimation)                prevAnimation->setNext(animation->next());            else                m_styleAvailableWaiters = animation->next();                        if (m_lastStyleAvailableWaiter == animation)                m_lastStyleAvailableWaiter = prevAnimation;                            animationToRemove->setNext(0);        }    }}void AnimationControllerPrivate::styleAvailable(){    // Go through list of waiters and send them on their way    for (AnimationBase* animation = m_styleAvailableWaiters; animation; ) {        AnimationBase* nextAnimation = animation->next();        animation->setNext(0);        animation->styleAvailable();        animation = nextAnimation;    }        m_styleAvailableWaiters = 0;    m_lastStyleAvailableWaiter = 0;}void AnimationControllerPrivate::addToStartTimeResponseWaitList(AnimationBase* animation, bool willGetResponse){    // If willGetResponse is true, it means this animation is actually waiting for a response    // (which will come in as a call to notifyAnimationStarted()).    // In that case we don't need to add it to this list. We just set a waitingForAResponse flag     // which says we are waiting for the response. If willGetResponse is false, this animation     // is not waiting for a response for itself, but rather for a notifyXXXStarted() call for     // another animation to which it will sync.    //    // When endAnimationUpdate() is called we check to see if the waitingForAResponse flag is    // true. If so, we just return and will do our work when the first notifyXXXStarted() call    // comes in. If it is false, we will not be getting a notifyXXXStarted() call, so we will    // do our work right away. In both cases we call the onAnimationStartResponse() method    // on each animation. In the first case we send in the time we got from notifyXXXStarted().    // In the second case, we just pass in the beginAnimationUpdateTime().    //    // This will synchronize all software and accelerated animations started in the same     // updateRendering cycle.    //    ASSERT(!animation->next());        if (willGetResponse)        m_waitingForAResponse = true;        if (m_responseWaiters)        m_lastResponseWaiter->setNext(animation);    else        m_responseWaiters = animation;            m_lastResponseWaiter = animation;    animation->setNext(0);}void AnimationControllerPrivate::removeFromStartTimeResponseWaitList(AnimationBase* animationToRemove){    AnimationBase* prevAnimation = 0;    for (AnimationBase* animation = m_responseWaiters; animation; animation = animation->next()) {        if (animation == animationToRemove) {            if (prevAnimation)                prevAnimation->setNext(animation->next());            else                m_responseWaiters = animation->next();                        if (m_lastResponseWaiter == animation)                m_lastResponseWaiter = prevAnimation;                            animationToRemove->setNext(0);        }    }}void AnimationControllerPrivate::startTimeResponse(double t){    // Go through list of waiters and send them on their way    for (AnimationBase* animation = m_responseWaiters; animation; ) {        AnimationBase* nextAnimation = animation->next();        animation->setNext(0);        animation->onAnimationStartResponse(t);        animation = nextAnimation;    }        m_responseWaiters = 0;    m_responseWaiters = 0;}AnimationController::AnimationController(Frame* frame)    : m_data(new AnimationControllerPrivate(frame)){}AnimationController::~AnimationController(){    delete m_data;}void AnimationController::cancelAnimations(RenderObject* renderer){    if (!m_data->hasAnimations())        return;    if (m_data->clear(renderer)) {        Node* node = renderer->node();        ASSERT(!node || (node->document() && !node->document()->inPageCache()));        node->setChanged(AnimationStyleChange);    }}PassRefPtr<RenderStyle> AnimationController::updateAnimations(RenderObject* renderer, RenderStyle* newStyle){    // Don't do anything if we're in the cache    if (!renderer->document() || renderer->document()->inPageCache())        return newStyle;    RenderStyle* oldStyle = renderer->style();    if ((!oldStyle || (!oldStyle->animations() && !oldStyle->transitions())) && (!newStyle->animations() && !newStyle->transitions()))        return newStyle;    // Fetch our current set of implicit animations from a hashtable.  We then compare them    // against the animations in the style and make sure we're in sync.  If destination values    // have changed, we reset the animation.  We then do a blend to get new values and we return    // a new style.    ASSERT(renderer->node()); // FIXME: We do not animate generated content yet.    RefPtr<CompositeAnimation> rendererAnimations = m_data->accessCompositeAnimation(renderer);    RefPtr<RenderStyle> blendedStyle = rendererAnimations->animate(renderer, oldStyle, newStyle);    m_data->updateAnimationTimer();    if (blendedStyle != newStyle) {        // If the animations/transitions change opacity or transform, we neeed to update        // the style to impose the stacking rules. Note that this is also        // done in CSSStyleSelector::adjustRenderStyle().        if (blendedStyle->hasAutoZIndex() && (blendedStyle->opacity() < 1.0f || blendedStyle->hasTransform()))            blendedStyle->setZIndex(0);    }    return blendedStyle.release();}PassRefPtr<RenderStyle> AnimationController::getAnimatedStyleForRenderer(RenderObject* renderer){    return m_data->getAnimatedStyleForRenderer(renderer);}void AnimationController::notifyAnimationStarted(RenderObject*, double startTime){    m_data->receivedStartTimeResponse(startTime);}bool AnimationController::pauseAnimationAtTime(RenderObject* renderer, const String& name, double t){    return m_data->pauseAnimationAtTime(renderer, name, t);}unsigned AnimationController::numberOfActiveAnimations() const{    return m_data->numberOfActiveAnimations();}bool AnimationController::pauseTransitionAtTime(RenderObject* renderer, const String& property, double t){    return m_data->pauseTransitionAtTime(renderer, property, t);}bool AnimationController::isAnimatingPropertyOnRenderer(RenderObject* renderer, CSSPropertyID property, bool isRunningNow) const{    return m_data->isAnimatingPropertyOnRenderer(renderer, property, isRunningNow);}void AnimationController::suspendAnimations(Document* document){    m_data->suspendAnimations(document);}void AnimationController::resumeAnimations(Document* document){    m_data->resumeAnimations(document);}void AnimationController::beginAnimationUpdate(){    m_data->setBeginAnimationUpdateTime(cBeginAnimationUpdateTimeNotSet);}void AnimationController::endAnimationUpdate(){    m_data->endAnimationUpdate();}bool AnimationController::supportsAcceleratedAnimationOfProperty(CSSPropertyID property){#if USE(ACCELERATED_COMPOSITING)    return AnimationBase::animationOfPropertyIsAccelerated(property);#else    UNUSED_PARAM(property);    return false;#endif}} // namespace WebCore

⌨️ 快捷键说明

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