| 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/events/ThreadLocalEventNames.h" | 43 #include "core/events/ThreadLocalEventNames.h" |
| 43 #include "core/events/TransitionEvent.h" | 44 #include "core/events/TransitionEvent.h" |
| 44 #include "core/events/WebKitAnimationEvent.h" | 45 #include "core/events/WebKitAnimationEvent.h" |
| 45 #include "core/frame/UseCounter.h" | 46 #include "core/frame/UseCounter.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 63 RefPtr<AnimatableValue> from; | 64 RefPtr<AnimatableValue> from; |
| 64 RefPtr<AnimatableValue> to; | 65 RefPtr<AnimatableValue> to; |
| 65 const CSSAnimationData* anim; | 66 const CSSAnimationData* anim; |
| 66 }; | 67 }; |
| 67 typedef HashMap<CSSPropertyID, CandidateTransition> CandidateTransitionMap; | 68 typedef HashMap<CSSPropertyID, CandidateTransition> CandidateTransitionMap; |
| 68 | 69 |
| 69 namespace { | 70 namespace { |
| 70 | 71 |
| 71 bool isEarlierPhase(TimedItem::Phase target, TimedItem::Phase reference) | 72 bool isEarlierPhase(TimedItem::Phase target, TimedItem::Phase reference) |
| 72 { | 73 { |
| 73 ASSERT(target != TimedItem::PhaseNone); | 74 // FIXME! |
| 74 ASSERT(reference != TimedItem::PhaseNone); | 75 // ASSERT(target != TimedItem::PhaseNone); |
| 76 // ASSERT(reference != TimedItem::PhaseNone); |
| 75 return target < reference; | 77 return target < reference; |
| 76 } | 78 } |
| 77 | 79 |
| 78 bool isLaterPhase(TimedItem::Phase target, TimedItem::Phase reference) | 80 bool isLaterPhase(TimedItem::Phase target, TimedItem::Phase reference) |
| 79 { | 81 { |
| 80 ASSERT(target != TimedItem::PhaseNone); | 82 // FIXME! |
| 81 ASSERT(reference != TimedItem::PhaseNone); | 83 // ASSERT(target != TimedItem::PhaseNone); |
| 84 // ASSERT(reference != TimedItem::PhaseNone); |
| 82 return target > reference; | 85 return target > reference; |
| 83 } | 86 } |
| 84 | 87 |
| 85 static PassRefPtr<TimingFunction> generateTimingFunction(const KeyframeAnimation
Effect::KeyframeVector keyframes, const HashMap<double, RefPtr<TimingFunction> >
perKeyframeTimingFunctions) | 88 static PassRefPtr<TimingFunction> generateTimingFunction(const KeyframeAnimation
Effect::KeyframeVector keyframes, const HashMap<double, RefPtr<TimingFunction> >
perKeyframeTimingFunctions) |
| 86 { | 89 { |
| 87 // Generate the chained timing function. Note that timing functions apply | 90 // Generate the chained timing function. Note that timing functions apply |
| 88 // from the keyframe in which they're specified to the next keyframe. | 91 // from the keyframe in which they're specified to the next keyframe. |
| 89 bool isTimingFunctionLinearThroughout = true; | 92 bool isTimingFunctionLinearThroughout = true; |
| 90 RefPtr<ChainedTimingFunction> chainedTimingFunction = ChainedTimingFunction:
:create(); | 93 RefPtr<ChainedTimingFunction> chainedTimingFunction = ChainedTimingFunction:
:create(); |
| 91 for (size_t i = 0; i < keyframes.size() - 1; ++i) { | 94 for (size_t i = 0; i < keyframes.size() - 1; ++i) { |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 } | 515 } |
| 513 | 516 |
| 514 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) { |
| 515 OwnPtr<AnimationEventDelegate> eventDelegate = adoptPtr(new AnimationEve
ntDelegate(element, iter->name)); | 518 OwnPtr<AnimationEventDelegate> eventDelegate = adoptPtr(new AnimationEve
ntDelegate(element, iter->name)); |
| 516 HashSet<RefPtr<Player> > players; | 519 HashSet<RefPtr<Player> > players; |
| 517 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) { |
| 518 const InertAnimation* inertAnimation = animationsIter->get(); | 521 const InertAnimation* inertAnimation = animationsIter->get(); |
| 519 // 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 |
| 520 // rely on the behavior of OwnPtr::release() to achieve this. | 523 // rely on the behavior of OwnPtr::release() to achieve this. |
| 521 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()); |
| 522 RefPtr<Player> player = element->document().timeline()->play(animati
on.get()); | 525 RefPtr<Player> player = element->document().timeline()->createPlayer
(animation.get()); |
| 523 player->setPaused(inertAnimation->paused()); | 526 player->setPaused(inertAnimation->paused()); |
| 527 element->document().cssPendingAnimations().add(player.get()); |
| 524 players.add(player.release()); | 528 players.add(player.release()); |
| 525 } | 529 } |
| 526 m_animations.set(iter->name, players); | 530 m_animations.set(iter->name, players); |
| 527 } | 531 } |
| 528 | 532 |
| 529 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) { |
| 530 ASSERT(m_transitions.contains(*iter)); | 534 ASSERT(m_transitions.contains(*iter)); |
| 531 m_transitions.take(*iter).transition->player()->cancel(); | 535 m_transitions.take(*iter).transition->player()->cancel(); |
| 532 } | 536 } |
| 533 | 537 |
| 534 for (size_t i = 0; i < update->newTransitions().size(); ++i) { | 538 for (size_t i = 0; i < update->newTransitions().size(); ++i) { |
| 535 const CSSAnimationUpdate::NewTransition& newTransition = update->newTran
sitions()[i]; | 539 const CSSAnimationUpdate::NewTransition& newTransition = update->newTran
sitions()[i]; |
| 536 | 540 |
| 537 RunningTransition runningTransition; | 541 RunningTransition runningTransition; |
| 538 runningTransition.from = newTransition.from; | 542 runningTransition.from = newTransition.from; |
| 539 runningTransition.to = newTransition.to; | 543 runningTransition.to = newTransition.to; |
| 540 | 544 |
| 541 CSSPropertyID id = newTransition.id; | 545 CSSPropertyID id = newTransition.id; |
| 542 InertAnimation* inertAnimation = newTransition.animation.get(); | 546 InertAnimation* inertAnimation = newTransition.animation.get(); |
| 543 OwnPtr<TransitionEventDelegate> eventDelegate = adoptPtr(new TransitionE
ventDelegate(element, id)); | 547 OwnPtr<TransitionEventDelegate> eventDelegate = adoptPtr(new TransitionE
ventDelegate(element, id)); |
| 544 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()); |
| 545 element->document().transitionTimeline()->play(transition.get()); | 549 RefPtr<Player> player = element->document().transitionTimeline()->create
Player(transition.get()); |
| 550 element->document().cssPendingAnimations().add(player.get()); |
| 546 runningTransition.transition = transition.get(); | 551 runningTransition.transition = transition.get(); |
| 547 m_transitions.set(id, runningTransition); | 552 m_transitions.set(id, runningTransition); |
| 548 ASSERT(id != CSSPropertyInvalid); | 553 ASSERT(id != CSSPropertyInvalid); |
| 549 blink::Platform::current()->histogramSparse("WebCore.Animation.CSSProper
ties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(id)); | 554 blink::Platform::current()->histogramSparse("WebCore.Animation.CSSProper
ties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(id)); |
| 550 } | 555 } |
| 551 } | 556 } |
| 552 | 557 |
| 553 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) |
| 554 { | 559 { |
| 555 if (existingTransitions) { | 560 if (existingTransitions) { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 } | 684 } |
| 680 | 685 |
| 681 // 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. |
| 682 if (!update->compositableValuesForAnimations().isEmpty() && !compositableVal
uesForTransitions.isEmpty()) { | 687 if (!update->compositableValuesForAnimations().isEmpty() && !compositableVal
uesForTransitions.isEmpty()) { |
| 683 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) |
| 684 compositableValuesForTransitions.remove(iter->key); | 689 compositableValuesForTransitions.remove(iter->key); |
| 685 } | 690 } |
| 686 update->adoptCompositableValuesForTransitions(compositableValuesForTransitio
ns); | 691 update->adoptCompositableValuesForTransitions(compositableValuesForTransitio
ns); |
| 687 } | 692 } |
| 688 | 693 |
| 694 bool CSSAnimations::hasPendingCandidateForCompositorAnimation() 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 if (CompositorAnimations::instance()->isCandidateForCompositorAnimat
ion((*it)->specified(), *(*it)->effect())) |
| 704 return true; |
| 705 } |
| 706 } |
| 707 |
| 708 for (size_t i = 0; i < m_pendingUpdate->newTransitions().size(); ++i) { |
| 709 const InertAnimation* animation = m_pendingUpdate->newTransitions()[i].a
nimation.get(); |
| 710 ASSERT(animation->effect()); |
| 711 if (CompositorAnimations::instance()->isCandidateForCompositorAnimation(
animation->specified(), *animation->effect())) |
| 712 return true; |
| 713 } |
| 714 |
| 715 return false; |
| 716 } |
| 717 |
| 689 void CSSAnimations::AnimationEventDelegate::maybeDispatch(Document::ListenerType
listenerType, const AtomicString& eventName, double elapsedTime) | 718 void CSSAnimations::AnimationEventDelegate::maybeDispatch(Document::ListenerType
listenerType, const AtomicString& eventName, double elapsedTime) |
| 690 { | 719 { |
| 691 if (m_target->document().hasListenerType(listenerType)) | 720 if (m_target->document().hasListenerType(listenerType)) |
| 692 m_target->document().timeline()->addEventToDispatch(m_target, WebKitAnim
ationEvent::create(eventName, m_name, elapsedTime)); | 721 m_target->document().timeline()->addEventToDispatch(m_target, WebKitAnim
ationEvent::create(eventName, m_name, elapsedTime)); |
| 693 } | 722 } |
| 694 | 723 |
| 695 void CSSAnimations::AnimationEventDelegate::onEventCondition(const TimedItem* ti
medItem, bool isFirstSample, TimedItem::Phase previousPhase, double previousIter
ation) | 724 void CSSAnimations::AnimationEventDelegate::onEventCondition(const TimedItem* ti
medItem, bool isFirstSample, TimedItem::Phase previousPhase, double previousIter
ation) |
| 696 { | 725 { |
| 697 // Events for a single document are queued and dispatched as a group at | 726 // Events for a single document are queued and dispatched as a group at |
| 698 // the end of DocumentTimeline::serviceAnimations. | 727 // the end of DocumentTimeline::serviceAnimations. |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 CSSPropertyID id = convertToCSSPropertyID(i); | 904 CSSPropertyID id = convertToCSSPropertyID(i); |
| 876 if (isAnimatableProperty(id)) | 905 if (isAnimatableProperty(id)) |
| 877 properties.append(id); | 906 properties.append(id); |
| 878 } | 907 } |
| 879 propertyShorthand = StylePropertyShorthand(CSSPropertyInvalid, propertie
s.begin(), properties.size()); | 908 propertyShorthand = StylePropertyShorthand(CSSPropertyInvalid, propertie
s.begin(), properties.size()); |
| 880 } | 909 } |
| 881 return propertyShorthand; | 910 return propertyShorthand; |
| 882 } | 911 } |
| 883 | 912 |
| 884 } // namespace WebCore | 913 } // namespace WebCore |
| OLD | NEW |