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

Side by Side Diff: cc/input/scrollbar_animation_controller.cc

Issue 2442573002: Implement fade-out animation for Aura overlay scrollbars (CC only). (Closed)
Patch Set: Address aelias@'s feedback Created 4 years, 2 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
OLDNEW
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)
20 : client_(client), 19 : client_(client),
21 delay_before_starting_(delay_before_starting), 20 delay_before_starting_(delay_before_starting),
22 resize_delay_before_starting_(resize_delay_before_starting), 21 resize_delay_before_starting_(resize_delay_before_starting),
23 duration_(duration),
24 is_animating_(false), 22 is_animating_(false),
25 scroll_layer_id_(scroll_layer_id), 23 scroll_layer_id_(scroll_layer_id),
26 currently_scrolling_(false), 24 currently_scrolling_(false),
27 scroll_gesture_has_scrolled_(false), 25 scroll_gesture_has_scrolled_(false),
28 weak_factory_(this) {} 26 weak_factory_(this) {}
29 27
30 ScrollbarAnimationController::~ScrollbarAnimationController() {} 28 ScrollbarAnimationController::~ScrollbarAnimationController() {}
31 29
32 bool ScrollbarAnimationController::Animate(base::TimeTicks now) { 30 bool ScrollbarAnimationController::Animate(base::TimeTicks now) {
33 if (!is_animating_) 31 if (!is_animating_)
34 return false; 32 return false;
35 33
36 if (last_awaken_time_.is_null()) 34 if (last_awaken_time_.is_null())
37 last_awaken_time_ = now; 35 last_awaken_time_ = now;
38 36
39 float progress = AnimationProgressAtTime(now); 37 float progress = AnimationProgressAtTime(now);
40 RunAnimationFrame(progress); 38 RunAnimationFrame(progress);
41 39
42 if (is_animating_) 40 if (is_animating_)
43 client_->SetNeedsAnimateForScrollbarAnimation(); 41 client_->SetNeedsAnimateForScrollbarAnimation();
44 return true; 42 return true;
45 } 43 }
46 44
47 float ScrollbarAnimationController::AnimationProgressAtTime( 45 float ScrollbarAnimationController::AnimationProgressAtTime(
48 base::TimeTicks now) { 46 base::TimeTicks now) {
49 base::TimeDelta delta = now - last_awaken_time_; 47 base::TimeDelta delta = now - last_awaken_time_;
50 float progress = delta.InSecondsF() / duration_.InSecondsF(); 48 float progress = delta.InSecondsF() / Duration().InSecondsF();
51 return std::max(std::min(progress, 1.f), 0.f); 49 return std::max(std::min(progress, 1.f), 0.f);
52 } 50 }
53 51
54 void ScrollbarAnimationController::DidScrollBegin() { 52 void ScrollbarAnimationController::DidScrollBegin() {
55 currently_scrolling_ = true; 53 currently_scrolling_ = true;
56 } 54 }
57 55
58 void ScrollbarAnimationController::DidScrollUpdate(bool on_resize) { 56 void ScrollbarAnimationController::DidScrollUpdate(bool on_resize) {
59 StopAnimation(); 57 StopAnimation();
60 delayed_scrollbar_fade_.Cancel();
61 58
62 // As an optimization, we avoid spamming fade delay tasks during active fast 59 // 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. 60 // scrolls. But if we're not within one, we need to post every scroll update.
64 if (!currently_scrolling_) 61 if (!currently_scrolling_)
65 PostDelayedAnimationTask(on_resize); 62 PostDelayedAnimationTask(on_resize);
66 else 63 else
67 scroll_gesture_has_scrolled_ = true; 64 scroll_gesture_has_scrolled_ = true;
68 } 65 }
69 66
70 void ScrollbarAnimationController::DidScrollEnd() { 67 void ScrollbarAnimationController::DidScrollEnd() {
(...skipping 16 matching lines...) Expand all
87 } 84 }
88 85
89 void ScrollbarAnimationController::StartAnimation() { 86 void ScrollbarAnimationController::StartAnimation() {
90 delayed_scrollbar_fade_.Cancel(); 87 delayed_scrollbar_fade_.Cancel();
91 is_animating_ = true; 88 is_animating_ = true;
92 last_awaken_time_ = base::TimeTicks(); 89 last_awaken_time_ = base::TimeTicks();
93 client_->SetNeedsAnimateForScrollbarAnimation(); 90 client_->SetNeedsAnimateForScrollbarAnimation();
94 } 91 }
95 92
96 void ScrollbarAnimationController::StopAnimation() { 93 void ScrollbarAnimationController::StopAnimation() {
94 delayed_scrollbar_fade_.Cancel();
97 is_animating_ = false; 95 is_animating_ = false;
98 } 96 }
99 97
100 ScrollbarSet ScrollbarAnimationController::Scrollbars() const { 98 ScrollbarSet ScrollbarAnimationController::Scrollbars() const {
101 return client_->ScrollbarsFor(scroll_layer_id_); 99 return client_->ScrollbarsFor(scroll_layer_id_);
102 } 100 }
103 101
104 } // namespace cc 102 } // namespace cc
OLDNEW
« no previous file with comments | « cc/input/scrollbar_animation_controller.h ('k') | cc/input/scrollbar_animation_controller_linear_fade.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698