Home | History | Annotate | Download | only in properties
      1 /*
      2  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
      3  * Copyright (C) 2013 Samsung Electronics. All rights reserved.
      4  *
      5  * This library is free software; you can redistribute it and/or
      6  * modify it under the terms of the GNU Library General Public
      7  * License as published by the Free Software Foundation; either
      8  * version 2 of the License, or (at your option) any later version.
      9  *
     10  * This library is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13  * Library General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU Library General Public License
     16  * along with this library; see the file COPYING.LIB.  If not, write to
     17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18  * Boston, MA 02110-1301, USA.
     19  */
     20 
     21 #ifndef SVGAnimatedProperty_h
     22 #define SVGAnimatedProperty_h
     23 
     24 #include "core/svg/properties/SVGAnimatedPropertyDescription.h"
     25 #include "core/svg/properties/SVGPropertyInfo.h"
     26 #include "wtf/RefCounted.h"
     27 
     28 namespace WebCore {
     29 
     30 class SVGElement;
     31 
     32 class SVGAnimatedProperty : public RefCounted<SVGAnimatedProperty> {
     33 public:
     34     SVGElement* contextElement() const { return m_contextElement.get(); }
     35     const QualifiedName& attributeName() const { return m_attributeName; }
     36     AnimatedPropertyType animatedPropertyType() const { return m_animatedPropertyType; }
     37     bool isAnimating() const { return m_isAnimating; }
     38     bool isReadOnly() const { return m_isReadOnly; }
     39     void setIsReadOnly() { m_isReadOnly = true; }
     40 
     41     void commitChange();
     42 
     43     virtual bool isAnimatedListTearOff() const { return false; }
     44 
     45     // Caching facilities.
     46     typedef HashMap<SVGAnimatedPropertyDescription, SVGAnimatedProperty*, SVGAnimatedPropertyDescriptionHash, SVGAnimatedPropertyDescriptionHashTraits> Cache;
     47 
     48     virtual ~SVGAnimatedProperty();
     49 
     50     template<typename OwnerType, typename TearOffType, typename PropertyType>
     51     static PassRefPtr<TearOffType> lookupOrCreateWrapper(OwnerType* element, const SVGPropertyInfo* info, PropertyType& property)
     52     {
     53         ASSERT(info);
     54         SVGAnimatedPropertyDescription key(element, info->propertyIdentifier);
     55         RefPtr<SVGAnimatedProperty> wrapper = animatedPropertyCache()->get(key);
     56         if (!wrapper) {
     57             wrapper = TearOffType::create(element, info->attributeName, info->animatedPropertyType, property);
     58             if (info->animatedPropertyState == PropertyIsReadOnly)
     59                 wrapper->setIsReadOnly();
     60             animatedPropertyCache()->set(key, wrapper.get());
     61         }
     62         return static_pointer_cast<TearOffType>(wrapper);
     63     }
     64 
     65     template<typename OwnerType, typename TearOffType>
     66     static TearOffType* lookupWrapper(OwnerType* element, const SVGPropertyInfo* info)
     67     {
     68         ASSERT(info);
     69         SVGAnimatedPropertyDescription key(element, info->propertyIdentifier);
     70         return static_cast<TearOffType*>(animatedPropertyCache()->get(key));
     71     }
     72 
     73     template<typename OwnerType, typename TearOffType>
     74     static TearOffType* lookupWrapper(const OwnerType* element, const SVGPropertyInfo* info)
     75     {
     76         return lookupWrapper<OwnerType, TearOffType>(const_cast<OwnerType*>(element), info);
     77     }
     78 
     79 protected:
     80     SVGAnimatedProperty(SVGElement*, const QualifiedName&, AnimatedPropertyType);
     81 
     82 private:
     83     static Cache* animatedPropertyCache();
     84 
     85     RefPtr<SVGElement> m_contextElement;
     86     const QualifiedName& m_attributeName;
     87     AnimatedPropertyType m_animatedPropertyType;
     88 
     89 protected:
     90     bool m_isAnimating;
     91     bool m_isReadOnly;
     92 };
     93 
     94 }
     95 
     96 #endif // SVGAnimatedProperty_h
     97