SVGAnimatedPathSegListPropertyTearOff.h [plain text]
#pragma once
#include "SVGAnimatedListPropertyTearOff.h"
#include "SVGPathByteStream.h"
#include "SVGPathElement.h"
#include "SVGPathSegList.h"
#include "SVGPathUtilities.h"
namespace WebCore {
class SVGAnimatedPathSegListPropertyTearOff final : public SVGAnimatedListPropertyTearOff<SVGPathSegListValues> {
public:
using Base = SVGAnimatedListPropertyTearOff<SVGPathSegListValues>;
static Ref<SVGAnimatedPathSegListPropertyTearOff> create(SVGElement* contextElement, const QualifiedName& attributeName, AnimatedPropertyType animatedPropertyType, SVGPathSegListValues& values)
{
ASSERT(contextElement);
return adoptRef(*new SVGAnimatedPathSegListPropertyTearOff(contextElement, attributeName, animatedPropertyType, values));
}
Ref<ListPropertyTearOff> baseVal() final
{
if (m_baseVal)
return *static_cast<ListPropertyTearOff*>(m_baseVal.get());
auto property = SVGPathSegList::create(*this, BaseValRole, PathSegUnalteredRole, m_values, m_wrappers);
m_baseVal = property->createWeakPtr();
return property;
}
Ref<ListPropertyTearOff> animVal() final
{
if (m_animVal)
return *static_cast<ListPropertyTearOff*>(m_animVal.get());
auto property = SVGPathSegList::create(*this, AnimValRole, PathSegUnalteredRole, m_values, m_wrappers);
m_animVal = property->createWeakPtr();
return property;
}
int findItem(const RefPtr<SVGPathSeg>& segment)
{
return baseVal()->findItem(segment);
}
void removeItemFromList(size_t itemIndex, bool shouldSynchronizeWrappers)
{
baseVal()->removeItemFromList(itemIndex, shouldSynchronizeWrappers);
}
using Base::animationStarted;
void animationStarted(SVGPathByteStream* byteStream, const SVGPathSegListValues* baseValue)
{
ASSERT(byteStream);
ASSERT(baseValue);
ASSERT(!m_animatedPathByteStream);
m_animatedPathByteStream = byteStream;
auto* copy = new SVGPathSegListValues(*baseValue);
Base::animationStarted(copy, true);
}
void animationEnded()
{
ASSERT(m_animatedPathByteStream);
m_animatedPathByteStream = nullptr;
Base::animationEnded();
}
void animValDidChange()
{
ASSERT(m_animatedPathByteStream);
auto pathElement = makeRefPtr(downcast<SVGPathElement>(contextElement()));
if (pathElement->isAnimValObserved()) {
auto& animatedList = currentAnimatedValue();
animatedList.clear();
buildSVGPathSegListValuesFromByteStream(*m_animatedPathByteStream, *pathElement, animatedList, UnalteredParsing);
}
Base::animValDidChange();
}
SVGPathByteStream* animatedPathByteStream() const { return m_animatedPathByteStream; }
private:
SVGAnimatedPathSegListPropertyTearOff(SVGElement* contextElement, const QualifiedName& attributeName, AnimatedPropertyType animatedPropertyType, SVGPathSegListValues& values)
: Base(contextElement, attributeName, animatedPropertyType, values)
, m_animatedPathByteStream(nullptr)
{
ASSERT(contextElement);
ASSERT(is<SVGPathElement>(contextElement));
}
virtual ~SVGAnimatedPathSegListPropertyTearOff()
{
downcast<SVGPathElement>(contextElement())->animatedPropertyWillBeDeleted();
}
SVGPathByteStream* m_animatedPathByteStream;
};
}