• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
contextElement()34     SVGElement* contextElement() const { return m_contextElement; }
resetContextElement()35     void resetContextElement() { m_contextElement = 0; }
attributeName()36     const QualifiedName& attributeName() const { return m_attributeName; }
animatedPropertyType()37     AnimatedPropertyType animatedPropertyType() const { return m_animatedPropertyType; }
isAnimating()38     bool isAnimating() const { return m_isAnimating; }
isReadOnly()39     bool isReadOnly() const { return m_isReadOnly; }
setIsReadOnly()40     void setIsReadOnly() { m_isReadOnly = true; }
41 
42     void commitChange();
43 
isAnimatedListTearOff()44     virtual bool isAnimatedListTearOff() const { return false; }
45 
46     // Caching facilities.
47     typedef HashMap<SVGAnimatedPropertyDescription, RefPtr<SVGAnimatedProperty>, SVGAnimatedPropertyDescriptionHash, SVGAnimatedPropertyDescriptionHashTraits> Cache;
48 
49     virtual ~SVGAnimatedProperty();
50 
51     template<typename OwnerType, typename TearOffType, typename PropertyType>
lookupOrCreateWrapper(OwnerType * element,const SVGPropertyInfo * info,PropertyType & property)52     static PassRefPtr<TearOffType> lookupOrCreateWrapper(OwnerType* element, const SVGPropertyInfo* info, PropertyType& property)
53     {
54         ASSERT(info);
55         SVGAnimatedPropertyDescription key(element, info->propertyIdentifier);
56         RefPtr<SVGAnimatedProperty> wrapper = animatedPropertyCache()->get(key);
57         if (!wrapper) {
58             wrapper = TearOffType::create(element, info->attributeName, info->animatedPropertyType, property);
59             if (info->animatedPropertyState == PropertyIsReadOnly)
60                 wrapper->setIsReadOnly();
61             animatedPropertyCache()->set(key, wrapper);
62         }
63         return static_pointer_cast<TearOffType>(wrapper);
64     }
65 
66     template<typename OwnerType, typename TearOffType>
lookupWrapper(OwnerType * element,const SVGPropertyInfo * info)67     static TearOffType* lookupWrapper(OwnerType* element, const SVGPropertyInfo* info)
68     {
69         ASSERT(info);
70         SVGAnimatedPropertyDescription key(element, info->propertyIdentifier);
71         return static_cast<TearOffType*>(animatedPropertyCache()->get(key));
72     }
73 
74     template<typename OwnerType, typename TearOffType>
lookupWrapper(const OwnerType * element,const SVGPropertyInfo * info)75     static TearOffType* lookupWrapper(const OwnerType* element, const SVGPropertyInfo* info)
76     {
77         return lookupWrapper<OwnerType, TearOffType>(const_cast<OwnerType*>(element), info);
78     }
79 
80     static void detachAnimatedPropertiesForElement(SVGElement*);
81 
82 protected:
83     SVGAnimatedProperty(SVGElement*, const QualifiedName&, AnimatedPropertyType);
84 
85 private:
86     static Cache* animatedPropertyCache();
87 
88     SVGElement* m_contextElement;
89     const QualifiedName& m_attributeName;
90     AnimatedPropertyType m_animatedPropertyType;
91 
92 protected:
93     bool m_isAnimating;
94     bool m_isReadOnly;
95 };
96 
97 }
98 
99 #endif // SVGAnimatedProperty_h
100