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
25#include "Animation.h"
26#include "RenderObject.h"
27
28namespace WebCore {
29
30KeyframeList::~KeyframeList() = default;
31
32void KeyframeList::clear()
33{
34 m_keyframes.clear();
35 m_properties.clear();
36}
37
38bool KeyframeList::operator==(const KeyframeList& o) const
39{
40 if (m_keyframes.size() != o.m_keyframes.size())
41 return false;
42
43 auto it2 = o.m_keyframes.begin();
44 for (auto it1 = m_keyframes.begin(); it1 != m_keyframes.end(); ++it1, ++it2) {
45 if (it1->key() != it2->key())
46 return false;
47 if (*it1->style() != *it2->style())
48 return false;
49 }
50
51 return true;
52}
53
54void KeyframeList::insert(KeyframeValue&& keyframe)
55{
56 if (keyframe.key() < 0 || keyframe.key() > 1)
57 return;
58
59 bool inserted = false;
60 size_t i = 0;
61 for (; i < m_keyframes.size(); ++i) {
62 if (m_keyframes[i].key() > keyframe.key()) {
63 // insert before
64 m_keyframes.insert(i, WTFMove(keyframe));
65 inserted = true;
66 break;
67 }
68 }
69
70 if (!inserted)
71 m_keyframes.append(WTFMove(keyframe));
72
73 for (auto& property : m_keyframes[i].properties())
74 m_properties.add(property);
75}
76
77} // namespace WebCore
78