SVGAnimatedTransformList.cpp [plain text]
#include "config.h"
#if ENABLE(SVG)
#include "SVGAnimatedTransformList.h"
#include "SVGAnimateTransformElement.h"
#include "SVGAnimatedNumber.h"
#include "SVGNames.h"
#include "SVGTransformDistance.h"
namespace WebCore {
SVGAnimatedTransformListAnimator::SVGAnimatedTransformListAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
: SVGAnimatedTypeAnimator(AnimatedTransformList, animationElement, contextElement)
, m_transformTypeString(SVGTransform::transformTypePrefixForParsing(static_cast<SVGAnimateTransformElement*>(animationElement)->transformType()))
{
ASSERT(animationElement->hasTagName(SVGNames::animateTransformTag));
}
PassOwnPtr<SVGAnimatedType> SVGAnimatedTransformListAnimator::constructFromString(const String& string)
{
OwnPtr<SVGAnimatedType> animatedType = SVGAnimatedType::createTransformList(new SVGTransformList);
animatedType->transformList().parse(m_transformTypeString + string + ')');
ASSERT(animatedType->transformList().size() <= 1);
return animatedType.release();
}
PassOwnPtr<SVGAnimatedType> SVGAnimatedTransformListAnimator::startAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
{
return SVGAnimatedType::createTransformList(constructFromBaseValue<SVGAnimatedTransformList>(animatedTypes));
}
void SVGAnimatedTransformListAnimator::stopAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
{
stopAnimValAnimationForType<SVGAnimatedTransformList>(animatedTypes);
}
void SVGAnimatedTransformListAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType* type)
{
resetFromBaseValue<SVGAnimatedTransformList>(animatedTypes, type, &SVGAnimatedType::transformList);
}
void SVGAnimatedTransformListAnimator::animValWillChange(const SVGElementAnimatedPropertyList& animatedTypes)
{
animValWillChangeForType<SVGAnimatedTransformList>(animatedTypes);
}
void SVGAnimatedTransformListAnimator::animValDidChange(const SVGElementAnimatedPropertyList& animatedTypes)
{
animValDidChangeForType<SVGAnimatedTransformList>(animatedTypes);
}
void SVGAnimatedTransformListAnimator::addAnimatedTypes(SVGAnimatedType* from, SVGAnimatedType* to)
{
ASSERT(from->type() == AnimatedTransformList);
ASSERT(from->type() == to->type());
const SVGTransformList& fromTransformList = from->transformList();
SVGTransformList& toTransformList = to->transformList();
unsigned fromTransformListSize = fromTransformList.size();
if (!fromTransformListSize || fromTransformListSize != toTransformList.size())
return;
ASSERT(fromTransformListSize == 1);
const SVGTransform& fromTransform = fromTransformList[0];
SVGTransform& toTransform = toTransformList[0];
ASSERT(fromTransform.type() == toTransform.type());
toTransform = SVGTransformDistance::addSVGTransforms(fromTransform, toTransform);
}
void SVGAnimatedTransformListAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGAnimatedType* from, SVGAnimatedType* to, SVGAnimatedType* toAtEndOfDuration, SVGAnimatedType* animated)
{
ASSERT(m_animationElement);
const SVGTransformList& fromTransformList = m_animationElement->animationMode() == ToAnimation ? animated->transformList() : from->transformList();
const SVGTransformList& toTransformList = to->transformList();
const SVGTransformList& toAtEndOfDurationTransformList = toAtEndOfDuration->transformList();
SVGTransformList& animatedTransformList = animated->transformList();
if (!m_animationElement->adjustFromToListValues<SVGTransformList>(fromTransformList, toTransformList, animatedTransformList, percentage, false))
return;
if (!animatedTransformList.isEmpty() && !m_animationElement->isAdditive())
animatedTransformList.clear();
unsigned fromTransformListSize = fromTransformList.size();
const SVGTransform& toTransform = toTransformList[0];
SVGTransform effectiveFrom = fromTransformListSize ? fromTransformList[0] : SVGTransform(toTransform.type(), SVGTransform::ConstructZeroTransform);
SVGTransform currentTransform = SVGTransformDistance(effectiveFrom, toTransform).scaledDistance(percentage).addToSVGTransform(effectiveFrom);
if (m_animationElement->isAccumulated() && repeatCount)
animatedTransformList.append(SVGTransformDistance::addSVGTransforms(currentTransform, toAtEndOfDurationTransformList[0], repeatCount));
else
animatedTransformList.append(currentTransform);
}
float SVGAnimatedTransformListAnimator::calculateDistance(const String& fromString, const String& toString)
{
ASSERT(m_animationElement);
OwnPtr<SVGAnimatedType> from = constructFromString(fromString);
OwnPtr<SVGAnimatedType> to = constructFromString(toString);
SVGTransformList& fromTransformList = from->transformList();
SVGTransformList& toTransformList = to->transformList();
unsigned itemsCount = fromTransformList.size();
if (!itemsCount || itemsCount != toTransformList.size())
return -1;
ASSERT(itemsCount == 1);
if (fromTransformList[0].type() != toTransformList[0].type())
return -1;
return SVGTransformDistance(fromTransformList[0], toTransformList[0]).distance();
}
}
#endif // ENABLE(SVG)