1/*
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com)
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25#pragma once
26
27#include "CSSPropertyNames.h"
28#include <wtf/Vector.h>
29#include <wtf/HashSet.h>
30#include <wtf/text/AtomString.h>
31
32namespace WebCore {
33
34class RenderStyle;
35class TimingFunction;
36
37class KeyframeValue {
38public:
39 KeyframeValue(double key, std::unique_ptr<RenderStyle> style)
40 : m_key(key)
41 , m_style(WTFMove(style))
42 {
43 }
44
45 void addProperty(CSSPropertyID prop) { m_properties.add(prop); }
46 bool containsProperty(CSSPropertyID prop) const { return m_properties.contains(prop); }
47 const HashSet<CSSPropertyID>& properties() const { return m_properties; }
48
49 double key() const { return m_key; }
50 void setKey(double key) { m_key = key; }
51
52 const RenderStyle* style() const { return m_style.get(); }
53 void setStyle(std::unique_ptr<RenderStyle> style) { m_style = WTFMove(style); }
54
55 TimingFunction* timingFunction() const { return m_timingFunction.get(); }
56 void setTimingFunction(const RefPtr<TimingFunction>& timingFunction) { m_timingFunction = timingFunction; }
57
58private:
59 double m_key;
60 HashSet<CSSPropertyID> m_properties; // The properties specified in this keyframe.
61 std::unique_ptr<RenderStyle> m_style;
62 RefPtr<TimingFunction> m_timingFunction;
63};
64
65class KeyframeList {
66public:
67 explicit KeyframeList(const AtomString& animationName)
68 : m_animationName(animationName)
69 {
70 }
71 ~KeyframeList();
72
73 KeyframeList& operator=(KeyframeList&&) = default;
74 bool operator==(const KeyframeList& o) const;
75 bool operator!=(const KeyframeList& o) const { return !(*this == o); }
76
77 const AtomString& animationName() const { return m_animationName; }
78
79 void insert(KeyframeValue&&);
80
81 void addProperty(CSSPropertyID prop) { m_properties.add(prop); }
82 bool containsProperty(CSSPropertyID prop) const { return m_properties.contains(prop); }
83 const HashSet<CSSPropertyID>& properties() const { return m_properties; }
84
85 void clear();
86 bool isEmpty() const { return m_keyframes.isEmpty(); }
87 size_t size() const { return m_keyframes.size(); }
88 const KeyframeValue& operator[](size_t index) const { return m_keyframes[index]; }
89 const Vector<KeyframeValue>& keyframes() const { return m_keyframes; }
90
91private:
92 AtomString m_animationName;
93 Vector<KeyframeValue> m_keyframes; // Kept sorted by key.
94 HashSet<CSSPropertyID> m_properties; // The properties being animated.
95};
96
97} // namespace WebCore
98