| 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 15 matching lines...) Expand all Loading... |
| 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/css/CSSAnimations.h" | 32 #include "core/animation/css/CSSAnimations.h" |
| 33 | 33 |
| 34 #include "StylePropertyShorthand.h" | 34 #include "StylePropertyShorthand.h" |
| 35 #include "core/animation/ActiveAnimations.h" | 35 #include "core/animation/ActiveAnimations.h" |
| 36 #include "core/animation/CompositorAnimations.h" |
| 36 #include "core/animation/DocumentTimeline.h" | 37 #include "core/animation/DocumentTimeline.h" |
| 37 #include "core/animation/KeyframeAnimationEffect.h" | 38 #include "core/animation/KeyframeAnimationEffect.h" |
| 38 #include "core/animation/css/CSSAnimatableValueFactory.h" | 39 #include "core/animation/css/CSSAnimatableValueFactory.h" |
| 39 #include "core/css/CSSKeyframeRule.h" | 40 #include "core/css/CSSKeyframeRule.h" |
| 40 #include "core/css/resolver/StyleResolver.h" | 41 #include "core/css/resolver/StyleResolver.h" |
| 41 #include "core/dom/Element.h" | 42 #include "core/dom/Element.h" |
| 42 #include "core/dom/PseudoElement.h" | 43 #include "core/dom/PseudoElement.h" |
| 43 #include "core/events/ThreadLocalEventNames.h" | 44 #include "core/events/ThreadLocalEventNames.h" |
| 44 #include "core/events/TransitionEvent.h" | 45 #include "core/events/TransitionEvent.h" |
| 45 #include "core/events/WebKitAnimationEvent.h" | 46 #include "core/events/WebKitAnimationEvent.h" |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 } | 515 } |
| 515 | 516 |
| 516 for (Vector<CSSAnimationUpdate::NewAnimation>::const_iterator iter = update-
>newAnimations().begin(); iter != update->newAnimations().end(); ++iter) { | 517 for (Vector<CSSAnimationUpdate::NewAnimation>::const_iterator iter = update-
>newAnimations().begin(); iter != update->newAnimations().end(); ++iter) { |
| 517 OwnPtr<AnimationEventDelegate> eventDelegate = adoptPtr(new AnimationEve
ntDelegate(element, iter->name)); | 518 OwnPtr<AnimationEventDelegate> eventDelegate = adoptPtr(new AnimationEve
ntDelegate(element, iter->name)); |
| 518 HashSet<RefPtr<Player> > players; | 519 HashSet<RefPtr<Player> > players; |
| 519 for (HashSet<RefPtr<InertAnimation> >::const_iterator animationsIter = i
ter->animations.begin(); animationsIter != iter->animations.end(); ++animationsI
ter) { | 520 for (HashSet<RefPtr<InertAnimation> >::const_iterator animationsIter = i
ter->animations.begin(); animationsIter != iter->animations.end(); ++animationsI
ter) { |
| 520 const InertAnimation* inertAnimation = animationsIter->get(); | 521 const InertAnimation* inertAnimation = animationsIter->get(); |
| 521 // The event delegate is set on the the first animation only. We | 522 // The event delegate is set on the the first animation only. We |
| 522 // rely on the behavior of OwnPtr::release() to achieve this. | 523 // rely on the behavior of OwnPtr::release() to achieve this. |
| 523 RefPtr<Animation> animation = Animation::create(element, inertAnimat
ion->effect(), inertAnimation->specified(), Animation::DefaultPriority, eventDel
egate.release()); | 524 RefPtr<Animation> animation = Animation::create(element, inertAnimat
ion->effect(), inertAnimation->specified(), Animation::DefaultPriority, eventDel
egate.release()); |
| 524 Player* player = element->document().timeline()->play(animation.get(
)); | 525 Player* player = element->document().timeline()->createPlayer(animat
ion.get()); |
| 525 player->setPaused(inertAnimation->paused()); | 526 player->setPaused(inertAnimation->paused()); |
| 527 element->document().cssPendingAnimations().add(player); |
| 526 players.add(player); | 528 players.add(player); |
| 527 } | 529 } |
| 528 m_animations.set(iter->name, players); | 530 m_animations.set(iter->name, players); |
| 529 } | 531 } |
| 530 | 532 |
| 531 for (HashSet<CSSPropertyID>::iterator iter = update->cancelledTransitions().
begin(); iter != update->cancelledTransitions().end(); ++iter) { | 533 for (HashSet<CSSPropertyID>::iterator iter = update->cancelledTransitions().
begin(); iter != update->cancelledTransitions().end(); ++iter) { |
| 532 ASSERT(m_transitions.contains(*iter)); | 534 ASSERT(m_transitions.contains(*iter)); |
| 533 m_transitions.take(*iter).transition->player()->cancel(); | 535 m_transitions.take(*iter).transition->player()->cancel(); |
| 534 } | 536 } |
| 535 | 537 |
| 536 for (size_t i = 0; i < update->newTransitions().size(); ++i) { | 538 for (size_t i = 0; i < update->newTransitions().size(); ++i) { |
| 537 const CSSAnimationUpdate::NewTransition& newTransition = update->newTran
sitions()[i]; | 539 const CSSAnimationUpdate::NewTransition& newTransition = update->newTran
sitions()[i]; |
| 538 | 540 |
| 539 RunningTransition runningTransition; | 541 RunningTransition runningTransition; |
| 540 runningTransition.from = newTransition.from; | 542 runningTransition.from = newTransition.from; |
| 541 runningTransition.to = newTransition.to; | 543 runningTransition.to = newTransition.to; |
| 542 | 544 |
| 543 CSSPropertyID id = newTransition.id; | 545 CSSPropertyID id = newTransition.id; |
| 544 InertAnimation* inertAnimation = newTransition.animation.get(); | 546 InertAnimation* inertAnimation = newTransition.animation.get(); |
| 545 OwnPtr<TransitionEventDelegate> eventDelegate = adoptPtr(new TransitionE
ventDelegate(element, id)); | 547 OwnPtr<TransitionEventDelegate> eventDelegate = adoptPtr(new TransitionE
ventDelegate(element, id)); |
| 546 RefPtr<Animation> transition = Animation::create(element, inertAnimation
->effect(), inertAnimation->specified(), Animation::TransitionPriority, eventDel
egate.release()); | 548 RefPtr<Animation> transition = Animation::create(element, inertAnimation
->effect(), inertAnimation->specified(), Animation::TransitionPriority, eventDel
egate.release()); |
| 547 element->document().transitionTimeline()->play(transition.get()); | 549 RefPtr<Player> player = element->document().transitionTimeline()->create
Player(transition.get()); |
| 550 element->document().cssPendingAnimations().add(player.get()); |
| 548 runningTransition.transition = transition.get(); | 551 runningTransition.transition = transition.get(); |
| 549 m_transitions.set(id, runningTransition); | 552 m_transitions.set(id, runningTransition); |
| 550 ASSERT(id != CSSPropertyInvalid); | 553 ASSERT(id != CSSPropertyInvalid); |
| 551 blink::Platform::current()->histogramSparse("WebCore.Animation.CSSProper
ties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(id)); | 554 blink::Platform::current()->histogramSparse("WebCore.Animation.CSSProper
ties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(id)); |
| 552 } | 555 } |
| 553 } | 556 } |
| 554 | 557 |
| 555 void CSSAnimations::calculateTransitionUpdateForProperty(CSSAnimationUpdate* upd
ate, CSSPropertyID id, const CandidateTransition& newTransition, const Transitio
nMap* existingTransitions) | 558 void CSSAnimations::calculateTransitionUpdateForProperty(CSSAnimationUpdate* upd
ate, CSSPropertyID id, const CandidateTransition& newTransition, const Transitio
nMap* existingTransitions) |
| 556 { | 559 { |
| 557 if (existingTransitions) { | 560 if (existingTransitions) { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 } | 684 } |
| 682 | 685 |
| 683 // Properties being animated by animations don't get values from transitions
applied. | 686 // Properties being animated by animations don't get values from transitions
applied. |
| 684 if (!update->compositableValuesForAnimations().isEmpty() && !compositableVal
uesForTransitions.isEmpty()) { | 687 if (!update->compositableValuesForAnimations().isEmpty() && !compositableVal
uesForTransitions.isEmpty()) { |
| 685 for (AnimationEffect::CompositableValueMap::const_iterator iter = update
->compositableValuesForAnimations().begin(); iter != update->compositableValuesF
orAnimations().end(); ++iter) | 688 for (AnimationEffect::CompositableValueMap::const_iterator iter = update
->compositableValuesForAnimations().begin(); iter != update->compositableValuesF
orAnimations().end(); ++iter) |
| 686 compositableValuesForTransitions.remove(iter->key); | 689 compositableValuesForTransitions.remove(iter->key); |
| 687 } | 690 } |
| 688 update->adoptCompositableValuesForTransitions(compositableValuesForTransitio
ns); | 691 update->adoptCompositableValuesForTransitions(compositableValuesForTransitio
ns); |
| 689 } | 692 } |
| 690 | 693 |
| 694 bool CSSAnimations::shouldCompositeForPendingAnimations(bool renderViewInComposi
tingMode) const |
| 695 { |
| 696 if (!m_pendingUpdate) |
| 697 return false; |
| 698 |
| 699 for (size_t i = 0; i < m_pendingUpdate->newAnimations().size(); ++i) { |
| 700 HashSet<RefPtr<InertAnimation> > animations = m_pendingUpdate->newAnimat
ions()[i].animations; |
| 701 for (HashSet<RefPtr<InertAnimation> >::const_iterator it = animations.be
gin(); it != animations.end(); ++it) { |
| 702 ASSERT((*it)->effect()); |
| 703 AnimationEffect* effect = (*it)->effect(); |
| 704 // FIXME: Perhaps pass a predicate function so that we can remove th
e explicit checks from this file? |
| 705 if ((effect->affects(CSSPropertyOpacity) && renderViewInCompositingM
ode) |
| 706 || effect->affects(CSSPropertyWebkitTransform) |
| 707 || effect->affects(CSSPropertyWebkitFilter)) |
| 708 return true; |
| 709 } |
| 710 } |
| 711 |
| 712 for (size_t i = 0; i < m_pendingUpdate->newTransitions().size(); ++i) { |
| 713 AnimationEffect* effect = m_pendingUpdate->newTransitions()[i].animation
->effect(); |
| 714 if ((effect->affects(CSSPropertyOpacity) && renderViewInCompositingMode) |
| 715 || effect->affects(CSSPropertyWebkitTransform) |
| 716 || effect->affects(CSSPropertyWebkitFilter)) |
| 717 return true; |
| 718 } |
| 719 |
| 720 return false; |
| 721 } |
| 722 |
| 691 void CSSAnimations::AnimationEventDelegate::maybeDispatch(Document::ListenerType
listenerType, const AtomicString& eventName, double elapsedTime) | 723 void CSSAnimations::AnimationEventDelegate::maybeDispatch(Document::ListenerType
listenerType, const AtomicString& eventName, double elapsedTime) |
| 692 { | 724 { |
| 693 if (m_target->document().hasListenerType(listenerType)) | 725 if (m_target->document().hasListenerType(listenerType)) |
| 694 m_target->document().timeline()->addEventToDispatch(m_target, WebKitAnim
ationEvent::create(eventName, m_name, elapsedTime)); | 726 m_target->document().timeline()->addEventToDispatch(m_target, WebKitAnim
ationEvent::create(eventName, m_name, elapsedTime)); |
| 695 } | 727 } |
| 696 | 728 |
| 697 void CSSAnimations::AnimationEventDelegate::onEventCondition(const TimedItem* ti
medItem, bool isFirstSample, TimedItem::Phase previousPhase, double previousIter
ation) | 729 void CSSAnimations::AnimationEventDelegate::onEventCondition(const TimedItem* ti
medItem, bool isFirstSample, TimedItem::Phase previousPhase, double previousIter
ation) |
| 698 { | 730 { |
| 699 // Events for a single document are queued and dispatched as a group at | 731 // Events for a single document are queued and dispatched as a group at |
| 700 // the end of DocumentTimeline::serviceAnimations. | 732 // the end of DocumentTimeline::serviceAnimations. |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 CSSPropertyID id = convertToCSSPropertyID(i); | 909 CSSPropertyID id = convertToCSSPropertyID(i); |
| 878 if (isAnimatableProperty(id)) | 910 if (isAnimatableProperty(id)) |
| 879 properties.append(id); | 911 properties.append(id); |
| 880 } | 912 } |
| 881 propertyShorthand = StylePropertyShorthand(CSSPropertyInvalid, propertie
s.begin(), properties.size()); | 913 propertyShorthand = StylePropertyShorthand(CSSPropertyInvalid, propertie
s.begin(), properties.size()); |
| 882 } | 914 } |
| 883 return propertyShorthand; | 915 return propertyShorthand; |
| 884 } | 916 } |
| 885 | 917 |
| 886 } // namespace WebCore | 918 } // namespace WebCore |
| OLD | NEW |