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* scrollable_area) | 21 ScrollableArea* scrollable_area) |
21 : scrollable_area_(scrollable_area), start_time_(0.0) {} | 22 : scrollable_area_(scrollable_area), start_time_(0.0) {} |
22 | 23 |
23 ProgrammaticScrollAnimator::~ProgrammaticScrollAnimator() {} | 24 ProgrammaticScrollAnimator::~ProgrammaticScrollAnimator() {} |
24 | 25 |
25 void ProgrammaticScrollAnimator::ResetAnimationState() { | 26 void ProgrammaticScrollAnimator::ResetAnimationState() { |
26 ScrollAnimatorCompositorCoordinator::ResetAnimationState(); | 27 ScrollAnimatorCompositorCoordinator::ResetAnimationState(); |
27 animation_curve_.reset(); | 28 animation_curve_.reset(); |
28 start_time_ = 0.0; | 29 start_time_ = 0.0; |
29 } | 30 } |
30 | 31 |
31 void ProgrammaticScrollAnimator::NotifyOffsetChanged( | 32 void ProgrammaticScrollAnimator::NotifyOffsetChanged( |
32 const ScrollOffset& offset) { | 33 const ScrollOffset& offset) { |
33 ScrollOffsetChanged(offset, kProgrammaticScroll); | 34 ScrollOffsetChanged(offset, kProgrammaticScroll); |
34 } | 35 } |
35 | 36 |
36 void ProgrammaticScrollAnimator::ScrollToOffsetWithoutAnimation( | 37 void ProgrammaticScrollAnimator::ScrollToOffsetWithoutAnimation( |
37 const ScrollOffset& offset) { | 38 const ScrollOffset& offset) { |
38 CancelAnimation(); | 39 CancelAnimation(); |
39 NotifyOffsetChanged(offset); | 40 NotifyOffsetChanged(offset); |
40 } | 41 } |
41 | 42 |
42 void ProgrammaticScrollAnimator::AnimateToOffset(const ScrollOffset& offset) { | 43 void ProgrammaticScrollAnimator::AnimateToOffset( |
| 44 const ScrollOffset& offset, |
| 45 bool sequenced_for_smooth_scroll) { |
43 if (run_state_ == RunState::kPostAnimationCleanup) | 46 if (run_state_ == RunState::kPostAnimationCleanup) |
44 ResetAnimationState(); | 47 ResetAnimationState(); |
45 | 48 |
46 start_time_ = 0.0; | 49 start_time_ = 0.0; |
47 target_offset_ = offset; | 50 target_offset_ = offset; |
| 51 sequenced_for_smooth_scroll_ = sequenced_for_smooth_scroll; |
48 animation_curve_ = CompositorScrollOffsetAnimationCurve::Create( | 52 animation_curve_ = CompositorScrollOffsetAnimationCurve::Create( |
49 CompositorOffsetFromBlinkOffset(target_offset_), | 53 CompositorOffsetFromBlinkOffset(target_offset_), |
50 CompositorScrollOffsetAnimationCurve::kScrollDurationDeltaBased); | 54 CompositorScrollOffsetAnimationCurve::kScrollDurationDeltaBased); |
51 | 55 |
52 scrollable_area_->RegisterForAnimation(); | 56 scrollable_area_->RegisterForAnimation(); |
53 if (!scrollable_area_->ScheduleAnimation()) { | 57 if (!scrollable_area_->ScheduleAnimation()) { |
54 ResetAnimationState(); | 58 ResetAnimationState(); |
55 NotifyOffsetChanged(offset); | 59 NotifyOffsetChanged(offset); |
56 } | 60 } |
57 run_state_ = RunState::kWaitingToSendToCompositor; | 61 run_state_ = RunState::kWaitingToSendToCompositor; |
(...skipping 11 matching lines...) Expand all Loading... |
69 if (!start_time_) | 73 if (!start_time_) |
70 start_time_ = monotonic_time; | 74 start_time_ = monotonic_time; |
71 double elapsed_time = monotonic_time - start_time_; | 75 double elapsed_time = monotonic_time - start_time_; |
72 bool is_finished = (elapsed_time > animation_curve_->Duration()); | 76 bool is_finished = (elapsed_time > animation_curve_->Duration()); |
73 ScrollOffset offset = | 77 ScrollOffset offset = |
74 BlinkOffsetFromCompositorOffset(animation_curve_->GetValue(elapsed_time)); | 78 BlinkOffsetFromCompositorOffset(animation_curve_->GetValue(elapsed_time)); |
75 NotifyOffsetChanged(offset); | 79 NotifyOffsetChanged(offset); |
76 | 80 |
77 if (is_finished) { | 81 if (is_finished) { |
78 run_state_ = RunState::kPostAnimationCleanup; | 82 run_state_ = RunState::kPostAnimationCleanup; |
| 83 if (sequenced_for_smooth_scroll_) { |
| 84 sequenced_for_smooth_scroll_ = false; |
| 85 GetScrollableArea()->GetSmoothScrollSequencer()->RunQueuedAnimations(); |
| 86 } |
79 } else if (!scrollable_area_->ScheduleAnimation()) { | 87 } else if (!scrollable_area_->ScheduleAnimation()) { |
80 NotifyOffsetChanged(offset); | 88 NotifyOffsetChanged(offset); |
81 ResetAnimationState(); | 89 ResetAnimationState(); |
82 } | 90 } |
83 } | 91 } |
84 | 92 |
85 void ProgrammaticScrollAnimator::UpdateCompositorAnimations() { | 93 void ProgrammaticScrollAnimator::UpdateCompositorAnimations() { |
86 if (run_state_ == RunState::kPostAnimationCleanup) { | 94 if (run_state_ == RunState::kPostAnimationCleanup) { |
87 // No special cleanup, simply reset animation state. We have this state | 95 // No special cleanup, simply reset animation state. We have this state |
88 // here because the state machine is shared with ScrollAnimator which | 96 // here because the state machine is shared with ScrollAnimator which |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 ResetAnimationState(); | 170 ResetAnimationState(); |
163 NotifyOffsetChanged(target_offset_); | 171 NotifyOffsetChanged(target_offset_); |
164 } | 172 } |
165 } | 173 } |
166 } | 174 } |
167 | 175 |
168 void ProgrammaticScrollAnimator::NotifyCompositorAnimationFinished( | 176 void ProgrammaticScrollAnimator::NotifyCompositorAnimationFinished( |
169 int group_id) { | 177 int group_id) { |
170 DCHECK_NE(run_state_, RunState::kRunningOnCompositorButNeedsUpdate); | 178 DCHECK_NE(run_state_, RunState::kRunningOnCompositorButNeedsUpdate); |
171 ScrollAnimatorCompositorCoordinator::CompositorAnimationFinished(group_id); | 179 ScrollAnimatorCompositorCoordinator::CompositorAnimationFinished(group_id); |
| 180 if (sequenced_for_smooth_scroll_) { |
| 181 sequenced_for_smooth_scroll_ = false; |
| 182 GetScrollableArea()->GetSmoothScrollSequencer()->RunQueuedAnimations(); |
| 183 } |
| 184 } |
| 185 |
| 186 void ProgrammaticScrollAnimator::AnimationFinished() { |
| 187 if (sequenced_for_smooth_scroll_) { |
| 188 sequenced_for_smooth_scroll_ = false; |
| 189 if (SmoothScrollSequencer* sequencer = |
| 190 GetScrollableArea()->GetSmoothScrollSequencer()) |
| 191 sequencer->RunQueuedAnimations(); |
| 192 } |
172 } | 193 } |
173 | 194 |
174 DEFINE_TRACE(ProgrammaticScrollAnimator) { | 195 DEFINE_TRACE(ProgrammaticScrollAnimator) { |
175 visitor->Trace(scrollable_area_); | 196 visitor->Trace(scrollable_area_); |
176 ScrollAnimatorCompositorCoordinator::Trace(visitor); | 197 ScrollAnimatorCompositorCoordinator::Trace(visitor); |
177 } | 198 } |
178 | 199 |
179 } // namespace blink | 200 } // namespace blink |
OLD | NEW |