| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> |
| 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> | 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> |
| 5 * Copyright (C) 2008 Apple Inc. All rights reserved. | 5 * Copyright (C) 2008 Apple Inc. All rights reserved. |
| 6 * Copyright (C) 2008 Cameron McCormack <cam@mcc.id.au> | 6 * Copyright (C) 2008 Cameron McCormack <cam@mcc.id.au> |
| 7 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 7 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 22 * Boston, MA 02110-1301, USA. | 22 * Boston, MA 02110-1301, USA. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #ifndef SVGAnimationElement_h | 25 #ifndef SVGAnimationElement_h |
| 26 #define SVGAnimationElement_h | 26 #define SVGAnimationElement_h |
| 27 | 27 |
| 28 #include "core/CoreExport.h" | 28 #include "core/CoreExport.h" |
| 29 #include "core/svg/animation/SVGSMILElement.h" | 29 #include "core/svg/animation/SVGSMILElement.h" |
| 30 #include "ui/gfx/geometry/cubic_bezier.h" | 30 #include "ui/gfx/geometry/cubic_bezier.h" |
| 31 #include "wtf/Functional.h" | |
| 32 #include "wtf/Vector.h" | 31 #include "wtf/Vector.h" |
| 33 | 32 |
| 34 namespace blink { | 33 namespace blink { |
| 35 | 34 |
| 36 class ExceptionState; | 35 class ExceptionState; |
| 37 | 36 |
| 38 enum AnimationMode { | 37 enum AnimationMode { |
| 39 NoAnimation, | 38 NoAnimation, |
| 40 FromToAnimation, | 39 FromToAnimation, |
| 41 FromByAnimation, | 40 FromByAnimation, |
| 42 ToAnimation, | 41 ToAnimation, |
| 43 ByAnimation, | 42 ByAnimation, |
| 44 ValuesAnimation, | 43 ValuesAnimation, |
| 45 PathAnimation // Used by AnimateMotion. | 44 PathAnimation // Used by AnimateMotion. |
| 46 }; | 45 }; |
| 47 | 46 |
| 48 // If we have 'inherit' as animation value, we need to grab the value | |
| 49 // during the animation since the value can be animated itself. | |
| 50 enum AnimatedPropertyValueType { RegularPropertyValue, InheritValue }; | |
| 51 | |
| 52 enum CalcMode { | 47 enum CalcMode { |
| 53 CalcModeDiscrete, | 48 CalcModeDiscrete, |
| 54 CalcModeLinear, | 49 CalcModeLinear, |
| 55 CalcModePaced, | 50 CalcModePaced, |
| 56 CalcModeSpline | 51 CalcModeSpline |
| 57 }; | 52 }; |
| 58 | 53 |
| 59 class CORE_EXPORT SVGAnimationElement : public SVGSMILElement { | 54 class CORE_EXPORT SVGAnimationElement : public SVGSMILElement { |
| 60 DEFINE_WRAPPERTYPEINFO(); | 55 DEFINE_WRAPPERTYPEINFO(); |
| 61 | 56 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 85 DontApplyAnimation, | 80 DontApplyAnimation, |
| 86 ApplyCSSAnimation, | 81 ApplyCSSAnimation, |
| 87 ApplyXMLAnimation, | 82 ApplyXMLAnimation, |
| 88 ApplyXMLandCSSAnimation | 83 ApplyXMLandCSSAnimation |
| 89 }; | 84 }; |
| 90 | 85 |
| 91 ShouldApplyAnimationType shouldApplyAnimation( | 86 ShouldApplyAnimationType shouldApplyAnimation( |
| 92 SVGElement* targetElement, | 87 SVGElement* targetElement, |
| 93 const QualifiedName& attributeName); | 88 const QualifiedName& attributeName); |
| 94 | 89 |
| 95 AnimatedPropertyValueType fromPropertyValueType() const { | |
| 96 return m_fromPropertyValueType; | |
| 97 } | |
| 98 AnimatedPropertyValueType toPropertyValueType() const { | |
| 99 return m_toPropertyValueType; | |
| 100 } | |
| 101 | |
| 102 template <typename AnimatedType, typename ParseTypeFromStringType> | |
| 103 void adjustForInheritance(ParseTypeFromStringType parseTypeFromString, | |
| 104 AnimatedPropertyValueType valueType, | |
| 105 AnimatedType& animatedType, | |
| 106 SVGElement* contextElement) { | |
| 107 if (valueType != InheritValue) | |
| 108 return; | |
| 109 // Replace 'inherit' by its computed property value. | |
| 110 String typeString; | |
| 111 adjustForInheritance(contextElement, attributeName(), typeString); | |
| 112 animatedType = parseTypeFromString(this, typeString); | |
| 113 } | |
| 114 | |
| 115 template <typename AnimatedType> | 90 template <typename AnimatedType> |
| 116 void animateDiscreteType(float percentage, | 91 void animateDiscreteType(float percentage, |
| 117 const AnimatedType& fromType, | 92 const AnimatedType& fromType, |
| 118 const AnimatedType& toType, | 93 const AnimatedType& toType, |
| 119 AnimatedType& animatedType) { | 94 AnimatedType& animatedType) { |
| 120 if ((getAnimationMode() == FromToAnimation && percentage > 0.5) || | 95 if ((getAnimationMode() == FromToAnimation && percentage > 0.5) || |
| 121 getAnimationMode() == ToAnimation || percentage == 1) { | 96 getAnimationMode() == ToAnimation || percentage == 1) { |
| 122 animatedType = AnimatedType(toType); | 97 animatedType = AnimatedType(toType); |
| 123 return; | 98 return; |
| 124 } | 99 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 142 | 117 |
| 143 if (isAdditive() && getAnimationMode() != ToAnimation) | 118 if (isAdditive() && getAnimationMode() != ToAnimation) |
| 144 animatedNumber += number; | 119 animatedNumber += number; |
| 145 else | 120 else |
| 146 animatedNumber = number; | 121 animatedNumber = number; |
| 147 } | 122 } |
| 148 | 123 |
| 149 protected: | 124 protected: |
| 150 SVGAnimationElement(const QualifiedName&, Document&); | 125 SVGAnimationElement(const QualifiedName&, Document&); |
| 151 | 126 |
| 152 void computeCSSPropertyValue(SVGElement*, CSSPropertyID, String& value); | |
| 153 void determinePropertyValueTypes(const String& from, const String& to); | |
| 154 | |
| 155 void parseAttribute(const QualifiedName&, | 127 void parseAttribute(const QualifiedName&, |
| 156 const AtomicString&, | 128 const AtomicString&, |
| 157 const AtomicString&) override; | 129 const AtomicString&) override; |
| 158 void svgAttributeChanged(const QualifiedName&) override; | 130 void svgAttributeChanged(const QualifiedName&) override; |
| 159 | 131 |
| 160 enum AttributeType { AttributeTypeCSS, AttributeTypeXML, AttributeTypeAuto }; | 132 enum AttributeType { AttributeTypeCSS, AttributeTypeXML, AttributeTypeAuto }; |
| 161 AttributeType getAttributeType() const { return m_attributeType; } | 133 AttributeType getAttributeType() const { return m_attributeType; } |
| 162 | 134 |
| 163 String toValue() const; | 135 String toValue() const; |
| 164 String byValue() const; | 136 String byValue() const; |
| 165 String fromValue() const; | 137 String fromValue() const; |
| 166 | 138 |
| 167 // from SVGSMILElement | 139 // from SVGSMILElement |
| 168 void startedActiveInterval() override; | 140 void startedActiveInterval() override; |
| 169 void updateAnimation(float percent, | 141 void updateAnimation(float percent, |
| 170 unsigned repeat, | 142 unsigned repeat, |
| 171 SVGSMILElement* resultElement) override; | 143 SVGSMILElement* resultElement) override; |
| 172 | 144 |
| 173 AnimatedPropertyValueType m_fromPropertyValueType; | |
| 174 AnimatedPropertyValueType m_toPropertyValueType; | |
| 175 | |
| 176 void setTargetElement(SVGElement*) override; | 145 void setTargetElement(SVGElement*) override; |
| 177 void setAttributeName(const QualifiedName&) override; | 146 void setAttributeName(const QualifiedName&) override; |
| 178 | 147 |
| 179 bool hasInvalidCSSAttributeType() const { | 148 bool hasInvalidCSSAttributeType() const { |
| 180 return m_hasInvalidCSSAttributeType; | 149 return m_hasInvalidCSSAttributeType; |
| 181 } | 150 } |
| 182 | 151 |
| 183 virtual void updateAnimationMode(); | 152 virtual void updateAnimationMode(); |
| 184 void setAnimationMode(AnimationMode animationMode) { | 153 void setAnimationMode(AnimationMode animationMode) { |
| 185 m_animationMode = animationMode; | 154 m_animationMode = animationMode; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 void calculateKeyTimesForCalcModePaced(); | 191 void calculateKeyTimesForCalcModePaced(); |
| 223 float calculatePercentFromKeyPoints(float percent) const; | 192 float calculatePercentFromKeyPoints(float percent) const; |
| 224 void currentValuesFromKeyPoints(float percent, | 193 void currentValuesFromKeyPoints(float percent, |
| 225 float& effectivePercent, | 194 float& effectivePercent, |
| 226 String& from, | 195 String& from, |
| 227 String& to) const; | 196 String& to) const; |
| 228 float calculatePercentForSpline(float percent, unsigned splineIndex) const; | 197 float calculatePercentForSpline(float percent, unsigned splineIndex) const; |
| 229 float calculatePercentForFromTo(float percent) const; | 198 float calculatePercentForFromTo(float percent) const; |
| 230 unsigned calculateKeyTimesIndex(float percent) const; | 199 unsigned calculateKeyTimesIndex(float percent) const; |
| 231 | 200 |
| 232 void adjustForInheritance(SVGElement* targetElement, | |
| 233 const QualifiedName& attributeName, | |
| 234 String&); | |
| 235 | |
| 236 void setCalcMode(const AtomicString&); | 201 void setCalcMode(const AtomicString&); |
| 237 | 202 |
| 238 bool m_animationValid; | 203 bool m_animationValid; |
| 239 | 204 |
| 240 AttributeType m_attributeType; | 205 AttributeType m_attributeType; |
| 241 Vector<String> m_values; | 206 Vector<String> m_values; |
| 242 // FIXME: We should probably use doubles for this, but there's no point | 207 // FIXME: We should probably use doubles for this, but there's no point |
| 243 // making such a change unless all SVG logic for sampling animations is | 208 // making such a change unless all SVG logic for sampling animations is |
| 244 // changed to use doubles. | 209 // changed to use doubles. |
| 245 Vector<float> m_keyTimes; | 210 Vector<float> m_keyTimes; |
| 246 Vector<float> m_keyPoints; | 211 Vector<float> m_keyPoints; |
| 247 Vector<gfx::CubicBezier> m_keySplines; | 212 Vector<gfx::CubicBezier> m_keySplines; |
| 248 String m_lastValuesAnimationFrom; | 213 String m_lastValuesAnimationFrom; |
| 249 String m_lastValuesAnimationTo; | 214 String m_lastValuesAnimationTo; |
| 250 bool m_hasInvalidCSSAttributeType; | 215 bool m_hasInvalidCSSAttributeType; |
| 251 CalcMode m_calcMode; | 216 CalcMode m_calcMode; |
| 252 AnimationMode m_animationMode; | 217 AnimationMode m_animationMode; |
| 253 }; | 218 }; |
| 254 | 219 |
| 255 } // namespace blink | 220 } // namespace blink |
| 256 | 221 |
| 257 #endif // SVGAnimationElement_h | 222 #endif // SVGAnimationElement_h |
| OLD | NEW |