Commit ce89b516 authored by kouhei@chromium.org's avatar kouhei@chromium.org

SVG: remove |SVGAnimateElement::m_animatedPropertyType|

Before this patch, |SVGAnimateElement::m_animatedPropertyType|
was maintained along |SVGAnimatedTypeAnimator::m_type|,
and there were many ASSERTs checking that they were same.

In this patch, I removed
|SVGAnimateElement::m_animatedPropertyType| and changed
their references to point to
|SVGAnimatedTypeAnimator::m_type| instead.

BUG=378670

Review URL: https://codereview.chromium.org/303093002

git-svn-id: svn://svn.chromium.org/blink/trunk@175245 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 6a48dba8
...@@ -35,7 +35,6 @@ namespace WebCore { ...@@ -35,7 +35,6 @@ namespace WebCore {
SVGAnimateElement::SVGAnimateElement(const QualifiedName& tagName, Document& document) SVGAnimateElement::SVGAnimateElement(const QualifiedName& tagName, Document& document)
: SVGAnimationElement(tagName, document) : SVGAnimationElement(tagName, document)
, m_animatedPropertyType(AnimatedString)
{ {
ASSERT(isSVGAnimateElement(*this)); ASSERT(isSVGAnimateElement(*this));
ScriptWrappable::init(this); ScriptWrappable::init(this);
...@@ -55,13 +54,18 @@ SVGAnimateElement::~SVGAnimateElement() ...@@ -55,13 +54,18 @@ SVGAnimateElement::~SVGAnimateElement()
#endif #endif
} }
AnimatedPropertyType SVGAnimateElement::animatedPropertyType()
{
return ensureAnimator()->type();
}
bool SVGAnimateElement::hasValidAttributeType() bool SVGAnimateElement::hasValidAttributeType()
{ {
SVGElement* targetElement = this->targetElement(); SVGElement* targetElement = this->targetElement();
if (!targetElement) if (!targetElement)
return false; return false;
return m_animatedPropertyType != AnimatedUnknown && !hasInvalidCSSAttributeType(); return animatedPropertyType() != AnimatedUnknown && !hasInvalidCSSAttributeType();
} }
void SVGAnimateElement::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGSMILElement* resultElement) void SVGAnimateElement::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGSMILElement* resultElement)
...@@ -71,20 +75,17 @@ void SVGAnimateElement::calculateAnimatedValue(float percentage, unsigned repeat ...@@ -71,20 +75,17 @@ void SVGAnimateElement::calculateAnimatedValue(float percentage, unsigned repeat
if (!targetElement || !isSVGAnimateElement(*resultElement)) if (!targetElement || !isSVGAnimateElement(*resultElement))
return; return;
ASSERT(m_animatedPropertyType == determineAnimatedPropertyType());
ASSERT(percentage >= 0 && percentage <= 1); ASSERT(percentage >= 0 && percentage <= 1);
ASSERT(m_animatedPropertyType != AnimatedTransformList || isSVGAnimateTransformElement(*this));
ASSERT(m_animatedPropertyType != AnimatedUnknown);
ASSERT(m_animator); ASSERT(m_animator);
ASSERT(m_animator->type() == m_animatedPropertyType); ASSERT(animatedPropertyType() != AnimatedTransformList || isSVGAnimateTransformElement(*this));
ASSERT(animatedPropertyType() != AnimatedUnknown);
ASSERT(m_fromProperty); ASSERT(m_fromProperty);
ASSERT(m_fromProperty->type() == m_animatedPropertyType); ASSERT(m_fromProperty->type() == animatedPropertyType());
ASSERT(m_toProperty); ASSERT(m_toProperty);
SVGAnimateElement* resultAnimationElement = toSVGAnimateElement(resultElement); SVGAnimateElement* resultAnimationElement = toSVGAnimateElement(resultElement);
ASSERT(resultAnimationElement->m_animatedProperty); ASSERT(resultAnimationElement->m_animatedProperty);
ASSERT(resultAnimationElement->m_animatedPropertyType == m_animatedPropertyType); ASSERT(resultAnimationElement->animatedPropertyType() == animatedPropertyType());
if (isSVGSetElement(*this)) if (isSVGSetElement(*this))
percentage = 1; percentage = 1;
...@@ -116,7 +117,6 @@ bool SVGAnimateElement::calculateFromAndToValues(const String& fromString, const ...@@ -116,7 +117,6 @@ bool SVGAnimateElement::calculateFromAndToValues(const String& fromString, const
determinePropertyValueTypes(fromString, toString); determinePropertyValueTypes(fromString, toString);
ensureAnimator()->calculateFromAndToValues(m_fromProperty, m_toProperty, fromString, toString); ensureAnimator()->calculateFromAndToValues(m_fromProperty, m_toProperty, fromString, toString);
ASSERT(m_animatedPropertyType == m_animator->type());
return true; return true;
} }
...@@ -137,7 +137,6 @@ bool SVGAnimateElement::calculateFromAndByValues(const String& fromString, const ...@@ -137,7 +137,6 @@ bool SVGAnimateElement::calculateFromAndByValues(const String& fromString, const
determinePropertyValueTypes(fromString, byString); determinePropertyValueTypes(fromString, byString);
ensureAnimator()->calculateFromAndByValues(m_fromProperty, m_toProperty, fromString, byString); ensureAnimator()->calculateFromAndByValues(m_fromProperty, m_toProperty, fromString, byString);
ASSERT(m_animatedPropertyType == m_animator->type());
return true; return true;
} }
...@@ -165,7 +164,6 @@ WillBeHeapVector<RawPtrWillBeMember<SVGElement> > findElementInstances(SVGElemen ...@@ -165,7 +164,6 @@ WillBeHeapVector<RawPtrWillBeMember<SVGElement> > findElementInstances(SVGElemen
void SVGAnimateElement::resetAnimatedType() void SVGAnimateElement::resetAnimatedType()
{ {
SVGAnimatedTypeAnimator* animator = ensureAnimator(); SVGAnimatedTypeAnimator* animator = ensureAnimator();
ASSERT(m_animatedPropertyType == animator->type());
SVGElement* targetElement = this->targetElement(); SVGElement* targetElement = this->targetElement();
const QualifiedName& attributeName = this->attributeName(); const QualifiedName& attributeName = this->attributeName();
...@@ -319,15 +317,15 @@ void SVGAnimateElement::clearAnimatedType(SVGElement* targetElement) ...@@ -319,15 +317,15 @@ void SVGAnimateElement::clearAnimatedType(SVGElement* targetElement)
void SVGAnimateElement::applyResultsToTarget() void SVGAnimateElement::applyResultsToTarget()
{ {
ASSERT(m_animatedPropertyType != AnimatedTransformList || isSVGAnimateTransformElement(*this));
ASSERT(m_animatedPropertyType != AnimatedUnknown);
ASSERT(m_animator); ASSERT(m_animator);
ASSERT(animatedPropertyType() != AnimatedTransformList || isSVGAnimateTransformElement(*this));
ASSERT(animatedPropertyType() != AnimatedUnknown);
// Early exit if our animated type got destructed by a previous endedActiveInterval(). // Early exit if our animated type got destructed by a previous endedActiveInterval().
if (!m_animatedProperty) if (!m_animatedProperty)
return; return;
if (ensureAnimator()->isAnimatingCSSProperty()) { if (m_animator->isAnimatingCSSProperty()) {
// CSS properties animation code-path. // CSS properties animation code-path.
// Convert the result of the animation to a String and apply it as CSS property on the target & all instances. // Convert the result of the animation to a String and apply it as CSS property on the target & all instances.
applyCSSPropertyToTargetAndInstances(targetElement(), attributeName(), m_animatedProperty->valueAsString()); applyCSSPropertyToTargetAndInstances(targetElement(), attributeName(), m_animatedProperty->valueAsString());
...@@ -340,10 +338,10 @@ void SVGAnimateElement::applyResultsToTarget() ...@@ -340,10 +338,10 @@ void SVGAnimateElement::applyResultsToTarget()
notifyTargetAndInstancesAboutAnimValChange(targetElement(), attributeName()); notifyTargetAndInstancesAboutAnimValChange(targetElement(), attributeName());
} }
bool SVGAnimateElement::animatedPropertyTypeSupportsAddition() const bool SVGAnimateElement::animatedPropertyTypeSupportsAddition()
{ {
// Spec: http://www.w3.org/TR/SVG/animate.html#AnimationAttributesAndProperties. // Spec: http://www.w3.org/TR/SVG/animate.html#AnimationAttributesAndProperties.
switch (m_animatedPropertyType) { switch (animatedPropertyType()) {
case AnimatedBoolean: case AnimatedBoolean:
case AnimatedEnumeration: case AnimatedEnumeration:
case AnimatedPreserveAspectRatio: case AnimatedPreserveAspectRatio:
...@@ -355,7 +353,7 @@ bool SVGAnimateElement::animatedPropertyTypeSupportsAddition() const ...@@ -355,7 +353,7 @@ bool SVGAnimateElement::animatedPropertyTypeSupportsAddition() const
} }
} }
bool SVGAnimateElement::isAdditive() const bool SVGAnimateElement::isAdditive()
{ {
if (animationMode() == ByAnimation || animationMode() == FromByAnimation) if (animationMode() == ByAnimation || animationMode() == FromByAnimation)
if (!animatedPropertyTypeSupportsAddition()) if (!animatedPropertyTypeSupportsAddition())
...@@ -393,14 +391,12 @@ void SVGAnimateElement::resetAnimatedPropertyType() ...@@ -393,14 +391,12 @@ void SVGAnimateElement::resetAnimatedPropertyType()
m_toProperty.clear(); m_toProperty.clear();
m_toAtEndOfDurationProperty.clear(); m_toAtEndOfDurationProperty.clear();
m_animator.clear(); m_animator.clear();
m_animatedPropertyType = determineAnimatedPropertyType();
} }
SVGAnimatedTypeAnimator* SVGAnimateElement::ensureAnimator() SVGAnimatedTypeAnimator* SVGAnimateElement::ensureAnimator()
{ {
if (!m_animator) if (!m_animator)
m_animator = SVGAnimatedTypeAnimator::create(m_animatedPropertyType, this, targetElement()); m_animator = SVGAnimatedTypeAnimator::create(this, targetElement());
ASSERT(m_animatedPropertyType == m_animator->type());
return m_animator.get(); return m_animator.get();
} }
......
...@@ -39,6 +39,9 @@ public: ...@@ -39,6 +39,9 @@ public:
virtual void trace(Visitor*) OVERRIDE; virtual void trace(Visitor*) OVERRIDE;
AnimatedPropertyType animatedPropertyType();
bool animatedPropertyTypeSupportsAddition();
protected: protected:
SVGAnimateElement(const QualifiedName&, Document&); SVGAnimateElement(const QualifiedName&, Document&);
...@@ -51,17 +54,14 @@ protected: ...@@ -51,17 +54,14 @@ protected:
virtual void calculateAnimatedValue(float percentage, unsigned repeatCount, SVGSMILElement* resultElement) OVERRIDE FINAL; virtual void calculateAnimatedValue(float percentage, unsigned repeatCount, SVGSMILElement* resultElement) OVERRIDE FINAL;
virtual void applyResultsToTarget() OVERRIDE FINAL; virtual void applyResultsToTarget() OVERRIDE FINAL;
virtual float calculateDistance(const String& fromString, const String& toString) OVERRIDE FINAL; virtual float calculateDistance(const String& fromString, const String& toString) OVERRIDE FINAL;
virtual bool isAdditive() const OVERRIDE FINAL; virtual bool isAdditive() OVERRIDE FINAL;
virtual void setTargetElement(SVGElement*) OVERRIDE FINAL; virtual void setTargetElement(SVGElement*) OVERRIDE FINAL;
virtual void setAttributeName(const QualifiedName&) OVERRIDE FINAL; virtual void setAttributeName(const QualifiedName&) OVERRIDE FINAL;
AnimatedPropertyType m_animatedPropertyType;
private: private:
void resetAnimatedPropertyType(); void resetAnimatedPropertyType();
SVGAnimatedTypeAnimator* ensureAnimator(); SVGAnimatedTypeAnimator* ensureAnimator();
bool animatedPropertyTypeSupportsAddition() const;
virtual bool hasValidAttributeType() OVERRIDE; virtual bool hasValidAttributeType() OVERRIDE;
......
...@@ -45,7 +45,7 @@ bool SVGAnimateTransformElement::hasValidAttributeType() ...@@ -45,7 +45,7 @@ bool SVGAnimateTransformElement::hasValidAttributeType()
if (attributeType() == AttributeTypeCSS) if (attributeType() == AttributeTypeCSS)
return false; return false;
return m_animatedPropertyType == AnimatedTransformList; return animatedPropertyType() == AnimatedTransformList;
} }
bool SVGAnimateTransformElement::isSupportedAttribute(const QualifiedName& attrName) bool SVGAnimateTransformElement::isSupportedAttribute(const QualifiedName& attrName)
......
...@@ -35,22 +35,26 @@ ...@@ -35,22 +35,26 @@
namespace WebCore { namespace WebCore {
SVGAnimatedTypeAnimator::SVGAnimatedTypeAnimator(AnimatedPropertyType type, SVGAnimationElement* animationElement, SVGElement* contextElement) SVGAnimatedTypeAnimator::SVGAnimatedTypeAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
: m_type(type) : m_animationElement(animationElement)
, m_animationElement(animationElement)
, m_contextElement(contextElement) , m_contextElement(contextElement)
{ {
ASSERT(m_animationElement); ASSERT(m_animationElement);
ASSERT(m_contextElement); ASSERT(m_contextElement);
ASSERT(m_type != AnimatedPoint
&& m_type != AnimatedStringList
&& m_type != AnimatedTransform
&& m_type != AnimatedUnknown);
const QualifiedName& attributeName = m_animationElement->attributeName(); const QualifiedName& attributeName = m_animationElement->attributeName();
m_animatedProperty = m_contextElement->propertyFromAttribute(attributeName); m_animatedProperty = m_contextElement->propertyFromAttribute(attributeName);
if (m_animatedProperty) m_type = m_animatedProperty ? m_animatedProperty->type()
ASSERT(m_animatedProperty->type() == m_type); : SVGElement::animatedPropertyTypeForCSSAttribute(attributeName);
// Only <animateTransform> is allowed to animate AnimatedTransformList.
// http://www.w3.org/TR/SVG/animate.html#AnimationAttributesAndProperties
if (m_type == AnimatedTransformList && !isSVGAnimateTransformElement(*animationElement))
m_type = AnimatedUnknown;
ASSERT(m_type != AnimatedPoint
&& m_type != AnimatedStringList
&& m_type != AnimatedTransform);
} }
SVGAnimatedTypeAnimator::~SVGAnimatedTypeAnimator() SVGAnimatedTypeAnimator::~SVGAnimatedTypeAnimator()
...@@ -105,27 +109,24 @@ PassRefPtr<SVGPropertyBase> SVGAnimatedTypeAnimator::createPropertyForAnimation( ...@@ -105,27 +109,24 @@ PassRefPtr<SVGPropertyBase> SVGAnimatedTypeAnimator::createPropertyForAnimation(
return property.release(); return property.release();
} }
// These types don't appear in the table in SVGElement::cssPropertyToTypeMap() and thus don't need support. // These types don't appear in the table in SVGElement::animatedPropertyTypeForCSSAttribute() and thus don't need support.
case AnimatedAngle:
case AnimatedBoolean: case AnimatedBoolean:
case AnimatedEnumeration:
case AnimatedInteger:
case AnimatedIntegerOptionalInteger:
case AnimatedNumberList: case AnimatedNumberList:
case AnimatedNumberOptionalNumber: case AnimatedNumberOptionalNumber:
case AnimatedPath:
case AnimatedPoint: case AnimatedPoint:
case AnimatedPoints: case AnimatedPoints:
case AnimatedPreserveAspectRatio:
case AnimatedRect: case AnimatedRect:
case AnimatedStringList:
case AnimatedTransform: case AnimatedTransform:
case AnimatedTransformList: case AnimatedTransformList:
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
// These properties are not yet migrated to NewProperty implementation. see http://crbug.com/308818
case AnimatedAngle:
case AnimatedEnumeration:
case AnimatedInteger:
case AnimatedIntegerOptionalInteger:
case AnimatedPath:
case AnimatedPreserveAspectRatio:
case AnimatedStringList:
ASSERT_NOT_REACHED();
case AnimatedUnknown: case AnimatedUnknown:
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
}; };
......
...@@ -38,9 +38,9 @@ class SVGAnimationElement; ...@@ -38,9 +38,9 @@ class SVGAnimationElement;
class SVGAnimatedTypeAnimator FINAL : public NoBaseWillBeGarbageCollectedFinalized<SVGAnimatedTypeAnimator> { class SVGAnimatedTypeAnimator FINAL : public NoBaseWillBeGarbageCollectedFinalized<SVGAnimatedTypeAnimator> {
WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
public: public:
static PassOwnPtrWillBeRawPtr<SVGAnimatedTypeAnimator> create(AnimatedPropertyType type, SVGAnimationElement* animationElement, SVGElement* targetElement) static PassOwnPtrWillBeRawPtr<SVGAnimatedTypeAnimator> create(SVGAnimationElement* animationElement, SVGElement* targetElement)
{ {
return adoptPtrWillBeNoop(new SVGAnimatedTypeAnimator(type, animationElement, targetElement)); return adoptPtrWillBeNoop(new SVGAnimatedTypeAnimator(animationElement, targetElement));
} }
~SVGAnimatedTypeAnimator(); ~SVGAnimatedTypeAnimator();
...@@ -65,7 +65,7 @@ public: ...@@ -65,7 +65,7 @@ public:
void trace(Visitor*); void trace(Visitor*);
private: private:
SVGAnimatedTypeAnimator(AnimatedPropertyType, SVGAnimationElement*, SVGElement*); SVGAnimatedTypeAnimator(SVGAnimationElement*, SVGElement*);
friend class ParsePropertyFromString; friend class ParsePropertyFromString;
PassRefPtr<SVGPropertyBase> createPropertyForAnimation(const String&); PassRefPtr<SVGPropertyBase> createPropertyForAnimation(const String&);
......
...@@ -336,7 +336,7 @@ String SVGAnimationElement::fromValue() const ...@@ -336,7 +336,7 @@ String SVGAnimationElement::fromValue() const
return fastGetAttribute(SVGNames::fromAttr); return fastGetAttribute(SVGNames::fromAttr);
} }
bool SVGAnimationElement::isAdditive() const bool SVGAnimationElement::isAdditive()
{ {
DEFINE_STATIC_LOCAL(const AtomicString, sum, ("sum", AtomicString::ConstructFromLiteral)); DEFINE_STATIC_LOCAL(const AtomicString, sum, ("sum", AtomicString::ConstructFromLiteral));
const AtomicString& value = fastGetAttribute(SVGNames::additiveAttr); const AtomicString& value = fastGetAttribute(SVGNames::additiveAttr);
...@@ -486,26 +486,6 @@ void SVGAnimationElement::currentValuesFromKeyPoints(float percent, float& effec ...@@ -486,26 +486,6 @@ void SVGAnimationElement::currentValuesFromKeyPoints(float percent, float& effec
to = m_values[index + 1]; to = m_values[index + 1];
} }
AnimatedPropertyType SVGAnimationElement::determineAnimatedPropertyType() const
{
if (!targetElement())
return AnimatedString;
RefPtr<SVGAnimatedPropertyBase> property = targetElement()->propertyFromAttribute(attributeName());
if (property) {
AnimatedPropertyType propertyType = property->type();
// Only <animatedTransform> is allowed to animate AnimatedTransformList.
// http://www.w3.org/TR/SVG/animate.html#AnimationAttributesAndProperties
if (propertyType == AnimatedTransformList && !isSVGAnimateTransformElement(*this))
return AnimatedUnknown;
return propertyType;
}
return SVGElement::animatedPropertyTypeForCSSAttribute(attributeName());
}
void SVGAnimationElement::currentValuesForValuesAnimation(float percent, float& effectivePercent, String& from, String& to) void SVGAnimationElement::currentValuesForValuesAnimation(float percent, float& effectivePercent, String& from, String& to)
{ {
unsigned valuesCount = m_values.size(); unsigned valuesCount = m_values.size();
...@@ -520,14 +500,13 @@ void SVGAnimationElement::currentValuesForValuesAnimation(float percent, float& ...@@ -520,14 +500,13 @@ void SVGAnimationElement::currentValuesForValuesAnimation(float percent, float&
} }
CalcMode calcMode = this->calcMode(); CalcMode calcMode = this->calcMode();
if (hasTagName(SVGNames::animateTag)) { if (isSVGAnimateElement(*this)) {
AnimatedPropertyType attributeType = determineAnimatedPropertyType(); SVGAnimateElement& animateElement = toSVGAnimateElement(*this);
// Fall back to discrete animations for Strings. if (!animateElement.animatedPropertyTypeSupportsAddition()) {
if (attributeType == AnimatedBoolean ASSERT(animateElement.animatedPropertyType() != AnimatedTransformList || isSVGAnimateTransformElement(*this));
|| attributeType == AnimatedEnumeration ASSERT(animateElement.animatedPropertyType() != AnimatedUnknown);
|| attributeType == AnimatedPreserveAspectRatio
|| attributeType == AnimatedString)
calcMode = CalcModeDiscrete; calcMode = CalcModeDiscrete;
}
} }
if (!m_keyPoints.isEmpty() && calcMode != CalcModePaced) if (!m_keyPoints.isEmpty() && calcMode != CalcModePaced)
return currentValuesFromKeyPoints(percent, effectivePercent, from, to); return currentValuesFromKeyPoints(percent, effectivePercent, from, to);
......
...@@ -80,7 +80,7 @@ public: ...@@ -80,7 +80,7 @@ public:
static bool isTargetAttributeCSSProperty(SVGElement*, const QualifiedName&); static bool isTargetAttributeCSSProperty(SVGElement*, const QualifiedName&);
virtual bool isAdditive() const; virtual bool isAdditive();
bool isAccumulated() const; bool isAccumulated() const;
AnimationMode animationMode() const { return m_animationMode; } AnimationMode animationMode() const { return m_animationMode; }
CalcMode calcMode() const { return m_calcMode; } CalcMode calcMode() const { return m_calcMode; }
...@@ -164,7 +164,6 @@ protected: ...@@ -164,7 +164,6 @@ protected:
virtual void setTargetElement(SVGElement*) OVERRIDE; virtual void setTargetElement(SVGElement*) OVERRIDE;
virtual void setAttributeName(const QualifiedName&) OVERRIDE; virtual void setAttributeName(const QualifiedName&) OVERRIDE;
AnimatedPropertyType determineAnimatedPropertyType() const;
bool hasInvalidCSSAttributeType() const { return m_hasInvalidCSSAttributeType; } bool hasInvalidCSSAttributeType() const { return m_hasInvalidCSSAttributeType; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment