Home | History | Annotate | Download | only in style
      1 /*
      2  * Copyright (C) 2000 Lars Knoll (knoll (at) kde.org)
      3  *           (C) 2000 Antti Koivisto (koivisto (at) kde.org)
      4  *           (C) 2000 Dirk Mueller (mueller (at) kde.org)
      5  * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
      6  * Copyright (C) 2006 Graham Dennis (graham.dennis (at) 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 #ifndef KeyframeList_h
     26 #define KeyframeList_h
     27 
     28 #include "CSSPropertyNames.h"
     29 #include "core/rendering/style/StyleInheritedData.h"
     30 #include "wtf/HashSet.h"
     31 #include "wtf/RefPtr.h"
     32 #include "wtf/Vector.h"
     33 #include "wtf/text/AtomicString.h"
     34 
     35 namespace WebCore {
     36 
     37 class RenderObject;
     38 class RenderStyle;
     39 class StylePropertySet;
     40 
     41 class KeyframeValue {
     42 public:
     43     KeyframeValue(float key, PassRefPtr<RenderStyle> style)
     44         : m_key(key)
     45         , m_style(style)
     46     {
     47     }
     48 
     49     void addProperties(const StylePropertySet*);
     50     void addProperty(CSSPropertyID prop) { m_properties.add(prop); }
     51     bool containsProperty(CSSPropertyID prop) const { return m_properties.contains(prop); }
     52     const HashSet<CSSPropertyID>& properties() const { return m_properties; }
     53 
     54     float key() const { return m_key; }
     55     void setKey(float key) { m_key = key; }
     56 
     57     const RenderStyle* style() const { return m_style.get(); }
     58     void setStyle(PassRefPtr<RenderStyle> style) { m_style = style; }
     59 
     60 private:
     61     float m_key;
     62     HashSet<CSSPropertyID> m_properties; // The properties specified in this keyframe.
     63     RefPtr<RenderStyle> m_style;
     64 };
     65 
     66 class KeyframeList {
     67 public:
     68     KeyframeList(RenderObject*, const AtomicString& animationName)
     69         : m_animationName(animationName)
     70     {
     71         insert(KeyframeValue(0, 0));
     72         insert(KeyframeValue(1, 0));
     73     }
     74     ~KeyframeList();
     75 
     76     bool operator==(const KeyframeList& o) const;
     77     bool operator!=(const KeyframeList& o) const { return !(*this == o); }
     78 
     79     const AtomicString& animationName() const { return m_animationName; }
     80 
     81     void insert(const KeyframeValue& keyframe);
     82 
     83     void addProperty(CSSPropertyID prop) { m_properties.add(prop); }
     84     bool containsProperty(CSSPropertyID prop) const { return m_properties.contains(prop); }
     85     HashSet<CSSPropertyID>::const_iterator beginProperties() const { return m_properties.begin(); }
     86     HashSet<CSSPropertyID>::const_iterator endProperties() const { return m_properties.end(); }
     87 
     88     void clear();
     89     bool isEmpty() const { return m_keyframes.isEmpty(); }
     90     size_t size() const { return m_keyframes.size(); }
     91     const KeyframeValue& operator[](size_t index) const { return m_keyframes[index]; }
     92 
     93 private:
     94     AtomicString m_animationName;
     95     Vector<KeyframeValue> m_keyframes; // Kept sorted by key.
     96     HashSet<CSSPropertyID> m_properties; // The properties being animated.
     97 };
     98 
     99 } // namespace WebCore
    100 
    101 #endif // KeyframeList_h
    102