OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "core/svg/SVGAnimatedNewPropertyAnimator.h" | 32 #include "core/svg/SVGAnimatedNewPropertyAnimator.h" |
33 | 33 |
34 #include "core/svg/SVGAnimationElement.h" | 34 #include "core/svg/SVGAnimationElement.h" |
35 #include "core/svg/SVGElementInstance.h" | 35 #include "core/svg/SVGElementInstance.h" |
| 36 #include "core/svg/SVGLength.h" |
| 37 #include "core/svg/SVGLengthList.h" |
36 | 38 |
37 namespace WebCore { | 39 namespace WebCore { |
38 | 40 |
39 SVGAnimatedNewPropertyAnimator::SVGAnimatedNewPropertyAnimator(SVGAnimationEleme
nt* animationElement, SVGElement* contextElement) | 41 SVGAnimatedNewPropertyAnimator::SVGAnimatedNewPropertyAnimator(SVGAnimationEleme
nt* animationElement, SVGElement* contextElement, AnimatedPropertyType propertyT
ype) |
40 : SVGAnimatedTypeAnimator(AnimatedNewProperty, animationElement, contextElem
ent) | 42 : SVGAnimatedTypeAnimator(propertyType, animationElement, contextElement) |
| 43 , m_propertyType(propertyType) |
41 { | 44 { |
42 ASSERT(m_animationElement); | 45 ASSERT(m_animationElement); |
43 ASSERT(m_contextElement); | 46 ASSERT(m_contextElement); |
44 | 47 |
45 const QualifiedName& attributeName = m_animationElement->attributeName(); | 48 const QualifiedName& attributeName = m_animationElement->attributeName(); |
46 m_animatedProperty = m_contextElement->propertyFromAttribute(attributeName); | 49 m_animatedProperty = m_contextElement->propertyFromAttribute(attributeName); |
47 ASSERT(m_animatedProperty); | 50 |
| 51 ASSERT(m_propertyType == AnimatedLength |
| 52 || m_propertyType == AnimatedLengthList |
| 53 || m_propertyType == AnimatedNewProperty); // FIXME |
48 } | 54 } |
49 | 55 |
50 SVGAnimatedNewPropertyAnimator::~SVGAnimatedNewPropertyAnimator() | 56 SVGAnimatedNewPropertyAnimator::~SVGAnimatedNewPropertyAnimator() |
51 { | 57 { |
52 } | 58 } |
53 | 59 |
54 PassRefPtr<NewSVGPropertyBase> SVGAnimatedNewPropertyAnimator::createPropertyFor
Animation(const String& value) | 60 PassRefPtr<NewSVGPropertyBase> SVGAnimatedNewPropertyAnimator::createPropertyFor
Animation(const String& value) |
55 { | 61 { |
56 return m_animatedProperty->currentValueBase()->cloneForAnimation(value); | 62 if (m_animatedProperty) { |
| 63 // SVG DOM animVal animation code-path. |
| 64 return m_animatedProperty->currentValueBase()->cloneForAnimation(value); |
| 65 } |
| 66 |
| 67 // CSS properties animation code-path. |
| 68 // Create a basic instance of the corresponding SVG property. |
| 69 // The instance will not have full context info. (e.g. SVGLengthMode) |
| 70 if (m_propertyType == AnimatedLength) { |
| 71 RefPtr<SVGLength> property = SVGLength::create(LengthModeOther); |
| 72 property->setValueAsString(value, IGNORE_EXCEPTION); |
| 73 return property.release(); |
| 74 } |
| 75 |
| 76 if (m_propertyType == AnimatedLengthList) { |
| 77 RefPtr<SVGLengthList> property = SVGLengthList::create(LengthModeOther); |
| 78 property->setValueAsString(value, IGNORE_EXCEPTION); |
| 79 return property.release(); |
| 80 } |
| 81 |
| 82 ASSERT_NOT_REACHED(); |
| 83 return 0; |
57 } | 84 } |
58 | 85 |
59 PassOwnPtr<SVGAnimatedType> SVGAnimatedNewPropertyAnimator::constructFromString(
const String& value) | 86 PassOwnPtr<SVGAnimatedType> SVGAnimatedNewPropertyAnimator::constructFromString(
const String& value) |
60 { | 87 { |
61 return SVGAnimatedType::createNewProperty(createPropertyForAnimation(value))
; | 88 return SVGAnimatedType::createNewProperty(createPropertyForAnimation(value),
m_propertyType); |
62 } | 89 } |
63 | 90 |
64 PassOwnPtr<SVGAnimatedType> SVGAnimatedNewPropertyAnimator::startAnimValAnimatio
n(const SVGElementAnimatedPropertyList&) | 91 namespace { |
| 92 |
| 93 typedef void (NewSVGAnimatedPropertyBase::*NewSVGAnimatedPropertyMethod)(); |
| 94 |
| 95 void invokeMethodOnAllTargetProperties(const SVGElementAnimatedPropertyList& lis
t, const QualifiedName& attributeName, NewSVGAnimatedPropertyMethod method) |
| 96 { |
| 97 SVGElementAnimatedPropertyList::const_iterator it = list.begin(); |
| 98 SVGElementAnimatedPropertyList::const_iterator itEnd = list.end(); |
| 99 for (; it != itEnd; ++it) { |
| 100 RefPtr<NewSVGAnimatedPropertyBase> animatedProperty = it->element->prope
rtyFromAttribute(attributeName); |
| 101 (animatedProperty.get()->*method)(); |
| 102 } |
| 103 } |
| 104 |
| 105 void setAnimatedValueOnAllTargetProperties(const SVGElementAnimatedPropertyList&
list, const QualifiedName& attributeName, PassRefPtr<NewSVGPropertyBase> passVa
lue) |
| 106 { |
| 107 RefPtr<NewSVGPropertyBase> value = passValue; |
| 108 |
| 109 SVGElementAnimatedPropertyList::const_iterator it = list.begin(); |
| 110 SVGElementAnimatedPropertyList::const_iterator itEnd = list.end(); |
| 111 for (; it != itEnd; ++it) { |
| 112 RefPtr<NewSVGAnimatedPropertyBase> animatedProperty = it->element->prope
rtyFromAttribute(attributeName); |
| 113 animatedProperty->setAnimatedValue(value); |
| 114 } |
| 115 } |
| 116 |
| 117 } |
| 118 |
| 119 PassRefPtr<NewSVGPropertyBase> SVGAnimatedNewPropertyAnimator::resetAnimation(co
nst SVGElementAnimatedPropertyList& list) |
| 120 { |
| 121 ASSERT(m_animatedProperty); |
| 122 RefPtr<NewSVGPropertyBase> animatedValue = m_animatedProperty->createAnimate
dValue(); |
| 123 setAnimatedValueOnAllTargetProperties(list, m_animatedProperty->attributeNam
e(), animatedValue); |
| 124 |
| 125 return animatedValue.release(); |
| 126 } |
| 127 |
| 128 PassOwnPtr<SVGAnimatedType> SVGAnimatedNewPropertyAnimator::startAnimValAnimatio
n(const SVGElementAnimatedPropertyList& list) |
65 { | 129 { |
66 SVGElementInstance::InstanceUpdateBlocker blocker(m_contextElement); | 130 SVGElementInstance::InstanceUpdateBlocker blocker(m_contextElement); |
67 | 131 |
68 m_animatedProperty->animationStarted(); | 132 ASSERT(m_animatedProperty); |
69 return SVGAnimatedType::createNewProperty(m_animatedProperty->currentValueBa
se()); | 133 invokeMethodOnAllTargetProperties(list, m_animatedProperty->attributeName(),
&NewSVGAnimatedPropertyBase::animationStarted); |
| 134 |
| 135 return SVGAnimatedType::createNewProperty(resetAnimation(list), m_propertyTy
pe); |
70 } | 136 } |
71 | 137 |
72 void SVGAnimatedNewPropertyAnimator::stopAnimValAnimation(const SVGElementAnimat
edPropertyList&) | 138 void SVGAnimatedNewPropertyAnimator::stopAnimValAnimation(const SVGElementAnimat
edPropertyList& list) |
73 { | 139 { |
74 SVGElementInstance::InstanceUpdateBlocker blocker(m_contextElement); | 140 SVGElementInstance::InstanceUpdateBlocker blocker(m_contextElement); |
75 | 141 |
76 m_animatedProperty->animationEnded(); | 142 ASSERT(m_animatedProperty); |
| 143 invokeMethodOnAllTargetProperties(list, m_animatedProperty->attributeName(),
&NewSVGAnimatedPropertyBase::animationEnded); |
77 } | 144 } |
78 | 145 |
79 void SVGAnimatedNewPropertyAnimator::resetAnimValToBaseVal(const SVGElementAnima
tedPropertyList&, SVGAnimatedType* animated) | 146 void SVGAnimatedNewPropertyAnimator::resetAnimValToBaseVal(const SVGElementAnima
tedPropertyList& list, SVGAnimatedType* animated) |
80 { | 147 { |
81 SVGElementInstance::InstanceUpdateBlocker blocker(m_contextElement); | 148 SVGElementInstance::InstanceUpdateBlocker blocker(m_contextElement); |
82 | 149 |
83 m_animatedProperty->resetToBaseVal(); | 150 animated->newProperty() = resetAnimation(list); |
84 animated->newProperty() = m_animatedProperty->currentValueBase(); | |
85 } | 151 } |
86 | 152 |
87 void SVGAnimatedNewPropertyAnimator::animValWillChange(const SVGElementAnimatedP
ropertyList&) | 153 void SVGAnimatedNewPropertyAnimator::animValWillChange(const SVGElementAnimatedP
ropertyList& list) |
88 { | 154 { |
89 SVGElementInstance::InstanceUpdateBlocker blocker(m_contextElement); | 155 SVGElementInstance::InstanceUpdateBlocker blocker(m_contextElement); |
90 | 156 |
91 m_animatedProperty->animValWillChange(); | 157 ASSERT(m_animatedProperty); |
| 158 invokeMethodOnAllTargetProperties(list, m_animatedProperty->attributeName(),
&NewSVGAnimatedPropertyBase::animValWillChange); |
92 } | 159 } |
93 | 160 |
94 void SVGAnimatedNewPropertyAnimator::animValDidChange(const SVGElementAnimatedPr
opertyList&) | 161 void SVGAnimatedNewPropertyAnimator::animValDidChange(const SVGElementAnimatedPr
opertyList& list) |
95 { | 162 { |
96 SVGElementInstance::InstanceUpdateBlocker blocker(m_contextElement); | 163 SVGElementInstance::InstanceUpdateBlocker blocker(m_contextElement); |
97 | 164 |
98 m_animatedProperty->animValDidChange(); | 165 ASSERT(m_animatedProperty); |
| 166 invokeMethodOnAllTargetProperties(list, m_animatedProperty->attributeName(),
&NewSVGAnimatedPropertyBase::animValDidChange); |
99 } | 167 } |
100 | 168 |
101 void SVGAnimatedNewPropertyAnimator::addAnimatedTypes(SVGAnimatedType* from, SVG
AnimatedType* to) | 169 void SVGAnimatedNewPropertyAnimator::addAnimatedTypes(SVGAnimatedType* from, SVG
AnimatedType* to) |
102 { | 170 { |
103 to->newProperty()->add(from->newProperty(), m_contextElement); | 171 to->newProperty()->add(from->newProperty(), m_contextElement); |
104 } | 172 } |
105 | 173 |
106 class ParsePropertyFromString { | 174 class ParsePropertyFromString { |
107 public: | 175 public: |
108 explicit ParsePropertyFromString(SVGAnimatedNewPropertyAnimator* animator) | 176 explicit ParsePropertyFromString(SVGAnimatedNewPropertyAnimator* animator) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 float SVGAnimatedNewPropertyAnimator::calculateDistance(const String& fromString
, const String& toString) | 208 float SVGAnimatedNewPropertyAnimator::calculateDistance(const String& fromString
, const String& toString) |
141 { | 209 { |
142 ASSERT(m_animationElement); | 210 ASSERT(m_animationElement); |
143 ASSERT(m_contextElement); | 211 ASSERT(m_contextElement); |
144 RefPtr<NewSVGPropertyBase> fromValue = createPropertyForAnimation(fromString
); | 212 RefPtr<NewSVGPropertyBase> fromValue = createPropertyForAnimation(fromString
); |
145 RefPtr<NewSVGPropertyBase> toValue = createPropertyForAnimation(toString); | 213 RefPtr<NewSVGPropertyBase> toValue = createPropertyForAnimation(toString); |
146 return fromValue->calculateDistance(toValue, m_contextElement); | 214 return fromValue->calculateDistance(toValue, m_contextElement); |
147 } | 215 } |
148 | 216 |
149 } // namespace WebCore | 217 } // namespace WebCore |
OLD | NEW |