1 | /* |
2 | * Copyright (C) 2007 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * |
8 | * 1. Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
13 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
14 | * its contributors may be used to endorse or promote products derived |
15 | * from this software without specific prior written permission. |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
20 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
28 | |
29 | #pragma once |
30 | |
31 | #include "AnimationBase.h" |
32 | #include "CSSPropertyNames.h" |
33 | #include "RenderStyle.h" |
34 | #include <wtf/Forward.h> |
35 | |
36 | namespace WebCore { |
37 | |
38 | class CSSAnimationControllerPrivate; |
39 | class Document; |
40 | class Element; |
41 | class Frame; |
42 | class LayoutRect; |
43 | class RenderElement; |
44 | |
45 | struct AnimationUpdate { |
46 | std::unique_ptr<RenderStyle> style; |
47 | bool animationChangeRequiresRecomposite { false }; |
48 | }; |
49 | |
50 | class CSSAnimationController { |
51 | WTF_MAKE_FAST_ALLOCATED; |
52 | public: |
53 | explicit CSSAnimationController(Frame&); |
54 | ~CSSAnimationController(); |
55 | |
56 | void cancelAnimations(Element&); |
57 | AnimationUpdate updateAnimations(Element&, const RenderStyle& newStyle, const RenderStyle* oldStyle); |
58 | std::unique_ptr<RenderStyle> animatedStyleForRenderer(RenderElement&); |
59 | |
60 | // If possible, compute the visual extent of any transform animation on the given renderer |
61 | // using the given rect, returning the result in the rect. Return false if there is some |
62 | // transform animation but we were unable to cheaply compute its affect on the extent. |
63 | bool computeExtentOfAnimation(RenderElement&, LayoutRect&) const; |
64 | |
65 | // This is called when an accelerated animation or transition has actually started to animate. |
66 | void notifyAnimationStarted(RenderElement&, MonotonicTime startTime); |
67 | |
68 | WEBCORE_EXPORT bool pauseAnimationAtTime(Element&, const AtomicString& name, double t); // To be used only for testing |
69 | WEBCORE_EXPORT bool pauseTransitionAtTime(Element&, const String& property, double t); // To be used only for testing |
70 | WEBCORE_EXPORT unsigned numberOfActiveAnimations(Document*) const; // To be used only for testing |
71 | |
72 | // "Running" here means the animation is running or paused. |
73 | bool isRunningAnimationOnRenderer(RenderElement&, CSSPropertyID) const; |
74 | bool isRunningAcceleratedAnimationOnRenderer(RenderElement&, CSSPropertyID) const; |
75 | |
76 | WEBCORE_EXPORT bool isSuspended() const; |
77 | WEBCORE_EXPORT void suspendAnimations(); |
78 | WEBCORE_EXPORT void resumeAnimations(); |
79 | void serviceAnimations(); |
80 | |
81 | void updateThrottlingState(); |
82 | WEBCORE_EXPORT Seconds animationInterval() const; |
83 | |
84 | WEBCORE_EXPORT void suspendAnimationsForDocument(Document*); |
85 | WEBCORE_EXPORT void resumeAnimationsForDocument(Document*); |
86 | WEBCORE_EXPORT bool animationsAreSuspendedForDocument(Document*); |
87 | void detachFromDocument(Document*); |
88 | void startAnimationsIfNotSuspended(Document*); |
89 | |
90 | void beginAnimationUpdate(); |
91 | void endAnimationUpdate(); |
92 | |
93 | WEBCORE_EXPORT bool allowsNewAnimationsWhileSuspended() const; |
94 | WEBCORE_EXPORT void setAllowsNewAnimationsWhileSuspended(bool); |
95 | |
96 | static bool supportsAcceleratedAnimationOfProperty(CSSPropertyID); |
97 | |
98 | bool hasAnimations() const; |
99 | |
100 | private: |
101 | const std::unique_ptr<CSSAnimationControllerPrivate> m_data; |
102 | }; |
103 | |
104 | class AnimationUpdateBlock { |
105 | public: |
106 | AnimationUpdateBlock(CSSAnimationController* animationController) |
107 | : m_animationController(animationController) |
108 | { |
109 | if (m_animationController) |
110 | m_animationController->beginAnimationUpdate(); |
111 | } |
112 | |
113 | ~AnimationUpdateBlock() |
114 | { |
115 | if (m_animationController) |
116 | m_animationController->endAnimationUpdate(); |
117 | } |
118 | |
119 | CSSAnimationController* m_animationController; |
120 | }; |
121 | |
122 | } // namespace WebCore |
123 | |