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
22#include "config.h"
23#include "SVGAnimatedTypeAnimator.h"
24
25#include "SVGAttributeToPropertyMap.h"
26#include "SVGElement.h"
27
28namespace WebCore {
29
30SVGElementAnimatedProperties::SVGElementAnimatedProperties()
31    : element(0)
32{ }
33
34SVGElementAnimatedProperties::SVGElementAnimatedProperties(SVGElement* element, Vector<RefPtr<SVGAnimatedProperty>>& properties)
35    : element(element)
36    , properties(properties)
37{ }
38
39SVGAnimatedTypeAnimator::SVGAnimatedTypeAnimator(AnimatedPropertyType type, SVGAnimationElement* animationElement, SVGElement* contextElement)
40    : m_type(type)
41    , m_animationElement(animationElement)
42    , m_contextElement(contextElement)
43{
44}
45
46SVGAnimatedTypeAnimator::~SVGAnimatedTypeAnimator()
47{ }
48
49void SVGAnimatedTypeAnimator::calculateFromAndToValues(std::unique_ptr<SVGAnimatedType>& from, std::unique_ptr<SVGAnimatedType>& to, const String& fromString, const String& toString)
50{
51    from = constructFromString(fromString);
52    to = constructFromString(toString);
53}
54
55void SVGAnimatedTypeAnimator::calculateFromAndByValues(std::unique_ptr<SVGAnimatedType>& from, std::unique_ptr<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
62SVGElementAnimatedPropertyList 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} // namespace WebCore
109