~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/svg/SVGAnimatedLengthList.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
22
#if ENABLE(SVG)
 
23
#include "SVGAnimatedLengthList.h"
 
24
 
 
25
#include "SVGAnimateElement.h"
 
26
#include "SVGAnimatedNumber.h"
 
27
 
 
28
namespace WebCore {
 
29
 
 
30
SVGAnimatedLengthListAnimator::SVGAnimatedLengthListAnimator(SVGAnimationElement* animationElement, SVGElement* contextElement)
 
31
    : SVGAnimatedTypeAnimator(AnimatedLengthList, animationElement, contextElement)
 
32
    , m_lengthMode(SVGLength::lengthModeForAnimatedLengthAttribute(animationElement->attributeName()))
 
33
{
 
34
}
 
35
 
 
36
PassOwnPtr<SVGAnimatedType> SVGAnimatedLengthListAnimator::constructFromString(const String& string)
 
37
{
 
38
    OwnPtr<SVGAnimatedType> animateType = SVGAnimatedType::createLengthList(new SVGLengthList);
 
39
    animateType->lengthList().parse(string, m_lengthMode);
 
40
    return animateType.release();
 
41
}
 
42
 
 
43
PassOwnPtr<SVGAnimatedType> SVGAnimatedLengthListAnimator::startAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
 
44
{
 
45
    return SVGAnimatedType::createLengthList(constructFromBaseValue<SVGAnimatedLengthList>(animatedTypes));
 
46
}
 
47
 
 
48
void SVGAnimatedLengthListAnimator::stopAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
 
49
{
 
50
    stopAnimValAnimationForType<SVGAnimatedLengthList>(animatedTypes);
 
51
}
 
52
 
 
53
void SVGAnimatedLengthListAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType* type)
 
54
{
 
55
    resetFromBaseValue<SVGAnimatedLengthList>(animatedTypes, type, &SVGAnimatedType::lengthList);
 
56
}
 
57
 
 
58
void SVGAnimatedLengthListAnimator::animValWillChange(const SVGElementAnimatedPropertyList& animatedTypes)
 
59
{
 
60
    animValWillChangeForType<SVGAnimatedLengthList>(animatedTypes);
 
61
}
 
62
 
 
63
void SVGAnimatedLengthListAnimator::animValDidChange(const SVGElementAnimatedPropertyList& animatedTypes)
 
64
{
 
65
    animValDidChangeForType<SVGAnimatedLengthList>(animatedTypes);
 
66
}
 
67
 
 
68
void SVGAnimatedLengthListAnimator::addAnimatedTypes(SVGAnimatedType* from, SVGAnimatedType* to)
 
69
{
 
70
    ASSERT(from->type() == AnimatedLengthList);
 
71
    ASSERT(from->type() == to->type());
 
72
 
 
73
    const SVGLengthList& fromLengthList = from->lengthList();
 
74
    SVGLengthList& toLengthList = to->lengthList();
 
75
 
 
76
    unsigned fromLengthListSize = fromLengthList.size();
 
77
    if (!fromLengthListSize || fromLengthListSize != toLengthList.size())
 
78
        return;
 
79
 
 
80
    SVGLengthContext lengthContext(m_contextElement);
 
81
    ExceptionCode ec = 0;
 
82
    for (unsigned i = 0; i < fromLengthListSize; ++i) {
 
83
        toLengthList[i].setValue(toLengthList[i].value(lengthContext) + fromLengthList[i].value(lengthContext), lengthContext, ec);
 
84
        ASSERT(!ec);
 
85
    }
 
86
}
 
87
 
 
88
static SVGLengthList parseLengthListFromString(SVGAnimationElement* animationElement, const String& string)
 
89
{
 
90
    SVGLengthList lengthList;
 
91
    lengthList.parse(string, SVGLength::lengthModeForAnimatedLengthAttribute(animationElement->attributeName()));
 
92
    return lengthList;
 
93
}
 
94
 
 
95
void SVGAnimatedLengthListAnimator::calculateAnimatedValue(float percentage, unsigned repeatCount, SVGAnimatedType* from, SVGAnimatedType* to, SVGAnimatedType* toAtEndOfDuration, SVGAnimatedType* animated)
 
96
{
 
97
    ASSERT(m_animationElement);
 
98
    ASSERT(m_contextElement);
 
99
 
 
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();
 
104
 
 
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);
 
108
 
 
109
    if (!m_animationElement->adjustFromToListValues<SVGLengthList>(fromLengthList, toLengthList, animatedLengthList, percentage))
 
110
        return;
 
111
 
 
112
    unsigned fromLengthListSize = fromLengthList.size();
 
113
    unsigned toLengthListSize = toLengthList.size();
 
114
    unsigned toAtEndOfDurationListSize = toAtEndOfDurationLengthList.size();
 
115
 
 
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);
 
126
        }
 
127
        float effectiveToAtEnd = i < toAtEndOfDurationListSize ? toAtEndOfDurationLengthList[i].value(lengthContext) : 0;
 
128
 
 
129
        m_animationElement->animateAdditiveNumber(percentage, repeatCount, effectiveFrom, toLengthList[i].value(lengthContext), effectiveToAtEnd, animatedNumber);
 
130
        animatedLengthList[i].setValue(lengthContext, animatedNumber, m_lengthMode, unitType, ec);
 
131
        ASSERT(!ec);
 
132
    }
 
133
}
 
134
 
 
135
float SVGAnimatedLengthListAnimator::calculateDistance(const String&, const String&)
 
136
{
 
137
    // FIXME: Distance calculation is not possible for SVGLengthList right now. We need the distance for every single value.
 
138
    return -1;
 
139
}
 
140
 
 
141
}
 
142
 
 
143
#endif // ENABLE(SVG)