Home | History | Annotate | Download | only in properties
      1 /*
      2  * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved.
      3  *
      4  * This library is free software; you can redistribute it and/or
      5  * modify it under the terms of the GNU Library General Public
      6  * License as published by the Free Software Foundation; either
      7  * version 2 of the License, or (at your option) any later version.
      8  *
      9  * This library is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  * Library General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Library General Public License
     15  * along with this library; see the file COPYING.LIB.  If not, write to
     16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17  * Boston, MA 02110-1301, USA.
     18  */
     19 
     20 #ifndef SVGAnimatedStaticPropertyTearOff_h
     21 #define SVGAnimatedStaticPropertyTearOff_h
     22 
     23 #include "core/svg/properties/SVGAnimatedProperty.h"
     24 
     25 namespace WebCore {
     26 
     27 class ExceptionState;
     28 
     29 template<typename PropertyType>
     30 class SVGAnimatedStaticPropertyTearOff : public SVGAnimatedProperty {
     31 public:
     32     typedef PropertyType ContentType;
     33 
     34     PropertyType& baseVal()
     35     {
     36         return m_property;
     37     }
     38 
     39     PropertyType& animVal()
     40     {
     41         if (m_animatedProperty)
     42             return *m_animatedProperty;
     43         return m_property;
     44     }
     45 
     46     virtual void setBaseVal(const PropertyType& property, ExceptionState&)
     47     {
     48         m_property = property;
     49         commitChange();
     50     }
     51 
     52     static PassRefPtr<SVGAnimatedStaticPropertyTearOff<PropertyType> > create(SVGElement* contextElement, const QualifiedName& attributeName, AnimatedPropertyType animatedPropertyType, PropertyType& property)
     53     {
     54         ASSERT(contextElement);
     55         return adoptRef(new SVGAnimatedStaticPropertyTearOff<PropertyType>(contextElement, attributeName, animatedPropertyType, property));
     56     }
     57 
     58     PropertyType& currentAnimatedValue()
     59     {
     60         ASSERT(m_isAnimating);
     61         ASSERT(m_animatedProperty);
     62         return *m_animatedProperty;
     63     }
     64 
     65     const PropertyType& currentBaseValue() const
     66     {
     67         return m_property;
     68     }
     69 
     70     void animationStarted(PropertyType* newAnimVal)
     71     {
     72         ASSERT(!m_isAnimating);
     73         ASSERT(!m_animatedProperty);
     74         ASSERT(newAnimVal);
     75         m_animatedProperty = newAnimVal;
     76         m_isAnimating = true;
     77     }
     78 
     79     void animationEnded()
     80     {
     81         ASSERT(m_isAnimating);
     82         ASSERT(m_animatedProperty);
     83         m_animatedProperty = 0;
     84         m_isAnimating = false;
     85     }
     86 
     87     void animValWillChange()
     88     {
     89         // no-op for non list types.
     90         ASSERT(m_isAnimating);
     91         ASSERT(m_animatedProperty);
     92     }
     93 
     94     void animValDidChange()
     95     {
     96         // no-op for non list types.
     97         ASSERT(m_isAnimating);
     98         ASSERT(m_animatedProperty);
     99     }
    100 
    101 protected:
    102     SVGAnimatedStaticPropertyTearOff(SVGElement* contextElement, const QualifiedName& attributeName, AnimatedPropertyType animatedPropertyType, PropertyType& property)
    103         : SVGAnimatedProperty(contextElement, attributeName, animatedPropertyType)
    104         , m_property(property)
    105         , m_animatedProperty(0)
    106     {
    107     }
    108 
    109 private:
    110     PropertyType& m_property;
    111     PropertyType* m_animatedProperty;
    112 };
    113 
    114 }
    115 
    116 #endif // SVGAnimatedStaticPropertyTearOff_h
    117