Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/animation/Animation.h" | 32 #include "core/animation/Animation.h" |
| 33 | 33 |
| 34 #include "core/animation/ActiveAnimations.h" | 34 #include "core/animation/ActiveAnimations.h" |
| 35 #include "core/animation/CompositorAnimations.h" | |
| 36 #include "core/animation/KeyframeAnimationEffect.h" | |
| 35 #include "core/animation/Player.h" | 37 #include "core/animation/Player.h" |
| 36 #include "core/dom/Element.h" | 38 #include "core/dom/Element.h" |
| 37 | 39 |
| 38 namespace WebCore { | 40 namespace WebCore { |
| 39 | 41 |
| 40 PassRefPtr<Animation> Animation::create(PassRefPtr<Element> target, PassRefPtr<A nimationEffect> effect, const Timing& timing, Priority priority, PassOwnPtr<Even tDelegate> eventDelegate) | 42 PassRefPtr<Animation> Animation::create(PassRefPtr<Element> target, PassRefPtr<A nimationEffect> effect, const Timing& timing, Priority priority, PassOwnPtr<Even tDelegate> eventDelegate) |
| 41 { | 43 { |
| 42 return adoptRef(new Animation(target, effect, timing, priority, eventDelegat e)); | 44 return adoptRef(new Animation(target, effect, timing, priority, eventDelegat e)); |
| 43 } | 45 } |
| 44 | 46 |
| 45 Animation::Animation(PassRefPtr<Element> target, PassRefPtr<AnimationEffect> eff ect, const Timing& timing, Priority priority, PassOwnPtr<EventDelegate> eventDel egate) | 47 Animation::Animation(PassRefPtr<Element> target, PassRefPtr<AnimationEffect> eff ect, const Timing& timing, Priority priority, PassOwnPtr<EventDelegate> eventDel egate) |
| 46 : TimedItem(timing, eventDelegate) | 48 : TimedItem(timing, eventDelegate) |
| 47 , m_target(target) | 49 , m_target(target) |
| 48 , m_effect(effect) | 50 , m_effect(effect) |
| 49 , m_activeInAnimationStack(false) | 51 , m_activeInAnimationStack(false) |
| 50 , m_priority(priority) | 52 , m_priority(priority) |
| 51 { | 53 { |
| 52 } | 54 } |
| 53 | 55 |
| 54 void Animation::didAttach() | 56 void Animation::didAttach() |
| 55 { | 57 { |
| 56 if (m_target) | 58 if (m_target) |
| 57 m_target->ensureActiveAnimations()->players().add(player()); | 59 m_target->ensureActiveAnimations()->players().add(player()); |
| 58 } | 60 } |
| 59 | 61 |
| 60 void Animation::willDetach() | 62 void Animation::willDetach() |
| 61 { | 63 { |
| 62 if (m_target) | 64 if (m_target) |
| 63 m_target->activeAnimations()->players().remove(player()); | 65 m_target->activeAnimations()->players().remove(player()); |
| 64 | |
| 65 if (m_activeInAnimationStack) | 66 if (m_activeInAnimationStack) |
| 66 clearEffects(); | 67 clearEffects(); |
| 67 } | 68 } |
| 68 | 69 |
| 69 static AnimationStack& ensureAnimationStack(Element* element) | 70 static AnimationStack& ensureAnimationStack(Element* element) |
| 70 { | 71 { |
| 71 return element->ensureActiveAnimations()->defaultStack(); | 72 return element->ensureActiveAnimations()->defaultStack(); |
| 72 } | 73 } |
| 73 | 74 |
| 74 bool Animation::applyEffects(bool previouslyInEffect) | 75 bool Animation::applyEffects(bool previouslyInEffect) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 85 m_compositableValues = m_effect->sample(currentIteration(), timeFraction()); | 86 m_compositableValues = m_effect->sample(currentIteration(), timeFraction()); |
| 86 m_target->setNeedsStyleRecalc(LocalStyleChange, StyleChangeFromRenderer); | 87 m_target->setNeedsStyleRecalc(LocalStyleChange, StyleChangeFromRenderer); |
| 87 return true; | 88 return true; |
| 88 } | 89 } |
| 89 | 90 |
| 90 void Animation::clearEffects() | 91 void Animation::clearEffects() |
| 91 { | 92 { |
| 92 ASSERT(player()); | 93 ASSERT(player()); |
| 93 ASSERT(m_activeInAnimationStack); | 94 ASSERT(m_activeInAnimationStack); |
| 94 ensureAnimationStack(m_target.get()).remove(this); | 95 ensureAnimationStack(m_target.get()).remove(this); |
| 96 cancelCompositorAnimations(); | |
| 95 m_activeInAnimationStack = false; | 97 m_activeInAnimationStack = false; |
| 96 m_compositableValues.clear(); | 98 m_compositableValues.clear(); |
| 97 m_target->setNeedsStyleRecalc(LocalStyleChange, StyleChangeFromRenderer); | 99 m_target->setNeedsStyleRecalc(LocalStyleChange, StyleChangeFromRenderer); |
| 98 } | 100 } |
| 99 | 101 |
| 100 bool Animation::updateChildrenAndEffects() const | 102 bool Animation::updateChildrenAndEffects() const |
| 101 { | 103 { |
| 102 if (!m_effect) | 104 if (!m_effect) |
| 103 return false; | 105 return false; |
| 104 | 106 |
| 105 if (isInEffect()) | 107 if (isInEffect()) |
| 106 return const_cast<Animation*>(this)->applyEffects(m_activeInAnimationSta ck); | 108 return const_cast<Animation*>(this)->applyEffects(m_activeInAnimationSta ck); |
| 107 | 109 |
| 108 if (m_activeInAnimationStack) { | 110 if (m_activeInAnimationStack) { |
| 109 const_cast<Animation*>(this)->clearEffects(); | 111 const_cast<Animation*>(this)->clearEffects(); |
| 110 return true; | 112 return true; |
| 111 } | 113 } |
| 112 return false; | 114 return false; |
| 113 } | 115 } |
| 114 | 116 |
| 115 double Animation::calculateTimeToEffectChange(double localTime, double) const | 117 double Animation::calculateTimeToEffectChange(double localTime, double timeToNex tIteration) const |
| 116 { | 118 { |
| 117 const double activeStartTime = startTime() + specified().startDelay; | 119 const double activeStartTime = startTime() + specified().startDelay; |
| 118 | |
| 119 switch (phase()) { | 120 switch (phase()) { |
| 120 case PhaseBefore: | 121 case PhaseBefore: |
| 121 return activeStartTime - localTime; | 122 return activeStartTime - localTime; |
| 122 case PhaseActive: | 123 case PhaseActive: |
| 124 if (isRunningCompositorAnimation()) { | |
| 125 // Need service to apply fill / fire events. | |
| 126 const double activeEndTime = activeStartTime + activeDuration(); | |
| 127 return isNull(timeToNextIteration) ? activeEndTime - localTime : tim eToNextIteration; | |
|
Steve Block
2013/11/18 05:03:03
Does this assume that timeToNextIteration is alway
dstockwell
2013/11/18 06:11:20
Done.
| |
| 128 } | |
| 123 return 0; | 129 return 0; |
| 124 case PhaseAfter: | 130 case PhaseAfter: |
| 125 // If this Animation is still in effect then it will need to update | 131 // If this Animation is still in effect then it will need to update |
| 126 // when its parent goes out of effect. We have no way of knowing when | 132 // when its parent goes out of effect. We have no way of knowing when |
| 127 // that will be, however, so the parent will need to supply it. | 133 // that will be, however, so the parent will need to supply it. |
| 128 return std::numeric_limits<double>::infinity(); | 134 return std::numeric_limits<double>::infinity(); |
| 129 case PhaseNone: | 135 case PhaseNone: |
| 130 default: | 136 default: |
| 131 ASSERT_NOT_REACHED(); | 137 ASSERT_NOT_REACHED(); |
| 132 return 0; | 138 return 0; |
| 133 } | 139 } |
| 134 } | 140 } |
| 135 | 141 |
| 142 bool Animation::isCandidateForCompositorAnimation() const | |
| 143 { | |
| 144 if (!effect() || !m_target) | |
| 145 return false; | |
| 146 return CompositorAnimations::instance()->isCandidateForCompositorAnimation(s pecified(), *effect()); | |
| 147 } | |
| 148 | |
| 149 bool Animation::startCompositorAnimations() | |
| 150 { | |
| 151 ASSERT(!isRunningCompositorAnimation()); | |
| 152 if (!isCandidateForCompositorAnimation()) | |
| 153 return false; | |
| 154 if (!CompositorAnimations::instance()->canStartCompositorAnimation(*m_target .get())) | |
| 155 return false; | |
| 156 if (CompositorAnimations::instance()->startCompositorAnimation(*m_target.get (), specified(), *effect(), m_acceleratedAnimationIds)) { | |
|
Steve Block
2013/11/18 05:03:03
Given that startCompositorAnimation() returns a ve
dstockwell
2013/11/18 06:11:20
Done.
| |
| 157 ASSERT(!m_acceleratedAnimationIds.isEmpty()); | |
| 158 return true; | |
|
Steve Block
2013/11/18 05:03:03
Can you invert this 'if' to make all the early-out
dstockwell
2013/11/18 06:11:20
Done.
| |
| 159 } | |
| 160 return false; | |
| 161 } | |
| 162 | |
| 163 bool Animation::isRunningCompositorAnimation() const | |
| 164 { | |
| 165 return !m_acceleratedAnimationIds.isEmpty(); | |
| 166 } | |
| 167 | |
| 168 bool Animation::isRunningCompositorAnimation(CSSPropertyID property) const | |
| 169 { | |
| 170 return isRunningCompositorAnimation() && affects(property); | |
| 171 } | |
| 172 | |
| 173 bool Animation::affects(CSSPropertyID property) const | |
| 174 { | |
| 175 return toKeyframeAnimationEffect(m_effect.get())->affects(property); | |
|
Steve Block
2013/11/18 05:03:03
Hmm, why isn't affects() on AnimationEffect, rathe
dstockwell
2013/11/18 06:11:20
Done.
| |
| 176 } | |
| 177 | |
| 178 void Animation::cancelCompositorAnimations() | |
| 179 { | |
| 180 if (!isRunningCompositorAnimation()) | |
| 181 return; | |
| 182 if (!m_target || !m_target->renderer()) | |
| 183 return; | |
| 184 for (size_t i = 0; i < m_acceleratedAnimationIds.size(); ++i) { | |
| 185 CompositorAnimations::instance()->cancelCompositorAnimation(*m_target.ge t(), m_acceleratedAnimationIds[i]); | |
| 186 } | |
| 187 m_acceleratedAnimationIds.clear(); | |
| 188 } | |
| 189 | |
| 136 } // namespace WebCore | 190 } // namespace WebCore |
| OLD | NEW |