diff options
Diffstat (limited to 'Source/WebCore/page/animation/AnimationBase.h')
-rw-r--r-- | Source/WebCore/page/animation/AnimationBase.h | 196 |
1 files changed, 107 insertions, 89 deletions
diff --git a/Source/WebCore/page/animation/AnimationBase.h b/Source/WebCore/page/animation/AnimationBase.h index 51673374d..f3387d2ef 100644 --- a/Source/WebCore/page/animation/AnimationBase.h +++ b/Source/WebCore/page/animation/AnimationBase.h @@ -10,7 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * 3. Neither the name of Apple Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -26,23 +26,19 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef AnimationBase_h -#define AnimationBase_h +#pragma once #include "Animation.h" #include "CSSPropertyNames.h" #include "RenderStyleConstants.h" -#include <wtf/HashMap.h> -#include <wtf/HashSet.h> -#include <wtf/RefCounted.h> #include <wtf/text/AtomicString.h> namespace WebCore { -class AnimationBase; -class AnimationController; class CompositeAnimation; class Element; +class FloatRect; +class LayoutRect; class RenderElement; class RenderStyle; class TimingFunction; @@ -50,7 +46,7 @@ class TimingFunction; class AnimationBase : public RefCounted<AnimationBase> { friend class CompositeAnimation; friend class CSSPropertyAnimation; - + WTF_MAKE_FAST_ALLOCATED; public: AnimationBase(const Animation& transition, RenderElement*, CompositeAnimation*); virtual ~AnimationBase() { } @@ -58,9 +54,9 @@ public: RenderElement* renderer() const { return m_object; } void clear() { - endAnimation(); - m_object = 0; - m_compAnim = 0; + endAnimation(); + m_object = nullptr; + m_compositeAnimation = nullptr; } double duration() const; @@ -68,106 +64,129 @@ public: // Animations and Transitions go through the states below. When entering the STARTED state // the animation is started. This may or may not require deferred response from the animator. // If so, we stay in this state until that response is received (and it returns the start time). - // Otherwise, we use the current time as the start time and go immediately to AnimationStateLooping - // or AnimationStateEnding. - enum AnimState { - AnimationStateNew, // animation just created, animation not running yet - AnimationStateStartWaitTimer, // start timer running, waiting for fire - AnimationStateStartWaitStyleAvailable, // waiting for style setup so we can start animations - AnimationStateStartWaitResponse, // animation started, waiting for response - AnimationStateLooping, // response received, animation running, loop timer running, waiting for fire - AnimationStateEnding, // received, animation running, end timer running, waiting for fire - AnimationStatePausedNew, // in pause mode when animation was created - AnimationStatePausedWaitTimer, // in pause mode when animation started - AnimationStatePausedWaitStyleAvailable, // in pause mode when waiting for style setup - AnimationStatePausedWaitResponse, // animation paused when in STARTING state - AnimationStatePausedRun, // animation paused when in LOOPING or ENDING state - AnimationStateDone, // end timer fired, animation finished and removed - AnimationStateFillingForwards // animation has ended and is retaining its final value + // Otherwise, we use the current time as the start time and go immediately to AnimationState::Looping + // or AnimationState::Ending. + enum class AnimationState { + New, // animation just created, animation not running yet + StartWaitTimer, // start timer running, waiting for fire + StartWaitStyleAvailable, // waiting for style setup so we can start animations + StartWaitResponse, // animation started, waiting for response + Looping, // response received, animation running, loop timer running, waiting for fire + Ending, // received, animation running, end timer running, waiting for fire + PausedNew, // in pause mode when animation was created + PausedWaitTimer, // in pause mode when animation started + PausedWaitStyleAvailable, // in pause mode when waiting for style setup + PausedWaitResponse, // animation paused when in STARTING state + PausedRun, // animation paused when in LOOPING or ENDING state + Done, // end timer fired, animation finished and removed + FillingForwards // animation has ended and is retaining its final value }; - enum AnimStateInput { - AnimationStateInputMakeNew, // reset back to new from any state - AnimationStateInputStartAnimation, // animation requests a start - AnimationStateInputRestartAnimation, // force a restart from any state - AnimationStateInputStartTimerFired, // start timer fired - AnimationStateInputStyleAvailable, // style is setup, ready to start animating - AnimationStateInputStartTimeSet, // m_startTime was set - AnimationStateInputLoopTimerFired, // loop timer fired - AnimationStateInputEndTimerFired, // end timer fired - AnimationStateInputPauseOverride, // pause an animation due to override - AnimationStateInputResumeOverride, // resume an overridden animation - AnimationStateInputPlayStateRunning, // play state paused -> running - AnimationStateInputPlayStatePaused, // play state running -> paused - AnimationStateInputEndAnimation // force an end from any state + enum class AnimationStateInput { + MakeNew, // reset back to new from any state + StartAnimation, // animation requests a start + RestartAnimation, // force a restart from any state + StartTimerFired, // start timer fired + StyleAvailable, // style is setup, ready to start animating + StartTimeSet, // m_startTime was set + LoopTimerFired, // loop timer fired + EndTimerFired, // end timer fired + PauseOverride, // pause an animation due to override + ResumeOverride, // resume an overridden animation + PlayStateRunning, // play state paused -> running + PlayStatePaused, // play state running -> paused + EndAnimation // force an end from any state }; - // Called when animation is in AnimationStateNew to start animation - void updateStateMachine(AnimStateInput, double param); + // Called when animation is in AnimationState::New to start animation + void updateStateMachine(AnimationStateInput, double param); // Animation has actually started, at passed time void onAnimationStartResponse(double startTime) { - updateStateMachine(AnimationBase::AnimationStateInputStartTimeSet, startTime); + updateStateMachine(AnimationStateInput::StartTimeSet, startTime); } // Called to change to or from paused state void updatePlayState(EAnimPlayState); bool playStatePlaying() const; - bool waitingToStart() const { return m_animState == AnimationStateNew || m_animState == AnimationStateStartWaitTimer || m_animState == AnimationStatePausedNew; } + bool waitingToStart() const { return m_animationState == AnimationState::New || m_animationState == AnimationState::StartWaitTimer || m_animationState == AnimationState::PausedNew; } bool preActive() const { - return m_animState == AnimationStateNew || m_animState == AnimationStateStartWaitTimer || m_animState == AnimationStateStartWaitStyleAvailable || m_animState == AnimationStateStartWaitResponse; + return m_animationState == AnimationState::New || m_animationState == AnimationState::StartWaitTimer || m_animationState == AnimationState::StartWaitStyleAvailable || m_animationState == AnimationState::StartWaitResponse; } - bool postActive() const { return m_animState == AnimationStateDone; } + bool postActive() const { return m_animationState == AnimationState::Done; } + bool fillingForwards() const { return m_animationState == AnimationState::FillingForwards; } bool active() const { return !postActive() && !preActive(); } bool running() const { return !isNew() && !postActive(); } - bool paused() const { return m_pauseTime >= 0 || m_animState == AnimationStatePausedNew; } - bool isNew() const { return m_animState == AnimationStateNew || m_animState == AnimationStatePausedNew; } - bool waitingForStartTime() const { return m_animState == AnimationStateStartWaitResponse; } - bool waitingForStyleAvailable() const { return m_animState == AnimationStateStartWaitStyleAvailable; } + bool paused() const { return m_pauseTime || m_animationState == AnimationState::PausedNew; } + bool inPausedState() const { return m_animationState >= AnimationState::PausedNew && m_animationState <= AnimationState::PausedRun; } + bool isNew() const { return m_animationState == AnimationState::New || m_animationState == AnimationState::PausedNew; } + bool waitingForStartTime() const { return m_animationState == AnimationState::StartWaitResponse; } + bool waitingForStyleAvailable() const { return m_animationState == AnimationState::StartWaitStyleAvailable; } + + bool isAccelerated() const { return m_isAccelerated; } virtual double timeToNextService(); - double progress(double scale, double offset, const TimingFunction*) const; + double progress(double scale = 1, double offset = 0, const TimingFunction* = nullptr) const; - virtual void animate(CompositeAnimation*, RenderElement*, const RenderStyle* /*currentStyle*/, RenderStyle* /*targetStyle*/, RefPtr<RenderStyle>& /*animatedStyle*/) = 0; - virtual void getAnimatedStyle(RefPtr<RenderStyle>& /*animatedStyle*/) = 0; + // Returns true if the animation state changed. + virtual bool animate(CompositeAnimation*, RenderElement*, const RenderStyle* /*currentStyle*/, const RenderStyle* /*targetStyle*/, std::unique_ptr<RenderStyle>& /*animatedStyle*/, bool& didBlendStyle) = 0; + virtual void getAnimatedStyle(std::unique_ptr<RenderStyle>& /*animatedStyle*/) = 0; + + virtual bool computeExtentOfTransformAnimation(LayoutRect&) const = 0; virtual bool shouldFireEvents() const { return false; } void fireAnimationEventsIfNeeded(); - bool animationsMatch(const Animation*) const; + bool animationsMatch(const Animation&) const; - void setAnimation(const Animation& animation) { m_animation = const_cast<Animation*>(&animation); } + const Animation& animation() const { return m_animation; } + void setAnimation(const Animation& animation) { m_animation = const_cast<Animation&>(animation); } // Return true if this animation is overridden. This will only be the case for // ImplicitAnimations and is used to determine whether or not we should force // set the start time. If an animation is overridden, it will probably not get - // back the AnimationStateInputStartTimeSet input. + // back the AnimationStateInput::StartTimeSet input. virtual bool overridden() const { return false; } // Does this animation/transition involve the given property? virtual bool affectsProperty(CSSPropertyID /*property*/) const { return false; } - bool isAnimatingProperty(CSSPropertyID property, bool acceleratedOnly, bool isRunningNow) const + enum RunningStates { + Delaying = 1 << 0, + Paused = 1 << 1, + Running = 1 << 2, + }; + typedef unsigned RunningState; + bool isAnimatingProperty(CSSPropertyID property, bool acceleratedOnly, RunningState runningState) const { if (acceleratedOnly && !m_isAccelerated) return false; - - if (isRunningNow) - return (!waitingToStart() && !postActive()) && affectsProperty(property); - return !postActive() && affectsProperty(property); + if (!affectsProperty(property)) + return false; + + if ((runningState & Delaying) && preActive()) + return true; + + if ((runningState & Paused) && inPausedState()) + return true; + + if ((runningState & Running) && !inPausedState() && (m_animationState >= AnimationState::StartWaitStyleAvailable && m_animationState < AnimationState::Done)) + return true; + + return false; } - // FIXME: rename this using the "lists match" terminology. - bool isTransformFunctionListValid() const { return m_transformFunctionListValid; } -#if ENABLE(CSS_FILTERS) + bool transformFunctionListsMatch() const { return m_transformFunctionListsMatch; } bool filterFunctionListsMatch() const { return m_filterFunctionListsMatch; } +#if ENABLE(FILTERS_LEVEL_2) + bool backdropFilterFunctionListsMatch() const { return m_backdropFilterFunctionListsMatch; } #endif // Freeze the animation; used by DumpRenderTree. @@ -186,16 +205,14 @@ public: void styleAvailable() { ASSERT(waitingForStyleAvailable()); - updateStateMachine(AnimationBase::AnimationStateInputStyleAvailable, -1); + updateStateMachine(AnimationStateInput::StyleAvailable, -1); } - const Animation& animation() const { return *m_animation; } - protected: virtual void overrideAnimations() { } virtual void resumeOverriddenAnimations() { } - CompositeAnimation* compositeAnimation() { return m_compAnim; } + CompositeAnimation* compositeAnimation() { return m_compositeAnimation; } // These are called when the corresponding timer fires so subclasses can do any extra work virtual void onAnimationStart(double /*elapsedTime*/) { } @@ -211,7 +228,7 @@ protected: void goIntoEndingOrLoopingState(); - bool isAccelerated() const { return m_isAccelerated; } + AnimationState state() const { return m_animationState; } static void setNeedsStyleRecalc(Element*); @@ -219,26 +236,27 @@ protected: double fractionalTime(double scale, double elapsedTime, double offset) const; - AnimState m_animState; - - bool m_isAccelerated; - bool m_transformFunctionListValid; -#if ENABLE(CSS_FILTERS) - bool m_filterFunctionListsMatch; -#endif - double m_startTime; - double m_pauseTime; - double m_requestedStartTime; - - double m_totalDuration; - double m_nextIterationDuration; + // These return true if we can easily compute a bounding box by applying the style's transform to the bounds rect. + bool computeTransformedExtentViaTransformList(const FloatRect& rendererBox, const RenderStyle&, LayoutRect& bounds) const; + bool computeTransformedExtentViaMatrix(const FloatRect& rendererBox, const RenderStyle&, LayoutRect& bounds) const; RenderElement* m_object; - - RefPtr<Animation> m_animation; - CompositeAnimation* m_compAnim; + CompositeAnimation* m_compositeAnimation; // Ideally this would be a reference, but it has to be cleared if an animation is destroyed inside an event callback. + Ref<Animation> m_animation; + + std::optional<double> m_startTime; + std::optional<double> m_pauseTime; + double m_requestedStartTime { 0 }; + std::optional<double> m_totalDuration; + std::optional<double> m_nextIterationDuration; + + AnimationState m_animationState { AnimationState::New }; + bool m_isAccelerated { false }; + bool m_transformFunctionListsMatch { false }; + bool m_filterFunctionListsMatch { false }; +#if ENABLE(FILTERS_LEVEL_2) + bool m_backdropFilterFunctionListsMatch { false }; +#endif }; } // namespace WebCore - -#endif // AnimationBase_h |