Home | History | Annotate | Download | only in animation
      1 /*
      2  * Copyright (C) 2000 Lars Knoll (knoll (at) kde.org)
      3  *           (C) 2000 Antti Koivisto (koivisto (at) kde.org)
      4  *           (C) 2000 Dirk Mueller (mueller (at) kde.org)
      5  * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
      6  * Copyright (C) 2006 Graham Dennis (graham.dennis (at) gmail.com)
      7  *
      8  * This library is free software; you can redistribute it and/or
      9  * modify it under the terms of the GNU Library General Public
     10  * License as published by the Free Software Foundation; either
     11  * version 2 of the License, or (at your option) any later version.
     12  *
     13  * This library is distributed in the hope that it will be useful,
     14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16  * Library General Public License for more details.
     17  *
     18  * You should have received a copy of the GNU Library General Public License
     19  * along with this library; see the file COPYING.LIB.  If not, write to
     20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     21  * Boston, MA 02110-1301, USA.
     22  *
     23  */
     24 
     25 #ifndef Animation_h
     26 #define Animation_h
     27 
     28 #include "PlatformString.h"
     29 #include "TimingFunction.h"
     30 #include <wtf/PassRefPtr.h>
     31 #include <wtf/RefCounted.h>
     32 
     33 namespace WebCore {
     34 
     35 const int cAnimateNone = 0;
     36 const int cAnimateAll = -2;
     37 
     38 class Animation : public RefCounted<Animation> {
     39 public:
     40     ~Animation();
     41 
     42     static PassRefPtr<Animation> create() { return adoptRef(new Animation); };
     43 
     44     bool isDelaySet() const { return m_delaySet; }
     45     bool isDirectionSet() const { return m_directionSet; }
     46     bool isDurationSet() const { return m_durationSet; }
     47     bool isIterationCountSet() const { return m_iterationCountSet; }
     48     bool isNameSet() const { return m_nameSet; }
     49     bool isPlayStateSet() const { return m_playStateSet; }
     50     bool isPropertySet() const { return m_propertySet; }
     51     bool isTimingFunctionSet() const { return m_timingFunctionSet; }
     52 
     53     // Flags this to be the special "none" animation (animation-name: none)
     54     bool isNoneAnimation() const { return m_isNone; }
     55     // We can make placeholder Animation objects to keep the comma-separated lists
     56     // of properties in sync. isValidAnimation means this is not a placeholder.
     57     bool isValidAnimation() const { return !m_isNone && !m_name.isEmpty(); }
     58 
     59     bool isEmpty() const
     60     {
     61         return (!m_directionSet && !m_durationSet && !m_nameSet && !m_playStateSet &&
     62                !m_iterationCountSet && !m_delaySet && !m_timingFunctionSet && !m_propertySet);
     63     }
     64 
     65     bool isEmptyOrZeroDuration() const
     66     {
     67         return isEmpty() || (m_duration == 0 && m_delay <= 0);
     68     }
     69 
     70     void clearDelay() { m_delaySet = false; }
     71     void clearDirection() { m_directionSet = false; }
     72     void clearDuration() { m_durationSet = false; }
     73     void clearIterationCount() { m_iterationCountSet = false; }
     74     void clearName() { m_nameSet = false; }
     75     void clearPlayState() { m_playStateSet = AnimPlayStatePlaying; }
     76     void clearProperty() { m_propertySet = false; }
     77     void clearTimingFunction() { m_timingFunctionSet = false; }
     78 
     79     double delay() const { return m_delay; }
     80 
     81     enum AnimationDirection { AnimationDirectionNormal, AnimationDirectionAlternate };
     82     AnimationDirection direction() const { return m_direction; }
     83 
     84     double duration() const { return m_duration; }
     85 
     86     enum { IterationCountInfinite = -1 };
     87     int iterationCount() const { return m_iterationCount; }
     88     const String& name() const { return m_name; }
     89     unsigned playState() const { return m_playState; }
     90     int property() const { return m_property; }
     91     const TimingFunction& timingFunction() const { return m_timingFunction; }
     92 
     93     void setDelay(double c) { m_delay = c; m_delaySet = true; }
     94     void setDirection(AnimationDirection d) { m_direction = d; m_directionSet = true; }
     95     void setDuration(double d) { ASSERT(d >= 0); m_duration = d; m_durationSet = true; }
     96     void setIterationCount(int c) { m_iterationCount = c; m_iterationCountSet = true; }
     97     void setName(const String& n) { m_name = n; m_nameSet = true; }
     98     void setPlayState(unsigned d) { m_playState = d; m_playStateSet = true; }
     99     void setProperty(int t) { m_property = t; m_propertySet = true; }
    100     void setTimingFunction(const TimingFunction& f) { m_timingFunction = f; m_timingFunctionSet = true; }
    101 
    102     void setIsNoneAnimation(bool n) { m_isNone = n; }
    103 
    104     Animation& operator=(const Animation& o);
    105 
    106     // return true if all members of this class match (excluding m_next)
    107     bool animationsMatch(const Animation*, bool matchPlayStates = true) const;
    108 
    109     // return true every Animation in the chain (defined by m_next) match
    110     bool operator==(const Animation& o) const { return animationsMatch(&o); }
    111     bool operator!=(const Animation& o) const { return !(*this == o); }
    112 
    113 private:
    114     Animation();
    115     Animation(const Animation& o);
    116 
    117     String m_name;
    118     int m_property;
    119     int m_iterationCount;
    120     double m_delay;
    121     double m_duration;
    122     TimingFunction m_timingFunction;
    123     AnimationDirection m_direction : 1;
    124 
    125     unsigned m_playState     : 2;
    126 
    127     bool m_delaySet          : 1;
    128     bool m_directionSet      : 1;
    129     bool m_durationSet       : 1;
    130     bool m_iterationCountSet : 1;
    131     bool m_nameSet           : 1;
    132     bool m_playStateSet      : 1;
    133     bool m_propertySet       : 1;
    134     bool m_timingFunctionSet : 1;
    135 
    136     bool m_isNone            : 1;
    137 
    138 public:
    139     static float initialAnimationDelay() { return 0; }
    140     static AnimationDirection initialAnimationDirection() { return AnimationDirectionNormal; }
    141     static double initialAnimationDuration() { return 0; }
    142     static int initialAnimationIterationCount() { return 1; }
    143     static String initialAnimationName() { return String("none"); }
    144     static unsigned initialAnimationPlayState() { return AnimPlayStatePlaying; }
    145     static int initialAnimationProperty() { return cAnimateAll; }
    146     static TimingFunction initialAnimationTimingFunction() { return TimingFunction(); }
    147 };
    148 
    149 } // namespace WebCore
    150 
    151 #endif // Animation_h
    152