SVGPropertyTearOff.h [plain text]
#ifndef SVGPropertyTearOff_h
#define SVGPropertyTearOff_h
#if ENABLE(SVG)
#include "SVGAnimatedProperty.h"
#include "SVGElement.h"
#include "SVGProperty.h"
namespace WebCore {
template<typename PropertyType>
class SVGPropertyTearOff : public SVGProperty {
public:
typedef SVGPropertyTearOff<PropertyType> Self;
static PassRefPtr<Self> create(SVGAnimatedProperty* animatedProperty, SVGPropertyRole role, PropertyType& value)
{
ASSERT(animatedProperty);
return adoptRef(new Self(animatedProperty, role, value));
}
static PassRefPtr<Self> create(const PropertyType& initialValue)
{
return adoptRef(new Self(initialValue));
}
PropertyType& propertyReference() { return *m_value; }
SVGAnimatedProperty* animatedProperty() const { return m_animatedProperty; }
void setValue(PropertyType& value)
{
if (m_valueIsCopy)
delete m_value;
m_valueIsCopy = false;
m_value = &value;
}
void setAnimatedProperty(SVGAnimatedProperty* animatedProperty)
{
m_animatedProperty = animatedProperty;
if (m_animatedProperty)
m_contextElement = m_animatedProperty->contextElement();
}
SVGElement* contextElement() const
{
if (!m_animatedProperty || m_valueIsCopy)
return 0;
return m_contextElement.get();
}
void detachWrapper()
{
if (m_valueIsCopy)
return;
m_value = new PropertyType(*m_value);
m_valueIsCopy = true;
m_animatedProperty = 0;
}
virtual void commitChange()
{
if (!m_animatedProperty || m_valueIsCopy)
return;
m_animatedProperty->commitChange();
}
virtual bool isReadOnly() const
{
if (m_role == AnimValRole)
return true;
if (m_animatedProperty && m_animatedProperty->isReadOnly())
return true;
return false;
}
protected:
SVGPropertyTearOff(SVGAnimatedProperty* animatedProperty, SVGPropertyRole role, PropertyType& value)
: m_animatedProperty(animatedProperty)
, m_role(role)
, m_value(&value)
, m_valueIsCopy(false)
{
if (m_animatedProperty)
m_contextElement = m_animatedProperty->contextElement();
}
SVGPropertyTearOff(const PropertyType& initialValue)
: m_animatedProperty(0)
, m_role(UndefinedRole)
, m_value(new PropertyType(initialValue))
, m_valueIsCopy(true)
{
}
virtual ~SVGPropertyTearOff()
{
if (m_valueIsCopy)
delete m_value;
}
RefPtr<SVGElement> m_contextElement;
SVGAnimatedProperty* m_animatedProperty;
SVGPropertyRole m_role;
PropertyType* m_value;
bool m_valueIsCopy : 1;
};
}
#endif // ENABLE(SVG)
#endif // SVGPropertyTearOff_h