• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "KeyframeList.h"
24 #include "RenderObject.h"
25 
26 namespace WebCore {
27 
~KeyframeList()28 KeyframeList::~KeyframeList()
29 {
30     clear();
31 }
32 
clear()33 void KeyframeList::clear()
34 {
35     m_keyframes.clear();
36     m_properties.clear();
37 }
38 
operator ==(const KeyframeList & o) const39 bool KeyframeList::operator==(const KeyframeList& o) const
40 {
41     if (m_keyframes.size() != o.m_keyframes.size())
42         return false;
43 
44     Vector<KeyframeValue>::const_iterator it2 = o.m_keyframes.begin();
45     for (Vector<KeyframeValue>::const_iterator it1 = m_keyframes.begin(); it1 != m_keyframes.end(); ++it1) {
46         if (it1->m_key != it2->m_key)
47             return false;
48         const RenderStyle& style1 = *it1->m_style;
49         const RenderStyle& style2 = *it2->m_style;
50         if (style1 != style2)
51             return false;
52         ++it2;
53     }
54 
55     return true;
56 }
57 
insert(float key,PassRefPtr<RenderStyle> style)58 void KeyframeList::insert(float key, PassRefPtr<RenderStyle> style)
59 {
60     if (key < 0 || key > 1)
61         return;
62 
63     int index = -1;
64 
65     for (size_t i = 0; i < m_keyframes.size(); ++i) {
66         if (m_keyframes[i].m_key == key) {
67             index = (int) i;
68             break;
69         }
70         if (m_keyframes[i].m_key > key) {
71             // insert before
72             m_keyframes.insert(i, KeyframeValue());
73             index = (int) i;
74             break;
75         }
76     }
77 
78     if (index < 0) {
79         // append
80         index = (int) m_keyframes.size();
81         m_keyframes.append(KeyframeValue());
82     }
83 
84     m_keyframes[index].m_key = key;
85     m_keyframes[index].m_style = style;
86 }
87 
88 } // namespace WebCore
89