Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: sky/engine/core/animation/Animation.cpp

Issue 1229273004: Remove Animations and Transitions. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/engine/core/animation/Animation.h ('k') | sky/engine/core/animation/Animation.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "sky/engine/core/animation/Animation.h"
32
33 #include "sky/engine/bindings/exception_state.h"
34 #include "sky/engine/core/animation/ActiveAnimations.h"
35 #include "sky/engine/core/animation/AnimationHelpers.h"
36 #include "sky/engine/core/animation/AnimationPlayer.h"
37 #include "sky/engine/core/animation/AnimationTimeline.h"
38 #include "sky/engine/core/animation/Interpolation.h"
39 #include "sky/engine/core/animation/KeyframeEffectModel.h"
40 #include "sky/engine/core/dom/Element.h"
41 #include "sky/engine/core/rendering/RenderLayer.h"
42
43 namespace blink {
44
45 PassRefPtr<Animation> Animation::create(Element* target, PassRefPtr<AnimationEff ect> effect, const Timing& timing, Priority priority, PassOwnPtr<EventDelegate> eventDelegate)
46 {
47 return adoptRef(new Animation(target, effect, timing, priority, eventDelegat e));
48 }
49
50 PassRefPtr<Animation> Animation::create(Element* element, double duration, Excep tionState&)
51 {
52 return create(element, PassRefPtr<AnimationEffect>(), TimingInput::convert(d uration));
53 }
54 PassRefPtr<Animation> Animation::create(Element* element, ExceptionState& es)
55 {
56 return create(element, 0.0, es);
57 }
58
59 Animation::Animation(Element* target, PassRefPtr<AnimationEffect> effect, const Timing& timing, Priority priority, PassOwnPtr<EventDelegate> eventDelegate)
60 : AnimationNode(timing, eventDelegate)
61 , m_target(target)
62 , m_effect(effect)
63 , m_sampledEffect(nullptr)
64 , m_priority(priority)
65 {
66 if (m_target)
67 m_target->ensureActiveAnimations().addAnimation(this);
68 }
69
70 Animation::~Animation()
71 {
72 if (m_target)
73 m_target->activeAnimations()->notifyAnimationDestroyed(this);
74 }
75
76 void Animation::attach(AnimationPlayer* player)
77 {
78 if (m_target) {
79 m_target->ensureActiveAnimations().players().add(player);
80 m_target->setNeedsAnimationStyleRecalc();
81 }
82 AnimationNode::attach(player);
83 }
84
85 void Animation::detach()
86 {
87 if (m_target)
88 m_target->activeAnimations()->players().remove(player());
89 if (m_sampledEffect)
90 clearEffects();
91 AnimationNode::detach();
92 }
93
94 void Animation::specifiedTimingChanged()
95 {
96 if (player()) {
97 // FIXME: Needs to consider groups when added.
98 ASSERT(player()->source() == this);
99 player()->setPending();
100 }
101 }
102
103 static AnimationStack& ensureAnimationStack(Element* element)
104 {
105 return element->ensureActiveAnimations().defaultStack();
106 }
107
108 void Animation::applyEffects()
109 {
110 ASSERT(isInEffect());
111 ASSERT(player());
112 if (!m_target || !m_effect)
113 return;
114
115 double iteration = currentIteration();
116 ASSERT(iteration >= 0);
117 // FIXME: Handle iteration values which overflow int.
118 OwnPtr<Vector<RefPtr<Interpolation> > > interpolations = m_effect->sample(st atic_cast<int>(iteration), timeFraction(), iterationDuration());
119 if (m_sampledEffect) {
120 m_sampledEffect->setInterpolations(interpolations.release());
121 } else if (!interpolations->isEmpty()) {
122 OwnPtr<SampledEffect> sampledEffect = SampledEffect::create(this, interp olations.release());
123 m_sampledEffect = sampledEffect.get();
124 ensureAnimationStack(m_target).add(sampledEffect.release());
125 } else {
126 return;
127 }
128
129 m_target->setNeedsAnimationStyleRecalc();
130 }
131
132 void Animation::clearEffects()
133 {
134 ASSERT(player());
135 ASSERT(m_sampledEffect);
136
137 m_sampledEffect->clear();
138 m_sampledEffect = nullptr;
139 m_target->setNeedsAnimationStyleRecalc();
140 invalidate();
141 }
142
143 void Animation::updateChildrenAndEffects() const
144 {
145 if (!m_effect)
146 return;
147 if (isInEffect())
148 const_cast<Animation*>(this)->applyEffects();
149 else if (m_sampledEffect)
150 const_cast<Animation*>(this)->clearEffects();
151 }
152
153 double Animation::calculateTimeToEffectChange(bool forwards, double localTime, d ouble timeToNextIteration) const
154 {
155 const double start = startTimeInternal() + specifiedTiming().startDelay;
156 const double end = start + activeDurationInternal();
157
158 switch (phase()) {
159 case PhaseBefore:
160 ASSERT(start >= localTime);
161 return forwards
162 ? start - localTime
163 : std::numeric_limits<double>::infinity();
164 case PhaseActive:
165 return 0;
166 case PhaseAfter:
167 ASSERT(localTime >= end);
168 // If this Animation is still in effect then it will need to update
169 // when its parent goes out of effect. We have no way of knowing when
170 // that will be, however, so the parent will need to supply it.
171 return forwards
172 ? std::numeric_limits<double>::infinity()
173 : localTime - end;
174 default:
175 ASSERT_NOT_REACHED();
176 return std::numeric_limits<double>::infinity();
177 }
178 }
179
180 void Animation::notifySampledEffectRemovedFromAnimationStack()
181 {
182 ASSERT(m_sampledEffect);
183 m_sampledEffect = nullptr;
184 }
185
186 void Animation::notifyElementDestroyed()
187 {
188 // If our player is kept alive just by the sampledEffect, we might get our
189 // destructor called when we call SampledEffect::clear(), so we need to
190 // clear m_sampledEffect first.
191 m_target = nullptr;
192 clearEventDelegate();
193 SampledEffect* sampledEffect = m_sampledEffect;
194 m_sampledEffect = nullptr;
195 if (sampledEffect)
196 sampledEffect->clear();
197 }
198
199 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/animation/Animation.h ('k') | sky/engine/core/animation/Animation.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698