• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 Google 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 are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef AnimationTimeline_h
32 #define AnimationTimeline_h
33 
34 #include "core/animation/AnimationEffect.h"
35 #include "core/animation/AnimationPlayer.h"
36 #include "core/dom/Element.h"
37 #include "core/events/Event.h"
38 #include "platform/Timer.h"
39 #include "platform/heap/Handle.h"
40 #include "wtf/RefCounted.h"
41 #include "wtf/RefPtr.h"
42 #include "wtf/Vector.h"
43 
44 namespace WebCore {
45 
46 class Document;
47 class AnimationNode;
48 
49 // AnimationTimeline is constructed and owned by Document, and tied to its lifecycle.
50 class AnimationTimeline : public RefCountedWillBeGarbageCollectedFinalized<AnimationTimeline> {
51 public:
52     class PlatformTiming : public NoBaseWillBeGarbageCollectedFinalized<PlatformTiming> {
53 
54     public:
55         // Calls AnimationTimeline's wake() method after duration seconds.
56         virtual void wakeAfter(double duration) = 0;
57         virtual void cancelWake() = 0;
58         virtual void serviceOnNextFrame() = 0;
~PlatformTiming()59         virtual ~PlatformTiming() { }
trace(Visitor *)60         virtual void trace(Visitor*) { }
61     };
62 
63     static PassRefPtrWillBeRawPtr<AnimationTimeline> create(Document*, PassOwnPtrWillBeRawPtr<PlatformTiming> = nullptr);
64     ~AnimationTimeline();
65 
66     void serviceAnimations(TimingUpdateReason);
67 
68     // Creates a player attached to this timeline, but without a start time.
69     AnimationPlayer* createAnimationPlayer(AnimationNode*);
70     AnimationPlayer* play(AnimationNode*);
71 
72 #if !ENABLE(OILPAN)
playerDestroyed(AnimationPlayer * player)73     void playerDestroyed(AnimationPlayer* player)
74     {
75         ASSERT(m_players.contains(player));
76         m_players.remove(player);
77     }
78 #endif
79 
hasPendingUpdates()80     bool hasPendingUpdates() const { return !m_playersNeedingUpdate.isEmpty(); }
zeroTime()81     double zeroTime() const { return 0; }
82     double currentTime(bool& isNull);
83     double currentTime();
84     double currentTimeInternal(bool& isNull);
85     double currentTimeInternal();
86     double effectiveTime();
87     void pauseAnimationsForTesting(double);
88     size_t numberOfActiveAnimationsForTesting() const;
89 
90     void setOutdatedAnimationPlayer(AnimationPlayer*);
91     bool hasOutdatedAnimationPlayer() const;
92 
document()93     Document* document() { return m_document.get(); }
94 #if !ENABLE(OILPAN)
95     void detachFromDocument();
96 #endif
97     void wake();
98 
99     void trace(Visitor*);
100 
101 protected:
102     AnimationTimeline(Document*, PassOwnPtrWillBeRawPtr<PlatformTiming>);
103 
104 private:
105     RawPtrWillBeMember<Document> m_document;
106     // AnimationPlayers which will be updated on the next frame
107     // i.e. current, in effect, or had timing changed
108     WillBeHeapHashSet<RefPtrWillBeMember<AnimationPlayer> > m_playersNeedingUpdate;
109     WillBeHeapHashSet<RawPtrWillBeWeakMember<AnimationPlayer> > m_players;
110 
111     friend class SMILTimeContainer;
112     static const double s_minimumDelay;
113 
114     OwnPtrWillBeMember<PlatformTiming> m_timing;
115 
116     class AnimationTimelineTiming FINAL : public PlatformTiming {
117     public:
AnimationTimelineTiming(AnimationTimeline * timeline)118         AnimationTimelineTiming(AnimationTimeline* timeline)
119             : m_timeline(timeline)
120             , m_timer(this, &AnimationTimelineTiming::timerFired)
121         {
122             ASSERT(m_timeline);
123         }
124 
125         virtual void wakeAfter(double duration) OVERRIDE;
126         virtual void cancelWake() OVERRIDE;
127         virtual void serviceOnNextFrame() OVERRIDE;
128 
timerFired(Timer<AnimationTimelineTiming> *)129         void timerFired(Timer<AnimationTimelineTiming>*) { m_timeline->wake(); }
130 
131         virtual void trace(Visitor*) OVERRIDE;
132 
133     private:
134         RawPtrWillBeMember<AnimationTimeline> m_timeline;
135         Timer<AnimationTimelineTiming> m_timer;
136     };
137 
138     friend class AnimationAnimationTimelineTest;
139 };
140 
141 } // namespace
142 
143 #endif
144