Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: Source/core/animation/KeyframeEffectModel.cpp

Issue 851693007: Prepare for responsive CSS animations. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase and tidy up Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/animation/KeyframeEffectModel.h" 32 #include "core/animation/KeyframeEffectModel.h"
33 33
34 #include "core/StylePropertyShorthand.h" 34 #include "core/StylePropertyShorthand.h"
35 #include "core/animation/AnimationNode.h" 35 #include "core/animation/AnimationNode.h"
36 #include "core/animation/CompositorAnimations.h"
37 #include "core/animation/css/CSSAnimatableValueFactory.h"
38 #include "core/animation/css/CSSPropertyEquality.h"
39 #include "core/css/resolver/StyleResolver.h"
36 #include "platform/animation/AnimationUtilities.h" 40 #include "platform/animation/AnimationUtilities.h"
37 #include "platform/geometry/FloatBox.h" 41 #include "platform/geometry/FloatBox.h"
38 #include "platform/transforms/TransformationMatrix.h" 42 #include "platform/transforms/TransformationMatrix.h"
39 #include "wtf/text/StringHash.h" 43 #include "wtf/text/StringHash.h"
40 44
41 namespace blink { 45 namespace blink {
42 46
43 PropertySet KeyframeEffectModelBase::properties() const 47 PropertySet KeyframeEffectModelBase::properties() const
44 { 48 {
45 PropertySet result; 49 PropertySet result;
46 for (const auto& keyframe : m_keyframes) { 50 for (const auto& keyframe : m_keyframes) {
47 for (const auto& property : keyframe->properties()) 51 for (const auto& property : keyframe->properties())
48 result.add(property); 52 result.add(property);
49 } 53 }
50 return result; 54 return result;
51 } 55 }
52 56
53 void KeyframeEffectModelBase::sample(int iteration, double fraction, double iter ationDuration, OwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpolat ion>>>& result) const 57 void KeyframeEffectModelBase::sample(int iteration, double fraction, double iter ationDuration, OwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpolat ion>>>& result) const
54 { 58 {
55 ASSERT(iteration >= 0); 59 ASSERT(iteration >= 0);
56 ASSERT(!isNull(fraction)); 60 ASSERT(!isNull(fraction));
57 ensureKeyframeGroups(); 61 ensureKeyframeGroups();
58 ensureInterpolationEffect(); 62 ensureInterpolationEffect();
59 63
60 return m_interpolationEffect->getActiveInterpolations(fraction, iterationDur ation, result); 64 return m_interpolationEffect->getActiveInterpolations(fraction, iterationDur ation, result);
61 } 65 }
62 66
67 void KeyframeEffectModelBase::snapshotCompositableProperties(const Element* elem ent, const LayoutStyle& style)
68 {
69 ensureKeyframeGroups();
70 for (CSSPropertyID property : CompositorAnimations::CompositableProperties) {
71 if (affects(property)) {
Timothy Loh 2015/02/11 04:09:00 Maybe reads better as (but no strong preference he
Timothy Loh 2015/02/11 04:16:10 Actually ignore this comment...
72 for (auto& keyframe : m_keyframeGroups->get(property)->m_keyframes) {
73 auto& stringKeyframe = toStringPropertySpecificKeyframe(*keyfram e);
74 if (!stringKeyframe.value()) {
75 stringKeyframe.setAnimatableValue(CSSAnimatableValueFactory: :create(property, style));
76 } else {
77 ASSERT(!stringKeyframe.getAnimatableValue());
78 stringKeyframe.setAnimatableValue(StyleResolver::createAnima tableValueSnapshot(const_cast<Element&>(*element), property, *stringKeyframe.val ue()));
79 }
80 }
81 }
82 }
83 }
84
85 void KeyframeEffectModelBase::updateNeutralKeyframeAnimatableValues(CSSPropertyI D property, PassRefPtrWillBeRawPtr<AnimatableValue> value)
86 {
87 ASSERT(CompositorAnimations::isCompositableProperty(property));
88
89 if (!value)
90 return;
91
92 ensureKeyframeGroups();
93 auto& keyframes = m_keyframeGroups->get(property)->m_keyframes;
94
95 ASSERT(keyframes.size() >= 2);
96 ASSERT(!toStringPropertySpecificKeyframe(*keyframes[0]).value() || !toString PropertySpecificKeyframe(*keyframes[keyframes.size() - 1]).value());
Timothy Loh 2015/02/11 04:09:00 Vector supports v.first() and v.last().
shend 2015/02/12 01:01:42 Done.
97
98 if (!toStringPropertySpecificKeyframe(*keyframes[0]).value())
99 toStringPropertySpecificKeyframe(*keyframes[0]).setAnimatableValue(value );
100 if (!toStringPropertySpecificKeyframe(*keyframes[keyframes.size() - 1]).valu e())
101 toStringPropertySpecificKeyframe(*keyframes[keyframes.size() - 1]).setAn imatableValue(value);
102
103 // FIXME: Handle neutral keyframes that are not at 0% or 100%.
104 }
105
63 KeyframeEffectModelBase::KeyframeVector KeyframeEffectModelBase::normalizedKeyfr ames(const KeyframeVector& keyframes) 106 KeyframeEffectModelBase::KeyframeVector KeyframeEffectModelBase::normalizedKeyfr ames(const KeyframeVector& keyframes)
64 { 107 {
65 double lastOffset = 0; 108 double lastOffset = 0;
66 KeyframeVector result; 109 KeyframeVector result;
67 result.reserveCapacity(keyframes.size()); 110 result.reserveCapacity(keyframes.size());
68 111
69 for (const auto& keyframe : keyframes) { 112 for (const auto& keyframe : keyframes) {
70 double offset = keyframe->offset(); 113 double offset = keyframe->offset();
71 if (!isNull(offset)) { 114 if (!isNull(offset)) {
72 ASSERT(offset >= 0); 115 ASSERT(offset >= 0);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 else 161 else
119 group = groupIter->value.get(); 162 group = groupIter->value.get();
120 163
121 group->appendKeyframe(keyframe->createPropertySpecificKeyframe(prope rty)); 164 group->appendKeyframe(keyframe->createPropertySpecificKeyframe(prope rty));
122 } 165 }
123 } 166 }
124 167
125 // Add synthetic keyframes. 168 // Add synthetic keyframes.
126 m_hasSyntheticKeyframes = false; 169 m_hasSyntheticKeyframes = false;
127 for (const auto& entry : *m_keyframeGroups) { 170 for (const auto& entry : *m_keyframeGroups) {
128 if (entry.value->addSyntheticKeyframeIfRequired()) 171 if (entry.value->addSyntheticKeyframeIfRequired(m_neutralKeyframeEasing) )
129 m_hasSyntheticKeyframes = true; 172 m_hasSyntheticKeyframes = true;
130 173
131 entry.value->removeRedundantKeyframes(); 174 entry.value->removeRedundantKeyframes();
132 } 175 }
133 } 176 }
134 177
135 void KeyframeEffectModelBase::ensureInterpolationEffect(Element* element) const 178 void KeyframeEffectModelBase::ensureInterpolationEffect(Element* element) const
136 { 179 {
137 if (m_interpolationEffect) 180 if (m_interpolationEffect)
138 return; 181 return;
139 m_interpolationEffect = InterpolationEffect::create(); 182 m_interpolationEffect = InterpolationEffect::create();
140 183
141 for (const auto& entry : *m_keyframeGroups) { 184 for (const auto& entry : *m_keyframeGroups) {
142 const PropertySpecificKeyframeVector& keyframes = entry.value->keyframes (); 185 const PropertySpecificKeyframeVector& keyframes = entry.value->keyframes ();
143 ASSERT(keyframes[0]->composite() == AnimationEffect::CompositeReplace);
144 for (size_t i = 0; i < keyframes.size() - 1; i++) { 186 for (size_t i = 0; i < keyframes.size() - 1; i++) {
145 ASSERT(keyframes[i + 1]->composite() == AnimationEffect::CompositeRe place);
146 double applyFrom = i ? keyframes[i]->offset() : (-std::numeric_limit s<double>::infinity()); 187 double applyFrom = i ? keyframes[i]->offset() : (-std::numeric_limit s<double>::infinity());
147 double applyTo = i == keyframes.size() - 2 ? std::numeric_limits<dou ble>::infinity() : keyframes[i + 1]->offset(); 188 double applyTo = i == keyframes.size() - 2 ? std::numeric_limits<dou ble>::infinity() : keyframes[i + 1]->offset();
148 if (applyTo == 1) 189 if (applyTo == 1)
149 applyTo = std::numeric_limits<double>::infinity(); 190 applyTo = std::numeric_limits<double>::infinity();
150 191
151 m_interpolationEffect->addInterpolationsFromKeyframes(entry.key, ele ment, *keyframes[i], *keyframes[i + 1], applyFrom, applyTo); 192 m_interpolationEffect->addInterpolationsFromKeyframes(entry.key, ele ment, *keyframes[i], *keyframes[i + 1], applyFrom, applyTo);
152 } 193 }
153 } 194 }
154 } 195 }
155 196
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 for (int i = m_keyframes.size() - 1; i >= 0; --i) { 241 for (int i = m_keyframes.size() - 1; i >= 0; --i) {
201 double offset = m_keyframes[i]->offset(); 242 double offset = m_keyframes[i]->offset();
202 bool hasSameOffsetAsPreviousNeighbor = !i || m_keyframes[i - 1]->offset( ) == offset; 243 bool hasSameOffsetAsPreviousNeighbor = !i || m_keyframes[i - 1]->offset( ) == offset;
203 bool hasSameOffsetAsNextNeighbor = i == static_cast<int>(m_keyframes.siz e() - 1) || m_keyframes[i + 1]->offset() == offset; 244 bool hasSameOffsetAsNextNeighbor = i == static_cast<int>(m_keyframes.siz e() - 1) || m_keyframes[i + 1]->offset() == offset;
204 if (hasSameOffsetAsPreviousNeighbor && hasSameOffsetAsNextNeighbor) 245 if (hasSameOffsetAsPreviousNeighbor && hasSameOffsetAsNextNeighbor)
205 m_keyframes.remove(i); 246 m_keyframes.remove(i);
206 } 247 }
207 ASSERT(m_keyframes.size() >= 2); 248 ASSERT(m_keyframes.size() >= 2);
208 } 249 }
209 250
210 bool KeyframeEffectModelBase::PropertySpecificKeyframeGroup::addSyntheticKeyfram eIfRequired() 251 bool KeyframeEffectModelBase::PropertySpecificKeyframeGroup::addSyntheticKeyfram eIfRequired(PassRefPtrWillBeRawPtr<TimingFunction> easing)
211 { 252 {
212 ASSERT(!m_keyframes.isEmpty()); 253 ASSERT(!m_keyframes.isEmpty());
213 254
214 bool addedSyntheticKeyframe = false; 255 bool addedSyntheticKeyframe = false;
215 256
216 if (m_keyframes.first()->offset() != 0.0) { 257 if (m_keyframes.first()->offset() != 0.0) {
217 m_keyframes.insert(0, m_keyframes.first()->neutralKeyframe(0, nullptr)); 258 m_keyframes.insert(0, m_keyframes.first()->neutralKeyframe(0, easing));
218 addedSyntheticKeyframe = true; 259 addedSyntheticKeyframe = true;
219 } 260 }
220 if (m_keyframes.last()->offset() != 1.0) { 261 if (m_keyframes.last()->offset() != 1.0) {
221 appendKeyframe(m_keyframes.last()->neutralKeyframe(1, nullptr)); 262 appendKeyframe(m_keyframes.last()->neutralKeyframe(1, easing));
222 addedSyntheticKeyframe = true; 263 addedSyntheticKeyframe = true;
223 } 264 }
224 265
225 return addedSyntheticKeyframe; 266 return addedSyntheticKeyframe;
226 } 267 }
227 268
228 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::trace(Visitor* visi tor) 269 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::trace(Visitor* visi tor)
229 { 270 {
230 #if ENABLE(OILPAN) 271 #if ENABLE(OILPAN)
231 visitor->trace(m_keyframes); 272 visitor->trace(m_keyframes);
232 #endif 273 #endif
233 } 274 }
234 275
235 } // namespace 276 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698