summaryrefslogtreecommitdiffstats
path: root/WebCore/svg/SVGAnimationElement.h
blob: 23d1e88be3a8ec369d35cfdebdd18f20b3ffe5cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
    Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
                  2004, 2005, 2006 Rob Buis <buis@kde.org>
    Copyright (C) 2007 Eric Seidel <eric@webkit.org>

    This file is part of the KDE project

    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 SVGAnimationElement_h
#define SVGAnimationElement_h
#if ENABLE(SVG)

#include "SVGExternalResourcesRequired.h"
#include "SVGStringList.h"
#include "SVGTests.h"

namespace WebCore {

    enum EFillMode {
        FILL_REMOVE = 0,
        FILL_FREEZE
    };

    enum EAdditiveMode {
        ADDITIVE_REPLACE = 0,
        ADDITIVE_SUM
    };

    enum EAccumulateMode {
        ACCUMULATE_NONE = 0,
        ACCUMULATE_SUM
    };

    enum ECalcMode {
        CALCMODE_DISCRETE = 0,
        CALCMODE_LINEAR,
        CALCMODE_PACED,
        CALCMODE_SPLINE
    };

    enum ERestart {
        RESTART_ALWAYS = 0,
        RESTART_WHENNOTACTIVE,
        RESTART_NEVER
    };

    enum EAttributeType {
        ATTRIBUTETYPE_CSS = 0,
        ATTRIBUTETYPE_XML,
        ATTRIBUTETYPE_AUTO
    };

    // internal
    enum EAnimationMode {
        NO_ANIMATION = 0,
        TO_ANIMATION,
        BY_ANIMATION,
        VALUES_ANIMATION,
        FROM_TO_ANIMATION,
        FROM_BY_ANIMATION
    };

    class SVGAnimationElement : public SVGElement,
                                public SVGTests,
                                public SVGExternalResourcesRequired
    {
    public:
        SVGAnimationElement(const QualifiedName&, Document*);
        virtual ~SVGAnimationElement();

        // 'SVGAnimationElement' functions
        SVGElement* targetElement() const;
        
        virtual bool hasValidTarget() const;
        bool isValidAnimation() const;
        
        virtual bool isValid() const { return SVGTests::isValid(); }

        float getEndTime() const;
        float getStartTime() const;
        float getCurrentTime() const;
        float getSimpleDuration(ExceptionCode&) const;
    
        virtual void parseMappedAttribute(MappedAttribute* attr);

        virtual void finishParsingChildren();

        virtual bool updateAnimationBaseValueFromElement();
        bool updateAnimatedValueForElapsedSeconds(double elapsedSeconds);
        virtual void applyAnimatedValueToElement();

        String attributeName() const;

        bool connectedToTimer() const;

        bool isFrozen() const;
        bool isAdditive() const;
        bool isAccumulated() const;

        double repeations() const;
        static bool isIndefinite(double value);

    protected:
        mutable SVGElement* m_targetElement;
        
        EAnimationMode detectAnimationMode() const;
        
        static double parseClockValue(const String&);
        static void setTargetAttribute(SVGElement* target, const String& name, const String& value, EAttributeType = ATTRIBUTETYPE_AUTO);
        
        String targetAttributeAnimatedValue() const;
        void setTargetAttributeAnimatedValue(const String&);
        
        void connectTimer();
        void disconnectTimer();

        virtual float calculateTotalDistance();
        virtual void valueIndexAndPercentagePastForDistance(float distancePercentage, unsigned& valueIndex, float& percentagePast);
        
        void calculateValueIndexAndPercentagePast(float timePercentage, unsigned& valueIndex, float& percentagePast);
        
        void handleTimerEvent(double elapsedSeconds, double timePercentage);
        
        virtual bool updateAnimatedValue(EAnimationMode, float timePercentage, unsigned valueIndex, float percentagePast) = 0;
        virtual bool calculateFromAndToValues(EAnimationMode, unsigned valueIndex) = 0;
        
        static void parseKeyNumbers(Vector<float>& keyNumbers, const String& value);
        static void parseBeginOrEndValue(double& number, const String& value);

        ANIMATED_PROPERTY_FORWARD_DECLARATIONS(SVGExternalResourcesRequired, bool, ExternalResourcesRequired, externalResourcesRequired)

        bool m_connectedToTimer : 1;
        
        double m_currentTime;
        double m_simpleDuration;

        // Shared animation properties
        unsigned m_fill : 1; // EFillMode m_fill
        unsigned m_restart : 2; // ERestart
        unsigned m_calcMode : 2; // ECalcMode
        unsigned m_additive : 1; // EAdditiveMode
        unsigned m_accumulate : 1; // EAccumulateMode
        unsigned m_attributeType : 2; // EAttributeType
        
        String m_to;
        String m_by;
        String m_from;
        String m_href;
        String m_repeatDur;
        String m_attributeName;
        
        String m_baseValue;
        String m_animatedValue;

        double m_max;
        double m_min;
        double m_end;
        double m_begin;

        double m_repetitions;
        double m_repeatCount;

        Vector<String> m_values;
        Vector<float> m_keyTimes;
        
        struct KeySpline {
            FloatPoint control1;
            FloatPoint control2;
        };
        Vector<KeySpline> m_keySplines;
    };

} // namespace WebCore

#endif // ENABLE(SVG)
#endif // SVGAnimationElement_h

// vim:ts=4:noet