OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | |
3 * | |
4 * This library is free software; you can redistribute it and/or | |
5 * modify it under the terms of the GNU Library General Public | |
6 * License as published by the Free Software Foundation; either | |
7 * version 2 of the License, or (at your option) any later version. | |
8 * | |
9 * This library is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 * Library General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU Library General Public License | |
15 * along with this library; see the file COPYING.LIB. If not, write to | |
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
17 * Boston, MA 02110-1301, USA. | |
18 */ | |
19 | |
20 #include "config.h" | |
21 #include "core/svg/SVGAnimatedLengthList.h" | |
22 | |
23 #include "bindings/v8/ExceptionStatePlaceholder.h" | |
24 #include "core/svg/SVGAnimateElement.h" | |
25 #include "core/svg/SVGAnimatedNumber.h" | |
26 | |
27 namespace WebCore { | |
28 | |
29 SVGAnimatedLengthListAnimator::SVGAnimatedLengthListAnimator(SVGAnimationElement
* animationElement, SVGElement* contextElement) | |
30 : SVGAnimatedTypeAnimator(AnimatedLengthList, animationElement, contextEleme
nt) | |
31 , m_lengthMode(SVGLength::lengthModeForAnimatedLengthAttribute(animationElem
ent->attributeName())) | |
32 { | |
33 } | |
34 | |
35 PassOwnPtr<SVGAnimatedType> SVGAnimatedLengthListAnimator::constructFromString(c
onst String& string) | |
36 { | |
37 OwnPtr<SVGAnimatedType> animateType = SVGAnimatedType::createLengthList(new
SVGLengthList); | |
38 animateType->lengthList().parse(string, m_lengthMode); | |
39 return animateType.release(); | |
40 } | |
41 | |
42 PassOwnPtr<SVGAnimatedType> SVGAnimatedLengthListAnimator::startAnimValAnimation
(const SVGElementAnimatedPropertyList& animatedTypes) | |
43 { | |
44 return SVGAnimatedType::createLengthList(constructFromBaseValue<SVGAnimatedL
engthList>(animatedTypes)); | |
45 } | |
46 | |
47 void SVGAnimatedLengthListAnimator::stopAnimValAnimation(const SVGElementAnimate
dPropertyList& animatedTypes) | |
48 { | |
49 stopAnimValAnimationForType<SVGAnimatedLengthList>(animatedTypes); | |
50 } | |
51 | |
52 void SVGAnimatedLengthListAnimator::resetAnimValToBaseVal(const SVGElementAnimat
edPropertyList& animatedTypes, SVGAnimatedType* type) | |
53 { | |
54 resetFromBaseValue<SVGAnimatedLengthList>(animatedTypes, type, &SVGAnimatedT
ype::lengthList); | |
55 } | |
56 | |
57 void SVGAnimatedLengthListAnimator::animValWillChange(const SVGElementAnimatedPr
opertyList& animatedTypes) | |
58 { | |
59 animValWillChangeForType<SVGAnimatedLengthList>(animatedTypes); | |
60 } | |
61 | |
62 void SVGAnimatedLengthListAnimator::animValDidChange(const SVGElementAnimatedPro
pertyList& animatedTypes) | |
63 { | |
64 animValDidChangeForType<SVGAnimatedLengthList>(animatedTypes); | |
65 } | |
66 | |
67 void SVGAnimatedLengthListAnimator::addAnimatedTypes(SVGAnimatedType* from, SVGA
nimatedType* to) | |
68 { | |
69 ASSERT(from->type() == AnimatedLengthList); | |
70 ASSERT(from->type() == to->type()); | |
71 | |
72 const SVGLengthList& fromLengthList = from->lengthList(); | |
73 SVGLengthList& toLengthList = to->lengthList(); | |
74 | |
75 unsigned fromLengthListSize = fromLengthList.size(); | |
76 if (!fromLengthListSize || fromLengthListSize != toLengthList.size()) | |
77 return; | |
78 | |
79 SVGLengthContext lengthContext(m_contextElement); | |
80 for (unsigned i = 0; i < fromLengthListSize; ++i) | |
81 toLengthList[i].setValue(toLengthList[i].value(lengthContext) + fromLeng
thList[i].value(lengthContext), lengthContext, ASSERT_NO_EXCEPTION); | |
82 } | |
83 | |
84 static SVGLengthList parseLengthListFromString(SVGAnimationElement* animationEle
ment, const String& string) | |
85 { | |
86 SVGLengthList lengthList; | |
87 lengthList.parse(string, SVGLength::lengthModeForAnimatedLengthAttribute(ani
mationElement->attributeName())); | |
88 return lengthList; | |
89 } | |
90 | |
91 void SVGAnimatedLengthListAnimator::calculateAnimatedValue(float percentage, uns
igned repeatCount, SVGAnimatedType* from, SVGAnimatedType* to, SVGAnimatedType*
toAtEndOfDuration, SVGAnimatedType* animated) | |
92 { | |
93 ASSERT(m_animationElement); | |
94 ASSERT(m_contextElement); | |
95 | |
96 SVGLengthList fromLengthList = m_animationElement->animationMode() == ToAnim
ation ? animated->lengthList() : from->lengthList(); | |
97 SVGLengthList toLengthList = to->lengthList(); | |
98 const SVGLengthList& toAtEndOfDurationLengthList = toAtEndOfDuration->length
List(); | |
99 SVGLengthList& animatedLengthList = animated->lengthList(); | |
100 | |
101 // Apply CSS inheritance rules. | |
102 m_animationElement->adjustForInheritance<SVGLengthList>(parseLengthListFromS
tring, m_animationElement->fromPropertyValueType(), fromLengthList, m_contextEle
ment); | |
103 m_animationElement->adjustForInheritance<SVGLengthList>(parseLengthListFromS
tring, m_animationElement->toPropertyValueType(), toLengthList, m_contextElement
); | |
104 | |
105 if (!m_animationElement->adjustFromToListValues<SVGLengthList>(fromLengthLis
t, toLengthList, animatedLengthList, percentage)) | |
106 return; | |
107 | |
108 unsigned fromLengthListSize = fromLengthList.size(); | |
109 unsigned toLengthListSize = toLengthList.size(); | |
110 unsigned toAtEndOfDurationListSize = toAtEndOfDurationLengthList.size(); | |
111 | |
112 SVGLengthContext lengthContext(m_contextElement); | |
113 for (unsigned i = 0; i < toLengthListSize; ++i) { | |
114 float animatedNumber = animatedLengthList[i].value(lengthContext); | |
115 SVGLengthType unitType = toLengthList[i].unitType(); | |
116 float effectiveFrom = 0; | |
117 if (fromLengthListSize) { | |
118 if (percentage < 0.5) | |
119 unitType = fromLengthList[i].unitType(); | |
120 effectiveFrom = fromLengthList[i].value(lengthContext); | |
121 } | |
122 float effectiveToAtEnd = i < toAtEndOfDurationListSize ? toAtEndOfDurati
onLengthList[i].value(lengthContext) : 0; | |
123 | |
124 m_animationElement->animateAdditiveNumber(percentage, repeatCount, effec
tiveFrom, toLengthList[i].value(lengthContext), effectiveToAtEnd, animatedNumber
); | |
125 animatedLengthList[i].setValue(lengthContext, animatedNumber, m_lengthMo
de, unitType, ASSERT_NO_EXCEPTION); | |
126 } | |
127 } | |
128 | |
129 float SVGAnimatedLengthListAnimator::calculateDistance(const String&, const Stri
ng&) | |
130 { | |
131 // FIXME: Distance calculation is not possible for SVGLengthList right now.
We need the distance for every single value. | |
132 return -1; | |
133 } | |
134 | |
135 } | |
OLD | NEW |