Upstream version 7.36.149.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 TimingFunction* KeyframeValue::timingFunction(const RenderStyle& keyframeStyle)
32 {
33     const CSSAnimationDataList* animations = keyframeStyle.animations();
34     ASSERT(animations && !animations->isEmpty());
35     return animations->animation(0)->timingFunction();
36 }
37
38 KeyframeList::~KeyframeList()
39 {
40     clear();
41 }
42
43 void KeyframeList::clear()
44 {
45     m_keyframes.clear();
46     m_properties.clear();
47 }
48
49 void KeyframeList::insert(const KeyframeValue& keyframe)
50 {
51     if (keyframe.key() < 0 || keyframe.key() > 1)
52         return;
53
54     bool inserted = false;
55     bool replaced = false;
56     for (size_t i = 0; i < m_keyframes.size(); ++i) {
57         if (m_keyframes[i].key() == keyframe.key()) {
58             m_keyframes[i] = keyframe;
59             replaced = true;
60             break;
61         }
62
63         if (m_keyframes[i].key() > keyframe.key()) {
64             // insert before
65             m_keyframes.insert(i, keyframe);
66             inserted = true;
67             break;
68         }
69     }
70
71     if (!replaced && !inserted)
72         m_keyframes.append(keyframe);
73
74     if (replaced) {
75         // We have to rebuild the properties list from scratch.
76         m_properties.clear();
77         for (Vector<KeyframeValue>::const_iterator it = m_keyframes.begin(); it != m_keyframes.end(); ++it) {
78             const KeyframeValue& currKeyframe = *it;
79             for (HashSet<CSSPropertyID>::const_iterator it = currKeyframe.properties().begin(); it != currKeyframe.properties().end(); ++it)
80                 m_properties.add(*it);
81         }
82     } else {
83         for (HashSet<CSSPropertyID>::const_iterator it = keyframe.properties().begin(); it != keyframe.properties().end(); ++it)
84             m_properties.add(*it);
85     }
86 }
87
88 } // namespace WebCore