| OLD | NEW |
| 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 17 matching lines...) Expand all Loading... |
| 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 "core/animation/css/CSSAnimations.h" | 31 #include "core/animation/css/CSSAnimations.h" |
| 32 | 32 |
| 33 #include "core/StylePropertyShorthand.h" | 33 #include "core/StylePropertyShorthand.h" |
| 34 #include "core/animation/Animation.h" | 34 #include "core/animation/Animation.h" |
| 35 #include "core/animation/AnimationTimeline.h" | 35 #include "core/animation/AnimationTimeline.h" |
| 36 #include "core/animation/CompositorAnimations.h" | 36 #include "core/animation/CompositorAnimations.h" |
| 37 #include "core/animation/ElementAnimations.h" | 37 #include "core/animation/ElementAnimations.h" |
| 38 #include "core/animation/InertEffect.h" |
| 38 #include "core/animation/Interpolation.h" | 39 #include "core/animation/Interpolation.h" |
| 39 #include "core/animation/KeyframeEffectModel.h" | 40 #include "core/animation/KeyframeEffectModel.h" |
| 40 #include "core/animation/LegacyStyleInterpolation.h" | 41 #include "core/animation/LegacyStyleInterpolation.h" |
| 41 #include "core/animation/css/CSSAnimatableValueFactory.h" | 42 #include "core/animation/css/CSSAnimatableValueFactory.h" |
| 42 #include "core/css/CSSKeyframeRule.h" | 43 #include "core/css/CSSKeyframeRule.h" |
| 43 #include "core/css/CSSPropertyEquality.h" | 44 #include "core/css/CSSPropertyEquality.h" |
| 44 #include "core/css/CSSPropertyMetadata.h" | 45 #include "core/css/CSSPropertyMetadata.h" |
| 45 #include "core/css/CSSValueList.h" | 46 #include "core/css/CSSValueList.h" |
| 46 #include "core/css/resolver/CSSToStyleMap.h" | 47 #include "core/css/resolver/CSSToStyleMap.h" |
| 47 #include "core/css/resolver/StyleResolver.h" | 48 #include "core/css/resolver/StyleResolver.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 bool startNeedsValue = missingStartValues && !startKeyframePropertie
s.contains(PropertyHandle(property)); | 168 bool startNeedsValue = missingStartValues && !startKeyframePropertie
s.contains(PropertyHandle(property)); |
| 168 bool endNeedsValue = missingEndValues && !endKeyframeProperties.cont
ains(PropertyHandle(property)); | 169 bool endNeedsValue = missingEndValues && !endKeyframeProperties.cont
ains(PropertyHandle(property)); |
| 169 if (!startNeedsValue && !endNeedsValue) | 170 if (!startNeedsValue && !endNeedsValue) |
| 170 continue; | 171 continue; |
| 171 if (CompositorAnimations::isCompositableProperty(property)) | 172 if (CompositorAnimations::isCompositableProperty(property)) |
| 172 UseCounter::count(elementForScoping->document(), UseCounter::Syn
theticKeyframesInCompositedCSSAnimation); | 173 UseCounter::count(elementForScoping->document(), UseCounter::Syn
theticKeyframesInCompositedCSSAnimation); |
| 173 } | 174 } |
| 174 } | 175 } |
| 175 | 176 |
| 176 StringKeyframeEffectModel* model = StringKeyframeEffectModel::create(keyfram
es, &keyframes[0]->easing()); | 177 StringKeyframeEffectModel* model = StringKeyframeEffectModel::create(keyfram
es, &keyframes[0]->easing()); |
| 177 model->forceConversionsToAnimatableValues(element, style); | |
| 178 if (animationIndex > 0 && model->hasSyntheticKeyframes()) | 178 if (animationIndex > 0 && model->hasSyntheticKeyframes()) |
| 179 UseCounter::count(elementForScoping->document(), UseCounter::CSSAnimatio
nsStackedNeutralKeyframe); | 179 UseCounter::count(elementForScoping->document(), UseCounter::CSSAnimatio
nsStackedNeutralKeyframe); |
| 180 return model; | 180 return model; |
| 181 } | 181 } |
| 182 | 182 |
| 183 } // namespace | 183 } // namespace |
| 184 | 184 |
| 185 CSSAnimations::CSSAnimations() | 185 CSSAnimations::CSSAnimations() |
| 186 { | 186 { |
| 187 } | 187 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 199 { | 199 { |
| 200 for (const auto& it : m_transitions) { | 200 for (const auto& it : m_transitions) { |
| 201 if (it.value.animation->sequenceNumber() == animation.sequenceNumber()) | 201 if (it.value.animation->sequenceNumber() == animation.sequenceNumber()) |
| 202 return true; | 202 return true; |
| 203 } | 203 } |
| 204 return false; | 204 return false; |
| 205 } | 205 } |
| 206 | 206 |
| 207 void CSSAnimations::calculateUpdate(const Element* animatingElement, Element& el
ement, const ComputedStyle& style, ComputedStyle* parentStyle, CSSAnimationUpdat
e& animationUpdate, StyleResolver* resolver) | 207 void CSSAnimations::calculateUpdate(const Element* animatingElement, Element& el
ement, const ComputedStyle& style, ComputedStyle* parentStyle, CSSAnimationUpdat
e& animationUpdate, StyleResolver* resolver) |
| 208 { | 208 { |
| 209 calculateCompositorAnimationUpdate(animationUpdate, animatingElement, elemen
t, style); | 209 calculateCompositorAnimationUpdate(animationUpdate, animatingElement, elemen
t, style, parentStyle); |
| 210 calculateAnimationUpdate(animationUpdate, animatingElement, element, style,
parentStyle, resolver); | 210 calculateAnimationUpdate(animationUpdate, animatingElement, element, style,
parentStyle, resolver); |
| 211 calculateAnimationActiveInterpolations(animationUpdate, animatingElement); | 211 calculateAnimationActiveInterpolations(animationUpdate, animatingElement); |
| 212 calculateTransitionUpdate(animationUpdate, animatingElement, style); | 212 calculateTransitionUpdate(animationUpdate, animatingElement, style); |
| 213 calculateTransitionActiveInterpolations(animationUpdate, animatingElement); | 213 calculateTransitionActiveInterpolations(animationUpdate, animatingElement); |
| 214 } | 214 } |
| 215 | 215 |
| 216 void CSSAnimations::calculateCompositorAnimationUpdate(CSSAnimationUpdate& updat
e, const Element* animatingElement, Element& element, const ComputedStyle& style
) | 216 static const KeyframeEffectModelBase* getKeyframeEffectModelBase(const Animation
Effect* effect) |
| 217 { |
| 218 if (!effect) |
| 219 return nullptr; |
| 220 const EffectModel* model = nullptr; |
| 221 if (effect->isKeyframeEffect()) |
| 222 model = toKeyframeEffect(effect)->model(); |
| 223 else if (effect->isInertEffect()) |
| 224 model = toInertEffect(effect)->model(); |
| 225 if (!model || !model->isKeyframeEffectModel()) |
| 226 return nullptr; |
| 227 return toKeyframeEffectModelBase(model); |
| 228 } |
| 229 |
| 230 void CSSAnimations::calculateCompositorAnimationUpdate(CSSAnimationUpdate& updat
e, const Element* animatingElement, Element& element, const ComputedStyle& style
, const ComputedStyle* parentStyle) |
| 217 { | 231 { |
| 218 ElementAnimations* elementAnimations = animatingElement ? animatingElement->
elementAnimations() : nullptr; | 232 ElementAnimations* elementAnimations = animatingElement ? animatingElement->
elementAnimations() : nullptr; |
| 219 | 233 |
| 220 // We only update compositor animations in response to changes in the base s
tyle. | 234 // We only update compositor animations in response to changes in the base s
tyle. |
| 221 if (!elementAnimations || elementAnimations->isAnimationStyleChange()) | 235 if (!elementAnimations || elementAnimations->isAnimationStyleChange()) |
| 222 return; | 236 return; |
| 223 | 237 |
| 224 if (!animatingElement->layoutObject() || !animatingElement->layoutObject()->
style()) | 238 if (!animatingElement->layoutObject() || !animatingElement->layoutObject()->
style()) |
| 225 return; | 239 return; |
| 226 | 240 |
| 227 const ComputedStyle& oldStyle = *animatingElement->layoutObject()->style(); | 241 const ComputedStyle& oldStyle = *animatingElement->layoutObject()->style(); |
| 228 if (!oldStyle.shouldCompositeForCurrentAnimations()) | 242 if (!oldStyle.shouldCompositeForCurrentAnimations()) |
| 229 return; | 243 return; |
| 230 | 244 |
| 231 bool transformZoomChanged = oldStyle.hasCurrentTransformAnimation() && oldSt
yle.effectiveZoom() != style.effectiveZoom(); | 245 bool transformZoomChanged = oldStyle.hasCurrentTransformAnimation() && oldSt
yle.effectiveZoom() != style.effectiveZoom(); |
| 232 for (auto& entry : elementAnimations->animations()) { | 246 for (auto& entry : elementAnimations->animations()) { |
| 233 Animation& animation = *entry.key; | 247 Animation& animation = *entry.key; |
| 234 if (!animation.effect() || !animation.effect()->isKeyframeEffect()) | 248 const KeyframeEffectModelBase* keyframeEffect = getKeyframeEffectModelBa
se(animation.effect()); |
| 249 if (!keyframeEffect) |
| 235 continue; | 250 continue; |
| 236 EffectModel* model = toKeyframeEffect(animation.effect())->model(); | |
| 237 if (!model || !model->isKeyframeEffectModel()) | |
| 238 continue; | |
| 239 KeyframeEffectModelBase& keyframeEffect = toKeyframeEffectModelBase(*mod
el); | |
| 240 | 251 |
| 241 bool updateCompositorKeyframes = false; | 252 bool updateCompositorKeyframes = false; |
| 242 if (transformZoomChanged && keyframeEffect.affects(PropertyHandle(CSSPro
pertyTransform)) | 253 if (transformZoomChanged && keyframeEffect->affects(PropertyHandle(CSSPr
opertyTransform)) |
| 243 && keyframeEffect.snapshotAllCompositorKeyframes(element, &style)) { | 254 && keyframeEffect->snapshotAllCompositorKeyframes(element, style, pa
rentStyle)) { |
| 244 updateCompositorKeyframes = true; | 255 updateCompositorKeyframes = true; |
| 245 } else if (keyframeEffect.hasSyntheticKeyframes() | 256 } else if (keyframeEffect->hasSyntheticKeyframes() |
| 246 && keyframeEffect.snapshotNeutralCompositorKeyframes(element, oldSty
le, style)) { | 257 && keyframeEffect->snapshotNeutralCompositorKeyframes(element, oldSt
yle, style, parentStyle)) { |
| 247 updateCompositorKeyframes = true; | 258 updateCompositorKeyframes = true; |
| 248 } | 259 } |
| 249 | 260 |
| 250 if (updateCompositorKeyframes) | 261 if (updateCompositorKeyframes) |
| 251 update.updateCompositorKeyframes(&animation); | 262 update.updateCompositorKeyframes(&animation); |
| 252 } | 263 } |
| 253 } | 264 } |
| 254 | 265 |
| 255 void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate& update, const E
lement* animatingElement, Element& element, const ComputedStyle& style, Computed
Style* parentStyle, StyleResolver* resolver) | 266 void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate& update, const E
lement* animatingElement, Element& element, const ComputedStyle& style, Computed
Style* parentStyle, StyleResolver* resolver) |
| 256 { | 267 { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 } | 351 } |
| 341 | 352 |
| 342 for (size_t i = 0; i < cancelRunningAnimationFlags.size(); i++) { | 353 for (size_t i = 0; i < cancelRunningAnimationFlags.size(); i++) { |
| 343 if (cancelRunningAnimationFlags[i]) { | 354 if (cancelRunningAnimationFlags[i]) { |
| 344 ASSERT(cssAnimations && !isAnimationStyleChange); | 355 ASSERT(cssAnimations && !isAnimationStyleChange); |
| 345 update.cancelAnimation(i, *cssAnimations->m_runningAnimations[i]->an
imation); | 356 update.cancelAnimation(i, *cssAnimations->m_runningAnimations[i]->an
imation); |
| 346 } | 357 } |
| 347 } | 358 } |
| 348 } | 359 } |
| 349 | 360 |
| 361 void CSSAnimations::snapshotCompositorKeyframes(Element& element, CSSAnimationUp
date& update, const ComputedStyle& style, const ComputedStyle* parentStyle) |
| 362 { |
| 363 const auto& snapshot = [&element, &style, parentStyle](const AnimationEffect
* effect) |
| 364 { |
| 365 const KeyframeEffectModelBase* keyframeEffect = getKeyframeEffectModelBa
se(effect); |
| 366 if (keyframeEffect && keyframeEffect->needsCompositorKeyframesSnapshot()
) |
| 367 keyframeEffect->snapshotAllCompositorKeyframes(element, style, paren
tStyle); |
| 368 }; |
| 369 |
| 370 ElementAnimations* elementAnimations = element.elementAnimations(); |
| 371 if (elementAnimations) { |
| 372 for (auto& entry : elementAnimations->animations()) |
| 373 snapshot(entry.key->effect()); |
| 374 } |
| 375 |
| 376 for (const auto& newAnimation : update.newAnimations()) |
| 377 snapshot(newAnimation.effect.get()); |
| 378 |
| 379 for (const auto& updatedAnimation : update.animationsWithUpdates()) |
| 380 snapshot(updatedAnimation.effect.get()); |
| 381 |
| 382 for (const auto& newTransition : update.newTransitions()) |
| 383 snapshot(newTransition.value.effect.get()); |
| 384 } |
| 385 |
| 350 void CSSAnimations::maybeApplyPendingUpdate(Element* element) | 386 void CSSAnimations::maybeApplyPendingUpdate(Element* element) |
| 351 { | 387 { |
| 352 m_previousActiveInterpolationsForAnimations.clear(); | 388 m_previousActiveInterpolationsForAnimations.clear(); |
| 353 if (m_pendingUpdate.isEmpty()) | 389 if (m_pendingUpdate.isEmpty()) |
| 354 return; | 390 return; |
| 355 | 391 |
| 356 m_previousActiveInterpolationsForAnimations.swap(m_pendingUpdate.activeInter
polationsForAnimations()); | 392 m_previousActiveInterpolationsForAnimations.swap(m_pendingUpdate.activeInter
polationsForAnimations()); |
| 357 | 393 |
| 358 // FIXME: cancelling, pausing, unpausing animations all query compositingSta
te, which is not necessarily up to date here | 394 // FIXME: cancelling, pausing, unpausing animations all query compositingSta
te, which is not necessarily up to date here |
| 359 // since we call this from recalc style. | 395 // since we call this from recalc style. |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 } | 897 } |
| 862 | 898 |
| 863 DEFINE_TRACE(CSSAnimations) | 899 DEFINE_TRACE(CSSAnimations) |
| 864 { | 900 { |
| 865 visitor->trace(m_transitions); | 901 visitor->trace(m_transitions); |
| 866 visitor->trace(m_pendingUpdate); | 902 visitor->trace(m_pendingUpdate); |
| 867 visitor->trace(m_runningAnimations); | 903 visitor->trace(m_runningAnimations); |
| 868 } | 904 } |
| 869 | 905 |
| 870 } // namespace blink | 906 } // namespace blink |
| OLD | NEW |