| OLD | NEW |
| (Empty) |
| 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 SKY_ENGINE_CORE_ANIMATION_ANIMATIONPLAYER_H_ | |
| 32 #define SKY_ENGINE_CORE_ANIMATION_ANIMATIONPLAYER_H_ | |
| 33 | |
| 34 #include "sky/engine/core/animation/AnimationNode.h" | |
| 35 #include "sky/engine/core/dom/ActiveDOMObject.h" | |
| 36 #include "sky/engine/core/events/EventTarget.h" | |
| 37 #include "sky/engine/wtf/RefPtr.h" | |
| 38 | |
| 39 namespace blink { | |
| 40 | |
| 41 class AnimationTimeline; | |
| 42 class ExceptionState; | |
| 43 | |
| 44 class AnimationPlayer final : public RefCounted<AnimationPlayer> | |
| 45 , public ActiveDOMObject | |
| 46 , public EventTargetWithInlineData { | |
| 47 DEFINE_WRAPPERTYPEINFO(); | |
| 48 REFCOUNTED_EVENT_TARGET(AnimationPlayer); | |
| 49 public: | |
| 50 enum AnimationPlayState { | |
| 51 Idle, | |
| 52 Pending, | |
| 53 Running, | |
| 54 Paused, | |
| 55 Finished | |
| 56 }; | |
| 57 | |
| 58 ~AnimationPlayer(); | |
| 59 static PassRefPtr<AnimationPlayer> create(ExecutionContext*, AnimationTimeli
ne&, AnimationNode*); | |
| 60 | |
| 61 // Returns whether the player is finished. | |
| 62 bool update(TimingUpdateReason); | |
| 63 | |
| 64 // timeToEffectChange returns: | |
| 65 // infinity - if this player is no longer in effect | |
| 66 // 0 - if this player requires an update on the next frame | |
| 67 // n - if this player requires an update after 'n' units of time | |
| 68 double timeToEffectChange(); | |
| 69 | |
| 70 void cancel(); | |
| 71 | |
| 72 double currentTime(); | |
| 73 void setCurrentTime(double newCurrentTime); | |
| 74 | |
| 75 double calculateCurrentTime() const; | |
| 76 double currentTimeInternal(); | |
| 77 void setCurrentTimeInternal(double newCurrentTime, TimingUpdateReason = Timi
ngUpdateOnDemand); | |
| 78 | |
| 79 bool paused() const { return m_paused && !m_isPausedForTesting; } | |
| 80 String playState(); | |
| 81 AnimationPlayState playStateInternal(); | |
| 82 | |
| 83 void pause(); | |
| 84 void play(); | |
| 85 void reverse(); | |
| 86 void finish(ExceptionState&); | |
| 87 bool finished() { return limited(currentTimeInternal()); } | |
| 88 bool playing() { return !(finished() || m_paused || m_isPausedForTesting); } | |
| 89 // FIXME: Resolve whether finished() should just return the flag, and | |
| 90 // remove this method. | |
| 91 bool finishedInternal() const { return m_finished; } | |
| 92 | |
| 93 virtual const AtomicString& interfaceName() const override; | |
| 94 virtual ExecutionContext* executionContext() const override; | |
| 95 virtual bool hasPendingActivity() const override; | |
| 96 virtual void stop() override; | |
| 97 virtual bool dispatchEvent(PassRefPtr<Event>) override; | |
| 98 | |
| 99 double playbackRate() const { return m_playbackRate; } | |
| 100 void setPlaybackRate(double); | |
| 101 const AnimationTimeline* timeline() const { return m_timeline; } | |
| 102 AnimationTimeline* timeline() { return m_timeline; } | |
| 103 | |
| 104 void timelineDestroyed() { m_timeline = nullptr; } | |
| 105 | |
| 106 double calculateStartTime(double currentTime) const; | |
| 107 bool hasStartTime() const { return !isNull(m_startTime); } | |
| 108 double startTime() const; | |
| 109 double startTimeInternal() const { return m_startTime; } | |
| 110 void setStartTime(double); | |
| 111 void setStartTimeInternal(double); | |
| 112 | |
| 113 const AnimationNode* source() const { return m_content.get(); } | |
| 114 AnimationNode* source() { return m_content.get(); } | |
| 115 void setSource(AnimationNode*); | |
| 116 | |
| 117 // Pausing via this method is not reflected in the value returned by | |
| 118 // paused() and must never overlap with pausing via pause(). | |
| 119 void pauseForTesting(double pauseTime); | |
| 120 // This should only be used for CSS | |
| 121 void unpause(); | |
| 122 | |
| 123 void setOutdated(); | |
| 124 bool outdated() { return m_outdated; } | |
| 125 | |
| 126 void setPending(); | |
| 127 void notifyCompositorStartTime(double timelineTime); | |
| 128 | |
| 129 | |
| 130 void preCommit(); | |
| 131 void postCommit(double timelineTime); | |
| 132 | |
| 133 unsigned sequenceNumber() const { return m_sequenceNumber; } | |
| 134 | |
| 135 static bool hasLowerPriority(AnimationPlayer* player1, AnimationPlayer* play
er2) | |
| 136 { | |
| 137 return player1->sequenceNumber() < player2->sequenceNumber(); | |
| 138 } | |
| 139 | |
| 140 // Checks if the AnimationStack is the last reference holder to the Player. | |
| 141 bool canFree() const; | |
| 142 | |
| 143 virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<Even
tListener>, bool useCapture = false) override; | |
| 144 | |
| 145 private: | |
| 146 AnimationPlayer(ExecutionContext*, AnimationTimeline&, AnimationNode*); | |
| 147 double sourceEnd() const; | |
| 148 bool limited(double currentTime) const; | |
| 149 void updateCurrentTimingState(TimingUpdateReason); | |
| 150 void unpauseInternal(); | |
| 151 | |
| 152 double m_playbackRate; | |
| 153 | |
| 154 double m_startTime; | |
| 155 double m_holdTime; | |
| 156 | |
| 157 unsigned m_sequenceNumber; | |
| 158 | |
| 159 RefPtr<AnimationNode> m_content; | |
| 160 RawPtr<AnimationTimeline> m_timeline; | |
| 161 // Reflects all pausing, including via pauseForTesting(). | |
| 162 bool m_paused; | |
| 163 bool m_held; | |
| 164 bool m_isPausedForTesting; | |
| 165 | |
| 166 // This indicates timing information relevant to the player's effect | |
| 167 // has changed by means other than the ordinary progression of time | |
| 168 bool m_outdated; | |
| 169 | |
| 170 bool m_finished; | |
| 171 // Holds a 'finished' event queued for asynchronous dispatch via the | |
| 172 // ScriptedAnimationController. This object remains active until the | |
| 173 // event is actually dispatched. | |
| 174 RefPtr<Event> m_pendingFinishedEvent; | |
| 175 | |
| 176 bool m_pending; | |
| 177 bool m_currentTimePending; | |
| 178 }; | |
| 179 | |
| 180 } // namespace blink | |
| 181 | |
| 182 #endif // SKY_ENGINE_CORE_ANIMATION_ANIMATIONPLAYER_H_ | |
| OLD | NEW |