| Index: Source/core/animation/css/CSSAnimations.cpp
|
| diff --git a/Source/core/animation/css/CSSAnimations.cpp b/Source/core/animation/css/CSSAnimations.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..188fc26ab62ac4f35d89260d3bcce1692ee0c854
|
| --- /dev/null
|
| +++ b/Source/core/animation/css/CSSAnimations.cpp
|
| @@ -0,0 +1,150 @@
|
| +
|
| +/*
|
| + * Copyright (C) 2013 Google Inc. All rights reserved.
|
| + *
|
| + * Redistribution and use in source and binary forms, with or without
|
| + * modification, are permitted provided that the following conditions are
|
| + * met:
|
| + *
|
| + * * Redistributions of source code must retain the above copyright
|
| + * notice, this list of conditions and the following disclaimer.
|
| + * * Redistributions in binary form must reproduce the above
|
| + * copyright notice, this list of conditions and the following disclaimer
|
| + * in the documentation and/or other materials provided with the
|
| + * distribution.
|
| + * * Neither the name of Google Inc. nor the names of its
|
| + * contributors may be used to endorse or promote products derived from
|
| + * this software without specific prior written permission.
|
| + *
|
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| + */
|
| +
|
| +#include "config.h"
|
| +#include "core/animation/css/CSSAnimations.h"
|
| +
|
| +#include "core/animation/DocumentTimeline.h"
|
| +#include "core/animation/KeyframeAnimationEffect.h"
|
| +#include "core/css/resolver/StyleResolver.h"
|
| +#include "core/dom/AnimationEvent.h"
|
| +#include "core/dom/Element.h"
|
| +#include "core/dom/EventNames.h"
|
| +#include "core/platform/animation/CSSAnimationDataList.h"
|
| +#include "core/platform/animation/TimingFunction.h"
|
| +#include "wtf/HashSet.h"
|
| +
|
| +namespace WebCore {
|
| +
|
| +void timingFromAnimationData(const CSSAnimationData* animationData, Timing& timing)
|
| +{
|
| + if (animationData->isDelaySet())
|
| + timing.startDelay = animationData->delay();
|
| + if (animationData->isDurationSet()) {
|
| + timing.iterationDuration = animationData->duration();
|
| + timing.hasIterationDuration = true;
|
| + }
|
| + if (animationData->isIterationCountSet()) {
|
| + if (animationData->iterationCount() == CSSAnimationData::IterationCountInfinite)
|
| + timing.iterationCount = std::numeric_limits<double>::infinity();
|
| + else
|
| + timing.iterationCount = animationData->iterationCount();
|
| + }
|
| + if (animationData->isTimingFunctionSet()) {
|
| + if (!animationData->timingFunction()->isLinearTimingFunction())
|
| + timing.timingFunction = animationData->timingFunction();
|
| + } else {
|
| + // CSS default is ease, default in model is linear.
|
| + timing.timingFunction = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Ease);
|
| + }
|
| + if (animationData->isFillModeSet()) {
|
| + switch (animationData->fillMode()) {
|
| + case AnimationFillModeForwards:
|
| + timing.fillMode = Timing::FillModeForwards;
|
| + break;
|
| + case AnimationFillModeBackwards:
|
| + timing.fillMode = Timing::FillModeBackwards;
|
| + break;
|
| + case AnimationFillModeBoth:
|
| + timing.fillMode = Timing::FillModeBoth;
|
| + break;
|
| + case AnimationFillModeNone:
|
| + timing.fillMode = Timing::FillModeNone;
|
| + break;
|
| + default:
|
| + ASSERT_NOT_REACHED();
|
| + }
|
| + }
|
| + if (animationData->isDirectionSet()) {
|
| + switch (animationData->direction()) {
|
| + case CSSAnimationData::AnimationDirectionNormal:
|
| + timing.direction = Timing::PlaybackDirectionNormal;
|
| + break;
|
| + case CSSAnimationData::AnimationDirectionAlternate:
|
| + timing.direction = Timing::PlaybackDirectionAlternate;
|
| + break;
|
| + case CSSAnimationData::AnimationDirectionReverse:
|
| + timing.direction = Timing::PlaybackDirectionReverse;
|
| + break;
|
| + case CSSAnimationData::AnimationDirectionAlternateReverse:
|
| + timing.direction = Timing::PlaybackDirectionAlternateReverse;
|
| + break;
|
| + default:
|
| + ASSERT_NOT_REACHED();
|
| + }
|
| + }
|
| +}
|
| +
|
| +void CSSAnimations::update(Element* element, EDisplay display, StyleResolver* resolver, const CSSAnimationDataList* animationDataList)
|
| +{
|
| + if (isEmpty() && !(animationDataList && animationDataList->size()))
|
| + return;
|
| +
|
| + HashSet<StringImpl*> inactive;
|
| + for (AnimationMap::iterator iter = m_animations.begin(); iter != m_animations.end(); ++iter)
|
| + inactive.add(iter->key);
|
| +
|
| + if (display != NONE) {
|
| + for (int i = 0; animationDataList && i < animationDataList->size(); ++i) {
|
| + const CSSAnimationData* animationData = animationDataList->animation(i);
|
| + ASSERT(animationData->isValidAnimation());
|
| + AtomicString animationName(animationData->name());
|
| +
|
| + AnimationMap::iterator existing(m_animations.find(animationName.impl()));
|
| + if (existing != m_animations.end()) {
|
| + bool paused = animationData->playState() == AnimPlayStatePaused;
|
| + existing->value->setPaused(paused);
|
| + inactive.remove(animationName.impl());
|
| + continue;
|
| + }
|
| +
|
| + KeyframeAnimationEffect::KeyframeVector keyframes;
|
| + resolver->keyframeStylesForAnimation(element, animationName.impl(), keyframes);
|
| + Timing timing;
|
| + timingFromAnimationData(animationData, timing);
|
| + m_animations.set(animationName.impl(), element->document()->timeline()->play(
|
| + Animation::create(element, KeyframeAnimationEffect::create(keyframes), timing).get()).get());
|
| + }
|
| + }
|
| +
|
| + for (HashSet<StringImpl*>::iterator iter = inactive.begin(); iter != inactive.end(); ++iter)
|
| + m_animations.take(*iter)->cancel();
|
| +}
|
| +
|
| +void CSSAnimations::cancel()
|
| +{
|
| + for (AnimationMap::iterator iter = m_animations.begin(); iter != m_animations.end(); ++iter)
|
| + iter->value->cancel();
|
| +
|
| + m_animations.clear();
|
| +}
|
| +
|
| +} // namespace WebCore
|
|
|