SVGAnimatedInteger.cpp [plain text]
#include "config.h"
#include "SVGAnimatedInteger.h"
#include "SVGAnimateElementBase.h"
#include "SVGAnimatedNumber.h"
#include <wtf/MathExtras.h>
namespace WebCore {
SVGAnimatedIntegerAnimator::SVGAnimatedIntegerAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
: SVGAnimatedTypeAnimator(AnimatedInteger, animationElement, contextElement)
{
}
std::unique_ptr<SVGAnimatedType> SVGAnimatedIntegerAnimator::constructFromString(const String& string)
{
auto animatedType = SVGAnimatedType::createInteger(std::make_unique<int>());
animatedType->integer() = string.toIntStrict();
return animatedType;
}
std::unique_ptr<SVGAnimatedType> SVGAnimatedIntegerAnimator::startAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
{
return SVGAnimatedType::createInteger(constructFromBaseValue<SVGAnimatedInteger>(animatedTypes));
}
void SVGAnimatedIntegerAnimator::stopAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
{
stopAnimValAnimationForType<SVGAnimatedInteger>(animatedTypes);
}
void SVGAnimatedIntegerAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType& type)
{
resetFromBaseValue<SVGAnimatedInteger>(animatedTypes, type, &SVGAnimatedType::integer);
}
void SVGAnimatedIntegerAnimator::animValWillChange(const SVGElementAnimatedPropertyList& animatedTypes)
{
animValWillChangeForType<SVGAnimatedInteger>(animatedTypes);
}
void SVGAnimatedIntegerAnimator::animValDidChange(const SVGElementAnimatedPropertyList& animatedTypes)
{
animValDidChangeForType<SVGAnimatedInteger>(animatedTypes);
}
void SVGAnimatedIntegerAnimator::addAnimatedTypes(SVGAnimatedType* from, SVGAnimatedType* to)
{
ASSERT(from->type() == AnimatedInteger);
ASSERT(from->type() == to->type());
to->integer() += from->integer();
}
void SVGAnimatedIntegerAnimator::calculateAnimatedInteger(SVGAnimationElement* animationElement, float percentage, unsigned repeatCount, int fromInteger, int toInteger, int toAtEndOfDurationInteger, int& animatedInteger)
{
float animatedNumber = animatedInteger;
animationElement->animateAdditiveNumber(percentage, repeatCount, fromInteger, toInteger, toAtEndOfDurationInteger, animatedNumber);
animatedInteger = static_cast<int>(roundf(animatedNumber));
}
void SVGAnimatedIntegerAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGAnimatedType* from, SVGAnimatedType* to, SVGAnimatedType* toAtEndOfDuration, SVGAnimatedType* animated)
{
ASSERT(m_animationElement);
ASSERT(m_contextElement);
int fromInteger = m_animationElement->animationMode() == ToAnimation ? animated->integer() : from->integer();
int toInteger = to->integer();
int toAtEndOfDurationInteger = toAtEndOfDuration->integer();
int& animatedInteger = animated->integer();
calculateAnimatedInteger(m_animationElement, percentage, repeatCount, fromInteger, toInteger, toAtEndOfDurationInteger, animatedInteger);
}
float SVGAnimatedIntegerAnimator::calculateDistance(const String& fromString, const String& toString)
{
ASSERT(m_contextElement);
int from = fromString.toIntStrict();
int to = toString.toIntStrict();
return abs(to - from);
}
}