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 {
SVGAnimateElement::SVGAnimateElement(const QualifiedName& tagName, Document& document)
: SVGAnimationElement(tagName, document)
, m_animatedPropertyType(AnimatedString)
{
ASSERT(isSVGAnimateElement(*this));
ScriptWrappable::init(this);
......@@ -55,13 +54,18 @@ SVGAnimateElement::~SVGAnimateElement()
#endif
}
AnimatedPropertyType SVGAnimateElement::animatedPropertyType()
{
return ensureAnimator()->type();
}
bool SVGAnimateElement::hasValidAttributeType()
{
SVGElement* targetElement = this->targetElement();
if (!targetElement)
return false;
return m_animatedPropertyType != AnimatedUnknown && !hasInvalidCSSAttributeType();
return animatedPropertyType() != AnimatedUnknown && !hasInvalidCSSAttributeType();
}
void SVGAnimateElement::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGSMILElement* resultElement)
......@@ -71,20 +75,17 @@ void SVGAnimateElement::calculateAnimatedValue(float percentage, unsigned repeat
if (!targetElement || !isSVGAnimateElement(*resultElement))
return;
ASSERT(m_animatedPropertyType == determineAnimatedPropertyType());
ASSERT(percentage >= 0 && percentage <= 1);
ASSERT(m_animatedPropertyType != AnimatedTransformList || isSVGAnimateTransformElement(*this));
ASSERT(m_animatedPropertyType != AnimatedUnknown);
ASSERT(m_animator);
ASSERT(m_animator->type() == m_animatedPropertyType);
ASSERT(animatedPropertyType() != AnimatedTransformList || isSVGAnimateTransformElement(*this));
ASSERT(animatedPropertyType() != AnimatedUnknown);
ASSERT(m_fromProperty);
ASSERT(m_fromProperty->type() == m_animatedPropertyType);
ASSERT(m_fromProperty->type() == animatedPropertyType());
ASSERT(m_toProperty);
SVGAnimateElement* resultAnimationElement = toSVGAnimateElement(resultElement);
ASSERT(resultAnimationElement->m_animatedProperty);
ASSERT(resultAnimationElement->m_animatedPropertyType == m_animatedPropertyType);
ASSERT(resultAnimationElement->animatedPropertyType() == animatedPropertyType());
if (isSVGSetElement(*this))
percentage = 1;
......@@ -116,7 +117,6 @@ bool SVGAnimateElement::calculateFromAndToValues(const String& fromString, const
determinePropertyValueTypes(fromString, toString);
ensureAnimator()->calculateFromAndToValues(m_fromProperty, m_toProperty, fromString, toString);
ASSERT(m_animatedPropertyType == m_animator->type());
return true;
}
......@@ -137,7 +137,6 @@ bool SVGAnimateElement::calculateFromAndByValues(const String& fromString, const
determinePropertyValueTypes(fromString, byString);
ensureAnimator()->calculateFromAndByValues(m_fromProperty, m_toProperty, fromString, byString);
ASSERT(m_animatedPropertyType == m_animator->type());
return true;
}
......@@ -165,7 +164,6 @@ WillBeHeapVector<RawPtrWillBeMember<SVGElement> > findElementInstances(SVGElemen
void SVGAnimateElement::resetAnimatedType()
{
SVGAnimatedTypeAnimator* animator = ensureAnimator();
ASSERT(m_animatedPropertyType == animator->type());
SVGElement* targetElement = this->targetElement();
const QualifiedName& attributeName = this->attributeName();
......@@ -319,15 +317,15 @@ void SVGAnimateElement::clearAnimatedType(SVGElement* targetElement)
void SVGAnimateElement::applyResultsToTarget()
{
ASSERT(m_animatedPropertyType != AnimatedTransformList || isSVGAnimateTransformElement(*this));
ASSERT(m_animatedPropertyType != AnimatedUnknown);
ASSERT(m_animator);
ASSERT(animatedPropertyType() != AnimatedTransformList || isSVGAnimateTransformElement(*this));
ASSERT(animatedPropertyType() != AnimatedUnknown);
// Early exit if our animated type got destructed by a previous endedActiveInterval().
if (!m_animatedProperty)
return;
if (ensureAnimator()->isAnimatingCSSProperty()) {
if (m_animator->isAnimatingCSSProperty()) {
// 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.
applyCSSPropertyToTargetAndInstances(targetElement(), attributeName(), m_animatedProperty->valueAsString());
......@@ -340,10 +338,10 @@ void SVGAnimateElement::applyResultsToTarget()
notifyTargetAndInstancesAboutAnimValChange(targetElement(), attributeName());
}
bool SVGAnimateElement::animatedPropertyTypeSupportsAddition() const
bool SVGAnimateElement::animatedPropertyTypeSupportsAddition()
{
// Spec: http://www.w3.org/TR/SVG/animate.html#AnimationAttributesAndProperties.
switch (m_animatedPropertyType) {
switch (animatedPropertyType()) {
case AnimatedBoolean:
case AnimatedEnumeration:
case AnimatedPreserveAspectRatio:
......@@ -355,7 +353,7 @@ bool SVGAnimateElement::animatedPropertyTypeSupportsAddition() const
}
}
bool SVGAnimateElement::isAdditive() const
bool SVGAnimateElement::isAdditive()
{
if (animationMode() == ByAnimation || animationMode() == FromByAnimation)
if (!animatedPropertyTypeSupportsAddition())
......@@ -393,14 +391,12 @@ void SVGAnimateElement::resetAnimatedPropertyType()
m_toProperty.clear();
m_toAtEndOfDurationProperty.clear();
m_animator.clear();
m_animatedPropertyType = determineAnimatedPropertyType();
}
SVGAnimatedTypeAnimator* SVGAnimateElement::ensureAnimator()
{
if (!m_animator)
m_animator = SVGAnimatedTypeAnimator::create(m_animatedPropertyType, this, targetElement());
ASSERT(m_animatedPropertyType == m_animator->type());
m_animator = SVGAnimatedTypeAnimator::create(this, targetElement());
return m_animator.get();
}
......
......@@ -39,6 +39,9 @@ public:
virtual void trace(Visitor*) OVERRIDE;
AnimatedPropertyType animatedPropertyType();
bool animatedPropertyTypeSupportsAddition();
protected:
SVGAnimateElement(const QualifiedName&, Document&);
......@@ -51,17 +54,14 @@ protected:
virtual void calculateAnimatedValue(float percentage, unsigned repeatCount, SVGSMILElement* resultElement) OVERRIDE FINAL;
virtual void applyResultsToTarget() 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 setAttributeName(const QualifiedName&) OVERRIDE FINAL;
AnimatedPropertyType m_animatedPropertyType;
private:
void resetAnimatedPropertyType();
SVGAnimatedTypeAnimator* ensureAnimator();
bool animatedPropertyTypeSupportsAddition() const;
virtual bool hasValidAttributeType() OVERRIDE;
......
......@@ -45,7 +45,7 @@ bool SVGAnimateTransformElement::hasValidAttributeType()
if (attributeType() == AttributeTypeCSS)
return false;
return m_animatedPropertyType == AnimatedTransformList;
return animatedPropertyType() == AnimatedTransformList;
}
bool SVGAnimateTransformElement::isSupportedAttribute(const QualifiedName& attrName)
......
......@@ -35,22 +35,26 @@
namespace WebCore {
SVGAnimatedTypeAnimator::SVGAnimatedTypeAnimator(AnimatedPropertyType type, SVGAnimationElement* animationElement, SVGElement* contextElement)
: m_type(type)
, m_animationElement(animationElement)
SVGAnimatedTypeAnimator::SVGAnimatedTypeAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
: m_animationElement(animationElement)
, m_contextElement(contextElement)
{
ASSERT(m_animationElement);
ASSERT(m_contextElement);
ASSERT(m_type != AnimatedPoint
&& m_type != AnimatedStringList
&& m_type != AnimatedTransform
&& m_type != AnimatedUnknown);
const QualifiedName& attributeName = m_animationElement->attributeName();
m_animatedProperty = m_contextElement->propertyFromAttribute(attributeName);
if (m_animatedProperty)
ASSERT(m_animatedProperty->type() == m_type);
m_type = m_animatedProperty ? m_animatedProperty->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()
......@@ -105,27 +109,24 @@ PassRefPtr<SVGPropertyBase> SVGAnimatedTypeAnimator::createPropertyForAnimation(
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 AnimatedEnumeration:
case AnimatedInteger:
case AnimatedIntegerOptionalInteger:
case AnimatedNumberList:
case AnimatedNumberOptionalNumber:
case AnimatedPath:
case AnimatedPoint:
case AnimatedPoints:
case AnimatedPreserveAspectRatio:
case AnimatedRect:
case AnimatedStringList:
case AnimatedTransform:
case AnimatedTransformList:
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:
ASSERT_NOT_REACHED();
};
......
......@@ -38,9 +38,9 @@ class SVGAnimationElement;
class SVGAnimatedTypeAnimator FINAL : public NoBaseWillBeGarbageCollectedFinalized<SVGAnimatedTypeAnimator> {
WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
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();
......@@ -65,7 +65,7 @@ public:
void trace(Visitor*);
private:
SVGAnimatedTypeAnimator(AnimatedPropertyType, SVGAnimationElement*, SVGElement*);
SVGAnimatedTypeAnimator(SVGAnimationElement*, SVGElement*);
friend class ParsePropertyFromString;
PassRefPtr<SVGPropertyBase> createPropertyForAnimation(const String&);
......
......@@ -336,7 +336,7 @@ String SVGAnimationElement::fromValue() const
return fastGetAttribute(SVGNames::fromAttr);
}
bool SVGAnimationElement::isAdditive() const
bool SVGAnimationElement::isAdditive()
{
DEFINE_STATIC_LOCAL(const AtomicString, sum, ("sum", AtomicString::ConstructFromLiteral));
const AtomicString& value = fastGetAttribute(SVGNames::additiveAttr);
......@@ -486,26 +486,6 @@ void SVGAnimationElement::currentValuesFromKeyPoints(float percent, float& effec
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)
{
unsigned valuesCount = m_values.size();
......@@ -520,15 +500,14 @@ void SVGAnimationElement::currentValuesForValuesAnimation(float percent, float&
}
CalcMode calcMode = this->calcMode();
if (hasTagName(SVGNames::animateTag)) {
AnimatedPropertyType attributeType = determineAnimatedPropertyType();
// Fall back to discrete animations for Strings.
if (attributeType == AnimatedBoolean
|| attributeType == AnimatedEnumeration
|| attributeType == AnimatedPreserveAspectRatio
|| attributeType == AnimatedString)
if (isSVGAnimateElement(*this)) {
SVGAnimateElement& animateElement = toSVGAnimateElement(*this);
if (!animateElement.animatedPropertyTypeSupportsAddition()) {
ASSERT(animateElement.animatedPropertyType() != AnimatedTransformList || isSVGAnimateTransformElement(*this));
ASSERT(animateElement.animatedPropertyType() != AnimatedUnknown);
calcMode = CalcModeDiscrete;
}
}
if (!m_keyPoints.isEmpty() && calcMode != CalcModePaced)
return currentValuesFromKeyPoints(percent, effectivePercent, from, to);
......
......@@ -80,7 +80,7 @@ public:
static bool isTargetAttributeCSSProperty(SVGElement*, const QualifiedName&);
virtual bool isAdditive() const;
virtual bool isAdditive();
bool isAccumulated() const;
AnimationMode animationMode() const { return m_animationMode; }
CalcMode calcMode() const { return m_calcMode; }
......@@ -164,7 +164,6 @@ protected:
virtual void setTargetElement(SVGElement*) OVERRIDE;
virtual void setAttributeName(const QualifiedName&) OVERRIDE;
AnimatedPropertyType determineAnimatedPropertyType() const;
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