diff options
Diffstat (limited to 'Source/WebCore/platform/animation')
| -rw-r--r-- | Source/WebCore/platform/animation/Animation.cpp | 133 | ||||
| -rw-r--r-- | Source/WebCore/platform/animation/Animation.h | 165 | ||||
| -rw-r--r-- | Source/WebCore/platform/animation/AnimationList.cpp | 64 | ||||
| -rw-r--r-- | Source/WebCore/platform/animation/AnimationList.h | 65 | ||||
| -rw-r--r-- | Source/WebCore/platform/animation/TimingFunction.h | 151 |
5 files changed, 578 insertions, 0 deletions
diff --git a/Source/WebCore/platform/animation/Animation.cpp b/Source/WebCore/platform/animation/Animation.cpp new file mode 100644 index 0000000..112ee36 --- /dev/null +++ b/Source/WebCore/platform/animation/Animation.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org) + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" +#include "Animation.h" + +namespace WebCore { + +Animation::Animation() + : m_name(initialAnimationName()) + , m_property(initialAnimationProperty()) + , m_iterationCount(initialAnimationIterationCount()) + , m_delay(initialAnimationDelay()) + , m_duration(initialAnimationDuration()) + , m_timingFunction(initialAnimationTimingFunction()) + , m_direction(initialAnimationDirection()) + , m_fillMode(initialAnimationFillMode()) + , m_playState(initialAnimationPlayState()) + , m_delaySet(false) + , m_directionSet(false) + , m_durationSet(false) + , m_fillModeSet(false) + , m_iterationCountSet(false) + , m_nameSet(false) + , m_playStateSet(false) + , m_propertySet(false) + , m_timingFunctionSet(false) + , m_isNone(false) +{ +} + +Animation::Animation(const Animation& o) + : RefCounted<Animation>() + , m_name(o.m_name) + , m_property(o.m_property) + , m_iterationCount(o.m_iterationCount) + , m_delay(o.m_delay) + , m_duration(o.m_duration) + , m_timingFunction(o.m_timingFunction) + , m_direction(o.m_direction) + , m_fillMode(o.m_fillMode) + , m_playState(o.m_playState) + , m_delaySet(o.m_delaySet) + , m_directionSet(o.m_directionSet) + , m_durationSet(o.m_durationSet) + , m_fillModeSet(o.m_fillModeSet) + , m_iterationCountSet(o.m_iterationCountSet) + , m_nameSet(o.m_nameSet) + , m_playStateSet(o.m_playStateSet) + , m_propertySet(o.m_propertySet) + , m_timingFunctionSet(o.m_timingFunctionSet) + , m_isNone(o.m_isNone) +{ +} + +Animation& Animation::operator=(const Animation& o) +{ + m_name = o.m_name; + m_property = o.m_property; + m_iterationCount = o.m_iterationCount; + m_delay = o.m_delay; + m_duration = o.m_duration; + m_timingFunction = o.m_timingFunction; + m_direction = o.m_direction; + m_fillMode = o.m_fillMode; + m_playState = o.m_playState; + + m_delaySet = o.m_delaySet; + m_directionSet = o.m_directionSet; + m_durationSet = o.m_durationSet; + m_fillModeSet = o.m_fillModeSet; + m_iterationCountSet = o.m_iterationCountSet; + m_nameSet = o.m_nameSet; + m_playStateSet = o.m_playStateSet; + m_propertySet = o.m_propertySet; + m_timingFunctionSet = o.m_timingFunctionSet; + m_isNone = o.m_isNone; + + return *this; +} + +Animation::~Animation() +{ +} + +bool Animation::animationsMatch(const Animation* o, bool matchPlayStates) const +{ + if (!o) + return false; + + bool result = m_name == o->m_name + && m_property == o->m_property + && m_iterationCount == o->m_iterationCount + && m_delay == o->m_delay + && m_duration == o->m_duration + && *(m_timingFunction.get()) == *(o->m_timingFunction.get()) + && m_direction == o->m_direction + && m_fillMode == o->m_fillMode + && m_delaySet == o->m_delaySet + && m_directionSet == o->m_directionSet + && m_durationSet == o->m_durationSet + && m_fillModeSet == o->m_fillModeSet + && m_iterationCountSet == o->m_iterationCountSet + && m_nameSet == o->m_nameSet + && m_propertySet == o->m_propertySet + && m_timingFunctionSet == o->m_timingFunctionSet + && m_isNone == o->m_isNone; + + if (!result) + return false; + + return !matchPlayStates || (m_playState == o->m_playState && m_playStateSet == o->m_playStateSet); +} + +} // namespace WebCore diff --git a/Source/WebCore/platform/animation/Animation.h b/Source/WebCore/platform/animation/Animation.h new file mode 100644 index 0000000..d16f74c --- /dev/null +++ b/Source/WebCore/platform/animation/Animation.h @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2000 Lars Knoll (knoll@kde.org) + * (C) 2000 Antti Koivisto (koivisto@kde.org) + * (C) 2000 Dirk Mueller (mueller@kde.org) + * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef Animation_h +#define Animation_h + +#include "PlatformString.h" +#include "RenderStyleConstants.h" +#include "TimingFunction.h" +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> + +namespace WebCore { + +const int cAnimateNone = 0; +const int cAnimateAll = -2; + +class Animation : public RefCounted<Animation> { +public: + ~Animation(); + + static PassRefPtr<Animation> create() { return adoptRef(new Animation); } + static PassRefPtr<Animation> create(const Animation* o) { return adoptRef(new Animation(*o)); } + + bool isDelaySet() const { return m_delaySet; } + bool isDirectionSet() const { return m_directionSet; } + bool isDurationSet() const { return m_durationSet; } + bool isFillModeSet() const { return m_fillModeSet; } + bool isIterationCountSet() const { return m_iterationCountSet; } + bool isNameSet() const { return m_nameSet; } + bool isPlayStateSet() const { return m_playStateSet; } + bool isPropertySet() const { return m_propertySet; } + bool isTimingFunctionSet() const { return m_timingFunctionSet; } + + // Flags this to be the special "none" animation (animation-name: none) + bool isNoneAnimation() const { return m_isNone; } + // We can make placeholder Animation objects to keep the comma-separated lists + // of properties in sync. isValidAnimation means this is not a placeholder. + bool isValidAnimation() const { return !m_isNone && !m_name.isEmpty(); } + + bool isEmpty() const + { + return (!m_directionSet && !m_durationSet && !m_fillModeSet + && !m_nameSet && !m_playStateSet && !m_iterationCountSet + && !m_delaySet && !m_timingFunctionSet && !m_propertySet); + } + + bool isEmptyOrZeroDuration() const + { + return isEmpty() || (m_duration == 0 && m_delay <= 0); + } + + void clearDelay() { m_delaySet = false; } + void clearDirection() { m_directionSet = false; } + void clearDuration() { m_durationSet = false; } + void clearFillMode() { m_fillModeSet = false; } + void clearIterationCount() { m_iterationCountSet = false; } + void clearName() { m_nameSet = false; } + void clearPlayState() { m_playStateSet = AnimPlayStatePlaying; } + void clearProperty() { m_propertySet = false; } + void clearTimingFunction() { m_timingFunctionSet = false; } + + double delay() const { return m_delay; } + + enum AnimationDirection { AnimationDirectionNormal, AnimationDirectionAlternate }; + AnimationDirection direction() const { return static_cast<AnimationDirection>(m_direction); } + + unsigned fillMode() const { return m_fillMode; } + + double duration() const { return m_duration; } + + enum { IterationCountInfinite = -1 }; + int iterationCount() const { return m_iterationCount; } + const String& name() const { return m_name; } + EAnimPlayState playState() const { return static_cast<EAnimPlayState>(m_playState); } + int property() const { return m_property; } + const PassRefPtr<TimingFunction> timingFunction() const { return m_timingFunction; } + + void setDelay(double c) { m_delay = c; m_delaySet = true; } + void setDirection(AnimationDirection d) { m_direction = d; m_directionSet = true; } + void setDuration(double d) { ASSERT(d >= 0); m_duration = d; m_durationSet = true; } + void setFillMode(unsigned f) { m_fillMode = f; m_fillModeSet = true; } + void setIterationCount(int c) { m_iterationCount = c; m_iterationCountSet = true; } + void setName(const String& n) { m_name = n; m_nameSet = true; } + void setPlayState(EAnimPlayState d) { m_playState = d; m_playStateSet = true; } + void setProperty(int t) { m_property = t; m_propertySet = true; } + void setTimingFunction(PassRefPtr<TimingFunction> f) { m_timingFunction = f; m_timingFunctionSet = true; } + + void setIsNoneAnimation(bool n) { m_isNone = n; } + + Animation& operator=(const Animation& o); + + // return true if all members of this class match (excluding m_next) + bool animationsMatch(const Animation*, bool matchPlayStates = true) const; + + // return true every Animation in the chain (defined by m_next) match + bool operator==(const Animation& o) const { return animationsMatch(&o); } + bool operator!=(const Animation& o) const { return !(*this == o); } + + bool fillsBackwards() const { return m_fillModeSet && (m_fillMode == AnimationFillModeBackwards || m_fillMode == AnimationFillModeBoth); } + bool fillsForwards() const { return m_fillModeSet && (m_fillMode == AnimationFillModeForwards || m_fillMode == AnimationFillModeBoth); } + +private: + Animation(); + Animation(const Animation& o); + + String m_name; + int m_property; + int m_iterationCount; + double m_delay; + double m_duration; + RefPtr<TimingFunction> m_timingFunction; + unsigned m_direction : 1; // AnimationDirection + unsigned m_fillMode : 2; + + unsigned m_playState : 2; + + bool m_delaySet : 1; + bool m_directionSet : 1; + bool m_durationSet : 1; + bool m_fillModeSet : 1; + bool m_iterationCountSet : 1; + bool m_nameSet : 1; + bool m_playStateSet : 1; + bool m_propertySet : 1; + bool m_timingFunctionSet : 1; + + bool m_isNone : 1; + +public: + static float initialAnimationDelay() { return 0; } + static AnimationDirection initialAnimationDirection() { return AnimationDirectionNormal; } + static double initialAnimationDuration() { return 0; } + static unsigned initialAnimationFillMode() { return AnimationFillModeNone; } + static int initialAnimationIterationCount() { return 1; } + static String initialAnimationName() { return String("none"); } + static EAnimPlayState initialAnimationPlayState() { return AnimPlayStatePlaying; } + static int initialAnimationProperty() { return cAnimateAll; } + static PassRefPtr<TimingFunction> initialAnimationTimingFunction() { return CubicBezierTimingFunction::create(); } +}; + +} // namespace WebCore + +#endif // Animation_h diff --git a/Source/WebCore/platform/animation/AnimationList.cpp b/Source/WebCore/platform/animation/AnimationList.cpp new file mode 100644 index 0000000..58a40aa --- /dev/null +++ b/Source/WebCore/platform/animation/AnimationList.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org) + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" +#include "AnimationList.h" + +namespace WebCore { + +#define FILL_UNSET_PROPERTY(test, propGet, propSet) \ +for (i = 0; i < size() && animation(i)->test(); ++i) { } \ +if (i < size() && i != 0) { \ + for (size_t j = 0; i < size(); ++i, ++j) \ + animation(i)->propSet(animation(j)->propGet()); \ +} + +AnimationList::AnimationList(const AnimationList& o) +{ + for (size_t i = 0; i < o.size(); ++i) + m_animations.append(Animation::create(o.animation(i))); +} + +void AnimationList::fillUnsetProperties() +{ + size_t i; + FILL_UNSET_PROPERTY(isDelaySet, delay, setDelay); + FILL_UNSET_PROPERTY(isDirectionSet, direction, setDirection); + FILL_UNSET_PROPERTY(isDurationSet, duration, setDuration); + FILL_UNSET_PROPERTY(isFillModeSet, fillMode, setFillMode); + FILL_UNSET_PROPERTY(isIterationCountSet, iterationCount, setIterationCount); + FILL_UNSET_PROPERTY(isPlayStateSet, playState, setPlayState); + FILL_UNSET_PROPERTY(isNameSet, name, setName); + FILL_UNSET_PROPERTY(isTimingFunctionSet, timingFunction, setTimingFunction); + FILL_UNSET_PROPERTY(isPropertySet, property, setProperty); +} + +bool AnimationList::operator==(const AnimationList& o) const +{ + if (size() != o.size()) + return false; + for (size_t i = 0; i < size(); ++i) + if (*animation(i) != *o.animation(i)) + return false; + return true; +} + +} // namespace WebCore diff --git a/Source/WebCore/platform/animation/AnimationList.h b/Source/WebCore/platform/animation/AnimationList.h new file mode 100644 index 0000000..9a334ca --- /dev/null +++ b/Source/WebCore/platform/animation/AnimationList.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2000 Lars Knoll (knoll@kde.org) + * (C) 2000 Antti Koivisto (koivisto@kde.org) + * (C) 2000 Dirk Mueller (mueller@kde.org) + * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef AnimationList_h +#define AnimationList_h + +#include "Animation.h" +#include <wtf/RefPtr.h> +#include <wtf/Vector.h> + +namespace WebCore { + +class AnimationList : public FastAllocBase { +public: + AnimationList() { } + AnimationList(const AnimationList&); + + void fillUnsetProperties(); + bool operator==(const AnimationList& o) const; + bool operator!=(const AnimationList& o) const + { + return !(*this == o); + } + + size_t size() const { return m_animations.size(); } + bool isEmpty() const { return m_animations.isEmpty(); } + + void resize(size_t n) { m_animations.resize(n); } + void remove(size_t i) { m_animations.remove(i); } + void append(PassRefPtr<Animation> anim) { m_animations.append(anim); } + + Animation* animation(size_t i) { return m_animations[i].get(); } + const Animation* animation(size_t i) const { return m_animations[i].get(); } + +private: + AnimationList& operator=(const AnimationList&); + + Vector<RefPtr<Animation> > m_animations; +}; + + +} // namespace WebCore + +#endif // AnimationList_h diff --git a/Source/WebCore/platform/animation/TimingFunction.h b/Source/WebCore/platform/animation/TimingFunction.h new file mode 100644 index 0000000..8ef2d8f --- /dev/null +++ b/Source/WebCore/platform/animation/TimingFunction.h @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2000 Lars Knoll (knoll@kde.org) + * (C) 2000 Antti Koivisto (koivisto@kde.org) + * (C) 2000 Dirk Mueller (mueller@kde.org) + * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef TimingFunction_h +#define TimingFunction_h + +#include <wtf/RefCounted.h> + +namespace WebCore { + +class TimingFunction : public RefCounted<TimingFunction> { +public: + + enum TimingFunctionType { + LinearFunction, CubicBezierFunction, StepsFunction + }; + + virtual ~TimingFunction() { } + + bool isLinearTimingFunction() const { return m_type == LinearFunction; } + bool isCubicBezierTimingFunction() const { return m_type == CubicBezierFunction; } + bool isStepsTimingFunction() const { return m_type == StepsFunction; } + + virtual bool operator==(const TimingFunction& other) = 0; + +protected: + TimingFunction(TimingFunctionType type) + : m_type(type) + { + } + + TimingFunctionType m_type; +}; + +class LinearTimingFunction : public TimingFunction { +public: + static PassRefPtr<LinearTimingFunction> create() + { + return adoptRef(new LinearTimingFunction); + } + + ~LinearTimingFunction() { } + + virtual bool operator==(const TimingFunction& other) + { + return other.isLinearTimingFunction(); + } + +private: + LinearTimingFunction() + : TimingFunction(LinearFunction) + { + } +}; + +class CubicBezierTimingFunction : public TimingFunction { +public: + static PassRefPtr<CubicBezierTimingFunction> create(double x1 = 0.25, double y1 = 0.1, double x2 = 0.25, double y2 = 1.0) + { + return adoptRef(new CubicBezierTimingFunction(x1, y1, x2, y2)); + } + + ~CubicBezierTimingFunction() { } + + virtual bool operator==(const TimingFunction& other) + { + if (other.isCubicBezierTimingFunction()) { + const CubicBezierTimingFunction* ctf = static_cast<const CubicBezierTimingFunction*>(&other); + return m_x1 == ctf->m_x1 && m_y1 == ctf->m_y1 && m_x2 == ctf->m_x2 && m_y2 == ctf->m_y2; + } + return false; + } + + double x1() const { return m_x1; } + double y1() const { return m_y1; } + double x2() const { return m_x2; } + double y2() const { return m_y2; } + +private: + CubicBezierTimingFunction(double x1, double y1, double x2, double y2) + : TimingFunction(CubicBezierFunction) + , m_x1(x1) + , m_y1(y1) + , m_x2(x2) + , m_y2(y2) + { + } + + double m_x1; + double m_y1; + double m_x2; + double m_y2; +}; + +class StepsTimingFunction : public TimingFunction { +public: + static PassRefPtr<StepsTimingFunction> create(int steps, bool stepAtStart) + { + return adoptRef(new StepsTimingFunction(steps, stepAtStart)); + } + + ~StepsTimingFunction() { } + + virtual bool operator==(const TimingFunction& other) + { + if (other.isStepsTimingFunction()) { + const StepsTimingFunction* stf = static_cast<const StepsTimingFunction*>(&other); + return m_steps == stf->m_steps && m_stepAtStart == stf->m_stepAtStart; + } + return false; + } + + int numberOfSteps() const { return m_steps; } + bool stepAtStart() const { return m_stepAtStart; } + +private: + StepsTimingFunction(int steps, bool stepAtStart) + : TimingFunction(StepsFunction) + , m_steps(steps) + , m_stepAtStart(stepAtStart) + { + } + + int m_steps; + bool m_stepAtStart; +}; + +} // namespace WebCore + +#endif // TimingFunction_h |
