OSDN Git Service

Merge WebKit at r71558: Initial merge by git.
[android-x86/external-webkit.git] / WebCore / svg / properties / SVGAnimatedPropertyMacros.h
1 /*
2  * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
4  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #ifndef SVGAnimatedPropertyMacros_h
23 #define SVGAnimatedPropertyMacros_h
24
25 #if ENABLE(SVG)
26 #include "SVGAnimatedListPropertyTearOff.h"
27 #include "SVGAnimatedStaticPropertyTearOff.h"
28 #include "SVGAnimatedPropertySynchronizer.h"
29 #include "SVGAnimatedPropertyTearOff.h"
30 #include "SVGNames.h" // FIXME: Temporary hack, until we expand the macros in all files, so we don't need a global SVGNames.h include
31 #include "SVGPropertyTraits.h"
32
33 namespace WebCore {
34
35 class SVGElement;
36
37 // GetOwnerElementForType implementation
38 template<typename OwnerType, bool isDerivedFromSVGElement>
39 struct GetOwnerElementForType;
40
41 template<typename OwnerType>
42 struct GetOwnerElementForType<OwnerType, true> {
43     static SVGElement* ownerElement(OwnerType* type)
44     {
45         return type;
46     }
47 };
48
49 template<typename OwnerType>
50 struct GetOwnerElementForType<OwnerType, false> {    
51     static SVGElement* ownerElement(OwnerType* type)
52     {
53         SVGElement* context = type->contextElement();
54         ASSERT(context);
55         return context;
56     }
57 };
58
59 // IsDerivedFromSVGElement implementation
60 template<typename OwnerType>
61 struct IsDerivedFromSVGElement {
62     static const bool value = true;
63 };
64
65 class SVGViewSpec;
66 template<>
67 struct IsDerivedFromSVGElement<SVGViewSpec> {
68     static const bool value = false;
69 };
70
71 template<typename PropertyType>
72 struct SVGSynchronizableAnimatedProperty {
73     SVGSynchronizableAnimatedProperty()
74         : value(SVGPropertyTraits<PropertyType>::initialValue())
75         , shouldSynchronize(false)
76     {
77     }
78
79     template<typename ConstructorParameter1>
80     SVGSynchronizableAnimatedProperty(const ConstructorParameter1& value1)
81         : value(value1)
82         , shouldSynchronize(false)
83     {
84     }
85
86     template<typename ConstructorParameter1, typename ConstructorParameter2>
87     SVGSynchronizableAnimatedProperty(const ConstructorParameter1& value1, const ConstructorParameter2& value2)
88         : value(value1, value2)
89         , shouldSynchronize(false)
90     {
91     }
92
93     PropertyType value;
94     bool shouldSynchronize : 1;
95 };
96
97 // FIXME: These macros should be removed, after the transition to the new SVGAnimatedProperty concept is finished.
98 #define DECLARE_ANIMATED_PROPERTY_NEW_SHARED(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, TearOffType, PropertyType, UpperProperty, LowerProperty) \
99 public: \
100 PropertyType& LowerProperty() const \
101 { \
102     return m_##LowerProperty.value; \
103 } \
104 \
105 PropertyType& LowerProperty##BaseValue() const \
106 { \
107     return m_##LowerProperty.value; \
108 } \
109 \
110 void set##UpperProperty##BaseValue(const PropertyType& type) \
111 { \
112     m_##LowerProperty.value = type; \
113     SVGElement* contextElement = GetOwnerElementForType<OwnerType, IsDerivedFromSVGElement<OwnerType>::value>::ownerElement(this); \
114     contextElement->invalidateSVGAttributes(); \
115 } \
116 \
117 void synchronize##UpperProperty() \
118 { \
119     if (!m_##LowerProperty.shouldSynchronize) \
120          return; \
121     AtomicString value(SVGPropertyTraits<PropertyType>::toString(LowerProperty##BaseValue())); \
122     SVGElement* contextElement = GetOwnerElementForType<OwnerType, IsDerivedFromSVGElement<OwnerType>::value>::ownerElement(this); \
123     SVGAnimatedPropertySynchronizer<IsDerivedFromSVGElement<OwnerType>::value>::synchronize(contextElement, DOMAttribute, value); \
124 } \
125 \
126 PassRefPtr<TearOffType> LowerProperty##Animated() \
127 { \
128     m_##LowerProperty.shouldSynchronize = true; \
129     SVGElement* contextElement = GetOwnerElementForType<OwnerType, IsDerivedFromSVGElement<OwnerType>::value>::ownerElement(this); \
130     return SVGAnimatedProperty::lookupOrCreateWrapper<TearOffType, PropertyType>(contextElement, DOMAttribute, SVGDOMAttributeIdentifier, m_##LowerProperty.value); \
131 } \
132 private: \
133     mutable SVGSynchronizableAnimatedProperty<PropertyType> m_##LowerProperty;
134
135 #define DECLARE_ANIMATED_PROPERTY_NEW(OwnerType, DOMAttribute, PropertyType, UpperProperty, LowerProperty) \
136 DECLARE_ANIMATED_PROPERTY_NEW_SHARED(OwnerType, DOMAttribute, DOMAttribute.localName(), SVGAnimatedPropertyTearOff<PropertyType>, PropertyType, UpperProperty, LowerProperty)
137
138 #define DECLARE_ANIMATED_PROPERTY_MULTIPLE_WRAPPERS_NEW(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, PropertyType, UpperProperty, LowerProperty) \
139 DECLARE_ANIMATED_PROPERTY_NEW_SHARED(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, SVGAnimatedPropertyTearOff<PropertyType>, PropertyType, UpperProperty, LowerProperty)
140
141 #define DECLARE_ANIMATED_STATIC_PROPERTY_MULTIPLE_WRAPPERS_NEW(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, PropertyType, UpperProperty, LowerProperty) \
142 DECLARE_ANIMATED_PROPERTY_NEW_SHARED(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, SVGAnimatedStaticPropertyTearOff<PropertyType>, PropertyType, UpperProperty, LowerProperty)
143
144 #define DECLARE_ANIMATED_STATIC_PROPERTY_NEW(OwnerType, DOMAttribute, PropertyType, UpperProperty, LowerProperty) \
145 DECLARE_ANIMATED_PROPERTY_NEW_SHARED(OwnerType, DOMAttribute, DOMAttribute.localName(), SVGAnimatedStaticPropertyTearOff<PropertyType>, PropertyType, UpperProperty, LowerProperty)
146
147 #define DECLARE_ANIMATED_LIST_PROPERTY_NEW(OwnerType, DOMAttribute, PropertyType, UpperProperty, LowerProperty) \
148 DECLARE_ANIMATED_PROPERTY_NEW_SHARED(OwnerType, DOMAttribute, DOMAttribute.localName(), SVGAnimatedListPropertyTearOff<PropertyType>, PropertyType, UpperProperty, LowerProperty) \
149 \
150 void detachAnimated##UpperProperty##ListWrappers(unsigned newListSize) \
151 { \
152     SVGElement* contextElement = GetOwnerElementForType<OwnerType, IsDerivedFromSVGElement<OwnerType>::value>::ownerElement(this); \
153     SVGAnimatedProperty* wrapper = SVGAnimatedProperty::lookupWrapper<SVGAnimatedListPropertyTearOff<PropertyType> >(contextElement, DOMAttribute.localName()); \
154     if (!wrapper) \
155         return; \
156     static_cast<SVGAnimatedListPropertyTearOff<PropertyType>*>(wrapper)->detachListWrappers(newListSize); \
157 }
158
159 }
160
161 #endif // ENABLE(SVG)
162 #endif // SVGAnimatedPropertyMacros_h