1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "core/animation/StringKeyframe.h"
8 #include "core/animation/Interpolation.h"
9 #include "core/animation/css/CSSAnimations.h"
10 #include "core/css/resolver/StyleResolver.h"
11 #include "core/rendering/style/RenderStyle.h"
15 StringKeyframe::StringKeyframe(const StringKeyframe& copyFrom)
16 : Keyframe(copyFrom.m_offset, copyFrom.m_composite, copyFrom.m_easing)
17 , m_propertySet(copyFrom.m_propertySet->mutableCopy())
21 void StringKeyframe::setPropertyValue(CSSPropertyID property, const String& value, StyleSheetContents* styleSheetContents)
23 ASSERT(property != CSSPropertyInvalid);
24 if (CSSAnimations::isAllowedAnimation(property))
25 m_propertySet->setProperty(property, value, false, styleSheetContents);
28 PropertySet StringKeyframe::properties() const
30 // This is not used in time-critical code, so we probably don't need to
31 // worry about caching this result.
32 PropertySet properties;
33 for (unsigned i = 0; i < m_propertySet->propertyCount(); ++i)
34 properties.add(m_propertySet->propertyAt(i).id());
38 PassRefPtrWillBeRawPtr<Keyframe> StringKeyframe::clone() const
40 return adoptRefWillBeNoop(new StringKeyframe(*this));
42 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::createPropertySpecificKeyframe(CSSPropertyID property) const
44 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset(), easing(), propertyValue(property), composite()));
47 void StringKeyframe::trace(Visitor* visitor)
49 visitor->trace(m_propertySet);
50 Keyframe::trace(visitor);
53 StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset, PassRefPtr<TimingFunction> easing, CSSValue* value, AnimationEffect::CompositeOperation op)
54 : Keyframe::PropertySpecificKeyframe(offset, easing, op)
58 StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset, PassRefPtr<TimingFunction> easing, CSSValue* value)
59 : Keyframe::PropertySpecificKeyframe(offset, easing, AnimationEffect::CompositeReplace)
62 ASSERT(!isNull(m_offset));
65 PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe::createInterpolation(CSSPropertyID property, Keyframe::PropertySpecificKeyframe* end, Element* element) const
67 CSSValue* fromCSSValue = m_value.get();
68 CSSValue* toCSSValue = toStringPropertySpecificKeyframe(end)->value();
70 if (!CSSAnimations::isAnimatableProperty(property))
71 return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, property);
75 case CSSPropertyRight:
76 case CSSPropertyWidth:
77 case CSSPropertyHeight:
78 if (LengthStyleInterpolation::canCreateFrom(*fromCSSValue) && LengthStyleInterpolation::canCreateFrom(*toCSSValue))
79 return LengthStyleInterpolation::create(fromCSSValue, toCSSValue, property);
85 // FIXME: Remove the use of AnimatableValues, RenderStyles and Elements here.
86 // FIXME: Remove this cache
87 if (!m_animatableValueCache)
88 m_animatableValueCache = StyleResolver::createAnimatableValueSnapshot(*element, property, fromCSSValue);
90 RefPtrWillBeRawPtr<AnimatableValue> to = StyleResolver::createAnimatableValueSnapshot(*element, property, toCSSValue);
91 toStringPropertySpecificKeyframe(end)->m_animatableValueCache = to;
93 return LegacyStyleInterpolation::create(m_animatableValueCache.get(), to.release(), property);
96 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::PropertySpecificKeyframe::neutralKeyframe(double offset, PassRefPtr<TimingFunction> easing) const
98 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset, easing, 0, AnimationEffect::CompositeAdd));
101 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::PropertySpecificKeyframe::cloneWithOffset(double offset) const
103 Keyframe::PropertySpecificKeyframe* theClone = new PropertySpecificKeyframe(offset, m_easing, m_value.get());
104 toStringPropertySpecificKeyframe(theClone)->m_animatableValueCache = m_animatableValueCache;
105 return adoptPtrWillBeNoop(theClone);
108 void StringKeyframe::PropertySpecificKeyframe::trace(Visitor* visitor)
110 visitor->trace(m_value);
111 visitor->trace(m_animatableValueCache);
112 Keyframe::PropertySpecificKeyframe::trace(visitor);