#ifndef SVGPropertyTearOff_h
#define SVGPropertyTearOff_h
#include "core/dom/QualifiedName.h"
#include "core/svg/properties/SVGProperty.h"
#include "wtf/RefCounted.h"
namespace WebCore {
enum PropertyIsAnimValType {
PropertyIsNotAnimVal,
PropertyIsAnimVal
};
class SVGPropertyTearOffBase : public RefCounted<SVGPropertyTearOffBase> {
public:
virtual ~SVGPropertyTearOffBase() { }
PropertyIsAnimValType propertyIsAnimVal() const
{
return m_propertyIsAnimVal;
}
bool isAnimVal() const
{
return m_propertyIsAnimVal == PropertyIsAnimVal;
}
bool isReadOnlyProperty() const
{
return m_isReadOnlyProperty;
}
void setIsReadOnlyProperty()
{
m_isReadOnlyProperty = true;
}
bool isImmutable() const
{
return isReadOnlyProperty() || isAnimVal();
}
virtual void commitChange();
SVGElement* contextElement()
{
return m_contextElement;
}
const QualifiedName& attributeName()
{
return m_attributeName;
}
virtual AnimatedPropertyType type() const = 0;
protected:
SVGPropertyTearOffBase(SVGElement* contextElement, PropertyIsAnimValType propertyIsAnimVal, const QualifiedName& attributeName = nullQName())
: m_contextElement(contextElement)
, m_propertyIsAnimVal(propertyIsAnimVal)
, m_isReadOnlyProperty(false)
, m_attributeName(attributeName)
{
}
private:
SVGElement* m_contextElement;
PropertyIsAnimValType m_propertyIsAnimVal;
bool m_isReadOnlyProperty;
QualifiedName m_attributeName;
};
template <typename Property>
class SVGPropertyTearOff : public SVGPropertyTearOffBase {
public:
Property* target()
{
return m_target.get();
}
void setTarget(PassRefPtr<Property> target)
{
m_target = target;
}
virtual AnimatedPropertyType type() const OVERRIDE
{
return Property::classType();
}
protected:
SVGPropertyTearOff(PassRefPtr<Property> target, SVGElement* contextElement, PropertyIsAnimValType propertyIsAnimVal, const QualifiedName& attributeName = nullQName())
: SVGPropertyTearOffBase(contextElement, propertyIsAnimVal, attributeName)
, m_target(target)
{
ASSERT(m_target);
}
private:
RefPtr<Property> m_target;
};
}
#endif