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

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 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
« no previous file with comments | « Source/core/animation/KeyframeEffectModel.h ('k') | Source/core/animation/StringKeyframe.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ASSERT(isStringKeyframeEffectModel());
70
71 ensureKeyframeGroups();
72 for (CSSPropertyID property : CompositorAnimations::CompositableProperties) {
73 if (affects(property)) {
74 for (auto& keyframe : m_keyframeGroups->get(property)->m_keyframes) {
75 auto& stringKeyframe = toStringPropertySpecificKeyframe(*keyfram e);
76 if (!stringKeyframe.value()) {
77 stringKeyframe.setAnimatableValue(CSSAnimatableValueFactory: :create(property, style));
78 } else {
79 ASSERT(!stringKeyframe.getAnimatableValue());
80 stringKeyframe.setAnimatableValue(StyleResolver::createAnima tableValueSnapshot(const_cast<Element&>(*element), property, *stringKeyframe.val ue()));
81 }
82 }
83 }
84 }
85 }
86
87 void KeyframeEffectModelBase::updateNeutralKeyframeAnimatableValues(CSSPropertyI D property, PassRefPtrWillBeRawPtr<AnimatableValue> value)
88 {
89 ASSERT(CompositorAnimations::isCompositableProperty(property));
90
91 if (!value)
92 return;
93
94 ensureKeyframeGroups();
95 auto& keyframes = m_keyframeGroups->get(property)->m_keyframes;
96
97 ASSERT(keyframes.size() >= 2);
98 ASSERT(!toStringPropertySpecificKeyframe(*keyframes[0]).value() || !toString PropertySpecificKeyframe(*keyframes[keyframes.size() - 1]).value());
99
100 if (!toStringPropertySpecificKeyframe(*keyframes.first()).value())
101 toStringPropertySpecificKeyframe(*keyframes.first()).setAnimatableValue( value);
102 if (!toStringPropertySpecificKeyframe(*keyframes.last()).value())
103 toStringPropertySpecificKeyframe(*keyframes.last()).setAnimatableValue(v alue);
104
105 // FIXME: Handle neutral keyframes that are not at 0% or 100%.
dstockwell 2015/02/18 02:27:03 Just ASSERT this, should not happen.
106 }
107
63 KeyframeEffectModelBase::KeyframeVector KeyframeEffectModelBase::normalizedKeyfr ames(const KeyframeVector& keyframes) 108 KeyframeEffectModelBase::KeyframeVector KeyframeEffectModelBase::normalizedKeyfr ames(const KeyframeVector& keyframes)
64 { 109 {
65 double lastOffset = 0; 110 double lastOffset = 0;
66 KeyframeVector result; 111 KeyframeVector result;
67 result.reserveCapacity(keyframes.size()); 112 result.reserveCapacity(keyframes.size());
68 113
69 for (const auto& keyframe : keyframes) { 114 for (const auto& keyframe : keyframes) {
70 double offset = keyframe->offset(); 115 double offset = keyframe->offset();
71 if (!isNull(offset)) { 116 if (!isNull(offset)) {
72 ASSERT(offset >= 0); 117 ASSERT(offset >= 0);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 else 163 else
119 group = groupIter->value.get(); 164 group = groupIter->value.get();
120 165
121 group->appendKeyframe(keyframe->createPropertySpecificKeyframe(prope rty)); 166 group->appendKeyframe(keyframe->createPropertySpecificKeyframe(prope rty));
122 } 167 }
123 } 168 }
124 169
125 // Add synthetic keyframes. 170 // Add synthetic keyframes.
126 m_hasSyntheticKeyframes = false; 171 m_hasSyntheticKeyframes = false;
127 for (const auto& entry : *m_keyframeGroups) { 172 for (const auto& entry : *m_keyframeGroups) {
128 if (entry.value->addSyntheticKeyframeIfRequired()) 173 if (entry.value->addSyntheticKeyframeIfRequired(m_neutralKeyframeEasing) )
129 m_hasSyntheticKeyframes = true; 174 m_hasSyntheticKeyframes = true;
130 175
131 entry.value->removeRedundantKeyframes(); 176 entry.value->removeRedundantKeyframes();
132 } 177 }
133 } 178 }
134 179
135 void KeyframeEffectModelBase::ensureInterpolationEffect(Element* element) const 180 void KeyframeEffectModelBase::ensureInterpolationEffect(Element* element) const
136 { 181 {
137 if (m_interpolationEffect) 182 if (m_interpolationEffect)
138 return; 183 return;
139 m_interpolationEffect = InterpolationEffect::create(); 184 m_interpolationEffect = InterpolationEffect::create();
140 185
141 for (const auto& entry : *m_keyframeGroups) { 186 for (const auto& entry : *m_keyframeGroups) {
142 const PropertySpecificKeyframeVector& keyframes = entry.value->keyframes (); 187 const PropertySpecificKeyframeVector& keyframes = entry.value->keyframes ();
143 ASSERT(keyframes[0]->composite() == AnimationEffect::CompositeReplace);
144 for (size_t i = 0; i < keyframes.size() - 1; i++) { 188 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()); 189 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(); 190 double applyTo = i == keyframes.size() - 2 ? std::numeric_limits<dou ble>::infinity() : keyframes[i + 1]->offset();
148 if (applyTo == 1) 191 if (applyTo == 1)
149 applyTo = std::numeric_limits<double>::infinity(); 192 applyTo = std::numeric_limits<double>::infinity();
150 193
151 m_interpolationEffect->addInterpolationsFromKeyframes(entry.key, ele ment, *keyframes[i], *keyframes[i + 1], applyFrom, applyTo); 194 m_interpolationEffect->addInterpolationsFromKeyframes(entry.key, ele ment, *keyframes[i], *keyframes[i + 1], applyFrom, applyTo);
152 } 195 }
153 } 196 }
154 } 197 }
155 198
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 for (int i = m_keyframes.size() - 1; i >= 0; --i) { 243 for (int i = m_keyframes.size() - 1; i >= 0; --i) {
201 double offset = m_keyframes[i]->offset(); 244 double offset = m_keyframes[i]->offset();
202 bool hasSameOffsetAsPreviousNeighbor = !i || m_keyframes[i - 1]->offset( ) == offset; 245 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; 246 bool hasSameOffsetAsNextNeighbor = i == static_cast<int>(m_keyframes.siz e() - 1) || m_keyframes[i + 1]->offset() == offset;
204 if (hasSameOffsetAsPreviousNeighbor && hasSameOffsetAsNextNeighbor) 247 if (hasSameOffsetAsPreviousNeighbor && hasSameOffsetAsNextNeighbor)
205 m_keyframes.remove(i); 248 m_keyframes.remove(i);
206 } 249 }
207 ASSERT(m_keyframes.size() >= 2); 250 ASSERT(m_keyframes.size() >= 2);
208 } 251 }
209 252
210 bool KeyframeEffectModelBase::PropertySpecificKeyframeGroup::addSyntheticKeyfram eIfRequired() 253 bool KeyframeEffectModelBase::PropertySpecificKeyframeGroup::addSyntheticKeyfram eIfRequired(PassRefPtrWillBeRawPtr<TimingFunction> easing)
211 { 254 {
212 ASSERT(!m_keyframes.isEmpty()); 255 ASSERT(!m_keyframes.isEmpty());
213 256
214 bool addedSyntheticKeyframe = false; 257 bool addedSyntheticKeyframe = false;
215 258
216 if (m_keyframes.first()->offset() != 0.0) { 259 if (m_keyframes.first()->offset() != 0.0) {
217 m_keyframes.insert(0, m_keyframes.first()->neutralKeyframe(0, nullptr)); 260 m_keyframes.insert(0, m_keyframes.first()->neutralKeyframe(0, easing));
218 addedSyntheticKeyframe = true; 261 addedSyntheticKeyframe = true;
219 } 262 }
220 if (m_keyframes.last()->offset() != 1.0) { 263 if (m_keyframes.last()->offset() != 1.0) {
221 appendKeyframe(m_keyframes.last()->neutralKeyframe(1, nullptr)); 264 appendKeyframe(m_keyframes.last()->neutralKeyframe(1, easing));
222 addedSyntheticKeyframe = true; 265 addedSyntheticKeyframe = true;
223 } 266 }
224 267
225 return addedSyntheticKeyframe; 268 return addedSyntheticKeyframe;
226 } 269 }
227 270
228 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::trace(Visitor* visi tor) 271 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::trace(Visitor* visi tor)
229 { 272 {
230 #if ENABLE(OILPAN) 273 #if ENABLE(OILPAN)
231 visitor->trace(m_keyframes); 274 visitor->trace(m_keyframes);
232 #endif 275 #endif
233 } 276 }
234 277
235 } // namespace 278 } // namespace
OLDNEW
« no previous file with comments | « Source/core/animation/KeyframeEffectModel.h ('k') | Source/core/animation/StringKeyframe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698