Home | History | Annotate | Download | only in ca
      1 /*
      2  * Copyright (C) 2010 Apple Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #ifndef PlatformCAAnimation_h
     27 #define PlatformCAAnimation_h
     28 
     29 #if USE(ACCELERATED_COMPOSITING)
     30 
     31 #include "Color.h"
     32 #include "FloatPoint3D.h"
     33 #include "TransformationMatrix.h"
     34 #include <wtf/RefCounted.h>
     35 #include <wtf/RetainPtr.h>
     36 #include <wtf/Vector.h>
     37 
     38 #if PLATFORM(MAC)
     39 #ifdef __OBJC__
     40 @class CAPropertyAnimation;
     41 #else
     42 class CAPropertyAnimation;
     43 #endif
     44 typedef CAPropertyAnimation* PlatformAnimationRef;
     45 #elif PLATFORM(WIN)
     46 typedef struct _CACFAnimation* CACFAnimationRef;
     47 typedef CACFAnimationRef PlatformAnimationRef;
     48 #endif
     49 
     50 namespace WebCore {
     51 
     52 class FloatRect;
     53 class PlatformCAAnimation;
     54 class TimingFunction;
     55 
     56 class PlatformCAAnimation : public RefCounted<PlatformCAAnimation> {
     57 public:
     58     friend class PlatformCALayer;
     59 
     60     enum AnimationType { Basic, Keyframe };
     61     enum FillModeType { NoFillMode, Forwards, Backwards, Both };
     62     enum ValueFunctionType { NoValueFunction, RotateX, RotateY, RotateZ, ScaleX, ScaleY, ScaleZ, Scale, TranslateX, TranslateY, TranslateZ, Translate };
     63 
     64     static PassRefPtr<PlatformCAAnimation> create(AnimationType, const String& keyPath);
     65     static PassRefPtr<PlatformCAAnimation> create(PlatformAnimationRef);
     66 
     67     ~PlatformCAAnimation();
     68 
     69     static bool supportsValueFunction();
     70 
     71     PassRefPtr<PlatformCAAnimation> copy() const;
     72 
     73     PlatformAnimationRef platformAnimation() const;
     74 
     75     AnimationType animationType() const { return m_type; }
     76     String keyPath() const;
     77 
     78     CFTimeInterval beginTime() const;
     79     void setBeginTime(CFTimeInterval);
     80 
     81     CFTimeInterval duration() const;
     82     void setDuration(CFTimeInterval);
     83 
     84     float speed() const;
     85     void setSpeed(float);
     86 
     87     CFTimeInterval timeOffset() const;
     88     void setTimeOffset(CFTimeInterval);
     89 
     90     float repeatCount() const;
     91     void setRepeatCount(float);
     92 
     93     bool autoreverses() const;
     94     void setAutoreverses(bool);
     95 
     96     FillModeType fillMode() const;
     97     void setFillMode(FillModeType);
     98 
     99     void setTimingFunction(const TimingFunction*);
    100     void copyTimingFunctionFrom(const PlatformCAAnimation*);
    101 
    102     bool isRemovedOnCompletion() const;
    103     void setRemovedOnCompletion(bool);
    104 
    105     bool isAdditive() const;
    106     void setAdditive(bool);
    107 
    108     ValueFunctionType valueFunction() const;
    109     void setValueFunction(ValueFunctionType);
    110 
    111     // Basic-animation properties.
    112     void setFromValue(float);
    113     void setFromValue(const WebCore::TransformationMatrix&);
    114     void setFromValue(const FloatPoint3D&);
    115     void setFromValue(const WebCore::Color&);
    116     void copyFromValueFrom(const PlatformCAAnimation*);
    117 
    118     void setToValue(float);
    119     void setToValue(const WebCore::TransformationMatrix&);
    120     void setToValue(const FloatPoint3D&);
    121     void setToValue(const WebCore::Color&);
    122     void copyToValueFrom(const PlatformCAAnimation*);
    123 
    124     // Keyframe-animation properties.
    125     void setValues(const Vector<float>&);
    126     void setValues(const Vector<WebCore::TransformationMatrix>&);
    127     void setValues(const Vector<FloatPoint3D>&);
    128     void setValues(const Vector<WebCore::Color>&);
    129     void copyValuesFrom(const PlatformCAAnimation*);
    130 
    131     void setKeyTimes(const Vector<float>&);
    132     void copyKeyTimesFrom(const PlatformCAAnimation*);
    133 
    134     void setTimingFunctions(const Vector<const TimingFunction*>&);
    135     void copyTimingFunctionsFrom(const PlatformCAAnimation*);
    136 
    137 protected:
    138     PlatformCAAnimation(AnimationType, const String& keyPath);
    139     PlatformCAAnimation(PlatformAnimationRef);
    140 
    141 private:
    142     AnimationType m_type;
    143 
    144 #if PLATFORM(MAC)
    145     RetainPtr<CAPropertyAnimation> m_animation;
    146 #elif PLATFORM(WIN)
    147     RetainPtr<CACFAnimationRef> m_animation;
    148 #endif
    149 };
    150 
    151 }
    152 
    153 #endif // USE(ACCELERATED_COMPOSITING)
    154 
    155 #endif // PlatformCAAnimation_h
    156