2
* Copyright (C) Research In Motion Limited 2011. All rights reserved.
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.
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.
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.
23
#include "SVGAnimatedLengthList.h"
25
#include "SVGAnimateElement.h"
26
#include "SVGAnimatedNumber.h"
30
SVGAnimatedLengthListAnimator::SVGAnimatedLengthListAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
31
: SVGAnimatedTypeAnimator(AnimatedLengthList, animationElement, contextElement)
32
, m_lengthMode(SVGLength::lengthModeForAnimatedLengthAttribute(animationElement->attributeName()))
36
PassOwnPtr<SVGAnimatedType> SVGAnimatedLengthListAnimator::constructFromString(const String& string)
38
OwnPtr<SVGAnimatedType> animateType = SVGAnimatedType::createLengthList(new SVGLengthList);
39
animateType->lengthList().parse(string, m_lengthMode);
40
return animateType.release();
43
PassOwnPtr<SVGAnimatedType> SVGAnimatedLengthListAnimator::startAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
45
return SVGAnimatedType::createLengthList(constructFromBaseValue<SVGAnimatedLengthList>(animatedTypes));
48
void SVGAnimatedLengthListAnimator::stopAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
50
stopAnimValAnimationForType<SVGAnimatedLengthList>(animatedTypes);
53
void SVGAnimatedLengthListAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType* type)
55
resetFromBaseValue<SVGAnimatedLengthList>(animatedTypes, type, &SVGAnimatedType::lengthList);
58
void SVGAnimatedLengthListAnimator::animValWillChange(const SVGElementAnimatedPropertyList& animatedTypes)
60
animValWillChangeForType<SVGAnimatedLengthList>(animatedTypes);
63
void SVGAnimatedLengthListAnimator::animValDidChange(const SVGElementAnimatedPropertyList& animatedTypes)
65
animValDidChangeForType<SVGAnimatedLengthList>(animatedTypes);
68
void SVGAnimatedLengthListAnimator::addAnimatedTypes(SVGAnimatedType* from, SVGAnimatedType* to)
70
ASSERT(from->type() == AnimatedLengthList);
71
ASSERT(from->type() == to->type());
73
const SVGLengthList& fromLengthList = from->lengthList();
74
SVGLengthList& toLengthList = to->lengthList();
76
unsigned fromLengthListSize = fromLengthList.size();
77
if (!fromLengthListSize || fromLengthListSize != toLengthList.size())
80
SVGLengthContext lengthContext(m_contextElement);
82
for (unsigned i = 0; i < fromLengthListSize; ++i) {
83
toLengthList[i].setValue(toLengthList[i].value(lengthContext) + fromLengthList[i].value(lengthContext), lengthContext, ec);
88
static SVGLengthList parseLengthListFromString(SVGAnimationElement* animationElement, const String& string)
90
SVGLengthList lengthList;
91
lengthList.parse(string, SVGLength::lengthModeForAnimatedLengthAttribute(animationElement->attributeName()));
95
void SVGAnimatedLengthListAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGAnimatedType* from, SVGAnimatedType* to, SVGAnimatedType* toAtEndOfDuration, SVGAnimatedType* animated)
97
ASSERT(m_animationElement);
98
ASSERT(m_contextElement);
100
SVGLengthList fromLengthList = m_animationElement->animationMode() == ToAnimation ? animated->lengthList() : from->lengthList();
101
SVGLengthList toLengthList = to->lengthList();
102
const SVGLengthList& toAtEndOfDurationLengthList = toAtEndOfDuration->lengthList();
103
SVGLengthList& animatedLengthList = animated->lengthList();
105
// Apply CSS inheritance rules.
106
m_animationElement->adjustForInheritance<SVGLengthList>(parseLengthListFromString, m_animationElement->fromPropertyValueType(), fromLengthList, m_contextElement);
107
m_animationElement->adjustForInheritance<SVGLengthList>(parseLengthListFromString, m_animationElement->toPropertyValueType(), toLengthList, m_contextElement);
109
if (!m_animationElement->adjustFromToListValues<SVGLengthList>(fromLengthList, toLengthList, animatedLengthList, percentage))
112
unsigned fromLengthListSize = fromLengthList.size();
113
unsigned toLengthListSize = toLengthList.size();
114
unsigned toAtEndOfDurationListSize = toAtEndOfDurationLengthList.size();
116
SVGLengthContext lengthContext(m_contextElement);
117
ExceptionCode ec = 0;
118
for (unsigned i = 0; i < toLengthListSize; ++i) {
119
float animatedNumber = animatedLengthList[i].value(lengthContext);
120
SVGLengthType unitType = toLengthList[i].unitType();
121
float effectiveFrom = 0;
122
if (fromLengthListSize) {
123
if (percentage < 0.5)
124
unitType = fromLengthList[i].unitType();
125
effectiveFrom = fromLengthList[i].value(lengthContext);
127
float effectiveToAtEnd = i < toAtEndOfDurationListSize ? toAtEndOfDurationLengthList[i].value(lengthContext) : 0;
129
m_animationElement->animateAdditiveNumber(percentage, repeatCount, effectiveFrom, toLengthList[i].value(lengthContext), effectiveToAtEnd, animatedNumber);
130
animatedLengthList[i].setValue(lengthContext, animatedNumber, m_lengthMode, unitType, ec);
135
float SVGAnimatedLengthListAnimator::calculateDistance(const String&, const String&)
137
// FIXME: Distance calculation is not possible for SVGLengthList right now. We need the distance for every single value.
143
#endif // ENABLE(SVG)