SVGAnimatedPointList.cpp [plain text]
#include "config.h"
#include "SVGAnimatedPointList.h"
#include "SVGAnimateElementBase.h"
#include "SVGParserUtilities.h"
#include "SVGPointList.h"
namespace WebCore {
SVGAnimatedPointListAnimator::SVGAnimatedPointListAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
: SVGAnimatedTypeAnimator(AnimatedPoints, animationElement, contextElement)
{
}
std::unique_ptr<SVGAnimatedType> SVGAnimatedPointListAnimator::constructFromString(const String& string)
{
auto animatedType = SVGAnimatedType::createPointList(std::make_unique<SVGPointList>());
pointsListFromSVGData(animatedType->pointList(), string);
return animatedType;
}
std::unique_ptr<SVGAnimatedType> SVGAnimatedPointListAnimator::startAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
{
return SVGAnimatedType::createPointList(constructFromBaseValue<SVGAnimatedPointList>(animatedTypes));
}
void SVGAnimatedPointListAnimator::stopAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
{
stopAnimValAnimationForType<SVGAnimatedPointList>(animatedTypes);
}
void SVGAnimatedPointListAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType* type)
{
resetFromBaseValue<SVGAnimatedPointList>(animatedTypes, type, &SVGAnimatedType::pointList);
}
void SVGAnimatedPointListAnimator::animValWillChange(const SVGElementAnimatedPropertyList& animatedTypes)
{
animValWillChangeForType<SVGAnimatedPointList>(animatedTypes);
}
void SVGAnimatedPointListAnimator::animValDidChange(const SVGElementAnimatedPropertyList& animatedTypes)
{
animValDidChangeForType<SVGAnimatedPointList>(animatedTypes);
}
void SVGAnimatedPointListAnimator::addAnimatedTypes(SVGAnimatedType* from, SVGAnimatedType* to)
{
ASSERT(from->type() == AnimatedPoints);
ASSERT(from->type() == to->type());
const SVGPointList& fromPointList = from->pointList();
SVGPointList& toPointList = to->pointList();
unsigned fromPointListSize = fromPointList.size();
if (!fromPointListSize || fromPointListSize != toPointList.size())
return;
for (unsigned i = 0; i < fromPointListSize; ++i)
toPointList[i] += fromPointList[i];
}
void SVGAnimatedPointListAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGAnimatedType* from, SVGAnimatedType* to, SVGAnimatedType* toAtEndOfDuration, SVGAnimatedType* animated)
{
ASSERT(m_animationElement);
const SVGPointList& fromPointList = m_animationElement->animationMode() == ToAnimation ? animated->pointList() : from->pointList();
const SVGPointList& toPointList = to->pointList();
const SVGPointList& toAtEndOfDurationPointList = toAtEndOfDuration->pointList();
SVGPointList& animatedPointList = animated->pointList();
if (!m_animationElement->adjustFromToListValues<SVGPointList>(fromPointList, toPointList, animatedPointList, percentage))
return;
unsigned fromPointListSize = fromPointList.size();
unsigned toPointListSize = toPointList.size();
unsigned toAtEndOfDurationSize = toAtEndOfDurationPointList.size();
for (unsigned i = 0; i < toPointListSize; ++i) {
FloatPoint effectiveFrom;
if (fromPointListSize)
effectiveFrom = fromPointList[i];
FloatPoint effectiveToAtEnd = i < toAtEndOfDurationSize ? toAtEndOfDurationPointList[i] : FloatPoint();
float animatedX = animatedPointList[i].x();
float animatedY = animatedPointList[i].y();
m_animationElement->animateAdditiveNumber(percentage, repeatCount, effectiveFrom.x(), toPointList[i].x(), effectiveToAtEnd.x(), animatedX);
m_animationElement->animateAdditiveNumber(percentage, repeatCount, effectiveFrom.y(), toPointList[i].y(), effectiveToAtEnd.y(), animatedY);
animatedPointList[i] = FloatPoint(animatedX, animatedY);
}
}
float SVGAnimatedPointListAnimator::calculateDistance(const String&, const String&)
{
return -1;
}
}