Commit 2e4064f9 authored by kouhei@chromium.org's avatar kouhei@chromium.org

[SVG] refactor determineAnimatedPropertyType logic.

- SVGElement::animatedPropertyTypeForAttribute() was deprecated. |SVGElement::animatedPropertyTypeForCSSAttribute()| is provided to retrieve CSS types.
- |SVGAnimateElement::determineAnimatedPropertyType()| is moved to SVGAnimationElement, and its argument is omitted.
-- Its argument was always targetElement()
-- This removes the need for cast in |SVGAnimationElement::currentValuesForValuesAnimation()|

BUG=349370

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

git-svn-id: svn://svn.chromium.org/blink/trunk@168615 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 9b270eb1
...@@ -62,29 +62,6 @@ bool SVGAnimateElement::hasValidAttributeType() ...@@ -62,29 +62,6 @@ bool SVGAnimateElement::hasValidAttributeType()
return m_animatedPropertyType != AnimatedUnknown && !hasInvalidCSSAttributeType(); return m_animatedPropertyType != AnimatedUnknown && !hasInvalidCSSAttributeType();
} }
AnimatedPropertyType SVGAnimateElement::determineAnimatedPropertyType(SVGElement* targetElement) const
{
ASSERT(targetElement);
Vector<AnimatedPropertyType> propertyTypes;
targetElement->animatedPropertyTypeForAttribute(attributeName(), propertyTypes);
if (propertyTypes.isEmpty())
return AnimatedUnknown;
ASSERT(propertyTypes.size() <= 2);
AnimatedPropertyType type = propertyTypes[0];
// Animations of transform lists are not allowed for <animate> or <set>
// http://www.w3.org/TR/SVG/animate.html#AnimationAttributesAndProperties
if (type == AnimatedTransformList && !hasTagName(SVGNames::animateTransformTag))
return AnimatedUnknown;
if (propertyTypes.size() == 2)
ASSERT(propertyTypes[0] == propertyTypes[1]);
return type;
}
void SVGAnimateElement::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGSMILElement* resultElement) void SVGAnimateElement::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGSMILElement* resultElement)
{ {
ASSERT(resultElement); ASSERT(resultElement);
...@@ -92,7 +69,7 @@ void SVGAnimateElement::calculateAnimatedValue(float percentage, unsigned repeat ...@@ -92,7 +69,7 @@ void SVGAnimateElement::calculateAnimatedValue(float percentage, unsigned repeat
if (!targetElement || !isSVGAnimateElement(*resultElement)) if (!targetElement || !isSVGAnimateElement(*resultElement))
return; return;
ASSERT(m_animatedPropertyType == determineAnimatedPropertyType(targetElement)); ASSERT(m_animatedPropertyType == determineAnimatedPropertyType());
ASSERT(percentage >= 0 && percentage <= 1); ASSERT(percentage >= 0 && percentage <= 1);
ASSERT(m_animatedPropertyType != AnimatedTransformList || hasTagName(SVGNames::animateTransformTag)); ASSERT(m_animatedPropertyType != AnimatedTransformList || hasTagName(SVGNames::animateTransformTag));
...@@ -418,7 +395,7 @@ void SVGAnimateElement::resetAnimatedPropertyType() ...@@ -418,7 +395,7 @@ void SVGAnimateElement::resetAnimatedPropertyType()
m_toProperty.clear(); m_toProperty.clear();
m_toAtEndOfDurationProperty.clear(); m_toAtEndOfDurationProperty.clear();
m_animator.clear(); m_animator.clear();
m_animatedPropertyType = targetElement() ? determineAnimatedPropertyType(targetElement()) : AnimatedString; m_animatedPropertyType = determineAnimatedPropertyType();
} }
SVGAnimatedTypeAnimator* SVGAnimateElement::ensureAnimator() SVGAnimatedTypeAnimator* SVGAnimateElement::ensureAnimator()
......
...@@ -38,8 +38,6 @@ public: ...@@ -38,8 +38,6 @@ public:
static PassRefPtr<SVGAnimateElement> create(Document&); static PassRefPtr<SVGAnimateElement> create(Document&);
virtual ~SVGAnimateElement(); virtual ~SVGAnimateElement();
AnimatedPropertyType determineAnimatedPropertyType(SVGElement*) const;
protected: protected:
SVGAnimateElement(const QualifiedName&, Document&); SVGAnimateElement(const QualifiedName&, Document&);
......
...@@ -483,6 +483,26 @@ void SVGAnimationElement::currentValuesFromKeyPoints(float percent, float& effec ...@@ -483,6 +483,26 @@ 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<NewSVGAnimatedPropertyBase> 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 && !hasTagName(SVGNames::animateTransformTag))
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();
...@@ -498,7 +518,7 @@ void SVGAnimationElement::currentValuesForValuesAnimation(float percent, float& ...@@ -498,7 +518,7 @@ void SVGAnimationElement::currentValuesForValuesAnimation(float percent, float&
CalcMode calcMode = this->calcMode(); CalcMode calcMode = this->calcMode();
if (hasTagName(SVGNames::animateTag)) { if (hasTagName(SVGNames::animateTag)) {
AnimatedPropertyType attributeType = toSVGAnimateElement(this)->determineAnimatedPropertyType(targetElement()); AnimatedPropertyType attributeType = determineAnimatedPropertyType();
// Fall back to discrete animations for Strings. // Fall back to discrete animations for Strings.
if (attributeType == AnimatedBoolean if (attributeType == AnimatedBoolean
|| attributeType == AnimatedEnumeration || attributeType == AnimatedEnumeration
......
...@@ -196,6 +196,8 @@ protected: ...@@ -196,6 +196,8 @@ 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; }
virtual void updateAnimationMode(); virtual void updateAnimationMode();
......
...@@ -657,84 +657,74 @@ void SVGElement::parseAttribute(const QualifiedName& name, const AtomicString& v ...@@ -657,84 +657,74 @@ void SVGElement::parseAttribute(const QualifiedName& name, const AtomicString& v
} }
typedef HashMap<QualifiedName, AnimatedPropertyType> AttributeToPropertyTypeMap; typedef HashMap<QualifiedName, AnimatedPropertyType> AttributeToPropertyTypeMap;
static inline AttributeToPropertyTypeMap& cssPropertyToTypeMap() AnimatedPropertyType SVGElement::animatedPropertyTypeForCSSAttribute(const QualifiedName& attributeName)
{ {
DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, s_cssPropertyMap, ()); DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, cssPropertyMap, ());
if (!s_cssPropertyMap.isEmpty()) if (cssPropertyMap.isEmpty()) {
return s_cssPropertyMap; // Fill the map for the first use.
cssPropertyMap.set(alignment_baselineAttr, AnimatedString);
// Fill the map for the first use. cssPropertyMap.set(baseline_shiftAttr, AnimatedString);
s_cssPropertyMap.set(alignment_baselineAttr, AnimatedString); cssPropertyMap.set(buffered_renderingAttr, AnimatedString);
s_cssPropertyMap.set(baseline_shiftAttr, AnimatedString); cssPropertyMap.set(clipAttr, AnimatedRect);
s_cssPropertyMap.set(buffered_renderingAttr, AnimatedString); cssPropertyMap.set(clip_pathAttr, AnimatedString);
s_cssPropertyMap.set(clipAttr, AnimatedRect); cssPropertyMap.set(clip_ruleAttr, AnimatedString);
s_cssPropertyMap.set(clip_pathAttr, AnimatedString); cssPropertyMap.set(SVGNames::colorAttr, AnimatedColor);
s_cssPropertyMap.set(clip_ruleAttr, AnimatedString); cssPropertyMap.set(color_interpolationAttr, AnimatedString);
s_cssPropertyMap.set(SVGNames::colorAttr, AnimatedColor); cssPropertyMap.set(color_interpolation_filtersAttr, AnimatedString);
s_cssPropertyMap.set(color_interpolationAttr, AnimatedString); cssPropertyMap.set(color_profileAttr, AnimatedString);
s_cssPropertyMap.set(color_interpolation_filtersAttr, AnimatedString); cssPropertyMap.set(color_renderingAttr, AnimatedString);
s_cssPropertyMap.set(color_profileAttr, AnimatedString); cssPropertyMap.set(cursorAttr, AnimatedString);
s_cssPropertyMap.set(color_renderingAttr, AnimatedString); cssPropertyMap.set(displayAttr, AnimatedString);
s_cssPropertyMap.set(cursorAttr, AnimatedString); cssPropertyMap.set(dominant_baselineAttr, AnimatedString);
s_cssPropertyMap.set(displayAttr, AnimatedString); cssPropertyMap.set(fillAttr, AnimatedColor);
s_cssPropertyMap.set(dominant_baselineAttr, AnimatedString); cssPropertyMap.set(fill_opacityAttr, AnimatedNumber);
s_cssPropertyMap.set(fillAttr, AnimatedColor); cssPropertyMap.set(fill_ruleAttr, AnimatedString);
s_cssPropertyMap.set(fill_opacityAttr, AnimatedNumber); cssPropertyMap.set(filterAttr, AnimatedString);
s_cssPropertyMap.set(fill_ruleAttr, AnimatedString); cssPropertyMap.set(flood_colorAttr, AnimatedColor);
s_cssPropertyMap.set(filterAttr, AnimatedString); cssPropertyMap.set(flood_opacityAttr, AnimatedNumber);
s_cssPropertyMap.set(flood_colorAttr, AnimatedColor); cssPropertyMap.set(font_familyAttr, AnimatedString);
s_cssPropertyMap.set(flood_opacityAttr, AnimatedNumber); cssPropertyMap.set(font_sizeAttr, AnimatedLength);
s_cssPropertyMap.set(font_familyAttr, AnimatedString); cssPropertyMap.set(font_stretchAttr, AnimatedString);
s_cssPropertyMap.set(font_sizeAttr, AnimatedLength); cssPropertyMap.set(font_styleAttr, AnimatedString);
s_cssPropertyMap.set(font_stretchAttr, AnimatedString); cssPropertyMap.set(font_variantAttr, AnimatedString);
s_cssPropertyMap.set(font_styleAttr, AnimatedString); cssPropertyMap.set(font_weightAttr, AnimatedString);
s_cssPropertyMap.set(font_variantAttr, AnimatedString); cssPropertyMap.set(image_renderingAttr, AnimatedString);
s_cssPropertyMap.set(font_weightAttr, AnimatedString); cssPropertyMap.set(kerningAttr, AnimatedLength);
s_cssPropertyMap.set(image_renderingAttr, AnimatedString); cssPropertyMap.set(letter_spacingAttr, AnimatedLength);
s_cssPropertyMap.set(kerningAttr, AnimatedLength); cssPropertyMap.set(lighting_colorAttr, AnimatedColor);
s_cssPropertyMap.set(letter_spacingAttr, AnimatedLength); cssPropertyMap.set(marker_endAttr, AnimatedString);
s_cssPropertyMap.set(lighting_colorAttr, AnimatedColor); cssPropertyMap.set(marker_midAttr, AnimatedString);
s_cssPropertyMap.set(marker_endAttr, AnimatedString); cssPropertyMap.set(marker_startAttr, AnimatedString);
s_cssPropertyMap.set(marker_midAttr, AnimatedString); cssPropertyMap.set(maskAttr, AnimatedString);
s_cssPropertyMap.set(marker_startAttr, AnimatedString); cssPropertyMap.set(mask_typeAttr, AnimatedString);
s_cssPropertyMap.set(maskAttr, AnimatedString); cssPropertyMap.set(opacityAttr, AnimatedNumber);
s_cssPropertyMap.set(mask_typeAttr, AnimatedString); cssPropertyMap.set(overflowAttr, AnimatedString);
s_cssPropertyMap.set(opacityAttr, AnimatedNumber); cssPropertyMap.set(paint_orderAttr, AnimatedString);
s_cssPropertyMap.set(overflowAttr, AnimatedString); cssPropertyMap.set(pointer_eventsAttr, AnimatedString);
s_cssPropertyMap.set(paint_orderAttr, AnimatedString); cssPropertyMap.set(shape_renderingAttr, AnimatedString);
s_cssPropertyMap.set(pointer_eventsAttr, AnimatedString); cssPropertyMap.set(stop_colorAttr, AnimatedColor);
s_cssPropertyMap.set(shape_renderingAttr, AnimatedString); cssPropertyMap.set(stop_opacityAttr, AnimatedNumber);
s_cssPropertyMap.set(stop_colorAttr, AnimatedColor); cssPropertyMap.set(strokeAttr, AnimatedColor);
s_cssPropertyMap.set(stop_opacityAttr, AnimatedNumber); cssPropertyMap.set(stroke_dasharrayAttr, AnimatedLengthList);
s_cssPropertyMap.set(strokeAttr, AnimatedColor); cssPropertyMap.set(stroke_dashoffsetAttr, AnimatedLength);
s_cssPropertyMap.set(stroke_dasharrayAttr, AnimatedLengthList); cssPropertyMap.set(stroke_linecapAttr, AnimatedString);
s_cssPropertyMap.set(stroke_dashoffsetAttr, AnimatedLength); cssPropertyMap.set(stroke_linejoinAttr, AnimatedString);
s_cssPropertyMap.set(stroke_linecapAttr, AnimatedString); cssPropertyMap.set(stroke_miterlimitAttr, AnimatedNumber);
s_cssPropertyMap.set(stroke_linejoinAttr, AnimatedString); cssPropertyMap.set(stroke_opacityAttr, AnimatedNumber);
s_cssPropertyMap.set(stroke_miterlimitAttr, AnimatedNumber); cssPropertyMap.set(stroke_widthAttr, AnimatedLength);
s_cssPropertyMap.set(stroke_opacityAttr, AnimatedNumber); cssPropertyMap.set(text_anchorAttr, AnimatedString);
s_cssPropertyMap.set(stroke_widthAttr, AnimatedLength); cssPropertyMap.set(text_decorationAttr, AnimatedString);
s_cssPropertyMap.set(text_anchorAttr, AnimatedString); cssPropertyMap.set(text_renderingAttr, AnimatedString);
s_cssPropertyMap.set(text_decorationAttr, AnimatedString); cssPropertyMap.set(vector_effectAttr, AnimatedString);
s_cssPropertyMap.set(text_renderingAttr, AnimatedString); cssPropertyMap.set(visibilityAttr, AnimatedString);
s_cssPropertyMap.set(vector_effectAttr, AnimatedString); cssPropertyMap.set(word_spacingAttr, AnimatedLength);
s_cssPropertyMap.set(visibilityAttr, AnimatedString);
s_cssPropertyMap.set(word_spacingAttr, AnimatedLength);
return s_cssPropertyMap;
}
void SVGElement::animatedPropertyTypeForAttribute(const QualifiedName& attributeName, Vector<AnimatedPropertyType>& propertyTypes)
{
RefPtr<NewSVGAnimatedPropertyBase> animatedProperty = m_newAttributeToPropertyMap.get(attributeName);
if (animatedProperty) {
propertyTypes.append(animatedProperty->type());
return;
} }
AttributeToPropertyTypeMap& cssPropertyTypeMap = cssPropertyToTypeMap(); if (cssPropertyMap.contains(attributeName))
if (cssPropertyTypeMap.contains(attributeName)) return cssPropertyMap.get(attributeName);
propertyTypes.append(cssPropertyTypeMap.get(attributeName));
return AnimatedUnknown;
} }
void SVGElement::addToPropertyMap(PassRefPtr<NewSVGAnimatedPropertyBase> passProperty) void SVGElement::addToPropertyMap(PassRefPtr<NewSVGAnimatedPropertyBase> passProperty)
...@@ -751,7 +741,7 @@ PassRefPtr<NewSVGAnimatedPropertyBase> SVGElement::propertyFromAttribute(const Q ...@@ -751,7 +741,7 @@ PassRefPtr<NewSVGAnimatedPropertyBase> SVGElement::propertyFromAttribute(const Q
bool SVGElement::isAnimatableCSSProperty(const QualifiedName& attrName) bool SVGElement::isAnimatableCSSProperty(const QualifiedName& attrName)
{ {
return cssPropertyToTypeMap().contains(attrName); return animatedPropertyTypeForCSSAttribute(attrName) != AnimatedUnknown;
} }
bool SVGElement::isPresentationAttribute(const QualifiedName& name) const bool SVGElement::isPresentationAttribute(const QualifiedName& name) const
......
...@@ -96,8 +96,8 @@ public: ...@@ -96,8 +96,8 @@ public:
virtual void svgAttributeChanged(const QualifiedName&); virtual void svgAttributeChanged(const QualifiedName&);
void animatedPropertyTypeForAttribute(const QualifiedName&, Vector<AnimatedPropertyType>&);
PassRefPtr<NewSVGAnimatedPropertyBase> propertyFromAttribute(const QualifiedName& attributeName); PassRefPtr<NewSVGAnimatedPropertyBase> propertyFromAttribute(const QualifiedName& attributeName);
static AnimatedPropertyType animatedPropertyTypeForCSSAttribute(const QualifiedName& attributeName);
void sendSVGLoadEventIfPossible(bool sendParentLoadEvents = false); void sendSVGLoadEventIfPossible(bool sendParentLoadEvents = false);
void sendSVGLoadEventIfPossibleAsynchronously(); void sendSVGLoadEventIfPossibleAsynchronously();
......
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