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 "FilterOperation.h"
33#include "FloatPoint3D.h"
34#include "TransformationMatrix.h"
35#include <wtf/RefCounted.h>
36#include <wtf/RetainPtr.h>
37#include <wtf/Vector.h>
38
39#if PLATFORM(MAC)
40OBJC_CLASS CAPropertyAnimation;
41typedef CAPropertyAnimation* PlatformAnimationRef;
42#elif PLATFORM(WIN)
43typedef struct _CACFAnimation* CACFAnimationRef;
44typedef CACFAnimationRef PlatformAnimationRef;
45#endif
46
47namespace WebCore {
48
49class FloatRect;
50class PlatformCAAnimation;
51class TimingFunction;
52
53class PlatformCAAnimation : public RefCounted<PlatformCAAnimation> {
54public:
55    friend class PlatformCALayer;
56
57    enum AnimationType { Basic, Keyframe };
58    enum FillModeType { NoFillMode, Forwards, Backwards, Both };
59    enum ValueFunctionType { NoValueFunction, RotateX, RotateY, RotateZ, ScaleX, ScaleY, ScaleZ, Scale, TranslateX, TranslateY, TranslateZ, Translate };
60
61    static PassRefPtr<PlatformCAAnimation> create(AnimationType, const String& keyPath);
62    static PassRefPtr<PlatformCAAnimation> create(PlatformAnimationRef);
63
64    ~PlatformCAAnimation();
65
66    static bool supportsValueFunction();
67
68    PassRefPtr<PlatformCAAnimation> copy() const;
69
70    PlatformAnimationRef platformAnimation() const;
71
72    AnimationType animationType() const { return m_type; }
73    String keyPath() const;
74
75    CFTimeInterval beginTime() const;
76    void setBeginTime(CFTimeInterval);
77
78    CFTimeInterval duration() const;
79    void setDuration(CFTimeInterval);
80
81    float speed() const;
82    void setSpeed(float);
83
84    CFTimeInterval timeOffset() const;
85    void setTimeOffset(CFTimeInterval);
86
87    float repeatCount() const;
88    void setRepeatCount(float);
89
90    bool autoreverses() const;
91    void setAutoreverses(bool);
92
93    FillModeType fillMode() const;
94    void setFillMode(FillModeType);
95
96    void setTimingFunction(const TimingFunction*, bool reverse = false);
97    void copyTimingFunctionFrom(const PlatformCAAnimation*);
98
99    bool isRemovedOnCompletion() const;
100    void setRemovedOnCompletion(bool);
101
102    bool isAdditive() const;
103    void setAdditive(bool);
104
105    ValueFunctionType valueFunction() const;
106    void setValueFunction(ValueFunctionType);
107
108    // Basic-animation properties.
109    void setFromValue(float);
110    void setFromValue(const WebCore::TransformationMatrix&);
111    void setFromValue(const FloatPoint3D&);
112    void setFromValue(const WebCore::Color&);
113#if ENABLE(CSS_FILTERS)
114    void setFromValue(const FilterOperation*, int internalFilterPropertyIndex);
115#endif
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#if ENABLE(CSS_FILTERS)
123    void setToValue(const FilterOperation*, int internalFilterPropertyIndex);
124#endif
125    void copyToValueFrom(const PlatformCAAnimation*);
126
127    // Keyframe-animation properties.
128    void setValues(const Vector<float>&);
129    void setValues(const Vector<WebCore::TransformationMatrix>&);
130    void setValues(const Vector<FloatPoint3D>&);
131    void setValues(const Vector<WebCore::Color>&);
132#if ENABLE(CSS_FILTERS)
133    void setValues(const Vector<RefPtr<FilterOperation> >&, int internalFilterPropertyIndex);
134#endif
135    void copyValuesFrom(const PlatformCAAnimation*);
136
137    void setKeyTimes(const Vector<float>&);
138    void copyKeyTimesFrom(const PlatformCAAnimation*);
139
140    void setTimingFunctions(const Vector<const TimingFunction*>&, bool reverse = false);
141    void copyTimingFunctionsFrom(const PlatformCAAnimation*);
142
143protected:
144    PlatformCAAnimation(AnimationType, const String& keyPath);
145    PlatformCAAnimation(PlatformAnimationRef);
146
147    void setActualStartTimeIfNeeded(CFTimeInterval t)
148    {
149        if (beginTime() <= 0)
150            setBeginTime(t);
151    }
152
153private:
154    AnimationType m_type;
155
156#if PLATFORM(MAC)
157    RetainPtr<CAPropertyAnimation> m_animation;
158#elif PLATFORM(WIN)
159    RetainPtr<CACFAnimationRef> m_animation;
160#endif
161};
162
163}
164
165#endif // USE(ACCELERATED_COMPOSITING)
166
167#endif // PlatformCAAnimation_h
168