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.
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.
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.
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.
22 #ifndef SVGAnimatedPropertyMacros_h
23 #define SVGAnimatedPropertyMacros_h
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"
37 // GetOwnerElementForType implementation
38 template<typename OwnerType, bool isDerivedFromSVGElement>
39 struct GetOwnerElementForType;
41 template<typename OwnerType>
42 struct GetOwnerElementForType<OwnerType, true> {
43 static SVGElement* ownerElement(OwnerType* type)
49 template<typename OwnerType>
50 struct GetOwnerElementForType<OwnerType, false> {
51 static SVGElement* ownerElement(OwnerType* type)
53 SVGElement* context = type->contextElement();
59 // IsDerivedFromSVGElement implementation
60 template<typename OwnerType>
61 struct IsDerivedFromSVGElement {
62 static const bool value = true;
67 struct IsDerivedFromSVGElement<SVGViewSpec> {
68 static const bool value = false;
71 template<typename PropertyType>
72 struct SVGSynchronizableAnimatedProperty {
73 SVGSynchronizableAnimatedProperty()
74 : value(SVGPropertyTraits<PropertyType>::initialValue())
75 , shouldSynchronize(false)
79 template<typename ConstructorParameter1>
80 SVGSynchronizableAnimatedProperty(const ConstructorParameter1& value1)
82 , shouldSynchronize(false)
86 template<typename ConstructorParameter1, typename ConstructorParameter2>
87 SVGSynchronizableAnimatedProperty(const ConstructorParameter1& value1, const ConstructorParameter2& value2)
88 : value(value1, value2)
89 , shouldSynchronize(false)
94 bool shouldSynchronize : 1;
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) \
100 PropertyType& LowerProperty() const \
102 return m_##LowerProperty.value; \
105 PropertyType& LowerProperty##BaseValue() const \
107 return m_##LowerProperty.value; \
110 void set##UpperProperty##BaseValue(const PropertyType& type) \
112 m_##LowerProperty.value = type; \
113 SVGElement* contextElement = GetOwnerElementForType<OwnerType, IsDerivedFromSVGElement<OwnerType>::value>::ownerElement(this); \
114 contextElement->invalidateSVGAttributes(); \
117 void synchronize##UpperProperty() \
119 if (!m_##LowerProperty.shouldSynchronize) \
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); \
126 PassRefPtr<TearOffType> LowerProperty##Animated() \
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); \
133 mutable SVGSynchronizableAnimatedProperty<PropertyType> m_##LowerProperty;
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)
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)
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)
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)
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) \
150 void detachAnimated##UpperProperty##ListWrappers(unsigned newListSize) \
152 SVGElement* contextElement = GetOwnerElementForType<OwnerType, IsDerivedFromSVGElement<OwnerType>::value>::ownerElement(this); \
153 SVGAnimatedProperty* wrapper = SVGAnimatedProperty::lookupWrapper<SVGAnimatedListPropertyTearOff<PropertyType> >(contextElement, DOMAttribute.localName()); \
156 static_cast<SVGAnimatedListPropertyTearOff<PropertyType>*>(wrapper)->detachListWrappers(newListSize); \
161 #endif // ENABLE(SVG)
162 #endif // SVGAnimatedPropertyMacros_h