summaryrefslogtreecommitdiff
path: root/Source/WebCore/svg/SVGAnimateMotionElement.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/svg/SVGAnimateMotionElement.cpp')
-rw-r--r--Source/WebCore/svg/SVGAnimateMotionElement.cpp68
1 files changed, 26 insertions, 42 deletions
diff --git a/Source/WebCore/svg/SVGAnimateMotionElement.cpp b/Source/WebCore/svg/SVGAnimateMotionElement.cpp
index 8bb615048..e808d7969 100644
--- a/Source/WebCore/svg/SVGAnimateMotionElement.cpp
+++ b/Source/WebCore/svg/SVGAnimateMotionElement.cpp
@@ -20,16 +20,12 @@
*/
#include "config.h"
-
-#if ENABLE(SVG)
#include "SVGAnimateMotionElement.h"
#include "AffineTransform.h"
-#include "Attribute.h"
#include "ElementIterator.h"
-#include "RenderObject.h"
+#include "PathTraversalState.h"
#include "RenderSVGResource.h"
-#include "SVGElementInstance.h"
#include "SVGImageElement.h"
#include "SVGMPathElement.h"
#include "SVGNames.h"
@@ -37,9 +33,9 @@
#include "SVGPathData.h"
#include "SVGPathElement.h"
#include "SVGPathUtilities.h"
-#include "SVGTransformList.h"
#include <wtf/MathExtras.h>
#include <wtf/StdLibExtras.h>
+#include <wtf/text/StringView.h>
namespace WebCore {
@@ -49,13 +45,13 @@ inline SVGAnimateMotionElement::SVGAnimateMotionElement(const QualifiedName& tag
: SVGAnimationElement(tagName, document)
, m_hasToPointAtEndOfDuration(false)
{
- setCalcMode(CalcModePaced);
+ setCalcMode(CalcMode::Paced);
ASSERT(hasTagName(animateMotionTag));
}
-PassRefPtr<SVGAnimateMotionElement> SVGAnimateMotionElement::create(const QualifiedName& tagName, Document& document)
+Ref<SVGAnimateMotionElement> SVGAnimateMotionElement::create(const QualifiedName& tagName, Document& document)
{
- return adoptRef(new SVGAnimateMotionElement(tagName, document));
+ return adoptRef(*new SVGAnimateMotionElement(tagName, document));
}
bool SVGAnimateMotionElement::hasValidAttributeType()
@@ -72,7 +68,7 @@ bool SVGAnimateMotionElement::hasValidAttributeType()
if (targetElement->hasTagName(gTag)
|| targetElement->hasTagName(defsTag)
|| targetElement->hasTagName(useTag)
- || isSVGImageElement(targetElement)
+ || is<SVGImageElement>(*targetElement)
|| targetElement->hasTagName(switchTag)
|| targetElement->hasTagName(pathTag)
|| targetElement->hasTagName(rectTag)
@@ -97,21 +93,8 @@ bool SVGAnimateMotionElement::hasValidAttributeName()
return true;
}
-bool SVGAnimateMotionElement::isSupportedAttribute(const QualifiedName& attrName)
-{
- DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
- if (supportedAttributes.isEmpty())
- supportedAttributes.add(SVGNames::pathAttr);
- return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
-}
-
void SVGAnimateMotionElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
- if (!isSupportedAttribute(name)) {
- SVGAnimationElement::parseAttribute(name, value);
- return;
- }
-
if (name == SVGNames::pathAttr) {
m_path = Path();
buildPathFromString(value, m_path);
@@ -119,13 +102,13 @@ void SVGAnimateMotionElement::parseAttribute(const QualifiedName& name, const At
return;
}
- ASSERT_NOT_REACHED();
+ SVGAnimationElement::parseAttribute(name, value);
}
SVGAnimateMotionElement::RotateMode SVGAnimateMotionElement::rotateMode() const
{
- DEFINE_STATIC_LOCAL(const AtomicString, autoVal, ("auto", AtomicString::ConstructFromLiteral));
- DEFINE_STATIC_LOCAL(const AtomicString, autoReverse, ("auto-reverse", AtomicString::ConstructFromLiteral));
+ static NeverDestroyed<const AtomicString> autoVal("auto", AtomicString::ConstructFromLiteral);
+ static NeverDestroyed<const AtomicString> autoReverse("auto-reverse", AtomicString::ConstructFromLiteral);
const AtomicString& rotate = getAttribute(SVGNames::rotateAttr);
if (rotate == autoVal)
return RotateAuto;
@@ -148,7 +131,7 @@ void SVGAnimateMotionElement::updateAnimationPath()
}
}
- if (!foundMPath && fastHasAttribute(SVGNames::pathAttr))
+ if (!foundMPath && hasAttributeWithoutSynchronization(SVGNames::pathAttr))
m_animationPath = m_path;
updateAnimationMode();
@@ -158,7 +141,8 @@ static bool parsePoint(const String& s, FloatPoint& point)
{
if (s.isEmpty())
return false;
- const UChar* cur = s.deprecatedCharacters();
+ auto upconvertedCharacters = StringView(s).upconvertedCharacters();
+ const UChar* cur = upconvertedCharacters;
const UChar* end = cur + s.length();
if (!skipOptionalSVGSpaces(cur, end))
@@ -228,16 +212,19 @@ void SVGAnimateMotionElement::buildTransformForProgress(AffineTransform* transfo
{
ASSERT(!m_animationPath.isEmpty());
- bool ok = false;
+ bool success = false;
float positionOnPath = m_animationPath.length() * percentage;
- FloatPoint position = m_animationPath.pointAtLength(positionOnPath, ok);
- if (!ok)
+ auto traversalState(m_animationPath.traversalStateAtLength(positionOnPath, success));
+ if (!success)
return;
+
+ FloatPoint position = traversalState.current();
+ float angle = traversalState.normalAngle();
+
transform->translate(position.x(), position.y());
RotateMode rotateMode = this->rotateMode();
if (rotateMode != RotateAuto && rotateMode != RotateAutoReverse)
return;
- float angle = m_animationPath.normalAngleAtLength(positionOnPath, ok);
if (rotateMode == RotateAutoReverse)
angle += 180;
transform->rotate(angle);
@@ -292,19 +279,17 @@ void SVGAnimateMotionElement::applyResultsToTarget()
if (RenderElement* renderer = targetElement->renderer())
RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer);
- AffineTransform* t = targetElement->supplementalTransform();
- if (!t)
+ AffineTransform* targetSupplementalTransform = targetElement->supplementalTransform();
+ if (!targetSupplementalTransform)
return;
// ...except in case where we have additional instances in <use> trees.
- for (auto instance : targetElement->instancesForElement()) {
- SVGElement* shadowTreeElement = instance->shadowTreeElement();
- ASSERT(shadowTreeElement);
- AffineTransform* transform = shadowTreeElement->supplementalTransform();
- if (!transform)
+ for (auto* instance : targetElement->instances()) {
+ AffineTransform* transform = instance->supplementalTransform();
+ if (!transform || *transform == *targetSupplementalTransform)
continue;
- transform->setMatrix(t->a(), t->b(), t->c(), t->d(), t->e(), t->f());
- if (RenderElement* renderer = shadowTreeElement->renderer()) {
+ *transform = *targetSupplementalTransform;
+ if (RenderElement* renderer = instance->renderer()) {
renderer->setNeedsTransformUpdate();
RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer);
}
@@ -332,4 +317,3 @@ void SVGAnimateMotionElement::updateAnimationMode()
}
}
-#endif // ENABLE(SVG)