OLD | NEW |
(Empty) | |
| 1 |
| 2 /* |
| 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 4 * |
| 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are |
| 7 * met: |
| 8 * |
| 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. |
| 11 * * Redistributions in binary form must reproduce the above |
| 12 * copyright notice, this list of conditions and the following disclaimer |
| 13 * in the documentation and/or other materials provided with the |
| 14 * distribution. |
| 15 * * Neither the name of Google Inc. nor the names of its |
| 16 * contributors may be used to endorse or promote products derived from |
| 17 * this software without specific prior written permission. |
| 18 * |
| 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ |
| 31 |
| 32 #include "config.h" |
| 33 #include "core/animation/css/CSSAnimations.h" |
| 34 |
| 35 #include "core/animation/DocumentTimeline.h" |
| 36 #include "core/animation/KeyframeAnimationEffect.h" |
| 37 #include "core/css/resolver/StyleResolver.h" |
| 38 #include "core/dom/AnimationEvent.h" |
| 39 #include "core/dom/Element.h" |
| 40 #include "core/dom/EventNames.h" |
| 41 #include "core/platform/animation/CSSAnimationDataList.h" |
| 42 #include "core/platform/animation/TimingFunction.h" |
| 43 #include "wtf/HashSet.h" |
| 44 |
| 45 namespace WebCore { |
| 46 |
| 47 void timingFromAnimationData(const CSSAnimationData* animationData, Timing& timi
ng) |
| 48 { |
| 49 if (animationData->isDelaySet()) |
| 50 timing.startDelay = animationData->delay(); |
| 51 if (animationData->isDurationSet()) { |
| 52 timing.iterationDuration = animationData->duration(); |
| 53 timing.hasIterationDuration = true; |
| 54 } |
| 55 if (animationData->isIterationCountSet()) { |
| 56 if (animationData->iterationCount() == CSSAnimationData::IterationCountI
nfinite) |
| 57 timing.iterationCount = std::numeric_limits<double>::infinity(); |
| 58 else |
| 59 timing.iterationCount = animationData->iterationCount(); |
| 60 } |
| 61 if (animationData->isTimingFunctionSet()) { |
| 62 if (!animationData->timingFunction()->isLinearTimingFunction()) |
| 63 timing.timingFunction = animationData->timingFunction(); |
| 64 } else { |
| 65 // CSS default is ease, default in model is linear. |
| 66 timing.timingFunction = CubicBezierTimingFunction::preset(CubicBezierTim
ingFunction::Ease); |
| 67 } |
| 68 if (animationData->isFillModeSet()) { |
| 69 switch (animationData->fillMode()) { |
| 70 case AnimationFillModeForwards: |
| 71 timing.fillMode = Timing::FillModeForwards; |
| 72 break; |
| 73 case AnimationFillModeBackwards: |
| 74 timing.fillMode = Timing::FillModeBackwards; |
| 75 break; |
| 76 case AnimationFillModeBoth: |
| 77 timing.fillMode = Timing::FillModeBoth; |
| 78 break; |
| 79 case AnimationFillModeNone: |
| 80 timing.fillMode = Timing::FillModeNone; |
| 81 break; |
| 82 default: |
| 83 ASSERT_NOT_REACHED(); |
| 84 } |
| 85 } |
| 86 if (animationData->isDirectionSet()) { |
| 87 switch (animationData->direction()) { |
| 88 case CSSAnimationData::AnimationDirectionNormal: |
| 89 timing.direction = Timing::PlaybackDirectionNormal; |
| 90 break; |
| 91 case CSSAnimationData::AnimationDirectionAlternate: |
| 92 timing.direction = Timing::PlaybackDirectionAlternate; |
| 93 break; |
| 94 case CSSAnimationData::AnimationDirectionReverse: |
| 95 timing.direction = Timing::PlaybackDirectionReverse; |
| 96 break; |
| 97 case CSSAnimationData::AnimationDirectionAlternateReverse: |
| 98 timing.direction = Timing::PlaybackDirectionAlternateReverse; |
| 99 break; |
| 100 default: |
| 101 ASSERT_NOT_REACHED(); |
| 102 } |
| 103 } |
| 104 } |
| 105 |
| 106 void CSSAnimations::update(Element* element, EDisplay display, StyleResolver* re
solver, const CSSAnimationDataList* animationDataList) |
| 107 { |
| 108 if (isEmpty() && !(animationDataList && animationDataList->size())) |
| 109 return; |
| 110 |
| 111 HashSet<StringImpl*> inactive; |
| 112 for (AnimationMap::iterator iter = m_animations.begin(); iter != m_animation
s.end(); ++iter) |
| 113 inactive.add(iter->key); |
| 114 |
| 115 if (display != NONE) { |
| 116 for (int i = 0; animationDataList && i < animationDataList->size(); ++i)
{ |
| 117 const CSSAnimationData* animationData = animationDataList->animation
(i); |
| 118 ASSERT(animationData->isValidAnimation()); |
| 119 AtomicString animationName(animationData->name()); |
| 120 |
| 121 AnimationMap::iterator existing(m_animations.find(animationName.impl
())); |
| 122 if (existing != m_animations.end()) { |
| 123 bool paused = animationData->playState() == AnimPlayStatePaused; |
| 124 existing->value->setPaused(paused); |
| 125 inactive.remove(animationName.impl()); |
| 126 continue; |
| 127 } |
| 128 |
| 129 KeyframeAnimationEffect::KeyframeVector keyframes; |
| 130 resolver->keyframeStylesForAnimation(element, animationName.impl(),
keyframes); |
| 131 Timing timing; |
| 132 timingFromAnimationData(animationData, timing); |
| 133 m_animations.set(animationName.impl(), element->document()->timeline
()->play( |
| 134 Animation::create(element, KeyframeAnimationEffect::create(keyfr
ames), timing).get()).get()); |
| 135 } |
| 136 } |
| 137 |
| 138 for (HashSet<StringImpl*>::iterator iter = inactive.begin(); iter != inactiv
e.end(); ++iter) |
| 139 m_animations.take(*iter)->cancel(); |
| 140 } |
| 141 |
| 142 void CSSAnimations::cancel() |
| 143 { |
| 144 for (AnimationMap::iterator iter = m_animations.begin(); iter != m_animation
s.end(); ++iter) |
| 145 iter->value->cancel(); |
| 146 |
| 147 m_animations.clear(); |
| 148 } |
| 149 |
| 150 } // namespace WebCore |
OLD | NEW |