diff options
Diffstat (limited to 'Source/WebCore/svg/SVGAnimatedAngle.cpp')
-rw-r--r-- | Source/WebCore/svg/SVGAnimatedAngle.cpp | 97 |
1 files changed, 44 insertions, 53 deletions
diff --git a/Source/WebCore/svg/SVGAnimatedAngle.cpp b/Source/WebCore/svg/SVGAnimatedAngle.cpp index f3e3b2ec9..c573255ec 100644 --- a/Source/WebCore/svg/SVGAnimatedAngle.cpp +++ b/Source/WebCore/svg/SVGAnimatedAngle.cpp @@ -18,11 +18,9 @@ */ #include "config.h" - -#if ENABLE(SVG) #include "SVGAnimatedAngle.h" -#include "SVGAnimateElement.h" +#include "SVGAnimateElementBase.h" #include "SVGMarkerElement.h" namespace WebCore { @@ -34,11 +32,11 @@ SVGAnimatedAngleAnimator::SVGAnimatedAngleAnimator(SVGAnimationElement* animatio std::unique_ptr<SVGAnimatedType> SVGAnimatedAngleAnimator::constructFromString(const String& string) { - auto animatedType = SVGAnimatedType::createAngleAndEnumeration(std::make_unique<std::pair<SVGAngle, unsigned>>()); - std::pair<SVGAngle, unsigned>& animatedPair = animatedType->angleAndEnumeration(); + auto animatedType = SVGAnimatedType::createAngleAndEnumeration(std::make_unique<std::pair<SVGAngleValue, unsigned>>()); + auto& animatedPair = animatedType->angleAndEnumeration(); - SVGAngle angle; - SVGMarkerOrientType orientType = SVGPropertyTraits<SVGMarkerOrientType>::fromString(string, angle); + SVGAngleValue angle; + SVGMarkerOrientType orientType = SVGPropertyTraits<SVGMarkerOrientType>::fromString(string, angle); if (orientType > 0) animatedPair.second = orientType; if (orientType == SVGMarkerOrientAngle) @@ -57,7 +55,7 @@ void SVGAnimatedAngleAnimator::stopAnimValAnimation(const SVGElementAnimatedProp stopAnimValAnimationForTypes<SVGAnimatedAngle, SVGAnimatedEnumeration>(animatedTypes); } -void SVGAnimatedAngleAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType* type) +void SVGAnimatedAngleAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType& type) { resetFromBaseValues<SVGAnimatedAngle, SVGAnimatedEnumeration>(animatedTypes, type, &SVGAnimatedType::angleAndEnumeration); } @@ -77,13 +75,13 @@ void SVGAnimatedAngleAnimator::addAnimatedTypes(SVGAnimatedType* from, SVGAnimat ASSERT(from->type() == AnimatedAngle); ASSERT(from->type() == to->type()); - const std::pair<SVGAngle, unsigned>& fromAngleAndEnumeration = from->angleAndEnumeration(); - std::pair<SVGAngle, unsigned>& toAngleAndEnumeration = to->angleAndEnumeration(); + const auto& fromAngleAndEnumeration = from->angleAndEnumeration(); + auto& toAngleAndEnumeration = to->angleAndEnumeration(); // Only respect by animations, if from and by are both specified in angles (and not eg. 'auto'). if (fromAngleAndEnumeration.second != toAngleAndEnumeration.second || fromAngleAndEnumeration.second != SVGMarkerOrientAngle) return; - const SVGAngle& fromAngle = fromAngleAndEnumeration.first; - SVGAngle& toAngle = toAngleAndEnumeration.first; + const auto& fromAngle = fromAngleAndEnumeration.first; + auto& toAngle = toAngleAndEnumeration.first; toAngle.setValue(toAngle.value() + fromAngle.value()); } @@ -92,64 +90,57 @@ void SVGAnimatedAngleAnimator::calculateAnimatedValue(float percentage, unsigned ASSERT(m_animationElement); ASSERT(m_contextElement); - const std::pair<SVGAngle, unsigned>& fromAngleAndEnumeration = m_animationElement->animationMode() == ToAnimation ? animated->angleAndEnumeration() : from->angleAndEnumeration(); - const std::pair<SVGAngle, unsigned>& toAngleAndEnumeration = to->angleAndEnumeration(); - const std::pair<SVGAngle, unsigned>& toAtEndOfDurationAngleAndEnumeration = toAtEndOfDuration->angleAndEnumeration(); - std::pair<SVGAngle, unsigned>& animatedAngleAndEnumeration = animated->angleAndEnumeration(); + const auto& fromAngleAndEnumeration = m_animationElement->animationMode() == ToAnimation ? animated->angleAndEnumeration() : from->angleAndEnumeration(); + auto& toAngleAndEnumeration = to->angleAndEnumeration(); + auto& toAtEndOfDurationAngleAndEnumeration = toAtEndOfDuration->angleAndEnumeration(); + auto& animatedAngleAndEnumeration = animated->angleAndEnumeration(); if (fromAngleAndEnumeration.second != toAngleAndEnumeration.second) { - // Animating from eg. auto to 90deg, or auto to 90deg. - if (fromAngleAndEnumeration.second == SVGMarkerOrientAngle) { - // Animating from an angle value to eg. 'auto' - this disabled additive as 'auto' is a keyword.. - if (toAngleAndEnumeration.second == SVGMarkerOrientAuto) { - if (percentage < 0.5f) { - animatedAngleAndEnumeration.first = fromAngleAndEnumeration.first; - animatedAngleAndEnumeration.second = SVGMarkerOrientAngle; - return; - } + // Discrete animation - no linear interpolation possible between values (e.g. auto to angle). + if (percentage < 0.5f) { + animatedAngleAndEnumeration.second = fromAngleAndEnumeration.second; + if (fromAngleAndEnumeration.second == SVGMarkerOrientAngle) + animatedAngleAndEnumeration.first = fromAngleAndEnumeration.first; + else animatedAngleAndEnumeration.first.setValue(0); - animatedAngleAndEnumeration.second = SVGMarkerOrientAuto; - return; - } - animatedAngleAndEnumeration.first.setValue(0); - animatedAngleAndEnumeration.second = SVGMarkerOrientUnknown; return; } - } - - // From 'auto' to 'auto'. - if (fromAngleAndEnumeration.second == SVGMarkerOrientAuto) { - animatedAngleAndEnumeration.first.setValue(0); - animatedAngleAndEnumeration.second = SVGMarkerOrientAuto; + animatedAngleAndEnumeration.second = toAngleAndEnumeration.second; + if (toAngleAndEnumeration.second == SVGMarkerOrientAngle) + animatedAngleAndEnumeration.first = toAngleAndEnumeration.first; + else + animatedAngleAndEnumeration.first.setValue(0); return; } - // If the enumeration value is not angle or auto, its unknown. - if (fromAngleAndEnumeration.second != SVGMarkerOrientAngle) { - animatedAngleAndEnumeration.first.setValue(0); - animatedAngleAndEnumeration.second = SVGMarkerOrientUnknown; + if (fromAngleAndEnumeration.second == SVGMarkerOrientAngle) { + // Regular from angle to angle animation, with support for smooth interpolation, and additive and accumulated animation. + animatedAngleAndEnumeration.second = SVGMarkerOrientAngle; + + auto& animatedSVGAngle = animatedAngleAndEnumeration.first; + const auto& toAtEndOfDurationSVGAngle = toAtEndOfDurationAngleAndEnumeration.first; + float animatedAngle = animatedSVGAngle.value(); + m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromAngleAndEnumeration.first.value(), toAngleAndEnumeration.first.value(), toAtEndOfDurationSVGAngle.value(), animatedAngle); + animatedSVGAngle.setValue(animatedAngle); return; } - // Regular from angle to angle animation, with all features like additive etc. - animatedAngleAndEnumeration.second = SVGMarkerOrientAngle; + // auto, auto-start-reverse, or unknown. + animatedAngleAndEnumeration.first.setValue(0); - SVGAngle& animatedSVGAngle = animatedAngleAndEnumeration.first; - const SVGAngle& toAtEndOfDurationSVGAngle = toAtEndOfDurationAngleAndEnumeration.first; - float animatedAngle = animatedSVGAngle.value(); - m_animationElement->animateAdditiveNumber(percentage, repeatCount, fromAngleAndEnumeration.first.value(), toAngleAndEnumeration.first.value(), toAtEndOfDurationSVGAngle.value(), animatedAngle); - animatedSVGAngle.setValue(animatedAngle); + if (fromAngleAndEnumeration.second == SVGMarkerOrientAuto || fromAngleAndEnumeration.second == SVGMarkerOrientAutoStartReverse) + animatedAngleAndEnumeration.second = fromAngleAndEnumeration.second; + else + animatedAngleAndEnumeration.second = SVGMarkerOrientUnknown; } float SVGAnimatedAngleAnimator::calculateDistance(const String& fromString, const String& toString) { - SVGAngle from = SVGAngle(); - from.setValueAsString(fromString, ASSERT_NO_EXCEPTION); - SVGAngle to = SVGAngle(); - to.setValueAsString(toString, ASSERT_NO_EXCEPTION); + auto from = SVGAngleValue(); + from.setValueAsString(fromString); + auto to = SVGAngleValue(); + to.setValueAsString(toString); return fabsf(to.value() - from.value()); } } - -#endif // ENABLE(SVG) |