SVGAnimatedListPropertyTearOff.h [plain text]
#ifndef SVGAnimatedListPropertyTearOff_h
#define SVGAnimatedListPropertyTearOff_h
#if ENABLE(SVG)
#include "SVGAnimatedProperty.h"
#include "SVGListPropertyTearOff.h"
#include "SVGStaticListPropertyTearOff.h"
namespace WebCore {
template<typename PropertyType>
class SVGPropertyTearOff;
template<typename PropertyType>
class SVGAnimatedListPropertyTearOff : public SVGAnimatedProperty {
public:
typedef typename SVGPropertyTraits<PropertyType>::ListItemType ListItemType;
typedef SVGPropertyTearOff<ListItemType> ListItemTearOff;
typedef Vector<RefPtr<ListItemTearOff> > ListWrapperCache;
SVGProperty* baseVal()
{
if (!m_baseVal)
m_baseVal = SVGListPropertyTearOff<PropertyType>::create(this, BaseValRole);
return m_baseVal.get();
}
SVGProperty* animVal()
{
if (!m_animVal)
m_animVal = SVGListPropertyTearOff<PropertyType>::create(this, AnimValRole);
return m_animVal.get();
}
virtual bool isAnimatedListTearOff() const { return true; }
int removeItemFromList(SVGProperty* property, bool shouldSynchronizeWrappers)
{
typedef SVGPropertyTearOff<typename SVGPropertyTraits<PropertyType>::ListItemType> ListItemTearOff;
return static_pointer_cast<SVGListPropertyTearOff<PropertyType> >(m_baseVal)->removeItemFromList(static_cast<ListItemTearOff*>(property), shouldSynchronizeWrappers);
}
void detachListWrappers(unsigned newListSize)
{
unsigned size = m_wrappers.size();
ASSERT(size == m_values.size());
for (unsigned i = 0; i < size; ++i) {
RefPtr<ListItemTearOff>& item = m_wrappers.at(i);
if (!item)
continue;
item->detachWrapper();
}
if (newListSize)
m_wrappers.fill(0, newListSize);
else
m_wrappers.clear();
}
PropertyType& values() { return m_values; }
ListWrapperCache& wrappers() { return m_wrappers; }
private:
friend class SVGAnimatedProperty;
static PassRefPtr<SVGAnimatedListPropertyTearOff<PropertyType> > create(SVGElement* contextElement, const QualifiedName& attributeName, PropertyType& values)
{
ASSERT(contextElement);
return adoptRef(new SVGAnimatedListPropertyTearOff<PropertyType>(contextElement, attributeName, values));
}
protected:
SVGAnimatedListPropertyTearOff(SVGElement* contextElement, const QualifiedName& attributeName, PropertyType& values)
: SVGAnimatedProperty(contextElement, attributeName)
, m_values(values)
{
if (!values.isEmpty())
m_wrappers.fill(0, values.size());
}
PropertyType& m_values;
ListWrapperCache m_wrappers;
RefPtr<SVGProperty> m_baseVal;
RefPtr<SVGProperty> m_animVal;
};
}
#endif // ENABLE(SVG)
#endif // SVGAnimatedListPropertyTearOff_h