• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
3                   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 
8     This library is free software; you can redistribute it and/or
9     modify it under the terms of the GNU Library General Public
10     License as published by the Free Software Foundation; either
11     version 2 of the License, or (at your option) any later version.
12 
13     This library is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16     Library General Public License for more details.
17 
18     You should have received a copy of the GNU Library General Public License
19     along with this library; see the file COPYING.LIB.  If not, write to
20     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21     Boston, MA 02110-1301, USA.
22 */
23 
24 #ifndef SVGAnimationElement_h
25 #define SVGAnimationElement_h
26 #if ENABLE(SVG_ANIMATION)
27 
28 #include "ElementTimeControl.h"
29 #include "Path.h"
30 #include "SMILTime.h"
31 #include "SVGSMILElement.h"
32 #include "SVGExternalResourcesRequired.h"
33 #include "SVGStringList.h"
34 #include "SVGTests.h"
35 #include "UnitBezier.h"
36 
37 namespace WebCore {
38 
39     class ConditionEventListener;
40     class TimeContainer;
41 
42     class SVGAnimationElement : public SVGSMILElement,
43                                 public SVGTests,
44                                 public SVGExternalResourcesRequired,
45                                 public ElementTimeControl {
46     public:
47         SVGAnimationElement(const QualifiedName&, Document*);
48         virtual ~SVGAnimationElement();
49 
50         virtual void parseMappedAttribute(MappedAttribute*);
51         virtual void attributeChanged(Attribute*, bool preserveDecls);
52         virtual void synchronizeProperty(const QualifiedName&);
53 
54         // SVGAnimationElement
55         float getStartTime() const;
56         float getCurrentTime() const;
57         float getSimpleDuration(ExceptionCode&) const;
58 
59         // ElementTimeControl
60         virtual void beginElement();
61         virtual void beginElementAt(float offset);
62         virtual void endElement();
63         virtual void endElementAt(float offset);
64 
65         static bool attributeIsCSS(const String& attributeName);
66 
67     protected:
68         enum CalcMode { CalcModeDiscrete, CalcModeLinear, CalcModePaced, CalcModeSpline };
69         CalcMode calcMode() const;
70 
71         enum AttributeType { AttributeTypeCSS, AttributeTypeXML, AttributeTypeAuto };
72         AttributeType attributeType() const;
73 
74         String toValue() const;
75         String byValue() const;
76         String fromValue() const;
77 
78         enum AnimationMode { NoAnimation, ToAnimation, ByAnimation, ValuesAnimation, FromToAnimation, FromByAnimation, PathAnimation };
79         AnimationMode animationMode() const;
80 
81         virtual bool hasValidTarget() const;
82 
83         String targetAttributeBaseValue() const;
84         void setTargetAttributeAnimatedValue(const String&);
85         bool targetAttributeIsCSS() const;
86 
87         bool isAdditive() const;
88         bool isAccumulated() const;
89 
90         // from SVGSMILElement
91         virtual void startedActiveInterval();
92         virtual void updateAnimation(float percent, unsigned repeat, SVGSMILElement* resultElement);
93         virtual void endedActiveInterval();
94 
95     private:
96         virtual bool calculateFromAndToValues(const String& fromString, const String& toString) = 0;
97         virtual bool calculateFromAndByValues(const String& fromString, const String& byString) = 0;
98         virtual void calculateAnimatedValue(float percentage, unsigned repeat, SVGSMILElement* resultElement) = 0;
calculateDistance(const String &,const String &)99         virtual float calculateDistance(const String& /*fromString*/, const String& /*toString*/) { return -1.f; }
animationPath()100         virtual Path animationPath() const { return Path(); }
101 
102         void currentValuesForValuesAnimation(float percent, float& effectivePercent, String& from, String& to) const;
103         void calculateKeyTimesForCalcModePaced();
104         float calculatePercentFromKeyPoints(float percent) const;
105         void currentValuesFromKeyPoints(float percent, float& effectivePercent, String& from, String& to) const;
106         float calculatePercentForSpline(float percent, unsigned splineIndex) const;
107 
108     protected:
109         // SVGExternalResourcesRequired
110         DECLARE_ANIMATED_PROPERTY(SVGAnimationElement, SVGNames::externalResourcesRequiredAttr, bool, ExternalResourcesRequired, externalResourcesRequired)
111 
112         bool m_animationValid;
113 
114         Vector<String> m_values;
115         Vector<float> m_keyTimes;
116         Vector<float> m_keyPoints;
117         Vector<UnitBezier> m_keySplines;
118         String m_lastValuesAnimationFrom;
119         String m_lastValuesAnimationTo;
120     };
121 
122 } // namespace WebCore
123 
124 #endif // ENABLE(SVG)
125 #endif // SVGAnimationElement_h
126