File indexing completed on 2024-04-21 14:58:20
0001 /* 0002 Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org> 0003 2004, 2005, 2006 Rob Buis <buis@kde.org> 0004 Copyright (C) 2007 Eric Seidel <eric@webkit.org> 0005 Copyright (C) 2008 Apple Inc. All rights reserved. 0006 0007 This file is part of the KDE project 0008 0009 This library is free software; you can redistribute it and/or 0010 modify it under the terms of the GNU Library General Public 0011 License as published by the Free Software Foundation; either 0012 version 2 of the License, or (at your option) any later version. 0013 0014 This library is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0017 Library General Public License for more details. 0018 0019 You should have received a copy of the GNU Library General Public License 0020 along with this library; see the file COPYING.LIB. If not, write to 0021 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0022 Boston, MA 02110-1301, USA. 0023 */ 0024 0025 #ifndef SVGAnimationElement_h 0026 #define SVGAnimationElement_h 0027 #if ENABLE(SVG_ANIMATION) 0028 0029 #include "ElementTimeControl.h" 0030 #include "Path.h" 0031 #include "SMILTime.h" 0032 #include "SVGSMILElement.h" 0033 #include "SVGExternalResourcesRequired.h" 0034 #include "SVGStringList.h" 0035 #include "SVGTests.h" 0036 #include "UnitBezier.h" 0037 0038 namespace WebCore 0039 { 0040 0041 class ConditionEventListener; 0042 class TimeContainer; 0043 0044 class SVGAnimationElement : public SVGSMILElement, 0045 public SVGTests, 0046 public SVGExternalResourcesRequired, 0047 public ElementTimeControl 0048 { 0049 public: 0050 SVGAnimationElement(const QualifiedName &, Document *); 0051 virtual ~SVGAnimationElement(); 0052 0053 virtual void parseMappedAttribute(MappedAttribute *); 0054 virtual void attributeChanged(Attribute *, bool preserveDecls); 0055 0056 // SVGAnimationElement 0057 float getStartTime() const; 0058 float getCurrentTime() const; 0059 float getSimpleDuration(ExceptionCode &) const; 0060 0061 // ElementTimeControl 0062 virtual bool beginElement(ExceptionCode &); 0063 virtual bool beginElementAt(float offset, ExceptionCode &); 0064 virtual bool endElement(ExceptionCode &); 0065 virtual bool endElementAt(float offset, ExceptionCode &); 0066 0067 static bool attributeIsCSS(const String &attributeName); 0068 0069 protected: 0070 0071 enum CalcMode { CalcModeDiscrete, CalcModeLinear, CalcModePaced, CalcModeSpline }; 0072 CalcMode calcMode() const; 0073 0074 enum AttributeType { AttributeTypeCSS, AttributeTypeXML, AttributeTypeAuto }; 0075 AttributeType attributeType() const; 0076 0077 String toValue() const; 0078 String byValue() const; 0079 String fromValue() const; 0080 0081 enum AnimationMode { NoAnimation, ToAnimation, ByAnimation, ValuesAnimation, FromToAnimation, FromByAnimation, PathAnimation }; 0082 AnimationMode animationMode() const; 0083 0084 virtual bool hasValidTarget() const; 0085 0086 String targetAttributeBaseValue() const; 0087 void setTargetAttributeAnimatedValue(const String &); 0088 bool targetAttributeIsCSS() const; 0089 0090 bool isAdditive() const; 0091 bool isAccumulated() const; 0092 0093 // from SVGSMILElement 0094 virtual void startedActiveInterval(); 0095 virtual void updateAnimation(float percent, unsigned repeat, SVGSMILElement *resultElement); 0096 virtual void endedActiveInterval(); 0097 0098 ANIMATED_PROPERTY_FORWARD_DECLARATIONS(SVGExternalResourcesRequired, bool, ExternalResourcesRequired, externalResourcesRequired) 0099 private: 0100 virtual bool calculateFromAndToValues(const String &fromString, const String &toString) = 0; 0101 virtual bool calculateFromAndByValues(const String &fromString, const String &byString) = 0; 0102 virtual void calculateAnimatedValue(float percentage, unsigned repeat, SVGSMILElement *resultElement) = 0; 0103 virtual float calculateDistance(const String &fromString, const String &toString) 0104 { 0105 return -1.f; 0106 } 0107 virtual Path animationPath() const 0108 { 0109 return Path(); 0110 } 0111 0112 void currentValuesForValuesAnimation(float percent, float &effectivePercent, String &from, String &to) const; 0113 void calculateKeyTimesForCalcModePaced(); 0114 float calculatePercentFromKeyPoints(float percent) const; 0115 void currentValuesFromKeyPoints(float percent, float &effectivePercent, String &from, String &to) const; 0116 float calculatePercentForSpline(float percent, unsigned splineIndex) const; 0117 0118 protected: 0119 bool m_animationValid; 0120 0121 Vector<String> m_values; 0122 Vector<float> m_keyTimes; 0123 Vector<float> m_keyPoints; 0124 Vector<UnitBezier> m_keySplines; 0125 String m_lastValuesAnimationFrom; 0126 String m_lastValuesAnimationTo; 0127 }; 0128 0129 } // namespace WebCore 0130 0131 #endif // ENABLE(SVG) 0132 #endif // SVGAnimationElement_h