Chromium Code Reviews| 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 "cc/input/scrollbar_animation_controller.h" | 5 #include "cc/input/scrollbar_animation_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "cc/trees/layer_tree_impl.h" | 10 #include "cc/trees/layer_tree_impl.h" |
| 11 | 11 |
| 12 namespace cc { | 12 namespace cc { |
| 13 | 13 |
| 14 ScrollbarAnimationController::ScrollbarAnimationController( | 14 ScrollbarAnimationController::ScrollbarAnimationController( |
| 15 int scroll_layer_id, | 15 int scroll_layer_id, |
| 16 ScrollbarAnimationControllerClient* client, | 16 ScrollbarAnimationControllerClient* client, |
| 17 base::TimeDelta delay_before_starting, | 17 base::TimeDelta delay_before_starting, |
| 18 base::TimeDelta resize_delay_before_starting, | 18 base::TimeDelta resize_delay_before_starting, |
| 19 base::TimeDelta duration) | 19 base::TimeDelta duration) |
| 20 : client_(client), | 20 : client_(client), |
| 21 duration_(duration), | |
| 21 delay_before_starting_(delay_before_starting), | 22 delay_before_starting_(delay_before_starting), |
| 22 resize_delay_before_starting_(resize_delay_before_starting), | 23 resize_delay_before_starting_(resize_delay_before_starting), |
| 23 duration_(duration), | |
| 24 is_animating_(false), | 24 is_animating_(false), |
| 25 scroll_layer_id_(scroll_layer_id), | 25 scroll_layer_id_(scroll_layer_id), |
| 26 currently_scrolling_(false), | 26 currently_scrolling_(false), |
| 27 scroll_gesture_has_scrolled_(false), | 27 scroll_gesture_has_scrolled_(false), |
| 28 weak_factory_(this) {} | 28 weak_factory_(this) {} |
| 29 | 29 |
| 30 ScrollbarAnimationController::~ScrollbarAnimationController() {} | 30 ScrollbarAnimationController::~ScrollbarAnimationController() {} |
| 31 | 31 |
| 32 bool ScrollbarAnimationController::Animate(base::TimeTicks now) { | 32 bool ScrollbarAnimationController::Animate(base::TimeTicks now) { |
| 33 if (!is_animating_) | 33 if (!is_animating_) |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 50 float progress = delta.InSecondsF() / duration_.InSecondsF(); | 50 float progress = delta.InSecondsF() / duration_.InSecondsF(); |
| 51 return std::max(std::min(progress, 1.f), 0.f); | 51 return std::max(std::min(progress, 1.f), 0.f); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void ScrollbarAnimationController::DidScrollBegin() { | 54 void ScrollbarAnimationController::DidScrollBegin() { |
| 55 currently_scrolling_ = true; | 55 currently_scrolling_ = true; |
| 56 } | 56 } |
| 57 | 57 |
| 58 void ScrollbarAnimationController::DidScrollUpdate(bool on_resize) { | 58 void ScrollbarAnimationController::DidScrollUpdate(bool on_resize) { |
| 59 StopAnimation(); | 59 StopAnimation(); |
| 60 delayed_scrollbar_fade_.Cancel(); | |
| 61 | 60 |
| 62 // As an optimization, we avoid spamming fade delay tasks during active fast | 61 // As an optimization, we avoid spamming fade delay tasks during active fast |
| 63 // scrolls. But if we're not within one, we need to post every scroll update. | 62 // scrolls. But if we're not within one, we need to post every scroll update. |
| 63 // TODO(bokan): When do we get ScrollUpdates without a ScrollBegin? This may | |
|
aelias_OOO_until_Jul13
2016/10/20 23:40:51
Any kind of main-thread scroll (JS, history or ges
bokan
2016/10/21 00:32:30
Got it, thanks. Removed TODO and added a test.
| |
| 64 // be unsupported behavior at this point. | |
| 64 if (!currently_scrolling_) | 65 if (!currently_scrolling_) |
| 65 PostDelayedAnimationTask(on_resize); | 66 PostDelayedAnimationTask(on_resize); |
| 66 else | 67 else |
| 67 scroll_gesture_has_scrolled_ = true; | 68 scroll_gesture_has_scrolled_ = true; |
| 68 } | 69 } |
| 69 | 70 |
| 70 void ScrollbarAnimationController::DidScrollEnd() { | 71 void ScrollbarAnimationController::DidScrollEnd() { |
| 71 if (scroll_gesture_has_scrolled_) { | 72 if (scroll_gesture_has_scrolled_) { |
| 72 PostDelayedAnimationTask(false); | 73 PostDelayedAnimationTask(false); |
| 73 scroll_gesture_has_scrolled_ = false; | 74 scroll_gesture_has_scrolled_ = false; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 87 } | 88 } |
| 88 | 89 |
| 89 void ScrollbarAnimationController::StartAnimation() { | 90 void ScrollbarAnimationController::StartAnimation() { |
| 90 delayed_scrollbar_fade_.Cancel(); | 91 delayed_scrollbar_fade_.Cancel(); |
| 91 is_animating_ = true; | 92 is_animating_ = true; |
| 92 last_awaken_time_ = base::TimeTicks(); | 93 last_awaken_time_ = base::TimeTicks(); |
| 93 client_->SetNeedsAnimateForScrollbarAnimation(); | 94 client_->SetNeedsAnimateForScrollbarAnimation(); |
| 94 } | 95 } |
| 95 | 96 |
| 96 void ScrollbarAnimationController::StopAnimation() { | 97 void ScrollbarAnimationController::StopAnimation() { |
| 98 delayed_scrollbar_fade_.Cancel(); | |
| 97 is_animating_ = false; | 99 is_animating_ = false; |
| 98 } | 100 } |
| 99 | 101 |
| 100 ScrollbarSet ScrollbarAnimationController::Scrollbars() const { | 102 ScrollbarSet ScrollbarAnimationController::Scrollbars() const { |
| 101 return client_->ScrollbarsFor(scroll_layer_id_); | 103 return client_->ScrollbarsFor(scroll_layer_id_); |
| 102 } | 104 } |
| 103 | 105 |
| 104 } // namespace cc | 106 } // namespace cc |
| OLD | NEW |