87af9d0540248c0f62cc19d24f2f239d2907e932
[vuplus_webkit] / Source / WebCore / svg / SVGAnimationElement.h
1 /*
2  * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
4  * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
5  * Copyright (C) 2008 Apple Inc. All rights reserved.
6  * Copyright (C) 2008 Cameron McCormack <cam@mcc.id.au>
7  * Copyright (C) Research In Motion Limited 2011. All rights reserved.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public License
20  * along with this library; see the file COPYING.LIB.  If not, write to
21  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  */
24
25 #ifndef SVGAnimationElement_h
26 #define SVGAnimationElement_h
27
28 #if ENABLE(SVG)
29 #include "ElementTimeControl.h"
30 #include "Path.h"
31 #include "SMILTime.h"
32 #include "SVGAnimatedBoolean.h"
33 #include "SVGExternalResourcesRequired.h"
34 #include "SVGSMILElement.h"
35 #include "SVGStringList.h"
36 #include "SVGTests.h"
37 #include "UnitBezier.h"
38
39 namespace WebCore {
40
41 enum AnimationMode {
42     NoAnimation,
43     FromToAnimation,
44     FromByAnimation,
45     ToAnimation,
46     ByAnimation,
47     ValuesAnimation,
48     PathAnimation // Used by AnimateMotion.
49 };
50
51 enum CalcMode {
52     CalcModeDiscrete,
53     CalcModeLinear,
54     CalcModePaced,
55     CalcModeSpline
56 };
57
58 class ConditionEventListener;
59 class TimeContainer;
60
61 class SVGAnimationElement : public SVGSMILElement,
62                             public SVGTests,
63                             public SVGExternalResourcesRequired,
64                             public ElementTimeControl {
65 public:
66     // SVGAnimationElement
67     float getStartTime() const;
68     float getCurrentTime() const;
69     float getSimpleDuration(ExceptionCode&) const;
70
71     // ElementTimeControl
72     virtual void beginElement();
73     virtual void beginElementAt(float offset);
74     virtual void endElement();
75     virtual void endElementAt(float offset);
76
77     static bool isTargetAttributeCSSProperty(SVGElement*, const QualifiedName&);
78
79     bool isAdditive() const;
80     bool isAccumulated() const;
81     AnimationMode animationMode() const;
82     CalcMode calcMode() const;
83
84 protected:
85     SVGAnimationElement(const QualifiedName&, Document*);
86
87     bool isSupportedAttribute(const QualifiedName&);
88     virtual void parseMappedAttribute(Attribute*);
89
90     enum AttributeType {
91         AttributeTypeCSS,
92         AttributeTypeXML,
93         AttributeTypeAuto
94     };
95     AttributeType attributeType() const;
96
97     String toValue() const;
98     String byValue() const;
99     String fromValue() const;
100
101     String targetAttributeBaseValue() const;
102     void setTargetAttributeAnimatedValue(const String&);
103
104     // from SVGSMILElement
105     virtual void startedActiveInterval();
106     virtual void updateAnimation(float percent, unsigned repeat, SVGSMILElement* resultElement);
107     virtual void endedActiveInterval();
108
109 private:
110     virtual void attributeChanged(Attribute*, bool preserveDecls);
111
112     virtual bool calculateFromAndToValues(const String& fromString, const String& toString) = 0;
113     virtual bool calculateFromAndByValues(const String& fromString, const String& byString) = 0;
114     virtual void calculateAnimatedValue(float percentage, unsigned repeat, SVGSMILElement* resultElement) = 0;
115     virtual float calculateDistance(const String& /*fromString*/, const String& /*toString*/) { return -1.f; }
116     virtual Path animationPath() const { return Path(); }
117
118     void currentValuesForValuesAnimation(float percent, float& effectivePercent, String& from, String& to);
119     void calculateKeyTimesForCalcModePaced();
120     float calculatePercentFromKeyPoints(float percent) const;
121     void currentValuesFromKeyPoints(float percent, float& effectivePercent, String& from, String& to) const;
122     float calculatePercentForSpline(float percent, unsigned splineIndex) const;
123     unsigned calculateKeyTimesIndex(float percent) const;
124
125     BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGAnimationElement)
126         DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired)
127     END_DECLARE_ANIMATED_PROPERTIES
128
129     // SVGTests
130     virtual void synchronizeRequiredFeatures() { SVGTests::synchronizeRequiredFeatures(this); }
131     virtual void synchronizeRequiredExtensions() { SVGTests::synchronizeRequiredExtensions(this); }
132     virtual void synchronizeSystemLanguage() { SVGTests::synchronizeSystemLanguage(this); }
133
134     bool m_animationValid;
135
136     Vector<String> m_values;
137     Vector<float> m_keyTimes;
138     Vector<float> m_keyPoints;
139     Vector<UnitBezier> m_keySplines;
140     String m_lastValuesAnimationFrom;
141     String m_lastValuesAnimationTo;
142 };
143
144 } // namespace WebCore
145
146 #endif // ENABLE(SVG)
147 #endif // SVGAnimationElement_h