SVGAnimatedPropertyMacros.h [plain text]
#ifndef SVGAnimatedPropertyMacros_h
#define SVGAnimatedPropertyMacros_h
#if ENABLE(SVG)
#include "SVGAnimatedProperty.h"
#include "SVGAttributeToPropertyMap.h"
#include "SVGPropertyTraits.h"
#include <wtf/StdLibExtras.h>
namespace WebCore {
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(SVGElement* ownerElement, const QualifiedName& attrName, const AtomicString& value)
{
ownerElement->setSynchronizedLazyAttribute(attrName, value);
}
PropertyType value;
bool shouldSynchronize : 1;
bool isValid : 1;
};
#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 }
#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; \
}
#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 (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
#define DECLARE_ANIMATED_LIST_PROPERTY(TearOffType, PropertyType, UpperProperty, LowerProperty) \
DECLARE_ANIMATED_PROPERTY(TearOffType, PropertyType, UpperProperty, LowerProperty) \
void detachAnimated##UpperProperty##ListWrappers(unsigned newListSize) \
{ \
if (TearOffType* wrapper = SVGAnimatedProperty::lookupWrapper<UseOwnerType, TearOffType>(this, LowerProperty##PropertyInfo())) \
wrapper->detachListWrappers(newListSize); \
}
}
#endif // ENABLE(SVG)
#endif // SVGAnimatedPropertyMacros_h