Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  * Copyright (C) 2004, 2005, 2006 Rob Buis <buis (at) kde.org>
      4  * Copyright (C) 2007 Eric Seidel <eric (at) webkit.org>
      5  * Copyright (C) 2008 Apple Inc. All rights reserved.
      6  * Copyright (C) 2008 Cameron McCormack <cam (at) 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 
     27 #if ENABLE(SVG_ANIMATION)
     28 #include "ElementTimeControl.h"
     29 #include "Path.h"
     30 #include "SMILTime.h"
     31 #include "SVGAnimatedBoolean.h"
     32 #include "SVGExternalResourcesRequired.h"
     33 #include "SVGSMILElement.h"
     34 #include "SVGStringList.h"
     35 #include "SVGTests.h"
     36 #include "UnitBezier.h"
     37 
     38 namespace WebCore {
     39 
     40 class ConditionEventListener;
     41 class TimeContainer;
     42 
     43 class SVGAnimationElement : public SVGSMILElement,
     44                             public SVGTests,
     45                             public SVGExternalResourcesRequired,
     46                             public ElementTimeControl {
     47 public:
     48     // SVGAnimationElement
     49     float getStartTime() const;
     50     float getCurrentTime() const;
     51     float getSimpleDuration(ExceptionCode&) const;
     52 
     53     // ElementTimeControl
     54     virtual void beginElement();
     55     virtual void beginElementAt(float offset);
     56     virtual void endElement();
     57     virtual void endElementAt(float offset);
     58 
     59     static bool isTargetAttributeCSSProperty(SVGElement*, const QualifiedName&);
     60 
     61 protected:
     62     SVGAnimationElement(const QualifiedName&, Document*);
     63 
     64     virtual void parseMappedAttribute(Attribute*);
     65 
     66     enum CalcMode { CalcModeDiscrete, CalcModeLinear, CalcModePaced, CalcModeSpline };
     67     CalcMode calcMode() const;
     68 
     69     enum AttributeType { AttributeTypeCSS, AttributeTypeXML, AttributeTypeAuto };
     70     AttributeType attributeType() const;
     71 
     72     String toValue() const;
     73     String byValue() const;
     74     String fromValue() const;
     75 
     76     enum AnimationMode { NoAnimation, ToAnimation, ByAnimation, ValuesAnimation, FromToAnimation, FromByAnimation, PathAnimation };
     77     AnimationMode animationMode() const;
     78 
     79     String targetAttributeBaseValue() const;
     80     void setTargetAttributeAnimatedValue(const String&);
     81 
     82     bool isAdditive() const;
     83     bool isAccumulated() const;
     84 
     85     // from SVGSMILElement
     86     virtual void startedActiveInterval();
     87     virtual void updateAnimation(float percent, unsigned repeat, SVGSMILElement* resultElement);
     88     virtual void endedActiveInterval();
     89 
     90 private:
     91     virtual void attributeChanged(Attribute*, bool preserveDecls);
     92     virtual void synchronizeProperty(const QualifiedName&);
     93 
     94     virtual bool calculateFromAndToValues(const String& fromString, const String& toString) = 0;
     95     virtual bool calculateFromAndByValues(const String& fromString, const String& byString) = 0;
     96     virtual void calculateAnimatedValue(float percentage, unsigned repeat, SVGSMILElement* resultElement) = 0;
     97     virtual float calculateDistance(const String& /*fromString*/, const String& /*toString*/) { return -1.f; }
     98     virtual Path animationPath() const { return Path(); }
     99 
    100     void currentValuesForValuesAnimation(float percent, float& effectivePercent, String& from, String& to) const;
    101     void calculateKeyTimesForCalcModePaced();
    102     float calculatePercentFromKeyPoints(float percent) const;
    103     void currentValuesFromKeyPoints(float percent, float& effectivePercent, String& from, String& to) const;
    104     float calculatePercentForSpline(float percent, unsigned splineIndex) const;
    105     unsigned calculateKeyTimesIndex(float percent) const;
    106 
    107     // Animated property declarations
    108 
    109     // SVGExternalResourcesRequired
    110     DECLARE_ANIMATED_BOOLEAN(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