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

Side by Side Diff: Source/core/animation/Animation.cpp

Issue 1162253005: Animations: Add the effect clipping primitive to web animations (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/animation/Animation.h ('k') | Source/core/animation/Animation.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 return animation.release(); 76 return animation.release();
77 } 77 }
78 78
79 Animation::Animation(ExecutionContext* executionContext, AnimationTimeline& time line, AnimationEffect* content) 79 Animation::Animation(ExecutionContext* executionContext, AnimationTimeline& time line, AnimationEffect* content)
80 : ActiveDOMObject(executionContext) 80 : ActiveDOMObject(executionContext)
81 , m_playState(Idle) 81 , m_playState(Idle)
82 , m_playbackRate(1) 82 , m_playbackRate(1)
83 , m_startTime(nullValue()) 83 , m_startTime(nullValue())
84 , m_holdTime(0) 84 , m_holdTime(0)
85 , m_startClip(-std::numeric_limits<double>::infinity())
86 , m_endClip(std::numeric_limits<double>::infinity())
85 , m_sequenceNumber(nextSequenceNumber()) 87 , m_sequenceNumber(nextSequenceNumber())
86 , m_content(content) 88 , m_content(content)
87 , m_timeline(&timeline) 89 , m_timeline(&timeline)
88 , m_paused(false) 90 , m_paused(false)
89 , m_held(true) 91 , m_held(true)
90 , m_isPausedForTesting(false) 92 , m_isPausedForTesting(false)
91 , m_outdated(false) 93 , m_outdated(false)
92 , m_finished(true) 94 , m_finished(true)
93 , m_compositorState(nullptr) 95 , m_compositorState(nullptr)
94 , m_compositorPending(false) 96 , m_compositorPending(false)
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 433
432 if (previousCurrentTime != newCurrentTime) { 434 if (previousCurrentTime != newCurrentTime) {
433 setOutdated(); 435 setOutdated();
434 } else if (!hadStartTime && m_timeline) { 436 } else if (!hadStartTime && m_timeline) {
435 // Even though this animation is not outdated, time to effect change is 437 // Even though this animation is not outdated, time to effect change is
436 // infinity until start time is set. 438 // infinity until start time is set.
437 m_timeline->wake(); 439 m_timeline->wake();
438 } 440 }
439 } 441 }
440 442
443 bool Animation::clipped(double time)
444 {
445 ASSERT(!isNull(time));
446 return time <= m_startClip || time > m_endClip + sourceEnd();
447 }
448
441 void Animation::setSource(AnimationEffect* newSource) 449 void Animation::setSource(AnimationEffect* newSource)
442 { 450 {
443 if (m_content == newSource) 451 if (m_content == newSource)
444 return; 452 return;
445 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand, SetCompositorP endingWithSourceChanged); 453 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand, SetCompositorP endingWithSourceChanged);
446 454
447 double storedCurrentTime = currentTimeInternal(); 455 double storedCurrentTime = currentTimeInternal();
448 if (m_content) 456 if (m_content)
449 m_content->detach(); 457 m_content->detach();
450 m_content = newSource; 458 m_content = newSource;
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 { 784 {
777 if (!m_timeline) 785 if (!m_timeline)
778 return false; 786 return false;
779 787
780 PlayStateUpdateScope updateScope(*this, reason, DoNotSetCompositorPending); 788 PlayStateUpdateScope updateScope(*this, reason, DoNotSetCompositorPending);
781 789
782 m_outdated = false; 790 m_outdated = false;
783 bool idle = playStateInternal() == Idle; 791 bool idle = playStateInternal() == Idle;
784 792
785 if (m_content) { 793 if (m_content) {
786 double inheritedTime = idle || isNull(m_timeline->currentTimeInternal()) ? nullValue() : currentTimeInternal(); 794 double inheritedTime = idle || isNull(m_timeline->currentTimeInternal())
795 ? nullValue()
796 : currentTimeInternal();
797
798 if (!isNull(inheritedTime)) {
799 double timeForClipping = m_held && (!limited(inheritedTime) || isNul l(m_startTime))
800 // Use hold time when there is no start time.
801 ? inheritedTime
802 // Use calculated current time when the animation is limited.
803 : calculateCurrentTime();
804 if (clipped(timeForClipping))
805 inheritedTime = nullValue();
806 }
787 // Special case for end-exclusivity when playing backwards. 807 // Special case for end-exclusivity when playing backwards.
788 if (inheritedTime == 0 && m_playbackRate < 0) 808 if (inheritedTime == 0 && m_playbackRate < 0)
789 inheritedTime = -1; 809 inheritedTime = -1;
790 m_content->updateInheritedTime(inheritedTime, reason); 810 m_content->updateInheritedTime(inheritedTime, reason);
791 } 811 }
792 812
793 if ((idle || limited()) && !m_finished) { 813 if ((idle || limited()) && !m_finished) {
794 if (reason == TimingUpdateForAnimationFrame && (idle || hasStartTime())) { 814 if (reason == TimingUpdateForAnimationFrame && (idle || hasStartTime())) {
795 const AtomicString& eventType = EventTypeNames::finish; 815 const AtomicString& eventType = EventTypeNames::finish;
796 if (executionContext() && hasEventListeners(eventType)) { 816 if (executionContext() && hasEventListeners(eventType)) {
797 double eventCurrentTime = currentTimeInternal() * 1000; 817 double eventCurrentTime = currentTimeInternal() * 1000;
798 m_pendingFinishedEvent = AnimationPlayerEvent::create(eventType, eventCurrentTime, timeline()->currentTime()); 818 m_pendingFinishedEvent = AnimationPlayerEvent::create(eventType, eventCurrentTime, timeline()->currentTime());
799 m_pendingFinishedEvent->setTarget(this); 819 m_pendingFinishedEvent->setTarget(this);
800 m_pendingFinishedEvent->setCurrentTarget(this); 820 m_pendingFinishedEvent->setCurrentTarget(this);
801 m_timeline->document()->enqueueAnimationFrameEvent(m_pendingFini shedEvent); 821 m_timeline->document()->enqueueAnimationFrameEvent(m_pendingFini shedEvent);
802 } 822 }
803 m_finished = true; 823 m_finished = true;
804 } 824 }
805 } 825 }
806 ASSERT(!m_outdated); 826 ASSERT(!m_outdated);
807 return !m_finished; 827 return !m_finished || std::isfinite(timeToEffectChange());
808 } 828 }
809 829
810 double Animation::timeToEffectChange() 830 double Animation::timeToEffectChange()
811 { 831 {
812 ASSERT(!m_outdated); 832 ASSERT(!m_outdated);
813 if (m_held || !hasStartTime()) 833 if (!hasStartTime())
814 return std::numeric_limits<double>::infinity(); 834 return std::numeric_limits<double>::infinity();
835
836 double currentTime = calculateCurrentTime();
837 if (m_held) {
838 if (limited(currentTime)) {
839 if (m_playbackRate > 0 && m_endClip + sourceEnd() > currentTime)
840 return m_endClip + sourceEnd() - currentTime;
841 if (m_playbackRate < 0 && m_startClip <= currentTime)
842 return m_startClip - currentTime;
843 }
844 return std::numeric_limits<double>::infinity();
845 }
846
815 if (!m_content) 847 if (!m_content)
816 return -currentTimeInternal() / m_playbackRate; 848 return -currentTimeInternal() / m_playbackRate;
817 double result = m_playbackRate > 0 849 double result = m_playbackRate > 0
818 ? m_content->timeToForwardsEffectChange() / m_playbackRate 850 ? m_content->timeToForwardsEffectChange() / m_playbackRate
819 : m_content->timeToReverseEffectChange() / -m_playbackRate; 851 : m_content->timeToReverseEffectChange() / -m_playbackRate;
852
820 return !hasActiveAnimationsOnCompositor() && m_content->phase() == Animation Effect::PhaseActive 853 return !hasActiveAnimationsOnCompositor() && m_content->phase() == Animation Effect::PhaseActive
821 ? 0 854 ? 0
822 : result; 855 : clipTimeToEffectChange(result);
856 }
857
858 double Animation::clipTimeToEffectChange(double result) const
859 {
860 double currentTime = calculateCurrentTime();
861 if (m_playbackRate > 0) {
862 if (currentTime <= m_startClip)
863 result = std::min(result, (m_startClip - currentTime) / m_playbackRa te);
864 else if (currentTime < m_endClip + sourceEnd())
865 result = std::min(result, (m_endClip + sourceEnd() - currentTime) / m_playbackRate);
866 } else {
867 if (currentTime >= m_endClip + sourceEnd())
868 result = std::min(result, (currentTime - m_endClip + sourceEnd()) / -m_playbackRate);
869 else if (currentTime > m_startClip)
870 result = std::min(result, (currentTime - m_startClip) / -m_playbackR ate);
871 }
872 return result;
823 } 873 }
824 874
825 void Animation::cancel() 875 void Animation::cancel()
826 { 876 {
827 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand); 877 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand);
828 878
829 if (playStateInternal() == Idle) 879 if (playStateInternal() == Idle)
830 return; 880 return;
831 881
832 m_holdTime = currentTimeInternal(); 882 m_holdTime = currentTimeInternal();
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 visitor->trace(m_content); 1074 visitor->trace(m_content);
1025 visitor->trace(m_timeline); 1075 visitor->trace(m_timeline);
1026 visitor->trace(m_pendingFinishedEvent); 1076 visitor->trace(m_pendingFinishedEvent);
1027 visitor->trace(m_finishedPromise); 1077 visitor->trace(m_finishedPromise);
1028 visitor->trace(m_readyPromise); 1078 visitor->trace(m_readyPromise);
1029 EventTargetWithInlineData::trace(visitor); 1079 EventTargetWithInlineData::trace(visitor);
1030 ActiveDOMObject::trace(visitor); 1080 ActiveDOMObject::trace(visitor);
1031 } 1081 }
1032 1082
1033 } // namespace 1083 } // namespace
OLDNEW
« no previous file with comments | « Source/core/animation/Animation.h ('k') | Source/core/animation/Animation.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698