Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: third_party/WebKit/Source/core/svg/SVGAnimatedTypeAnimator.cpp

Issue 2595393002: Fold SVGAnimatedTypeAnimator into SVGAnimateElement (Closed)
Patch Set: More ASSERT to DCHECK Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) Research In Motion Limited 2011-2012. All rights reserved.
3 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #include "core/svg/SVGAnimatedTypeAnimator.h"
22
23 #include "core/svg/SVGAnimateTransformElement.h"
24 #include "core/svg/SVGAnimatedColor.h"
25 #include "core/svg/SVGAnimationElement.h"
26 #include "core/svg/SVGLength.h"
27 #include "core/svg/SVGLengthList.h"
28 #include "core/svg/SVGNumber.h"
29 #include "core/svg/SVGString.h"
30 #include "core/svg/SVGTransformList.h"
31 #include "core/svg/properties/SVGAnimatedProperty.h"
32
33 namespace blink {
34
35 SVGAnimatedTypeAnimator::SVGAnimatedTypeAnimator(
36 SVGAnimationElement* animationElement)
37 : m_animationElement(animationElement),
38 m_type(AnimatedUnknown),
39 m_cssProperty(CSSPropertyInvalid) {
40 DCHECK(m_animationElement);
41 }
42
43 void SVGAnimatedTypeAnimator::clear() {
44 m_animatedProperty = nullptr;
45 m_type = AnimatedUnknown;
46 m_cssProperty = CSSPropertyInvalid;
47 }
48
49 void SVGAnimatedTypeAnimator::reset(const SVGElement& contextElement) {
50 const QualifiedName& attributeName = m_animationElement->attributeName();
51 m_animatedProperty = contextElement.propertyFromAttribute(attributeName);
52 if (m_animatedProperty) {
53 m_type = m_animatedProperty->type();
54 m_cssProperty = m_animatedProperty->cssPropertyId();
55
56 if (m_type == AnimatedTransformList) {
57 // Only <animateTransform> is allowed to animate AnimatedTransformList.
58 // http://www.w3.org/TR/SVG/animate.html#AnimationAttributesAndProperties
59 if (!isSVGAnimateTransformElement(*m_animationElement))
60 m_type = AnimatedUnknown;
61 // Because of the syntactic mismatch between the CSS and SVGProperty
62 // representations, disallow CSS animations of transform list for
63 // now. (We also reject this case via
64 // SVGAnimateTransformElement::hasValidAttributeType ATM.)
65 m_cssProperty = CSSPropertyInvalid;
66 }
67 } else {
68 m_type = SVGElement::animatedPropertyTypeForCSSAttribute(attributeName);
69 m_cssProperty = m_type != AnimatedUnknown
70 ? cssPropertyID(attributeName.localName())
71 : CSSPropertyInvalid;
72 DCHECK_NE(m_type, AnimatedTransformList);
73 }
74
75 DCHECK(m_type != AnimatedPoint && m_type != AnimatedStringList &&
76 m_type != AnimatedTransform);
77 }
78
79 SVGPropertyBase* SVGAnimatedTypeAnimator::createPropertyForAttributeAnimation(
80 const String& value) const {
81 // SVG DOM animVal animation code-path.
82 if (m_type == AnimatedTransformList) {
83 // TransformList must be animated via <animateTransform>, and its
84 // {from,by,to} attribute values needs to be parsed w.r.t. its "type"
85 // attribute. Spec:
86 // http://www.w3.org/TR/SVG/single-page.html#animate-AnimateTransformElement
87 DCHECK(m_animationElement);
88 SVGTransformType transformType =
89 toSVGAnimateTransformElement(m_animationElement)->transformType();
90 return SVGTransformList::create(transformType, value);
91 }
92 DCHECK(m_animatedProperty);
93 return m_animatedProperty->currentValueBase()->cloneForAnimation(value);
94 }
95
96 SVGPropertyBase* SVGAnimatedTypeAnimator::createPropertyForCSSAnimation(
97 const String& value) const {
98 // CSS properties animation code-path.
99 // Create a basic instance of the corresponding SVG property.
100 // The instance will not have full context info. (e.g. SVGLengthMode)
101 switch (m_type) {
102 case AnimatedColor:
103 return SVGColorProperty::create(value);
104 case AnimatedNumber: {
105 SVGNumber* property = SVGNumber::create();
106 property->setValueAsString(value);
107 return property;
108 }
109 case AnimatedLength: {
110 SVGLength* property = SVGLength::create();
111 property->setValueAsString(value);
112 return property;
113 }
114 case AnimatedLengthList: {
115 SVGLengthList* property = SVGLengthList::create();
116 property->setValueAsString(value);
117 return property;
118 }
119 case AnimatedString: {
120 SVGString* property = SVGString::create();
121 property->setValueAsString(value);
122 return property;
123 }
124 // These types don't appear in the table in
125 // SVGElement::animatedPropertyTypeForCSSAttribute() and thus don't need
126 // support.
127 case AnimatedAngle:
128 case AnimatedBoolean:
129 case AnimatedEnumeration:
130 case AnimatedInteger:
131 case AnimatedIntegerOptionalInteger:
132 case AnimatedNumberList:
133 case AnimatedNumberOptionalNumber:
134 case AnimatedPath:
135 case AnimatedPoint:
136 case AnimatedPoints:
137 case AnimatedPreserveAspectRatio:
138 case AnimatedRect:
139 case AnimatedStringList:
140 case AnimatedTransform:
141 case AnimatedTransformList:
142 case AnimatedUnknown:
143 break;
144 default:
145 break;
146 }
147 NOTREACHED();
148 return nullptr;
149 }
150
151 SVGPropertyBase* SVGAnimatedTypeAnimator::createPropertyForAnimation(
152 const String& value) const {
153 if (isAnimatingSVGDom())
154 return createPropertyForAttributeAnimation(value);
155 DCHECK(isAnimatingCSSProperty());
156 return createPropertyForCSSAnimation(value);
157 }
158
159 SVGPropertyBase* SVGAnimatedTypeAnimator::createAnimatedValue() const {
160 DCHECK(isAnimatingSVGDom());
161 SVGPropertyBase* animatedValue = m_animatedProperty->createAnimatedValue();
162 DCHECK_EQ(animatedValue->type(), m_type);
163 return animatedValue;
164 }
165
166 DEFINE_TRACE(SVGAnimatedTypeAnimator) {
167 visitor->trace(m_animationElement);
168 visitor->trace(m_animatedProperty);
169 }
170
171 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698