SVGAnimatedPath.cpp [plain text]
#include "config.h"
#include "SVGAnimatedPath.h"
#include "SVGAnimateElement.h"
#include "SVGAnimatedPathSegListPropertyTearOff.h"
#include "SVGPathUtilities.h"
namespace WebCore {
SVGAnimatedPathAnimator::SVGAnimatedPathAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
: SVGAnimatedTypeAnimator(AnimatedPath, animationElement, contextElement)
{
}
std::unique_ptr<SVGAnimatedType> SVGAnimatedPathAnimator::constructFromString(const String& string)
{
auto byteStream = std::make_unique<SVGPathByteStream>();
buildSVGPathByteStreamFromString(string, byteStream.get(), UnalteredParsing);
return SVGAnimatedType::createPath(WTF::move(byteStream));
}
std::unique_ptr<SVGAnimatedType> SVGAnimatedPathAnimator::startAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
{
ASSERT(animatedTypes.size() >= 1);
SVGAnimatedPathSegListPropertyTearOff* property = castAnimatedPropertyToActualType<SVGAnimatedPathSegListPropertyTearOff>(animatedTypes[0].properties[0].get());
const SVGPathSegList& baseValue = property->currentBaseValue();
auto byteStream = std::make_unique<SVGPathByteStream>();
buildSVGPathByteStreamFromSVGPathSegList(baseValue, byteStream.get(), UnalteredParsing);
Vector<RefPtr<SVGAnimatedPathSegListPropertyTearOff>> result;
SVGElementAnimatedPropertyList::const_iterator end = animatedTypes.end();
for (SVGElementAnimatedPropertyList::const_iterator it = animatedTypes.begin(); it != end; ++it)
result.append(castAnimatedPropertyToActualType<SVGAnimatedPathSegListPropertyTearOff>(it->properties[0].get()));
SVGElementInstance::InstanceUpdateBlocker blocker(property->contextElement());
size_t resultSize = result.size();
for (size_t i = 0; i < resultSize; ++i)
result[i]->animationStarted(byteStream.get(), &baseValue);
return SVGAnimatedType::createPath(WTF::move(byteStream));
}
void SVGAnimatedPathAnimator::stopAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
{
stopAnimValAnimationForType<SVGAnimatedPathSegListPropertyTearOff>(animatedTypes);
}
void SVGAnimatedPathAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType* type)
{
ASSERT(animatedTypes.size() >= 1);
ASSERT(type);
ASSERT(type->type() == m_type);
const SVGPathSegList& baseValue = castAnimatedPropertyToActualType<SVGAnimatedPathSegListPropertyTearOff>(animatedTypes[0].properties[0].get())->currentBaseValue();
buildSVGPathByteStreamFromSVGPathSegList(baseValue, type->path(), UnalteredParsing);
}
void SVGAnimatedPathAnimator::animValWillChange(const SVGElementAnimatedPropertyList& animatedTypes)
{
animValWillChangeForType<SVGAnimatedPathSegListPropertyTearOff>(animatedTypes);
}
void SVGAnimatedPathAnimator::animValDidChange(const SVGElementAnimatedPropertyList& animatedTypes)
{
animValDidChangeForType<SVGAnimatedPathSegListPropertyTearOff>(animatedTypes);
}
void SVGAnimatedPathAnimator::addAnimatedTypes(SVGAnimatedType* from, SVGAnimatedType* to)
{
ASSERT(from->type() == AnimatedPath);
ASSERT(from->type() == to->type());
SVGPathByteStream* fromPath = from->path();
SVGPathByteStream* toPath = to->path();
unsigned fromPathSize = fromPath->size();
if (!fromPathSize || fromPathSize != toPath->size())
return;
addToSVGPathByteStream(toPath, fromPath);
}
void SVGAnimatedPathAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGAnimatedType* from, SVGAnimatedType* to, SVGAnimatedType* toAtEndOfDuration, SVGAnimatedType* animated)
{
ASSERT(m_animationElement);
ASSERT(m_contextElement);
SVGPathByteStream* fromPath = from->path();
SVGPathByteStream* toPath = to->path();
SVGPathByteStream* toAtEndOfDurationPath = toAtEndOfDuration->path();
SVGPathByteStream* animatedPath = animated->path();
std::unique_ptr<SVGPathByteStream> underlyingPath;
bool isToAnimation = m_animationElement->animationMode() == ToAnimation;
if (isToAnimation) {
underlyingPath = animatedPath->copy();
fromPath = underlyingPath.get();
}
std::unique_ptr<SVGPathByteStream> lastAnimatedPath;
if (!fromPath->size() || (m_animationElement->isAdditive() && !isToAnimation))
lastAnimatedPath = animatedPath->copy();
if (!m_animationElement->adjustFromToListValues<SVGPathByteStream>(*fromPath, *toPath, *animatedPath, percentage, false))
return;
buildAnimatedSVGPathByteStream(fromPath, toPath, animatedPath, percentage);
if (lastAnimatedPath)
addToSVGPathByteStream(animatedPath, lastAnimatedPath.get());
if (m_animationElement->isAccumulated() && repeatCount)
addToSVGPathByteStream(animatedPath, toAtEndOfDurationPath, repeatCount);
}
float SVGAnimatedPathAnimator::calculateDistance(const String&, const String&)
{
return -1;
}
}