1e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch/*
2e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * Copyright (C) Research In Motion Limited 2011-2012. All rights reserved.
3e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * Copyright (C) 2013 Samsung Electronics. All rights reserved.
4e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch *
5e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * This library is free software; you can redistribute it and/or
6e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * modify it under the terms of the GNU Library General Public
7e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * License as published by the Free Software Foundation; either
8e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * version 2 of the License, or (at your option) any later version.
9e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch *
10e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * This library is distributed in the hope that it will be useful,
11e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * but WITHOUT ANY WARRANTY; without even the implied warranty of
12e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * Library General Public License for more details.
14e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch *
15e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * You should have received a copy of the GNU Library General Public License
16e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * along with this library; see the file COPYING.LIB.  If not, write to
17e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * Boston, MA 02110-1301, USA.
19e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch */
20e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
21e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "config.h"
22e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGAnimatedTypeAnimator.h"
23e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
247242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#include "core/css/parser/CSSParser.h"
25d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/svg/SVGAnimateTransformElement.h"
26d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/svg/SVGAnimatedColor.h"
27d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/svg/SVGAnimationElement.h"
28e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGElement.h"
29d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/svg/SVGLength.h"
30d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/svg/SVGLengthList.h"
31d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/svg/SVGNumber.h"
32d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/svg/SVGPointList.h"
33d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/svg/SVGString.h"
34d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/svg/SVGTransformList.h"
35e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
36c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
37e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
38f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)SVGAnimatedTypeAnimator::SVGAnimatedTypeAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
39f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    : m_animationElement(animationElement)
40e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    , m_contextElement(contextElement)
41e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch{
4209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    ASSERT(m_animationElement);
4309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    ASSERT(m_contextElement);
44d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
45d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    const QualifiedName& attributeName = m_animationElement->attributeName();
46d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    m_animatedProperty = m_contextElement->propertyFromAttribute(attributeName);
47f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    m_type = m_animatedProperty ? m_animatedProperty->type()
48f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        : SVGElement::animatedPropertyTypeForCSSAttribute(attributeName);
49f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
50f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    // Only <animateTransform> is allowed to animate AnimatedTransformList.
51f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    // http://www.w3.org/TR/SVG/animate.html#AnimationAttributesAndProperties
52f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    if (m_type == AnimatedTransformList && !isSVGAnimateTransformElement(*animationElement))
53f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        m_type = AnimatedUnknown;
54f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
55f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    ASSERT(m_type != AnimatedPoint
56f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        && m_type != AnimatedStringList
57f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        && m_type != AnimatedTransform);
58e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch}
59e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
60e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben MurdochSVGAnimatedTypeAnimator::~SVGAnimatedTypeAnimator()
61e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch{
62e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch}
63e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
6407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben MurdochPassRefPtr<SVGPropertyBase> SVGAnimatedTypeAnimator::createPropertyForAnimation(const String& value)
65d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
66d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    if (isAnimatingSVGDom()) {
67d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        // SVG DOM animVal animation code-path.
68d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
69d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        if (m_type == AnimatedTransformList) {
70d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            // TransformList must be animated via <animateTransform>,
71d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            // and its {from,by,to} attribute values needs to be parsed w.r.t. its "type" attribute.
72d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            // Spec: http://www.w3.org/TR/SVG/single-page.html#animate-AnimateTransformElement
73d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            ASSERT(m_animationElement);
74d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            SVGTransformType transformType = toSVGAnimateTransformElement(m_animationElement)->transformType();
75d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            return SVGTransformList::create(transformType, value);
76d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        }
77d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
78d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        ASSERT(m_animatedProperty);
79d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        return m_animatedProperty->currentValueBase()->cloneForAnimation(value);
80d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    }
81d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
82d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(isAnimatingCSSProperty());
83d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
84d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // CSS properties animation code-path.
85d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // Create a basic instance of the corresponding SVG property.
86d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // The instance will not have full context info. (e.g. SVGLengthMode)
87d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
88d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    switch (m_type) {
89d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    case AnimatedColor:
907242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        return SVGColorProperty::create(value.isEmpty() ? StyleColor::currentColor() : CSSParser::colorFromRGBColorString(value));
91d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    case AnimatedNumber: {
92d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        RefPtr<SVGNumber> property = SVGNumber::create();
93d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        property->setValueAsString(value, IGNORE_EXCEPTION);
94d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        return property.release();
95d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    }
96d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    case AnimatedLength: {
97d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        RefPtr<SVGLength> property = SVGLength::create(LengthModeOther);
98d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        property->setValueAsString(value, IGNORE_EXCEPTION);
99d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        return property.release();
100d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    }
101d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    case AnimatedLengthList: {
102d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        RefPtr<SVGLengthList> property = SVGLengthList::create(LengthModeOther);
103d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        property->setValueAsString(value, IGNORE_EXCEPTION);
104d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        return property.release();
105d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    }
106d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    case AnimatedString: {
107d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        RefPtr<SVGString> property = SVGString::create();
108d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        property->setValueAsString(value, IGNORE_EXCEPTION);
109d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        return property.release();
110d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    }
111d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
112f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    // These types don't appear in the table in SVGElement::animatedPropertyTypeForCSSAttribute() and thus don't need support.
113f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    case AnimatedAngle:
114d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    case AnimatedBoolean:
115f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    case AnimatedEnumeration:
116f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    case AnimatedInteger:
117f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    case AnimatedIntegerOptionalInteger:
118d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    case AnimatedNumberList:
119d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    case AnimatedNumberOptionalNumber:
120f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    case AnimatedPath:
121d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    case AnimatedPoint:
122d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    case AnimatedPoints:
123f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    case AnimatedPreserveAspectRatio:
124d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    case AnimatedRect:
125f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    case AnimatedStringList:
126d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    case AnimatedTransform:
127d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    case AnimatedTransformList:
128d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        ASSERT_NOT_REACHED();
129d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
130d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    case AnimatedUnknown:
131d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        ASSERT_NOT_REACHED();
132d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    };
133d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
134d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT_NOT_REACHED();
135d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    return nullptr;
136d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
137d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
13807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben MurdochPassRefPtr<SVGPropertyBase> SVGAnimatedTypeAnimator::constructFromString(const String& value)
139d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
140d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    return createPropertyForAnimation(value);
141d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
142d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
14307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdochvoid SVGAnimatedTypeAnimator::calculateFromAndToValues(RefPtr<SVGPropertyBase>& from, RefPtr<SVGPropertyBase>& to, const String& fromString, const String& toString)
144e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch{
145e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    from = constructFromString(fromString);
146e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    to = constructFromString(toString);
147e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch}
148e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
14907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdochvoid SVGAnimatedTypeAnimator::calculateFromAndByValues(RefPtr<SVGPropertyBase>& from, RefPtr<SVGPropertyBase>& to, const String& fromString, const String& byString)
150e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch{
151e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    from = constructFromString(fromString);
152e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    to = constructFromString(byString);
153d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // FIXME(oilpan): Below .get() should be removed after transition types are gone.
154d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    to->add(from.get(), m_contextElement);
155e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch}
156e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
157d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)namespace {
158d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
159d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)void setAnimatedValueOnAllTargetProperties(const WillBeHeapVector<RawPtrWillBeMember<SVGElement> >& list, const QualifiedName& attributeName, PassRefPtr<SVGPropertyBase> passValue)
160d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
16107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    RefPtr<SVGPropertyBase> value = passValue;
162e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
163d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    WillBeHeapVector<RawPtrWillBeMember<SVGElement> >::const_iterator it = list.begin();
164d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    WillBeHeapVector<RawPtrWillBeMember<SVGElement> >::const_iterator itEnd = list.end();
165d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    for (; it != itEnd; ++it) {
16607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        RefPtr<SVGAnimatedPropertyBase> animatedProperty = (*it)->propertyFromAttribute(attributeName);
167d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        if (animatedProperty)
168d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            animatedProperty->setAnimatedValue(value);
169d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    }
170d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
171d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
172d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
173d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
174d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)PassRefPtr<SVGPropertyBase> SVGAnimatedTypeAnimator::resetAnimation(const WillBeHeapVector<RawPtrWillBeMember<SVGElement> >& list)
175d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
176d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(isAnimatingSVGDom());
17707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    RefPtr<SVGPropertyBase> animatedValue = m_animatedProperty->createAnimatedValue();
178d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(animatedValue->type() == m_type);
179d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    setAnimatedValueOnAllTargetProperties(list, m_animatedProperty->attributeName(), animatedValue);
180e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
181d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    return animatedValue.release();
182d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
183e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
184d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)PassRefPtr<SVGPropertyBase> SVGAnimatedTypeAnimator::startAnimValAnimation(const WillBeHeapVector<RawPtrWillBeMember<SVGElement> >& list)
185d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
186d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(isAnimatingSVGDom());
187323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    SVGElement::InstanceUpdateBlocker blocker(m_contextElement);
188e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
189d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    return resetAnimation(list);
190d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
191e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
192d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)void SVGAnimatedTypeAnimator::stopAnimValAnimation(const WillBeHeapVector<RawPtrWillBeMember<SVGElement> >& list)
193d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
194d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(isAnimatingSVGDom());
195323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    SVGElement::InstanceUpdateBlocker blocker(m_contextElement);
196d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
197f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    WillBeHeapVector<RawPtrWillBeMember<SVGElement> >::const_iterator it = list.begin();
198f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    WillBeHeapVector<RawPtrWillBeMember<SVGElement> >::const_iterator itEnd = list.end();
199f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    for (; it != itEnd; ++it) {
200f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        RefPtr<SVGAnimatedPropertyBase> animatedProperty = (*it)->propertyFromAttribute(m_animatedProperty->attributeName());
201f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        if (animatedProperty)
202f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)            animatedProperty->animationEnded();
203f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    }
204d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
205d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
206d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)PassRefPtr<SVGPropertyBase> SVGAnimatedTypeAnimator::resetAnimValToBaseVal(const WillBeHeapVector<RawPtrWillBeMember<SVGElement> >& list)
207d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
208323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    SVGElement::InstanceUpdateBlocker blocker(m_contextElement);
209d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
210d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    return resetAnimation(list);
211d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
212d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
213d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)class ParsePropertyFromString {
214d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)public:
215d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    explicit ParsePropertyFromString(SVGAnimatedTypeAnimator* animator)
216d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        : m_animator(animator)
217d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    {
218e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    }
219e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
22007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    PassRefPtr<SVGPropertyBase> operator()(SVGAnimationElement*, const String& value)
221d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    {
222d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        return m_animator->createPropertyForAnimation(value);
223e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    }
224e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
225d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)private:
226d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    SVGAnimatedTypeAnimator* m_animator;
227d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)};
228d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
22907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdochvoid SVGAnimatedTypeAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGPropertyBase* from, SVGPropertyBase* to, SVGPropertyBase* toAtEndOfDuration, SVGPropertyBase* animated)
230d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
231d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(m_animationElement);
232d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(m_contextElement);
233d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
23407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    RefPtr<SVGPropertyBase> fromValue = m_animationElement->animationMode() == ToAnimation ? animated : from;
23507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    RefPtr<SVGPropertyBase> toValue = to;
23607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    RefPtr<SVGPropertyBase> toAtEndOfDurationValue = toAtEndOfDuration;
23707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    RefPtr<SVGPropertyBase> animatedValue = animated;
238d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
239d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    // Apply CSS inheritance rules.
240d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ParsePropertyFromString parsePropertyFromString(this);
24107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    m_animationElement->adjustForInheritance<RefPtr<SVGPropertyBase>, ParsePropertyFromString>(parsePropertyFromString, m_animationElement->fromPropertyValueType(), fromValue, m_contextElement);
24207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    m_animationElement->adjustForInheritance<RefPtr<SVGPropertyBase>, ParsePropertyFromString>(parsePropertyFromString, m_animationElement->toPropertyValueType(), toValue, m_contextElement);
243d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
244d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    animatedValue->calculateAnimatedValue(m_animationElement, percentage, repeatCount, fromValue, toValue, toAtEndOfDurationValue, m_contextElement);
245d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
246d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
247d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)float SVGAnimatedTypeAnimator::calculateDistance(const String& fromString, const String& toString)
248d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
249d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(m_animationElement);
250d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(m_contextElement);
25107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    RefPtr<SVGPropertyBase> fromValue = createPropertyForAnimation(fromString);
25207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    RefPtr<SVGPropertyBase> toValue = createPropertyForAnimation(toString);
253d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    return fromValue->calculateDistance(toValue, m_contextElement);
254e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch}
255e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
256d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)void SVGAnimatedTypeAnimator::trace(Visitor* visitor)
257d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles){
258d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    visitor->trace(m_animationElement);
259d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    visitor->trace(m_contextElement);
260d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)}
261d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
262e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch}
263