Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGAnimatedType.cpp
1 /*
2  * Copyright (C) Research In Motion Limited 2011. All rights reserved.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #include "config.h"
21 #include "core/svg/SVGAnimatedType.h"
22
23 #include "bindings/v8/ExceptionState.h"
24 #include "core/svg/SVGParserUtilities.h"
25 #include "core/svg/SVGPathByteStream.h"
26
27 namespace WebCore {
28
29 SVGAnimatedType::SVGAnimatedType(AnimatedPropertyType type)
30     : m_type(type)
31 {
32 }
33
34 SVGAnimatedType::~SVGAnimatedType()
35 {
36     switch (m_type) {
37     case AnimatedAngle:
38         delete m_data.angleAndEnumeration;
39         break;
40     case AnimatedEnumeration:
41         delete m_data.enumeration;
42         break;
43     case AnimatedPath:
44         delete m_data.path;
45         break;
46     case AnimatedTransformList:
47         delete m_data.transformList;
48         break;
49     // Below properties are migrated to new property implementation.
50     case AnimatedBoolean:
51     case AnimatedColor:
52     case AnimatedInteger:
53     case AnimatedIntegerOptionalInteger:
54     case AnimatedNumber:
55     case AnimatedNumberList:
56     case AnimatedNumberOptionalNumber:
57     case AnimatedLength:
58     case AnimatedLengthList:
59     case AnimatedPoints:
60     case AnimatedPreserveAspectRatio:
61     case AnimatedRect:
62     case AnimatedString:
63     case AnimatedStringList:
64         // handled by RefPtr
65         break;
66
67     // There is no SVGAnimatedPoint
68     case AnimatedPoint:
69         ASSERT_NOT_REACHED();
70         break;
71
72     case AnimatedUnknown:
73         ASSERT_NOT_REACHED();
74         break;
75     }
76 }
77
78 PassOwnPtr<SVGAnimatedType> SVGAnimatedType::createAngleAndEnumeration(std::pair<SVGAngle, unsigned>* angleAndEnumeration)
79 {
80     ASSERT(angleAndEnumeration);
81     OwnPtr<SVGAnimatedType> animatedType = adoptPtr(new SVGAnimatedType(AnimatedAngle));
82     animatedType->m_data.angleAndEnumeration = angleAndEnumeration;
83     return animatedType.release();
84 }
85
86 PassOwnPtr<SVGAnimatedType> SVGAnimatedType::createEnumeration(unsigned* enumeration)
87 {
88     ASSERT(enumeration);
89     OwnPtr<SVGAnimatedType> animatedType = adoptPtr(new SVGAnimatedType(AnimatedEnumeration));
90     animatedType->m_data.enumeration = enumeration;
91     return animatedType.release();
92 }
93
94 PassOwnPtr<SVGAnimatedType> SVGAnimatedType::createPath(PassOwnPtr<SVGPathByteStream> path)
95 {
96     ASSERT(path);
97     OwnPtr<SVGAnimatedType> animatedType = adoptPtr(new SVGAnimatedType(AnimatedPath));
98     animatedType->m_data.path = path.leakPtr();
99     return animatedType.release();
100 }
101
102 PassOwnPtr<SVGAnimatedType> SVGAnimatedType::createTransformList(SVGTransformList* transformList)
103 {
104     ASSERT(transformList);
105     OwnPtr<SVGAnimatedType> animatedType = adoptPtr(new SVGAnimatedType(AnimatedTransformList));
106     animatedType->m_data.transformList = transformList;
107     return animatedType.release();
108 }
109
110 PassOwnPtr<SVGAnimatedType> SVGAnimatedType::createNewProperty(PassRefPtr<NewSVGPropertyBase> newProperty)
111 {
112     ASSERT(newProperty);
113     OwnPtr<SVGAnimatedType> animatedType = adoptPtr(new SVGAnimatedType(newProperty->type()));
114     animatedType->m_newProperty = newProperty;
115     return animatedType.release();
116 }
117
118 String SVGAnimatedType::valueAsString()
119 {
120     switch (m_type) {
121     // Below properties have migrated to new property implementation.
122     case AnimatedColor:
123     case AnimatedNumber:
124     case AnimatedNumberList:
125     case AnimatedNumberOptionalNumber:
126     case AnimatedLength:
127     case AnimatedLengthList:
128     case AnimatedPoints:
129     case AnimatedPreserveAspectRatio:
130     case AnimatedRect:
131     case AnimatedString:
132     case AnimatedStringList:
133         return m_newProperty->valueAsString();
134
135     // These types don't appear in the table in SVGElement::cssPropertyToTypeMap() and thus don't need valueAsString() support.
136     case AnimatedAngle:
137     case AnimatedBoolean:
138     case AnimatedEnumeration:
139     case AnimatedInteger:
140     case AnimatedIntegerOptionalInteger:
141     case AnimatedPath:
142     case AnimatedPoint:
143     case AnimatedTransformList:
144     case AnimatedUnknown:
145         // Only SVG DOM animations use these property types - that means valueAsString() is never used for those.
146         ASSERT_NOT_REACHED();
147         break;
148     }
149     ASSERT_NOT_REACHED();
150     return String();
151 }
152
153 bool SVGAnimatedType::setValueAsString(const QualifiedName& attrName, const String& value)
154 {
155     switch (m_type) {
156     // Below properties have migrated to new property implementation.
157     case AnimatedColor:
158     case AnimatedNumber:
159     case AnimatedNumberList:
160     case AnimatedNumberOptionalNumber:
161     case AnimatedLength:
162     case AnimatedLengthList:
163     case AnimatedPoints:
164     case AnimatedPreserveAspectRatio:
165     case AnimatedRect:
166     case AnimatedString:
167     case AnimatedStringList:
168         // Always use createForAnimation call path for these implementations.
169         return false;
170
171     // These types don't appear in the table in SVGElement::cssPropertyToTypeMap() and thus don't need setValueAsString() support.
172     case AnimatedAngle:
173     case AnimatedBoolean:
174     case AnimatedEnumeration:
175     case AnimatedInteger:
176     case AnimatedIntegerOptionalInteger:
177     case AnimatedPath:
178     case AnimatedPoint:
179     case AnimatedTransformList:
180     case AnimatedUnknown:
181         // Only SVG DOM animations use these property types - that means setValueAsString() is never used for those.
182         ASSERT_NOT_REACHED();
183         break;
184     }
185     return true;
186 }
187
188 bool SVGAnimatedType::supportsAnimVal(AnimatedPropertyType type)
189 {
190     // AnimatedColor is only used for CSS property animations.
191     return type != AnimatedUnknown && type != AnimatedColor;
192 }
193
194 } // namespace WebCore