1 /* 2 * Copyright (C) 1999 Antti Koivisto (koivisto (at) 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/css/StylePropertySet.h" 26 #include "core/rendering/RenderObject.h" 27 28 namespace WebCore { 29 30 void KeyframeValue::addProperties(const StylePropertySet* propertySet) 31 { 32 if (!propertySet) 33 return; 34 unsigned propertyCount = propertySet->propertyCount(); 35 for (unsigned i = 0; i < propertyCount; ++i) { 36 CSSPropertyID property = propertySet->propertyAt(i).id(); 37 // Timing-function within keyframes is special, because it is not animated; it just 38 // describes the timing function between this keyframe and the next. 39 if (property != CSSPropertyWebkitAnimationTimingFunction) 40 addProperty(property); 41 } 42 } 43 44 KeyframeList::~KeyframeList() 45 { 46 clear(); 47 } 48 49 void KeyframeList::clear() 50 { 51 m_keyframes.clear(); 52 m_properties.clear(); 53 } 54 55 bool KeyframeList::operator==(const KeyframeList& o) const 56 { 57 if (m_keyframes.size() != o.m_keyframes.size()) 58 return false; 59 60 Vector<KeyframeValue>::const_iterator it2 = o.m_keyframes.begin(); 61 for (Vector<KeyframeValue>::const_iterator it1 = m_keyframes.begin(); it1 != m_keyframes.end(); ++it1) { 62 if (it1->key() != it2->key()) 63 return false; 64 const RenderStyle& style1 = *it1->style(); 65 const RenderStyle& style2 = *it2->style(); 66 if (style1 != style2) 67 return false; 68 ++it2; 69 } 70 71 return true; 72 } 73 74 void KeyframeList::insert(const KeyframeValue& keyframe) 75 { 76 if (keyframe.key() < 0 || keyframe.key() > 1) 77 return; 78 79 bool inserted = false; 80 bool replaced = false; 81 for (size_t i = 0; i < m_keyframes.size(); ++i) { 82 if (m_keyframes[i].key() == keyframe.key()) { 83 m_keyframes[i] = keyframe; 84 replaced = true; 85 break; 86 } 87 88 if (m_keyframes[i].key() > keyframe.key()) { 89 // insert before 90 m_keyframes.insert(i, keyframe); 91 inserted = true; 92 break; 93 } 94 } 95 96 if (!replaced && !inserted) 97 m_keyframes.append(keyframe); 98 99 if (replaced) { 100 // We have to rebuild the properties list from scratch. 101 m_properties.clear(); 102 for (Vector<KeyframeValue>::const_iterator it = m_keyframes.begin(); it != m_keyframes.end(); ++it) { 103 const KeyframeValue& currKeyframe = *it; 104 for (HashSet<CSSPropertyID>::const_iterator it = currKeyframe.properties().begin(); it != currKeyframe.properties().end(); ++it) 105 m_properties.add(*it); 106 } 107 } else { 108 for (HashSet<CSSPropertyID>::const_iterator it = keyframe.properties().begin(); it != keyframe.properties().end(); ++it) 109 m_properties.add(*it); 110 } 111 } 112 113 } // namespace WebCore 114