OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/animation/StringKeyframe.h" | 6 #include "core/animation/StringKeyframe.h" |
7 | 7 |
8 #include "core/animation/Interpolation.h" | 8 #include "core/animation/Interpolation.h" |
9 #include "core/animation/css/CSSAnimations.h" | |
10 #include "core/css/StylePropertySet.h" | |
11 #include "core/css/resolver/StyleResolver.h" | |
12 #include "core/rendering/style/RenderStyle.h" | |
9 | 13 |
10 namespace WebCore { | 14 namespace WebCore { |
11 | 15 |
12 StringKeyframe::StringKeyframe(const StringKeyframe& copyFrom) | 16 StringKeyframe::StringKeyframe(const StringKeyframe& copyFrom) |
13 : Keyframe(copyFrom.m_offset, copyFrom.m_composite, copyFrom.m_easing) | 17 : Keyframe(copyFrom.m_offset, copyFrom.m_composite, copyFrom.m_easing) |
14 { | 18 { |
15 for (PropertyValueMap::const_iterator iter = copyFrom.m_propertyValues.begin (); iter != copyFrom.m_propertyValues.end(); ++iter) | 19 for (PropertyValueMap::const_iterator iter = copyFrom.m_propertyValues.begin (); iter != copyFrom.m_propertyValues.end(); ++iter) |
16 setPropertyValue(iter->key, iter->value); | 20 setPropertyCSSValue(iter->key, iter->value.get()); |
21 } | |
22 | |
23 void StringKeyframe::setPropertyValue(CSSPropertyID property, const String& valu e, StyleSheetContents* styleSheetContents) | |
24 { | |
25 ASSERT(property != CSSPropertyInvalid); | |
26 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::creat e(); | |
27 propertySet->setProperty(property, value, false, styleSheetContents); | |
28 for (size_t i = 0; i < propertySet->propertyCount(); ++i) { | |
29 CSSPropertyID id = propertySet->propertyAt(i).id(); | |
30 // FIXME: Allow for non-animatable properties. | |
31 if (CSSAnimations::isAnimatableProperty(id)) | |
32 setPropertyCSSValue(id, propertySet->getPropertyCSSValue(id).get()); | |
33 } | |
34 } | |
35 | |
36 void StringKeyframe::setPropertyCSSValue(CSSPropertyID property, CSSValue* value ) | |
37 { | |
38 ASSERT(property != CSSPropertyInvalid); | |
39 m_propertyValues.add(property, value); | |
esprehn
2014/04/04 22:37:12
Why aren't you using a StylePropertySet? It seems
alancutter (OOO until 2018)
2014/04/07 00:02:26
Good idea, done.
| |
17 } | 40 } |
18 | 41 |
19 PropertySet StringKeyframe::properties() const | 42 PropertySet StringKeyframe::properties() const |
20 { | 43 { |
21 // This is not used in time-critical code, so we probably don't need to | 44 // This is not used in time-critical code, so we probably don't need to |
22 // worry about caching this result. | 45 // worry about caching this result. |
23 PropertySet properties; | 46 PropertySet properties; |
24 for (PropertyValueMap::const_iterator iter = m_propertyValues.begin(); iter != m_propertyValues.end(); ++iter) | 47 for (PropertyValueMap::const_iterator iter = m_propertyValues.begin(); iter != m_propertyValues.end(); ++iter) |
25 properties.add(*iter.keys()); | 48 properties.add(*iter.keys()); |
26 return properties; | 49 return properties; |
27 } | 50 } |
28 | 51 |
29 PassRefPtrWillBeRawPtr<Keyframe> StringKeyframe::clone() const | 52 PassRefPtrWillBeRawPtr<Keyframe> StringKeyframe::clone() const |
30 { | 53 { |
31 return adoptRefWillBeNoop(new StringKeyframe(*this)); | 54 return adoptRefWillBeNoop(new StringKeyframe(*this)); |
32 } | 55 } |
33 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::creat ePropertySpecificKeyframe(CSSPropertyID property) const | 56 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::creat ePropertySpecificKeyframe(CSSPropertyID property) const |
34 { | 57 { |
35 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset(), easing(), p ropertyValue(property), composite())); | 58 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset(), easing(), p ropertyValue(property), composite())); |
36 } | 59 } |
37 | 60 |
38 void StringKeyframe::trace(Visitor* visitor) | 61 void StringKeyframe::trace(Visitor* visitor) |
39 { | 62 { |
40 Keyframe::trace(visitor); | 63 Keyframe::trace(visitor); |
41 } | 64 } |
42 | 65 |
43 StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset , PassRefPtr<TimingFunction> easing, const String& value, AnimationEffect::Compo siteOperation op) | 66 StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset , PassRefPtr<TimingFunction> easing, CSSValue* value, AnimationEffect::Composite Operation op) |
44 : Keyframe::PropertySpecificKeyframe(offset, easing, op) | 67 : Keyframe::PropertySpecificKeyframe(offset, easing, op) |
45 , m_value(value) | 68 , m_value(value) |
46 { } | 69 { } |
47 | 70 |
48 StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset , PassRefPtr<TimingFunction> easing, const String& value) | 71 StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset , PassRefPtr<TimingFunction> easing, CSSValue* value) |
49 : Keyframe::PropertySpecificKeyframe(offset, easing, AnimationEffect::Compos iteReplace) | 72 : Keyframe::PropertySpecificKeyframe(offset, easing, AnimationEffect::Compos iteReplace) |
50 , m_value(value) | 73 , m_value(value) |
51 { | 74 { |
52 ASSERT(!isNull(m_offset)); | 75 ASSERT(!isNull(m_offset)); |
53 } | 76 } |
54 | 77 |
55 PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe:: createInterpolation(CSSPropertyID property, Keyframe::PropertySpecificKeyframe* end) const | 78 PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe:: createInterpolation(CSSPropertyID property, Keyframe::PropertySpecificKeyframe* end, Element* element) const |
56 { | 79 { |
57 ASSERT_UNUSED(end, end); | 80 ASSERT(element); |
58 // FIXME: Convert string keyframe value pairs to interpolations. | 81 CSSValue* fromCSSValue = m_value.get(); |
59 return nullptr; | 82 CSSValue* toCSSValue = toStringPropertySpecificKeyframe(end)->value(); |
83 | |
84 // FIXME: Remove the use of AnimatableValues and RenderStyles here. | |
85 RefPtr<RenderStyle> style = RenderStyle::clone(element->renderStyle()); | |
86 RefPtr<AnimatableValue> from = StyleResolver::createAnimatableValueSnapshot( *element, *style.get(), property, fromCSSValue); | |
87 RefPtr<AnimatableValue> to = StyleResolver::createAnimatableValueSnapshot(*e lement, *style.get(), property, toCSSValue); | |
esprehn
2014/04/04 22:37:12
Why is it okay to reuse the same style object for
alancutter (OOO until 2018)
2014/04/07 00:02:26
It probably isn't in some corner case. Changed to
| |
88 | |
89 return LegacyStyleInterpolation::create(from.release(), to.release(), proper ty); | |
60 } | 90 } |
61 | 91 |
62 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::neutralKeyframe(double offset, PassRefPtr<TimingFunction> e asing) const | 92 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::neutralKeyframe(double offset, PassRefPtr<TimingFunction> e asing) const |
63 { | 93 { |
64 return adoptPtrWillBeNoop(new StringKeyframe::PropertySpecificKeyframe(offse t, easing, emptyString(), AnimationEffect::CompositeAdd)); | 94 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset, easing, nullp tr, AnimationEffect::CompositeAdd)); |
65 } | 95 } |
66 | 96 |
67 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::cloneWithOffset(double offset) const | 97 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::cloneWithOffset(double offset) const |
68 { | 98 { |
69 Keyframe::PropertySpecificKeyframe *theClone = new PropertySpecificKeyframe( offset, m_easing, m_value); | 99 Keyframe::PropertySpecificKeyframe *theClone = new PropertySpecificKeyframe( offset, m_easing, m_value.get()); |
70 return adoptPtrWillBeNoop(theClone); | 100 return adoptPtrWillBeNoop(theClone); |
71 } | 101 } |
72 | 102 |
73 void StringKeyframe::PropertySpecificKeyframe::trace(Visitor* visitor) | 103 void StringKeyframe::PropertySpecificKeyframe::trace(Visitor* visitor) |
74 { | 104 { |
105 visitor->trace(m_value); | |
75 } | 106 } |
76 | 107 |
77 } | 108 } |
OLD | NEW |