Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / style / KeyframeList.cpp
1 /*
2  * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
3  * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  *
20  */
21
22 #include "config.h"
23 #include "core/rendering/style/KeyframeList.h"
24
25 #include "core/animation/Animation.h"
26 #include "core/css/StylePropertySet.h"
27 #include "core/rendering/RenderObject.h"
28
29 namespace WebCore {
30
31 void KeyframeValue::addProperties(const StylePropertySet* propertySet)
32 {
33     if (!propertySet)
34         return;
35     unsigned propertyCount = propertySet->propertyCount();
36     for (unsigned i = 0; i < propertyCount; ++i) {
37         CSSPropertyID property = propertySet->propertyAt(i).id();
38         // Timing-function within keyframes is special, because it is not animated; it just
39         // describes the timing function between this keyframe and the next.
40         if (property != CSSPropertyWebkitAnimationTimingFunction && property != CSSPropertyAnimationTimingFunction)
41             addProperty(property);
42     }
43 }
44
45 TimingFunction* KeyframeValue::timingFunction(const RenderStyle& keyframeStyle)
46 {
47     const CSSAnimationDataList* animations = keyframeStyle.animations();
48     ASSERT(animations && !animations->isEmpty());
49     return animations->animation(0)->timingFunction();
50 }
51
52 KeyframeList::~KeyframeList()
53 {
54     clear();
55 }
56
57 void KeyframeList::clear()
58 {
59     m_keyframes.clear();
60     m_properties.clear();
61 }
62
63 void KeyframeList::insert(const KeyframeValue& keyframe)
64 {
65     if (keyframe.key() < 0 || keyframe.key() > 1)
66         return;
67
68     bool inserted = false;
69     bool replaced = false;
70     for (size_t i = 0; i < m_keyframes.size(); ++i) {
71         if (m_keyframes[i].key() == keyframe.key()) {
72             m_keyframes[i] = keyframe;
73             replaced = true;
74             break;
75         }
76
77         if (m_keyframes[i].key() > keyframe.key()) {
78             // insert before
79             m_keyframes.insert(i, keyframe);
80             inserted = true;
81             break;
82         }
83     }
84
85     if (!replaced && !inserted)
86         m_keyframes.append(keyframe);
87
88     if (replaced) {
89         // We have to rebuild the properties list from scratch.
90         m_properties.clear();
91         for (Vector<KeyframeValue>::const_iterator it = m_keyframes.begin(); it != m_keyframes.end(); ++it) {
92             const KeyframeValue& currKeyframe = *it;
93             for (HashSet<CSSPropertyID>::const_iterator it = currKeyframe.properties().begin(); it != currKeyframe.properties().end(); ++it)
94                 m_properties.add(*it);
95         }
96     } else {
97         for (HashSet<CSSPropertyID>::const_iterator it = keyframe.properties().begin(); it != keyframe.properties().end(); ++it)
98             m_properties.add(*it);
99     }
100 }
101
102 } // namespace WebCore