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 "config.h"
22 #include "core/svg/SVGAnimatedTypeAnimator.h"
23
24 #include "core/svg/SVGElement.h"
25 #include "core/svg/properties/SVGAttributeToPropertyMap.h"
26
27 namespace WebCore {
28
SVGElementAnimatedProperties()29 SVGElementAnimatedProperties::SVGElementAnimatedProperties()
30 : element(0)
31 { }
32
SVGElementAnimatedProperties(SVGElement * element,Vector<RefPtr<SVGAnimatedProperty>> & properties)33 SVGElementAnimatedProperties::SVGElementAnimatedProperties(SVGElement* element, Vector<RefPtr<SVGAnimatedProperty> >& properties)
34 : element(element)
35 , properties(properties)
36 { }
37
SVGAnimatedTypeAnimator(AnimatedPropertyType type,SVGAnimationElement * animationElement,SVGElement * contextElement)38 SVGAnimatedTypeAnimator::SVGAnimatedTypeAnimator(AnimatedPropertyType type, SVGAnimationElement* animationElement, SVGElement* contextElement)
39 : m_type(type)
40 , m_animationElement(animationElement)
41 , m_contextElement(contextElement)
42 {
43 }
44
~SVGAnimatedTypeAnimator()45 SVGAnimatedTypeAnimator::~SVGAnimatedTypeAnimator()
46 {
47 }
48
calculateFromAndToValues(OwnPtr<SVGAnimatedType> & from,OwnPtr<SVGAnimatedType> & to,const String & fromString,const String & toString)49 void SVGAnimatedTypeAnimator::calculateFromAndToValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& toString)
50 {
51 from = constructFromString(fromString);
52 to = constructFromString(toString);
53 }
54
calculateFromAndByValues(OwnPtr<SVGAnimatedType> & from,OwnPtr<SVGAnimatedType> & to,const String & fromString,const String & byString)55 void SVGAnimatedTypeAnimator::calculateFromAndByValues(OwnPtr<SVGAnimatedType>& from, OwnPtr<SVGAnimatedType>& to, const String& fromString, const String& byString)
56 {
57 from = constructFromString(fromString);
58 to = constructFromString(byString);
59 addAnimatedTypes(from.get(), to.get());
60 }
61
findAnimatedPropertiesForAttributeName(SVGElement * targetElement,const QualifiedName & attributeName)62 SVGElementAnimatedPropertyList SVGAnimatedTypeAnimator::findAnimatedPropertiesForAttributeName(SVGElement* targetElement, const QualifiedName& attributeName)
63 {
64 ASSERT(targetElement);
65
66 SVGElementAnimatedPropertyList propertiesByInstance;
67
68 Vector<RefPtr<SVGAnimatedProperty> > targetProperties;
69 targetElement->localAttributeToPropertyMap().animatedPropertiesForAttribute(targetElement, attributeName, targetProperties);
70
71 if (!SVGAnimatedType::supportsAnimVal(m_type))
72 return SVGElementAnimatedPropertyList();
73
74 SVGElementAnimatedProperties propertiesPair(targetElement, targetProperties);
75 propertiesByInstance.append(propertiesPair);
76
77 const HashSet<SVGElementInstance*>& instances = targetElement->instancesForElement();
78 const HashSet<SVGElementInstance*>::const_iterator end = instances.end();
79 for (HashSet<SVGElementInstance*>::const_iterator it = instances.begin(); it != end; ++it) {
80 SVGElement* shadowTreeElement = (*it)->shadowTreeElement();
81 if (!shadowTreeElement)
82 continue;
83
84 Vector<RefPtr<SVGAnimatedProperty> > instanceProperties;
85 targetElement->localAttributeToPropertyMap().animatedPropertiesForAttribute(shadowTreeElement, attributeName, instanceProperties);
86
87 SVGElementAnimatedProperties instancePropertiesPair(shadowTreeElement, instanceProperties);
88 propertiesByInstance.append(instancePropertiesPair);
89 }
90
91 #if !ASSERT_DISABLED
92 SVGElementAnimatedPropertyList::const_iterator propertiesEnd = propertiesByInstance.end();
93 for (SVGElementAnimatedPropertyList::const_iterator it = propertiesByInstance.begin(); it != propertiesEnd; ++it) {
94 size_t propertiesSize = it->properties.size();
95 for (size_t i = 0; i < propertiesSize; ++i) {
96 RefPtr<SVGAnimatedProperty> property = it->properties[i];
97 if (property->animatedPropertyType() != m_type) {
98 ASSERT(m_type == AnimatedAngle);
99 ASSERT(property->animatedPropertyType() == AnimatedEnumeration);
100 }
101 }
102 }
103 #endif
104
105 return propertiesByInstance;
106 }
107
108 }
109