summaryrefslogtreecommitdiff
path: root/Source/WebCore/svg/SVGAnimatedLength.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/svg/SVGAnimatedLength.cpp')
-rw-r--r--Source/WebCore/svg/SVGAnimatedLength.cpp52
1 files changed, 22 insertions, 30 deletions
diff --git a/Source/WebCore/svg/SVGAnimatedLength.cpp b/Source/WebCore/svg/SVGAnimatedLength.cpp
index 922fbfeb7..ab58f1831 100644
--- a/Source/WebCore/svg/SVGAnimatedLength.cpp
+++ b/Source/WebCore/svg/SVGAnimatedLength.cpp
@@ -18,31 +18,23 @@
*/
#include "config.h"
-
-#if ENABLE(SVG)
#include "SVGAnimatedLength.h"
-#include "SVGAnimateElement.h"
+#include "SVGAnimateElementBase.h"
#include "SVGAnimatedNumber.h"
+#include <wtf/NeverDestroyed.h>
namespace WebCore {
SVGAnimatedLengthAnimator::SVGAnimatedLengthAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
: SVGAnimatedTypeAnimator(AnimatedLength, animationElement, contextElement)
- , m_lengthMode(SVGLength::lengthModeForAnimatedLengthAttribute(animationElement->attributeName()))
+ , m_lengthMode(SVGLengthValue::lengthModeForAnimatedLengthAttribute(animationElement->attributeName()))
{
}
-static inline SVGLength& sharedSVGLength(SVGLengthMode mode, const String& valueAsString)
-{
- DEFINE_STATIC_LOCAL(SVGLength, sharedLength, ());
- sharedLength.setValueAsString(valueAsString, mode, ASSERT_NO_EXCEPTION);
- return sharedLength;
-}
-
std::unique_ptr<SVGAnimatedType> SVGAnimatedLengthAnimator::constructFromString(const String& string)
{
- return SVGAnimatedType::createLength(std::make_unique<SVGLength>(m_lengthMode, string));
+ return SVGAnimatedType::createLength(std::make_unique<SVGLengthValue>(m_lengthMode, string));
}
std::unique_ptr<SVGAnimatedType> SVGAnimatedLengthAnimator::startAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
@@ -55,7 +47,7 @@ void SVGAnimatedLengthAnimator::stopAnimValAnimation(const SVGElementAnimatedPro
stopAnimValAnimationForType<SVGAnimatedLength>(animatedTypes);
}
-void SVGAnimatedLengthAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType* type)
+void SVGAnimatedLengthAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType& type)
{
resetFromBaseValue<SVGAnimatedLength>(animatedTypes, type, &SVGAnimatedType::length);
}
@@ -76,15 +68,17 @@ void SVGAnimatedLengthAnimator::addAnimatedTypes(SVGAnimatedType* from, SVGAnima
ASSERT(from->type() == to->type());
SVGLengthContext lengthContext(m_contextElement);
- const SVGLength& fromLength = from->length();
- SVGLength& toLength = to->length();
+ const auto& fromLength = from->length();
+ auto& toLength = to->length();
- toLength.setValue(toLength.value(lengthContext) + fromLength.value(lengthContext), lengthContext, ASSERT_NO_EXCEPTION);
+ toLength.setValue(toLength.value(lengthContext) + fromLength.value(lengthContext), lengthContext);
}
-static SVGLength parseLengthFromString(SVGAnimationElement* animationElement, const String& string)
+static SVGLengthValue parseLengthFromString(SVGAnimationElement* animationElement, const String& string)
{
- return sharedSVGLength(SVGLength::lengthModeForAnimatedLengthAttribute(animationElement->attributeName()), string);
+ SVGLengthValue length;
+ length.setValueAsString(string, SVGLengthValue::lengthModeForAnimatedLengthAttribute(animationElement->attributeName()));
+ return length;
}
void SVGAnimatedLengthAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGAnimatedType* from, SVGAnimatedType* to, SVGAnimatedType* toAtEndOfDuration, SVGAnimatedType* animated)
@@ -92,34 +86,32 @@ void SVGAnimatedLengthAnimator::calculateAnimatedValue(float percentage, unsigne
ASSERT(m_animationElement);
ASSERT(m_contextElement);
- SVGLength fromSVGLength = m_animationElement->animationMode() == ToAnimation ? animated->length() : from->length();
- SVGLength toSVGLength = to->length();
- const SVGLength& toAtEndOfDurationSVGLength = toAtEndOfDuration->length();
- SVGLength& animatedSVGLength = animated->length();
+ auto fromSVGLength = m_animationElement->animationMode() == ToAnimation ? animated->length() : from->length();
+ auto toSVGLength = to->length();
+ const auto& toAtEndOfDurationSVGLength = toAtEndOfDuration->length();
+ auto& animatedSVGLength = animated->length();
// Apply CSS inheritance rules.
- m_animationElement->adjustForInheritance<SVGLength>(parseLengthFromString, m_animationElement->fromPropertyValueType(), fromSVGLength, m_contextElement);
- m_animationElement->adjustForInheritance<SVGLength>(parseLengthFromString, m_animationElement->toPropertyValueType(), toSVGLength, m_contextElement);
+ m_animationElement->adjustForInheritance<SVGLengthValue>(parseLengthFromString, m_animationElement->fromPropertyValueType(), fromSVGLength, m_contextElement);
+ m_animationElement->adjustForInheritance<SVGLengthValue>(parseLengthFromString, m_animationElement->toPropertyValueType(), toSVGLength, m_contextElement);
SVGLengthContext lengthContext(m_contextElement);
float animatedNumber = animatedSVGLength.value(lengthContext);
SVGLengthType unitType = percentage < 0.5 ? fromSVGLength.unitType() : toSVGLength.unitType();
m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromSVGLength.value(lengthContext), toSVGLength.value(lengthContext), toAtEndOfDurationSVGLength.value(lengthContext), animatedNumber);
- animatedSVGLength.setValue(lengthContext, animatedNumber, m_lengthMode, unitType, ASSERT_NO_EXCEPTION);
+ animatedSVGLength.setValue(lengthContext, animatedNumber, m_lengthMode, unitType);
}
float SVGAnimatedLengthAnimator::calculateDistance(const String& fromString, const String& toString)
{
ASSERT(m_animationElement);
ASSERT(m_contextElement);
- SVGLengthMode lengthMode = SVGLength::lengthModeForAnimatedLengthAttribute(m_animationElement->attributeName());
- SVGLength from = SVGLength(lengthMode, fromString);
- SVGLength to = SVGLength(lengthMode, toString);
+ auto lengthMode = SVGLengthValue::lengthModeForAnimatedLengthAttribute(m_animationElement->attributeName());
+ auto from = SVGLengthValue(lengthMode, fromString);
+ auto to = SVGLengthValue(lengthMode, toString);
SVGLengthContext lengthContext(m_contextElement);
return fabsf(to.value(lengthContext) - from.value(lengthContext));
}
}
-
-#endif // ENABLE(SVG)