⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 181655 in webkit


Ignore:
Timestamp:
Mar 17, 2015, 12:01:46 PM (11 years ago)
Author:
dino@apple.com
Message:

Implement Scroll Container Animation Triggers
https://bugs.webkit.org/show_bug.cgi?id=142732

Reviewed by Simon Fraser.

Source/WebCore:

Test: animations/trigger-container-scroll-simple.html

Basic implementation of container-scroll. It only checks
the page scroll position for trigger values (not the scrolling
container in an overflow).

  • css/CSSComputedStyleDeclaration.cpp: Add CSSPropertyWebkitAnimationTrigger

so that this property will appear in the inspector.

  • page/FrameView.cpp:

(WebCore::FrameView::sendScrollEvent): If the page has scrolled, let the animation
controller know about it.

  • page/animation/AnimationBase.cpp:

(WebCore::AnimationBase::updateStateMachine): Whitespace fix.
(WebCore::AnimationBase::fireAnimationEventsIfNeeded): If there is a trigger,
and the scroll position is past it, then tell the state machine that
we should start.
(WebCore::AnimationBase::timeToNextService): Use the scroll position as
an input to the update timer if a trigger is involved.

  • page/animation/AnimationController.cpp:

(WebCore::AnimationControllerPrivate::ensureCompositeAnimation): Add whitespace.
(WebCore::AnimationControllerPrivate::scrollWasUpdated): Call updateAnimations.
(WebCore::AnimationController::scrollWasUpdated): Call into AnimationControllerPrivate.

  • page/animation/AnimationController.h:
  • page/animation/AnimationControllerPrivate.h:
  • page/animation/CompositeAnimation.cpp: Keep a record of whether we have a scroll

triggered animation.
(WebCore::CompositeAnimation::CompositeAnimation):
(WebCore::CompositeAnimation::updateKeyframeAnimations):

  • page/animation/CompositeAnimation.h:

(WebCore::CompositeAnimation::hasScrollTriggeredAnimation):

  • platform/animation/Animation.cpp:

(WebCore::Animation::operator=):

LayoutTests:

Test that checks if an animation only triggers when the page
is scrolled.

  • animations/trigger-container-scroll-simple-expected.txt: Added.
  • animations/trigger-container-scroll-simple.html: Added.
Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r181652 r181655  
     12015-03-17  Dean Jackson  <dino@apple.com>
     2
     3        Implement Scroll Container Animation Triggers
     4        https://bugs.webkit.org/show_bug.cgi?id=142732
     5
     6        Reviewed by Simon Fraser.
     7
     8        Test that checks if an animation only triggers when the page
     9        is scrolled.
     10
     11        * animations/trigger-container-scroll-simple-expected.txt: Added.
     12        * animations/trigger-container-scroll-simple.html: Added.
     13
    1142015-03-17  Brent Fulgham  <bfulgham@apple.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r181654 r181655  
     12015-03-17  Dean Jackson  <dino@apple.com>
     2
     3        Implement Scroll Container Animation Triggers
     4        https://bugs.webkit.org/show_bug.cgi?id=142732
     5
     6        Reviewed by Simon Fraser.
     7
     8        Test: animations/trigger-container-scroll-simple.html
     9
     10        Basic implementation of container-scroll. It only checks
     11        the page scroll position for trigger values (not the scrolling
     12        container in an overflow).
     13
     14        * css/CSSComputedStyleDeclaration.cpp: Add CSSPropertyWebkitAnimationTrigger
     15        so that this property will appear in the inspector.
     16
     17        * page/FrameView.cpp:
     18        (WebCore::FrameView::sendScrollEvent): If the page has scrolled, let the animation
     19        controller know about it.
     20
     21        * page/animation/AnimationBase.cpp:
     22        (WebCore::AnimationBase::updateStateMachine): Whitespace fix.
     23        (WebCore::AnimationBase::fireAnimationEventsIfNeeded): If there is a trigger,
     24        and the scroll position is past it, then tell the state machine that
     25        we should start.
     26        (WebCore::AnimationBase::timeToNextService): Use the scroll position as
     27        an input to the update timer if a trigger is involved.
     28
     29        * page/animation/AnimationController.cpp:
     30        (WebCore::AnimationControllerPrivate::ensureCompositeAnimation): Add whitespace.
     31        (WebCore::AnimationControllerPrivate::scrollWasUpdated): Call updateAnimations.
     32        (WebCore::AnimationController::scrollWasUpdated): Call into AnimationControllerPrivate.
     33        * page/animation/AnimationController.h:
     34        * page/animation/AnimationControllerPrivate.h:
     35
     36        * page/animation/CompositeAnimation.cpp: Keep a record of whether we have a scroll
     37        triggered animation.
     38        (WebCore::CompositeAnimation::CompositeAnimation):
     39        (WebCore::CompositeAnimation::updateKeyframeAnimations):
     40        * page/animation/CompositeAnimation.h:
     41        (WebCore::CompositeAnimation::hasScrollTriggeredAnimation):
     42        * platform/animation/Animation.cpp:
     43        (WebCore::Animation::operator=):
     44
    1452015-03-17  Simon Fraser  <simon.fraser@apple.com>
    246
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r181602 r181655  
    246246    CSSPropertyWebkitAnimationPlayState,
    247247    CSSPropertyWebkitAnimationTimingFunction,
     248    CSSPropertyWebkitAnimationTrigger,
    248249    CSSPropertyWebkitAppearance,
    249250    CSSPropertyWebkitBackfaceVisibility,
  • trunk/Source/WebCore/page/FrameView.cpp

    r181617 r181655  
    43754375    frame().eventHandler().sendScrollEvent();
    43764376    frame().eventHandler().dispatchFakeMouseMoveEventSoon();
     4377#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
     4378    frame().animation().scrollWasUpdated();
     4379#endif
    43774380}
    43784381
  • trunk/Source/WebCore/page/animation/AnimationBase.cpp

    r181515 r181655  
    4141#include "RenderBox.h"
    4242#include "RenderStyle.h"
     43#include "RenderView.h"
    4344#include "UnitBezier.h"
    4445#include <algorithm>
     
    199200        case AnimationState::New:
    200201            ASSERT(input == AnimationStateInput::StartAnimation || input == AnimationStateInput::PlayStateRunning || input == AnimationStateInput::PlayStatePaused);
     202
    201203            if (input == AnimationStateInput::StartAnimation || input == AnimationStateInput::PlayStateRunning) {
    202204                m_requestedStartTime = beginAnimationUpdateTime();
     
    458460    // Check for start timeout
    459461    if (m_animationState == AnimationState::StartWaitTimer) {
     462#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
     463        if (m_animation->trigger() && m_animation->trigger()->isScrollAnimationTrigger()) {
     464            if (m_object) {
     465                LayoutSize offset = m_object->view().frameView().scrollOffsetForFixedPosition();
     466                ScrollAnimationTrigger* scrollTrigger = static_cast<ScrollAnimationTrigger*>(m_animation->trigger().get());
     467                if (offset.height().toFloat() > scrollTrigger->startValue().value())
     468                    updateStateMachine(AnimationStateInput::StartTimerFired, 0);
     469            }
     470
     471            return;
     472        }
     473#endif
    460474        if (beginAnimationUpdateTime() - m_requestedStartTime >= m_animation->delay())
    461475            updateStateMachine(AnimationStateInput::StartTimerFired, 0);
     
    464478   
    465479    double elapsedDuration = beginAnimationUpdateTime() - m_startTime;
     480#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
     481    if (m_animation->trigger() && m_animation->trigger()->isScrollAnimationTrigger())
     482        elapsedDuration = getElapsedTime();
     483#endif
     484
    466485    // FIXME: we need to ensure that elapsedDuration is never < 0. If it is, this suggests that
    467486    // we had a recalcStyle() outside of beginAnimationUpdate()/endAnimationUpdate().
     
    522541   
    523542    if (m_animationState == AnimationState::StartWaitTimer) {
     543#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
     544        if (m_animation->trigger()->isScrollAnimationTrigger()) {
     545            if (m_object) {
     546                float currentScrollOffset = m_object->view().frameView().scrollOffsetForFixedPosition().height().toFloat();
     547                ScrollAnimationTrigger* scrollTrigger = static_cast<ScrollAnimationTrigger*>(m_animation->trigger().get());
     548                if (currentScrollOffset >= scrollTrigger->startValue().value() && (!scrollTrigger->hasEndValue() || currentScrollOffset <= scrollTrigger->endValue().value()))
     549                    return 0;
     550            }
     551            return -1;
     552        }
     553#endif
    524554        double timeFromNow = m_animation->delay() - (beginAnimationUpdateTime() - m_requestedStartTime);
    525555        return std::max(timeFromNow, 0.0);
     
    673703double AnimationBase::getElapsedTime() const
    674704{
    675     if (paused())   
     705    if (paused())
    676706        return m_pauseTime - m_startTime;
    677707    if (m_startTime <= 0)
  • trunk/Source/WebCore/page/animation/AnimationController.cpp

    r181515 r181655  
    9393        renderer.setIsCSSAnimating(true);
    9494    }
     95
    9596    return *result.iterator->value;
    9697}
     
    515516}
    516517
     518#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
     519void AnimationControllerPrivate::scrollWasUpdated()
     520{
     521    updateAnimations(CallSetChanged);
     522}
     523#endif
     524
    517525AnimationController::AnimationController(Frame& frame)
    518526    : m_data(std::make_unique<AnimationControllerPrivate>(frame))
     
    701709}
    702710
     711#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
     712void AnimationController::scrollWasUpdated()
     713{
     714    m_data->scrollWasUpdated();
     715}
     716#endif
     717
    703718} // namespace WebCore
  • trunk/Source/WebCore/page/animation/AnimationController.h

    r181515 r181655  
    8787    static bool supportsAcceleratedAnimationOfProperty(CSSPropertyID);
    8888
     89#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
     90    void scrollWasUpdated();
     91#endif
     92
    8993private:
    9094    const std::unique_ptr<AnimationControllerPrivate> m_data;
  • trunk/Source/WebCore/page/animation/AnimationControllerPrivate.h

    r181515 r181655  
    118118    void setAllowsNewAnimationsWhileSuspended(bool);
    119119
     120#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
     121    void scrollWasUpdated();
     122#endif
     123
    120124private:
    121125    void animationTimerFired();
  • trunk/Source/WebCore/page/animation/CompositeAnimation.cpp

    r181515 r181655  
    4444CompositeAnimation::CompositeAnimation(AnimationControllerPrivate* animationController)
    4545    : m_animationController(animationController)
     46#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
     47    , m_hasScrollTriggeredAnimation(false)
     48#endif
    4649{
    4750    m_suspended = animationController->isSuspended() && !animationController->allowsNewAnimationsWhileSuspended();
     
    223226        for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != kfend; ++it)
    224227            it->value->setIndex(-1);
    225            
     228
     229#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
     230        m_hasScrollTriggeredAnimation = false;
     231#endif
     232
    226233        // Toss the animation order map.
    227234        m_keyframeAnimationOrderMap.clear();
     
    246253                    if (keyframeAnim->postActive())
    247254                        continue;
    248                    
     255
     256#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
     257                    if (animation.trigger()->isScrollAnimationTrigger())
     258                        m_hasScrollTriggeredAnimation = true;
     259#endif
     260
    249261                    // This one is still active.
    250262
     
    266278                        LOG(Animations, "  property %s", getPropertyName(*it));
    267279#endif
     280
     281#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
     282                    if (animation.trigger()->isScrollAnimationTrigger())
     283                        m_hasScrollTriggeredAnimation = true;
     284#endif
     285
    268286                    m_keyframeAnimations.set(keyframeAnim->name().impl(), keyframeAnim);
    269287                }
  • trunk/Source/WebCore/page/animation/CompositeAnimation.h

    r181515 r181655  
    8181    unsigned numberOfActiveAnimations() const;
    8282
     83#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
     84    bool hasScrollTriggeredAnimation() const { return m_hasScrollTriggeredAnimation; }
     85#endif
     86
    8387private:
    8488    CompositeAnimation(AnimationControllerPrivate*);
     
    8892   
    8993    typedef HashMap<int, RefPtr<ImplicitAnimation>> CSSPropertyTransitionsMap;
    90     typedef HashMap<AtomicStringImpl*, RefPtr<KeyframeAnimation>>  AnimationNameMap;
     94    typedef HashMap<AtomicStringImpl*, RefPtr<KeyframeAnimation>> AnimationNameMap;
    9195
    9296    AnimationControllerPrivate* m_animationController;
     
    9599    Vector<AtomicStringImpl*> m_keyframeAnimationOrderMap;
    96100    bool m_suspended;
     101#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
     102    bool m_hasScrollTriggeredAnimation;
     103#endif
    97104};
    98105
  • trunk/Source/WebCore/platform/animation/Animation.cpp

    r181602 r181655  
    9595    m_duration = o.m_duration;
    9696    m_timingFunction = o.m_timingFunction;
     97#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
     98    m_trigger = o.m_trigger;
     99#endif
    97100    m_direction = o.m_direction;
    98101    m_fillMode = o.m_fillMode;
Note: See TracChangeset for help on using the changeset viewer.