OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/scroll/ProgrammaticScrollAnimator.h" | 5 #include "platform/scroll/ProgrammaticScrollAnimator.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include "platform/animation/CompositorAnimation.h" | 8 #include "platform/animation/CompositorAnimation.h" |
9 #include "platform/animation/CompositorScrollOffsetAnimationCurve.h" | 9 #include "platform/animation/CompositorScrollOffsetAnimationCurve.h" |
10 #include "platform/geometry/IntSize.h" | 10 #include "platform/geometry/IntSize.h" |
11 #include "platform/graphics/GraphicsLayer.h" | 11 #include "platform/graphics/GraphicsLayer.h" |
12 #include "platform/scroll/ScrollableArea.h" | 12 #include "platform/scroll/ScrollableArea.h" |
13 #include "platform/scroll/SmoothScrollSequencer.h" | |
13 #include "platform/wtf/PtrUtil.h" | 14 #include "platform/wtf/PtrUtil.h" |
14 #include "public/platform/Platform.h" | 15 #include "public/platform/Platform.h" |
15 #include "public/platform/WebCompositorSupport.h" | 16 #include "public/platform/WebCompositorSupport.h" |
16 | 17 |
17 namespace blink { | 18 namespace blink { |
18 | 19 |
19 ProgrammaticScrollAnimator::ProgrammaticScrollAnimator( | 20 ProgrammaticScrollAnimator::ProgrammaticScrollAnimator( |
20 ScrollableArea* scrollableArea) | 21 ScrollableArea* scrollableArea) |
21 : m_scrollableArea(scrollableArea), m_startTime(0.0) {} | 22 : m_scrollableArea(scrollableArea), m_startTime(0.0) {} |
22 | 23 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 if (!m_startTime) | 70 if (!m_startTime) |
70 m_startTime = monotonicTime; | 71 m_startTime = monotonicTime; |
71 double elapsedTime = monotonicTime - m_startTime; | 72 double elapsedTime = monotonicTime - m_startTime; |
72 bool isFinished = (elapsedTime > m_animationCurve->duration()); | 73 bool isFinished = (elapsedTime > m_animationCurve->duration()); |
73 ScrollOffset offset = | 74 ScrollOffset offset = |
74 blinkOffsetFromCompositorOffset(m_animationCurve->getValue(elapsedTime)); | 75 blinkOffsetFromCompositorOffset(m_animationCurve->getValue(elapsedTime)); |
75 notifyOffsetChanged(offset); | 76 notifyOffsetChanged(offset); |
76 | 77 |
77 if (isFinished) { | 78 if (isFinished) { |
78 m_runState = RunState::PostAnimationCleanup; | 79 m_runState = RunState::PostAnimationCleanup; |
80 getScrollableArea()->getSmoothScrollSequencer()->notifyAnimationFinished(); | |
bokan
2017/04/07 15:56:52
What other programmatic animations is this class h
sunyunjia
2017/05/12 18:40:25
Done.
| |
79 } else if (!m_scrollableArea->scheduleAnimation()) { | 81 } else if (!m_scrollableArea->scheduleAnimation()) { |
80 notifyOffsetChanged(offset); | 82 notifyOffsetChanged(offset); |
81 resetAnimationState(); | 83 resetAnimationState(); |
82 } | 84 } |
83 } | 85 } |
84 | 86 |
85 void ProgrammaticScrollAnimator::updateCompositorAnimations() { | 87 void ProgrammaticScrollAnimator::updateCompositorAnimations() { |
86 if (m_runState == RunState::PostAnimationCleanup) { | 88 if (m_runState == RunState::PostAnimationCleanup) { |
87 // No special cleanup, simply reset animation state. We have this state | 89 // No special cleanup, simply reset animation state. We have this state |
88 // here because the state machine is shared with ScrollAnimator which | 90 // here because the state machine is shared with ScrollAnimator which |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 resetAnimationState(); | 163 resetAnimationState(); |
162 notifyOffsetChanged(m_targetOffset); | 164 notifyOffsetChanged(m_targetOffset); |
163 } | 165 } |
164 } | 166 } |
165 } | 167 } |
166 | 168 |
167 void ProgrammaticScrollAnimator::notifyCompositorAnimationFinished( | 169 void ProgrammaticScrollAnimator::notifyCompositorAnimationFinished( |
168 int groupId) { | 170 int groupId) { |
169 ASSERT(m_runState != RunState::RunningOnCompositorButNeedsUpdate); | 171 ASSERT(m_runState != RunState::RunningOnCompositorButNeedsUpdate); |
170 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); | 172 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); |
173 getScrollableArea()->getSmoothScrollSequencer()->notifyAnimationFinished(); | |
171 } | 174 } |
172 | 175 |
173 DEFINE_TRACE(ProgrammaticScrollAnimator) { | 176 DEFINE_TRACE(ProgrammaticScrollAnimator) { |
174 visitor->trace(m_scrollableArea); | 177 visitor->trace(m_scrollableArea); |
175 ScrollAnimatorCompositorCoordinator::trace(visitor); | 178 ScrollAnimatorCompositorCoordinator::trace(visitor); |
176 } | 179 } |
177 | 180 |
178 } // namespace blink | 181 } // namespace blink |
OLD | NEW |