1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
/*
* Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
* Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
* Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef SVGAnimatedPropertyMacros_h
#define SVGAnimatedPropertyMacros_h
#if ENABLE(SVG)
#include "Element.h"
#include "SVGAnimatedProperty.h"
#include "SVGAttributeToPropertyMap.h"
#include "SVGPropertyTraits.h"
#include <wtf/StdLibExtras.h>
namespace WebCore {
// SVGSynchronizableAnimatedProperty implementation
template<typename PropertyType>
struct SVGSynchronizableAnimatedProperty {
SVGSynchronizableAnimatedProperty()
: value(SVGPropertyTraits<PropertyType>::initialValue())
, shouldSynchronize(false)
, isValid(false)
{
}
template<typename ConstructorParameter1>
SVGSynchronizableAnimatedProperty(const ConstructorParameter1& value1)
: value(value1)
, shouldSynchronize(false)
, isValid(false)
{
}
template<typename ConstructorParameter1, typename ConstructorParameter2>
SVGSynchronizableAnimatedProperty(const ConstructorParameter1& value1, const ConstructorParameter2& value2)
: value(value1, value2)
, shouldSynchronize(false)
, isValid(false)
{
}
void synchronize(Element* ownerElement, const QualifiedName& attrName, const AtomicString& value)
{
ownerElement->setSynchronizedLazyAttribute(attrName, value);
}
PropertyType value;
bool shouldSynchronize : 1;
bool isValid : 1;
};
// Property registration helpers
#define BEGIN_REGISTER_ANIMATED_PROPERTIES(OwnerType) \
SVGAttributeToPropertyMap& OwnerType::attributeToPropertyMap() \
{ \
DEFINE_STATIC_LOCAL(SVGAttributeToPropertyMap, s_attributeToPropertyMap, ()); \
return s_attributeToPropertyMap; \
} \
\
static void registerAnimatedPropertiesFor##OwnerType() \
{ \
SVGAttributeToPropertyMap& map = OwnerType::attributeToPropertyMap(); \
if (!map.isEmpty()) \
return; \
typedef OwnerType UseOwnerType;
#define REGISTER_LOCAL_ANIMATED_PROPERTY(LowerProperty) \
map.addProperty(UseOwnerType::LowerProperty##PropertyInfo());
#define REGISTER_PARENT_ANIMATED_PROPERTIES(ClassName) \
map.addProperties(ClassName::attributeToPropertyMap()); \
#define END_REGISTER_ANIMATED_PROPERTIES }
// Property definition helpers (used in SVG*.cpp files)
#define DEFINE_ANIMATED_PROPERTY(AnimatedPropertyTypeEnum, OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, UpperProperty, LowerProperty) \
const SVGPropertyInfo* OwnerType::LowerProperty##PropertyInfo() { \
DEFINE_STATIC_LOCAL(const SVGPropertyInfo, s_propertyInfo, \
(AnimatedPropertyTypeEnum, \
PropertyIsReadWrite, \
DOMAttribute, \
SVGDOMAttributeIdentifier, \
&OwnerType::synchronize##UpperProperty, \
&OwnerType::lookupOrCreate##UpperProperty##Wrapper)); \
return &s_propertyInfo; \
}
// Property declaration helpers (used in SVG*.h files)
#define BEGIN_DECLARE_ANIMATED_PROPERTIES(OwnerType) \
public: \
static SVGAttributeToPropertyMap& attributeToPropertyMap(); \
virtual SVGAttributeToPropertyMap& localAttributeToPropertyMap() \
{ \
return attributeToPropertyMap(); \
} \
typedef OwnerType UseOwnerType;
#define DECLARE_ANIMATED_PROPERTY(TearOffType, PropertyType, UpperProperty, LowerProperty) \
public: \
static const SVGPropertyInfo* LowerProperty##PropertyInfo(); \
PropertyType& LowerProperty() const \
{ \
if (RefPtr<TearOffType> wrapper = SVGAnimatedProperty::lookupWrapper<UseOwnerType, TearOffType>(this, LowerProperty##PropertyInfo())) { \
if (wrapper->isAnimating()) \
return wrapper->currentAnimatedValue(); \
} \
return m_##LowerProperty.value; \
} \
\
PropertyType& LowerProperty##BaseValue() const \
{ \
return m_##LowerProperty.value; \
} \
\
void set##UpperProperty##BaseValue(const PropertyType& type, const bool validValue = true) \
{ \
m_##LowerProperty.value = type; \
m_##LowerProperty.isValid = validValue; \
} \
\
PassRefPtr<TearOffType> LowerProperty##Animated() \
{ \
m_##LowerProperty.shouldSynchronize = true; \
return static_pointer_cast<TearOffType>(lookupOrCreate##UpperProperty##Wrapper(this)); \
} \
\
bool LowerProperty##IsValid() const \
{ \
return m_##LowerProperty.isValid; \
} \
\
private: \
void synchronize##UpperProperty() \
{ \
if (!m_##LowerProperty.shouldSynchronize) \
return; \
AtomicString value(SVGPropertyTraits<PropertyType>::toString(m_##LowerProperty.value)); \
m_##LowerProperty.synchronize(this, LowerProperty##PropertyInfo()->attributeName, value); \
} \
\
static PassRefPtr<SVGAnimatedProperty> lookupOrCreate##UpperProperty##Wrapper(SVGElement* maskedOwnerType) \
{ \
ASSERT(maskedOwnerType); \
UseOwnerType* ownerType = static_cast<UseOwnerType*>(maskedOwnerType); \
return SVGAnimatedProperty::lookupOrCreateWrapper<UseOwnerType, TearOffType, PropertyType>(ownerType, LowerProperty##PropertyInfo(), ownerType->m_##LowerProperty.value); \
} \
\
static void synchronize##UpperProperty(SVGElement* maskedOwnerType) \
{ \
ASSERT(maskedOwnerType); \
UseOwnerType* ownerType = static_cast<UseOwnerType*>(maskedOwnerType); \
ownerType->synchronize##UpperProperty(); \
} \
\
mutable SVGSynchronizableAnimatedProperty<PropertyType> m_##LowerProperty;
#define END_DECLARE_ANIMATED_PROPERTIES
// List specific definition/declaration helpers
#define DECLARE_ANIMATED_LIST_PROPERTY(TearOffType, PropertyType, UpperProperty, LowerProperty) \
DECLARE_ANIMATED_PROPERTY(TearOffType, PropertyType, UpperProperty, LowerProperty) \
void detachAnimated##UpperProperty##ListWrappers(unsigned newListSize) \
{ \
if (RefPtr<TearOffType> wrapper = SVGAnimatedProperty::lookupWrapper<UseOwnerType, TearOffType>(this, LowerProperty##PropertyInfo())) \
wrapper->detachListWrappers(newListSize); \
}
}
#endif // ENABLE(SVG)
#endif // SVGAnimatedPropertyMacros_h
|