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 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#include "Color.h"
30#include "FilterOperation.h"
31#include "FloatPoint3D.h"
32#include "TransformationMatrix.h"
33#include <wtf/RefCounted.h>
34#include <wtf/Vector.h>
35
36namespace WebCore {
37
38class FloatRect;
39class TimingFunction;
40
41class PlatformCAAnimation : public RefCounted<PlatformCAAnimation> {
42public:
43    enum AnimationType { Basic, Keyframe };
44    enum FillModeType { NoFillMode, Forwards, Backwards, Both };
45    enum ValueFunctionType { NoValueFunction, RotateX, RotateY, RotateZ, ScaleX, ScaleY, ScaleZ, Scale, TranslateX, TranslateY, TranslateZ, Translate };
46
47    virtual ~PlatformCAAnimation() { }
48
49    virtual bool isPlatformCAAnimationMac() const { return false; }
50    virtual bool isPlatformCAAnimationWin() const { return false; }
51    virtual bool isPlatformCAAnimationRemote() const { return false; }
52
53    virtual PassRefPtr<PlatformCAAnimation> copy() const = 0;
54
55    AnimationType animationType() const { return m_type; }
56    virtual String keyPath() const = 0;
57
58    virtual CFTimeInterval beginTime() const = 0;
59    virtual void setBeginTime(CFTimeInterval) = 0;
60
61    virtual CFTimeInterval duration() const = 0;
62    virtual void setDuration(CFTimeInterval) = 0;
63
64    virtual float speed() const = 0;
65    virtual void setSpeed(float) = 0;
66
67    virtual CFTimeInterval timeOffset() const = 0;
68    virtual void setTimeOffset(CFTimeInterval) = 0;
69
70    virtual float repeatCount() const = 0;
71    virtual void setRepeatCount(float) = 0;
72
73    virtual bool autoreverses() const = 0;
74    virtual void setAutoreverses(bool) = 0;
75
76    virtual FillModeType fillMode() const = 0;
77    virtual void setFillMode(FillModeType) = 0;
78
79    virtual void setTimingFunction(const TimingFunction*, bool reverse = false) = 0;
80    virtual void copyTimingFunctionFrom(const PlatformCAAnimation*) = 0;
81
82    virtual bool isRemovedOnCompletion() const = 0;
83    virtual void setRemovedOnCompletion(bool) = 0;
84
85    virtual bool isAdditive() const = 0;
86    virtual void setAdditive(bool) = 0;
87
88    virtual ValueFunctionType valueFunction() const = 0;
89    virtual void setValueFunction(ValueFunctionType) = 0;
90
91    // Basic-animation properties.
92    virtual void setFromValue(float) = 0;
93    virtual void setFromValue(const WebCore::TransformationMatrix&) = 0;
94    virtual void setFromValue(const FloatPoint3D&) = 0;
95    virtual void setFromValue(const WebCore::Color&) = 0;
96#if ENABLE(CSS_FILTERS)
97    virtual void setFromValue(const FilterOperation*, int internalFilterPropertyIndex) = 0;
98#endif
99    virtual void copyFromValueFrom(const PlatformCAAnimation*) = 0;
100
101    virtual void setToValue(float) = 0;
102    virtual void setToValue(const WebCore::TransformationMatrix&) = 0;
103    virtual void setToValue(const FloatPoint3D&) = 0;
104    virtual void setToValue(const WebCore::Color&) = 0;
105#if ENABLE(CSS_FILTERS)
106    virtual void setToValue(const FilterOperation*, int internalFilterPropertyIndex) = 0;
107#endif
108    virtual void copyToValueFrom(const PlatformCAAnimation*) = 0;
109
110    // Keyframe-animation properties.
111    virtual void setValues(const Vector<float>&) = 0;
112    virtual void setValues(const Vector<WebCore::TransformationMatrix>&) = 0;
113    virtual void setValues(const Vector<FloatPoint3D>&) = 0;
114    virtual void setValues(const Vector<WebCore::Color>&) = 0;
115#if ENABLE(CSS_FILTERS)
116    virtual void setValues(const Vector<RefPtr<FilterOperation>>&, int internalFilterPropertyIndex) = 0;
117#endif
118    virtual void copyValuesFrom(const PlatformCAAnimation*) = 0;
119
120    virtual void setKeyTimes(const Vector<float>&) = 0;
121    virtual void copyKeyTimesFrom(const PlatformCAAnimation*) = 0;
122
123    virtual void setTimingFunctions(const Vector<const TimingFunction*>&, bool reverse = false) = 0;
124    virtual void copyTimingFunctionsFrom(const PlatformCAAnimation*) = 0;
125
126    void setActualStartTimeIfNeeded(CFTimeInterval t)
127    {
128        if (beginTime() <= 0)
129            setBeginTime(t);
130    }
131
132protected:
133    PlatformCAAnimation(AnimationType type = Basic)
134        : m_type(type)
135    {
136    }
137
138    void setType(AnimationType type) { m_type = type; }
139
140private:
141    AnimationType m_type;
142};
143
144#define PLATFORM_CAANIMATION_TYPE_CASTS(ToValueTypeName, predicate) \
145    TYPE_CASTS_BASE(ToValueTypeName, WebCore::PlatformCAAnimation, object, object->predicate, object.predicate)
146
147}
148
149#endif // PlatformCAAnimation_h
150