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

Side by Side Diff: Source/core/animation/css/CSSAnimations.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
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 18 matching lines...) Expand all
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/animation/css/CSSAnimations.h" 32 #include "core/animation/css/CSSAnimations.h"
33 33
34 #include "core/StylePropertyShorthand.h" 34 #include "core/StylePropertyShorthand.h"
35 #include "core/animation/ActiveAnimations.h" 35 #include "core/animation/ActiveAnimations.h"
36 #include "core/animation/AnimationPlayer.h" 36 #include "core/animation/AnimationPlayer.h"
37 #include "core/animation/AnimationTimeline.h" 37 #include "core/animation/AnimationTimeline.h"
38 #include "core/animation/CompositorAnimations.h" 38 #include "core/animation/CompositorAnimations.h"
39 #include "core/animation/DeferredLegacyStyleInterpolation.h"
39 #include "core/animation/Interpolation.h" 40 #include "core/animation/Interpolation.h"
40 #include "core/animation/KeyframeEffectModel.h" 41 #include "core/animation/KeyframeEffectModel.h"
41 #include "core/animation/LegacyStyleInterpolation.h"
42 #include "core/animation/css/CSSAnimatableValueFactory.h" 42 #include "core/animation/css/CSSAnimatableValueFactory.h"
43 #include "core/animation/css/CSSPropertyEquality.h" 43 #include "core/animation/css/CSSPropertyEquality.h"
44 #include "core/css/CSSKeyframeRule.h" 44 #include "core/css/CSSKeyframeRule.h"
45 #include "core/css/CSSPropertyMetadata.h" 45 #include "core/css/CSSPropertyMetadata.h"
46 #include "core/css/resolver/CSSToStyleMap.h" 46 #include "core/css/resolver/CSSToStyleMap.h"
47 #include "core/css/resolver/StyleResolver.h" 47 #include "core/css/resolver/StyleResolver.h"
48 #include "core/dom/Element.h" 48 #include "core/dom/Element.h"
49 #include "core/dom/PseudoElement.h" 49 #include "core/dom/PseudoElement.h"
50 #include "core/dom/StyleEngine.h" 50 #include "core/dom/StyleEngine.h"
51 #include "core/events/TransitionEvent.h" 51 #include "core/events/TransitionEvent.h"
(...skipping 26 matching lines...) Expand all
78 case CSSPropertyWebkitTransformOriginY: 78 case CSSPropertyWebkitTransformOriginY:
79 case CSSPropertyWebkitTransformOriginZ: 79 case CSSPropertyWebkitTransformOriginZ:
80 case CSSPropertyWebkitTransformOrigin: 80 case CSSPropertyWebkitTransformOrigin:
81 return CSSPropertyTransformOrigin; 81 return CSSPropertyTransformOrigin;
82 default: 82 default:
83 break; 83 break;
84 } 84 }
85 return property; 85 return property;
86 } 86 }
87 87
88 static void resolveKeyframes(StyleResolver* resolver, const Element* animatingEl ement, Element& element, const LayoutStyle& style, LayoutStyle* parentStyle, con st AtomicString& name, TimingFunction* defaultTimingFunction, 88 static PassRefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> createKeyframe Effect(StyleResolver* resolver, const Element* animatingElement, Element& elemen t, const LayoutStyle& style, LayoutStyle* parentStyle,
89 AnimatableValueKeyframeVector& keyframes) 89 const AtomicString& name, TimingFunction* defaultTimingFunction)
90 { 90 {
91 // When the animating element is null, use its parent for scoping purposes. 91 // When the animating element is null, use its parent for scoping purposes.
92 const Element* elementForScoping = animatingElement ? animatingElement : &el ement; 92 const Element* elementForScoping = animatingElement ? animatingElement : &el ement;
93 const StyleRuleKeyframes* keyframesRule = resolver->findKeyframesRule(elemen tForScoping, name); 93 const StyleRuleKeyframes* keyframesRule = resolver->findKeyframesRule(elemen tForScoping, name);
94 if (!keyframesRule) 94 ASSERT(keyframesRule);
95 return;
96 95
96 AnimatableValueKeyframeVector keyframes;
97 const WillBeHeapVector<RefPtrWillBeMember<StyleRuleKeyframe>>& styleKeyframe s = keyframesRule->keyframes(); 97 const WillBeHeapVector<RefPtrWillBeMember<StyleRuleKeyframe>>& styleKeyframe s = keyframesRule->keyframes();
98 98
99 // Construct and populate the style for each keyframe 99 // Construct and populate the style for each keyframe
100 PropertySet specifiedPropertiesForUseCounter; 100 PropertySet specifiedPropertiesForUseCounter;
101 for (size_t i = 0; i < styleKeyframes.size(); ++i) { 101 for (size_t i = 0; i < styleKeyframes.size(); ++i) {
102 const StyleRuleKeyframe* styleKeyframe = styleKeyframes[i].get(); 102 const StyleRuleKeyframe* styleKeyframe = styleKeyframes[i].get();
103 RefPtr<LayoutStyle> keyframeStyle = resolver->styleForKeyframe(element, style, parentStyle, styleKeyframe, name); 103 RefPtr<LayoutStyle> keyframeStyle = resolver->styleForKeyframe(element, style, parentStyle, styleKeyframe, name);
104 RefPtrWillBeRawPtr<AnimatableValueKeyframe> keyframe = AnimatableValueKe yframe::create(); 104 RefPtrWillBeRawPtr<AnimatableValueKeyframe> keyframe = AnimatableValueKe yframe::create();
105 const Vector<double>& offsets = styleKeyframe->keys(); 105 const Vector<double>& offsets = styleKeyframe->keys();
106 ASSERT(!offsets.isEmpty()); 106 ASSERT(!offsets.isEmpty());
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 if (startNeedsValue) 192 if (startNeedsValue)
193 startKeyframe->setPropertyValue(property, snapshotValue.get()); 193 startKeyframe->setPropertyValue(property, snapshotValue.get());
194 if (endNeedsValue) 194 if (endNeedsValue)
195 endKeyframe->setPropertyValue(property, snapshotValue.get()); 195 endKeyframe->setPropertyValue(property, snapshotValue.get());
196 if (property == CSSPropertyOpacity || property == CSSPropertyTransfo rm) 196 if (property == CSSPropertyOpacity || property == CSSPropertyTransfo rm)
197 UseCounter::count(elementForScoping->document(), UseCounter::Syn theticKeyframesInCompositedCSSAnimation); 197 UseCounter::count(elementForScoping->document(), UseCounter::Syn theticKeyframesInCompositedCSSAnimation);
198 } 198 }
199 } 199 }
200 ASSERT(startKeyframe->properties().size() == allProperties.size()); 200 ASSERT(startKeyframe->properties().size() == allProperties.size());
201 ASSERT(endKeyframe->properties().size() == allProperties.size()); 201 ASSERT(endKeyframe->properties().size() == allProperties.size());
202
203 return AnimatableValueKeyframeEffectModel::create(keyframes, &keyframes[0]-> easing());
202 } 204 }
203
204 } // namespace 205 } // namespace
205 206
206 CSSAnimations::CSSAnimations() 207 CSSAnimations::CSSAnimations()
207 { 208 {
208 } 209 }
209 210
210 const AtomicString CSSAnimations::getAnimationNameForInspector(const AnimationPl ayer& player) 211 const AtomicString CSSAnimations::getAnimationNameForInspector(const AnimationPl ayer& player)
211 { 212 {
212 for (const auto& it : m_animations) { 213 for (const auto& it : m_animations) {
213 if (it.value->player->sequenceNumber() == player.sequenceNumber()) 214 if (it.value->player->sequenceNumber() == player.sequenceNumber())
(...skipping 18 matching lines...) Expand all
232 calculateAnimationActiveInterpolations(update.get(), animatingElement, eleme nt.document().timeline().currentTimeInternal()); 233 calculateAnimationActiveInterpolations(update.get(), animatingElement, eleme nt.document().timeline().currentTimeInternal());
233 calculateTransitionUpdate(update.get(), animatingElement, style); 234 calculateTransitionUpdate(update.get(), animatingElement, style);
234 calculateTransitionActiveInterpolations(update.get(), animatingElement, elem ent.document().timeline().currentTimeInternal()); 235 calculateTransitionActiveInterpolations(update.get(), animatingElement, elem ent.document().timeline().currentTimeInternal());
235 return update->isEmpty() ? nullptr : update.release(); 236 return update->isEmpty() ? nullptr : update.release();
236 } 237 }
237 238
238 void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate* update, const E lement* animatingElement, Element& element, const LayoutStyle& style, LayoutStyl e* parentStyle, StyleResolver* resolver) 239 void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate* update, const E lement* animatingElement, Element& element, const LayoutStyle& style, LayoutStyl e* parentStyle, StyleResolver* resolver)
239 { 240 {
240 const ActiveAnimations* activeAnimations = animatingElement ? animatingEleme nt->activeAnimations() : nullptr; 241 const ActiveAnimations* activeAnimations = animatingElement ? animatingEleme nt->activeAnimations() : nullptr;
241 242
243 bool isAnimationStyleChange = activeAnimations && activeAnimations->isAnimat ionStyleChange();
244
242 #if !ENABLE(ASSERT) 245 #if !ENABLE(ASSERT)
243 // If we're in an animation style change, no animations can have started, be en cancelled or changed play state. 246 // If we're in an animation style change, no animations can have started, be en cancelled or changed play state.
244 // When ASSERT is enabled, we verify this optimization. 247 // When ASSERT is enabled, we verify this optimization.
245 if (activeAnimations && activeAnimations->isAnimationStyleChange()) 248 if (isAnimationStyleChange)
246 return; 249 return;
247 #endif 250 #endif
248 251
249 const CSSAnimationData* animationData = style.animations(); 252 const CSSAnimationData* animationData = style.animations();
250 const CSSAnimations* cssAnimations = activeAnimations ? &activeAnimations->c ssAnimations() : nullptr; 253 const CSSAnimations* cssAnimations = activeAnimations ? &activeAnimations->c ssAnimations() : nullptr;
251 const Element* elementForScoping = animatingElement ? animatingElement : &el ement; 254 const Element* elementForScoping = animatingElement ? animatingElement : &el ement;
252 255
253 HashSet<AtomicString> inactive; 256 HashSet<AtomicString> inactive;
254 if (cssAnimations) { 257 if (cssAnimations) {
255 for (const auto& entry : cssAnimations->m_animations) 258 for (const auto& entry : cssAnimations->m_animations)
(...skipping 18 matching lines...) Expand all
274 continue; // Cancel the animation if there's no style rule for i t. 277 continue; // Cancel the animation if there's no style rule for i t.
275 278
276 if (cssAnimations) { 279 if (cssAnimations) {
277 AnimationMap::const_iterator existing(cssAnimations->m_animation s.find(animationName)); 280 AnimationMap::const_iterator existing(cssAnimations->m_animation s.find(animationName));
278 if (existing != cssAnimations->m_animations.end()) { 281 if (existing != cssAnimations->m_animations.end()) {
279 inactive.remove(animationName); 282 inactive.remove(animationName);
280 283
281 const RunningAnimation* runningAnimation = existing->value.g et(); 284 const RunningAnimation* runningAnimation = existing->value.g et();
282 AnimationPlayer* player = runningAnimation->player.get(); 285 AnimationPlayer* player = runningAnimation->player.get();
283 286
284 ASSERT(keyframesRule);
285 if (keyframesRule != runningAnimation->styleRule || keyframe sRule->version() != runningAnimation->styleRuleVersion || runningAnimation->spec ifiedTiming != specifiedTiming) { 287 if (keyframesRule != runningAnimation->styleRule || keyframe sRule->version() != runningAnimation->styleRuleVersion || runningAnimation->spec ifiedTiming != specifiedTiming) {
286 AnimatableValueKeyframeVector resolvedKeyframes; 288 ASSERT(!isAnimationStyleChange);
287 resolveKeyframes(resolver, animatingElement, element, st yle, parentStyle, animationName, keyframeTimingFunction.get(), resolvedKeyframes ); 289 update->updateAnimation(animationName, player, InertAnim ation::create(
288 290 createKeyframeEffect(resolver, animatingElement, ele ment, style, parentStyle, animationName, keyframeTimingFunction.get()),
289 update->updateAnimation(animationName, player, InertAnim ation::create(AnimatableValueKeyframeEffectModel::create(resolvedKeyframes),
290 timing, isPaused, player->currentTimeInternal()), sp ecifiedTiming, keyframesRule); 291 timing, isPaused, player->currentTimeInternal()), sp ecifiedTiming, keyframesRule);
291 } 292 }
292 293
293 if (isPaused != player->paused()) { 294 if (isPaused != player->paused()) {
294 ASSERT(!activeAnimations || !activeAnimations->isAnimati onStyleChange()); 295 ASSERT(!isAnimationStyleChange);
295 update->toggleAnimationPaused(animationName); 296 update->toggleAnimationPaused(animationName);
296 } 297 }
297 298
298 continue; 299 continue;
299 } 300 }
300 } 301 }
301 302
302 AnimatableValueKeyframeVector resolvedKeyframes; 303 ASSERT(!isAnimationStyleChange);
303 resolveKeyframes(resolver, animatingElement, element, style, parentS tyle, animationName, keyframeTimingFunction.get(), resolvedKeyframes); 304 update->startAnimation(animationName, InertAnimation::create(
304 if (!resolvedKeyframes.isEmpty()) { 305 createKeyframeEffect(resolver, animatingElement, element, style, parentStyle, animationName, keyframeTimingFunction.get()),
305 ASSERT(!activeAnimations || !activeAnimations->isAnimationStyleC hange()); 306 timing, isPaused, 0), specifiedTiming, keyframesRule);
306 update->startAnimation(animationName, InertAnimation::create(Ani matableValueKeyframeEffectModel::create(resolvedKeyframes), timing, isPaused, 0) , specifiedTiming, keyframesRule);
307 }
308 } 307 }
309 } 308 }
310 309
311 ASSERT(inactive.isEmpty() || cssAnimations); 310 ASSERT(inactive.isEmpty() || cssAnimations);
312 for (const AtomicString& animationName : inactive) { 311 for (const AtomicString& animationName : inactive) {
313 ASSERT(!activeAnimations || !activeAnimations->isAnimationStyleChange()) ; 312 ASSERT(!isAnimationStyleChange);
314 update->cancelAnimation(animationName, *cssAnimations->m_animations.get( animationName)->player); 313 update->cancelAnimation(animationName, *cssAnimations->m_animations.get( animationName)->player);
315 } 314 }
316 } 315 }
317 316
318 void CSSAnimations::maybeApplyPendingUpdate(Element* element) 317 void CSSAnimations::maybeApplyPendingUpdate(Element* element)
319 { 318 {
320 if (!m_pendingUpdate) { 319 if (!m_pendingUpdate) {
321 m_previousActiveInterpolationsForAnimations.clear(); 320 m_previousActiveInterpolationsForAnimations.clear();
322 return; 321 return;
323 } 322 }
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 visitor->trace(m_newTransitions); 796 visitor->trace(m_newTransitions);
798 visitor->trace(m_activeInterpolationsForAnimations); 797 visitor->trace(m_activeInterpolationsForAnimations);
799 visitor->trace(m_activeInterpolationsForTransitions); 798 visitor->trace(m_activeInterpolationsForTransitions);
800 visitor->trace(m_newAnimations); 799 visitor->trace(m_newAnimations);
801 visitor->trace(m_suppressedAnimationPlayers); 800 visitor->trace(m_suppressedAnimationPlayers);
802 visitor->trace(m_animationsWithUpdates); 801 visitor->trace(m_animationsWithUpdates);
803 #endif 802 #endif
804 } 803 }
805 804
806 } // namespace blink 805 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698