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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 if (const StyleRuleKeyframes* keyframesRule = stack.at(i)->keyframeStyle
sForAnimation(animationName)) | 342 if (const StyleRuleKeyframes* keyframesRule = stack.at(i)->keyframeStyle
sForAnimation(animationName)) |
343 return keyframesRule; | 343 return keyframesRule; |
344 } | 344 } |
345 return 0; | 345 return 0; |
346 } | 346 } |
347 | 347 |
348 PassOwnPtr<CSSAnimationUpdate> CSSAnimations::calculateUpdate(Element* element,
const Element& parentElement, const RenderStyle& style, RenderStyle* parentStyle
, StyleResolver* resolver) | 348 PassOwnPtr<CSSAnimationUpdate> CSSAnimations::calculateUpdate(Element* element,
const Element& parentElement, const RenderStyle& style, RenderStyle* parentStyle
, StyleResolver* resolver) |
349 { | 349 { |
350 OwnPtr<CSSAnimationUpdate> update = adoptPtr(new CSSAnimationUpdate()); | 350 OwnPtr<CSSAnimationUpdate> update = adoptPtr(new CSSAnimationUpdate()); |
351 calculateAnimationUpdate(update.get(), element, parentElement, style, parent
Style, resolver); | 351 calculateAnimationUpdate(update.get(), element, parentElement, style, parent
Style, resolver); |
352 calculateAnimationCompositableValues(update.get(), element); | 352 calculateAnimationActiveInterpolations(update.get(), element); |
353 calculateTransitionUpdate(update.get(), element, style); | 353 calculateTransitionUpdate(update.get(), element, style); |
354 calculateTransitionCompositableValues(update.get(), element); | 354 calculateTransitionActiveInterpolations(update.get(), element); |
355 return update->isEmpty() ? nullptr : update.release(); | 355 return update->isEmpty() ? nullptr : update.release(); |
356 } | 356 } |
357 | 357 |
358 void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate* update, Element
* element, const Element& parentElement, const RenderStyle& style, RenderStyle*
parentStyle, StyleResolver* resolver) | 358 void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate* update, Element
* element, const Element& parentElement, const RenderStyle& style, RenderStyle*
parentStyle, StyleResolver* resolver) |
359 { | 359 { |
360 const ActiveAnimations* activeAnimations = element ? element->activeAnimatio
ns() : 0; | 360 const ActiveAnimations* activeAnimations = element ? element->activeAnimatio
ns() : 0; |
361 | 361 |
362 #if ASSERT_DISABLED | 362 #if ASSERT_DISABLED |
363 // If we're in an animation style change, no animations can have started, be
en cancelled or changed play state. | 363 // If we're in an animation style change, no animations can have started, be
en cancelled or changed play state. |
364 // When ASSERT is enabled, we verify this optimization. | 364 // When ASSERT is enabled, we verify this optimization. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 ASSERT(inactive.isEmpty() || cssAnimations); | 426 ASSERT(inactive.isEmpty() || cssAnimations); |
427 for (HashSet<AtomicString>::const_iterator iter = inactive.begin(); iter !=
inactive.end(); ++iter) { | 427 for (HashSet<AtomicString>::const_iterator iter = inactive.begin(); iter !=
inactive.end(); ++iter) { |
428 ASSERT(!activeAnimations || !activeAnimations->isAnimationStyleChange())
; | 428 ASSERT(!activeAnimations || !activeAnimations->isAnimationStyleChange())
; |
429 update->cancelAnimation(*iter, cssAnimations->m_animations.get(*iter)); | 429 update->cancelAnimation(*iter, cssAnimations->m_animations.get(*iter)); |
430 } | 430 } |
431 } | 431 } |
432 | 432 |
433 void CSSAnimations::maybeApplyPendingUpdate(Element* element) | 433 void CSSAnimations::maybeApplyPendingUpdate(Element* element) |
434 { | 434 { |
435 if (!m_pendingUpdate) { | 435 if (!m_pendingUpdate) { |
436 m_previousCompositableValuesForAnimations.clear(); | 436 m_previousActiveInterpolationsForAnimations.clear(); |
437 return; | 437 return; |
438 } | 438 } |
439 | 439 |
440 OwnPtr<CSSAnimationUpdate> update = m_pendingUpdate.release(); | 440 OwnPtr<CSSAnimationUpdate> update = m_pendingUpdate.release(); |
441 | 441 |
442 m_previousCompositableValuesForAnimations.swap(update->compositableValuesFor
Animations()); | 442 m_previousActiveInterpolationsForAnimations.swap(update->activeInterpolation
sForAnimations()); |
443 | 443 |
444 // FIXME: cancelling, pausing, unpausing animations all query compositingSta
te, which is not necessarily up to date here | 444 // FIXME: cancelling, pausing, unpausing animations all query compositingSta
te, which is not necessarily up to date here |
445 // since we call this from recalc style. | 445 // since we call this from recalc style. |
446 // https://code.google.com/p/chromium/issues/detail?id=339847 | 446 // https://code.google.com/p/chromium/issues/detail?id=339847 |
447 DisableCompositingQueryAsserts disabler; | 447 DisableCompositingQueryAsserts disabler; |
448 | 448 |
449 for (Vector<AtomicString>::const_iterator iter = update->cancelledAnimationN
ames().begin(); iter != update->cancelledAnimationNames().end(); ++iter) { | 449 for (Vector<AtomicString>::const_iterator iter = update->cancelledAnimationN
ames().begin(); iter != update->cancelledAnimationNames().end(); ++iter) { |
450 const HashSet<RefPtr<Player> >& players = m_animations.take(*iter); | 450 const HashSet<RefPtr<Player> >& players = m_animations.take(*iter); |
451 for (HashSet<RefPtr<Player> >::const_iterator iter = players.begin(); it
er != players.end(); ++iter) | 451 for (HashSet<RefPtr<Player> >::const_iterator iter = players.begin(); it
er != players.end(); ++iter) |
452 (*iter)->cancel(); | 452 (*iter)->cancel(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 const std::pair<RefPtr<Animation>, double>& oldTransition = retarget
edCompositorTransitions.get(id); | 517 const std::pair<RefPtr<Animation>, double>& oldTransition = retarget
edCompositorTransitions.get(id); |
518 RefPtr<Animation> oldAnimation = oldTransition.first; | 518 RefPtr<Animation> oldAnimation = oldTransition.first; |
519 double oldStartTime = oldTransition.second; | 519 double oldStartTime = oldTransition.second; |
520 double inheritedTime = isNull(oldStartTime) ? 0 : element->document(
).transitionTimeline().currentTime() - oldStartTime; | 520 double inheritedTime = isNull(oldStartTime) ? 0 : element->document(
).transitionTimeline().currentTime() - oldStartTime; |
521 oldAnimation->updateInheritedTime(inheritedTime); | 521 oldAnimation->updateInheritedTime(inheritedTime); |
522 KeyframeEffectModel* oldEffect = toKeyframeEffectModel(inertAnimatio
n->effect()); | 522 KeyframeEffectModel* oldEffect = toKeyframeEffectModel(inertAnimatio
n->effect()); |
523 const KeyframeEffectModel::KeyframeVector& frames = oldEffect->getFr
ames(); | 523 const KeyframeEffectModel::KeyframeVector& frames = oldEffect->getFr
ames(); |
524 KeyframeEffectModel::KeyframeVector newFrames; | 524 KeyframeEffectModel::KeyframeVector newFrames; |
525 newFrames.append(frames[0]->clone()); | 525 newFrames.append(frames[0]->clone()); |
526 newFrames[0]->clearPropertyValue(id); | 526 newFrames[0]->clearPropertyValue(id); |
527 ASSERT(oldAnimation->compositableValues()->size() == 1); | 527 ASSERT(oldAnimation->activeInterpolations()->size() == 1); |
528 const AnimationEffect::CompositableValue* compositableValue = oldAni
mation->compositableValues()->at(0).second.get(); | 528 const AnimatableValue* value = toLegacyStyleInterpolation(oldAnimati
on->activeInterpolations()->at(0).get())->currentValue(); |
529 ASSERT(!compositableValue->dependsOnUnderlyingValue()); | 529 newFrames[0]->setPropertyValue(id, value); |
530 newFrames[0]->setPropertyValue(id, compositableValue->compositeOnto(
0).get()); | |
531 newFrames.append(frames[1]->clone()); | 530 newFrames.append(frames[1]->clone()); |
532 effect = KeyframeEffectModel::create(newFrames); | 531 effect = KeyframeEffectModel::create(newFrames); |
533 } | 532 } |
534 RefPtr<Animation> transition = Animation::create(element, effect, inertA
nimation->specifiedTiming(), Animation::TransitionPriority, eventDelegate.releas
e()); | 533 RefPtr<Animation> transition = Animation::create(element, effect, inertA
nimation->specifiedTiming(), Animation::TransitionPriority, eventDelegate.releas
e()); |
535 RefPtr<Player> player = element->document().transitionTimeline().createP
layer(transition.get()); | 534 RefPtr<Player> player = element->document().transitionTimeline().createP
layer(transition.get()); |
536 player->update(); | 535 player->update(); |
537 element->document().cssPendingAnimations().add(player.get()); | 536 element->document().cssPendingAnimations().add(player.get()); |
538 runningTransition.transition = transition.get(); | 537 runningTransition.transition = transition.get(); |
539 m_transitions.set(id, runningTransition); | 538 m_transitions.set(id, runningTransition); |
540 ASSERT(id != CSSPropertyInvalid); | 539 ASSERT(id != CSSPropertyInvalid); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 | 635 |
637 if (!animateAll) { | 636 if (!animateAll) { |
638 if (CSSAnimations::isAnimatableProperty(id)) | 637 if (CSSAnimations::isAnimatableProperty(id)) |
639 listedProperties.set(id); | 638 listedProperties.set(id); |
640 else | 639 else |
641 continue; | 640 continue; |
642 } | 641 } |
643 | 642 |
644 // FIXME: We should transition if an !important property changes
even when an animation is running, | 643 // FIXME: We should transition if an !important property changes
even when an animation is running, |
645 // but this is a bit hard to do with the current applyMatchedPro
perties system. | 644 // but this is a bit hard to do with the current applyMatchedPro
perties system. |
646 if (!update->compositableValuesForAnimations().contains(id) | 645 if (!update->activeInterpolationsForAnimations().contains(id) |
647 && (!activeAnimations || !activeAnimations->cssAnimations().
m_previousCompositableValuesForAnimations.contains(id))) { | 646 && (!activeAnimations || !activeAnimations->cssAnimations().
m_previousActiveInterpolationsForAnimations.contains(id))) { |
648 calculateTransitionUpdateForProperty(id, anim, oldStyle, sty
le, activeTransitions, update, element); | 647 calculateTransitionUpdateForProperty(id, anim, oldStyle, sty
le, activeTransitions, update, element); |
649 } | 648 } |
650 } | 649 } |
651 } | 650 } |
652 } | 651 } |
653 | 652 |
654 if (activeTransitions) { | 653 if (activeTransitions) { |
655 for (TransitionMap::const_iterator iter = activeTransitions->begin(); it
er != activeTransitions->end(); ++iter) { | 654 for (TransitionMap::const_iterator iter = activeTransitions->begin(); it
er != activeTransitions->end(); ++iter) { |
656 const TimedItem* timedItem = iter->value.transition; | 655 const TimedItem* timedItem = iter->value.transition; |
657 CSSPropertyID id = iter->key; | 656 CSSPropertyID id = iter->key; |
(...skipping 14 matching lines...) Expand all Loading... |
672 } | 671 } |
673 | 672 |
674 for (TransitionMap::iterator iter = m_transitions.begin(); iter != m_transit
ions.end(); ++iter) | 673 for (TransitionMap::iterator iter = m_transitions.begin(); iter != m_transit
ions.end(); ++iter) |
675 iter->value.transition->player()->cancel(); | 674 iter->value.transition->player()->cancel(); |
676 | 675 |
677 m_animations.clear(); | 676 m_animations.clear(); |
678 m_transitions.clear(); | 677 m_transitions.clear(); |
679 m_pendingUpdate = nullptr; | 678 m_pendingUpdate = nullptr; |
680 } | 679 } |
681 | 680 |
682 void CSSAnimations::calculateAnimationCompositableValues(CSSAnimationUpdate* upd
ate, const Element* element) | 681 void CSSAnimations::calculateAnimationActiveInterpolations(CSSAnimationUpdate* u
pdate, const Element* element) |
683 { | 682 { |
684 ActiveAnimations* activeAnimations = element ? element->activeAnimations() :
0; | 683 ActiveAnimations* activeAnimations = element ? element->activeAnimations() :
0; |
685 AnimationStack* animationStack = activeAnimations ? &activeAnimations->defau
ltStack() : 0; | 684 AnimationStack* animationStack = activeAnimations ? &activeAnimations->defau
ltStack() : 0; |
686 | 685 |
687 if (update->newAnimations().isEmpty() && update->cancelledAnimationPlayers()
.isEmpty()) { | 686 if (update->newAnimations().isEmpty() && update->cancelledAnimationPlayers()
.isEmpty()) { |
688 AnimationEffect::CompositableValueMap compositableValuesForAnimations(An
imationStack::compositableValues(animationStack, 0, 0, Animation::DefaultPriorit
y)); | 687 HashMap<CSSPropertyID, RefPtr<Interpolation> > activeInterpolationsForAn
imations(AnimationStack::activeInterpolations(animationStack, 0, 0, Animation::D
efaultPriority)); |
689 update->adoptCompositableValuesForAnimations(compositableValuesForAnimat
ions); | 688 update->adoptActiveInterpolationsForAnimations(activeInterpolationsForAn
imations); |
690 return; | 689 return; |
691 } | 690 } |
692 | 691 |
693 Vector<InertAnimation*> newAnimations; | 692 Vector<InertAnimation*> newAnimations; |
694 for (size_t i = 0; i < update->newAnimations().size(); ++i) { | 693 for (size_t i = 0; i < update->newAnimations().size(); ++i) { |
695 HashSet<RefPtr<InertAnimation> > animations = update->newAnimations()[i]
.animations; | 694 HashSet<RefPtr<InertAnimation> > animations = update->newAnimations()[i]
.animations; |
696 for (HashSet<RefPtr<InertAnimation> >::const_iterator animationsIter = a
nimations.begin(); animationsIter != animations.end(); ++animationsIter) | 695 for (HashSet<RefPtr<InertAnimation> >::const_iterator animationsIter = a
nimations.begin(); animationsIter != animations.end(); ++animationsIter) |
697 newAnimations.append(animationsIter->get()); | 696 newAnimations.append(animationsIter->get()); |
698 } | 697 } |
699 AnimationEffect::CompositableValueMap compositableValuesForAnimations(Animat
ionStack::compositableValues(animationStack, &newAnimations, &update->cancelledA
nimationPlayers(), Animation::DefaultPriority)); | 698 HashMap<CSSPropertyID, RefPtr<Interpolation> > activeInterpolationsForAnimat
ions(AnimationStack::activeInterpolations(animationStack, &newAnimations, &updat
e->cancelledAnimationPlayers(), Animation::DefaultPriority)); |
700 update->adoptCompositableValuesForAnimations(compositableValuesForAnimations
); | 699 update->adoptActiveInterpolationsForAnimations(activeInterpolationsForAnimat
ions); |
701 } | 700 } |
702 | 701 |
703 void CSSAnimations::calculateTransitionCompositableValues(CSSAnimationUpdate* up
date, const Element* element) | 702 void CSSAnimations::calculateTransitionActiveInterpolations(CSSAnimationUpdate*
update, const Element* element) |
704 { | 703 { |
705 ActiveAnimations* activeAnimations = element ? element->activeAnimations() :
0; | 704 ActiveAnimations* activeAnimations = element ? element->activeAnimations() :
0; |
706 AnimationStack* animationStack = activeAnimations ? &activeAnimations->defau
ltStack() : 0; | 705 AnimationStack* animationStack = activeAnimations ? &activeAnimations->defau
ltStack() : 0; |
707 | 706 |
708 AnimationEffect::CompositableValueMap compositableValuesForTransitions; | 707 HashMap<CSSPropertyID, RefPtr<Interpolation> > activeInterpolationsForTransi
tions; |
709 if (update->newTransitions().isEmpty() && update->cancelledTransitions().isE
mpty()) { | 708 if (update->newTransitions().isEmpty() && update->cancelledTransitions().isE
mpty()) { |
710 compositableValuesForTransitions = AnimationStack::compositableValues(an
imationStack, 0, 0, Animation::TransitionPriority); | 709 activeInterpolationsForTransitions = AnimationStack::activeInterpolation
s(animationStack, 0, 0, Animation::TransitionPriority); |
711 } else { | 710 } else { |
712 Vector<InertAnimation*> newTransitions; | 711 Vector<InertAnimation*> newTransitions; |
713 for (CSSAnimationUpdate::NewTransitionMap::const_iterator iter = update-
>newTransitions().begin(); iter != update->newTransitions().end(); ++iter) | 712 for (CSSAnimationUpdate::NewTransitionMap::const_iterator iter = update-
>newTransitions().begin(); iter != update->newTransitions().end(); ++iter) |
714 newTransitions.append(iter->value.animation.get()); | 713 newTransitions.append(iter->value.animation.get()); |
715 | 714 |
716 HashSet<const Player*> cancelledPlayers; | 715 HashSet<const Player*> cancelledPlayers; |
717 if (!update->cancelledTransitions().isEmpty()) { | 716 if (!update->cancelledTransitions().isEmpty()) { |
718 ASSERT(activeAnimations); | 717 ASSERT(activeAnimations); |
719 const TransitionMap& transitionMap = activeAnimations->cssAnimations
().m_transitions; | 718 const TransitionMap& transitionMap = activeAnimations->cssAnimations
().m_transitions; |
720 for (HashSet<CSSPropertyID>::iterator iter = update->cancelledTransi
tions().begin(); iter != update->cancelledTransitions().end(); ++iter) { | 719 for (HashSet<CSSPropertyID>::iterator iter = update->cancelledTransi
tions().begin(); iter != update->cancelledTransitions().end(); ++iter) { |
721 ASSERT(transitionMap.contains(*iter)); | 720 ASSERT(transitionMap.contains(*iter)); |
722 cancelledPlayers.add(transitionMap.get(*iter).transition->player
()); | 721 cancelledPlayers.add(transitionMap.get(*iter).transition->player
()); |
723 } | 722 } |
724 } | 723 } |
725 | 724 |
726 compositableValuesForTransitions = AnimationStack::compositableValues(an
imationStack, &newTransitions, &cancelledPlayers, Animation::TransitionPriority)
; | 725 activeInterpolationsForTransitions = AnimationStack::activeInterpolation
s(animationStack, &newTransitions, &cancelledPlayers, Animation::TransitionPrior
ity); |
727 } | 726 } |
728 | 727 |
729 // Properties being animated by animations don't get values from transitions
applied. | 728 // Properties being animated by animations don't get values from transitions
applied. |
730 if (!update->compositableValuesForAnimations().isEmpty() && !compositableVal
uesForTransitions.isEmpty()) { | 729 if (!update->activeInterpolationsForAnimations().isEmpty() && !activeInterpo
lationsForTransitions.isEmpty()) { |
731 for (AnimationEffect::CompositableValueMap::const_iterator iter = update
->compositableValuesForAnimations().begin(); iter != update->compositableValuesF
orAnimations().end(); ++iter) | 730 for (HashMap<CSSPropertyID, RefPtr<Interpolation> >::const_iterator iter
= update->activeInterpolationsForAnimations().begin(); iter != update->activeIn
terpolationsForAnimations().end(); ++iter) |
732 compositableValuesForTransitions.remove(iter->key); | 731 activeInterpolationsForTransitions.remove(iter->key); |
733 } | 732 } |
734 update->adoptCompositableValuesForTransitions(compositableValuesForTransitio
ns); | 733 update->adoptActiveInterpolationsForTransitions(activeInterpolationsForTrans
itions); |
735 } | 734 } |
736 | 735 |
737 void CSSAnimations::AnimationEventDelegate::maybeDispatch(Document::ListenerType
listenerType, const AtomicString& eventName, double elapsedTime) | 736 void CSSAnimations::AnimationEventDelegate::maybeDispatch(Document::ListenerType
listenerType, const AtomicString& eventName, double elapsedTime) |
738 { | 737 { |
739 if (m_target->document().hasListenerType(listenerType)) { | 738 if (m_target->document().hasListenerType(listenerType)) { |
740 RefPtr<WebKitAnimationEvent> event = WebKitAnimationEvent::create(eventN
ame, m_name, elapsedTime); | 739 RefPtr<WebKitAnimationEvent> event = WebKitAnimationEvent::create(eventN
ame, m_name, elapsedTime); |
741 event->setTarget(m_target); | 740 event->setTarget(m_target); |
742 m_target->document().enqueueAnimationFrameEvent(event); | 741 m_target->document().enqueueAnimationFrameEvent(event); |
743 } | 742 } |
744 } | 743 } |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 CSSPropertyID id = convertToCSSPropertyID(i); | 915 CSSPropertyID id = convertToCSSPropertyID(i); |
917 if (isAnimatableProperty(id)) | 916 if (isAnimatableProperty(id)) |
918 properties.append(id); | 917 properties.append(id); |
919 } | 918 } |
920 propertyShorthand = StylePropertyShorthand(CSSPropertyInvalid, propertie
s.begin(), properties.size()); | 919 propertyShorthand = StylePropertyShorthand(CSSPropertyInvalid, propertie
s.begin(), properties.size()); |
921 } | 920 } |
922 return propertyShorthand; | 921 return propertyShorthand; |
923 } | 922 } |
924 | 923 |
925 } // namespace WebCore | 924 } // namespace WebCore |
OLD | NEW |