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

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

Issue 960873002: Update from https://crrev.com/318214 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 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/animation/scrollbar_animation_controller.h" 5 #include "cc/animation/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 11
11 namespace cc { 12 namespace cc {
12 13
13 ScrollbarAnimationController::ScrollbarAnimationController( 14 ScrollbarAnimationController::ScrollbarAnimationController(
15 LayerImpl* scroll_layer,
14 ScrollbarAnimationControllerClient* client, 16 ScrollbarAnimationControllerClient* client,
15 base::TimeDelta delay_before_starting, 17 base::TimeDelta delay_before_starting,
16 base::TimeDelta resize_delay_before_starting, 18 base::TimeDelta resize_delay_before_starting,
17 base::TimeDelta duration) 19 base::TimeDelta duration)
18 : client_(client), 20 : scroll_layer_(scroll_layer),
21 client_(client),
19 delay_before_starting_(delay_before_starting), 22 delay_before_starting_(delay_before_starting),
20 resize_delay_before_starting_(resize_delay_before_starting), 23 resize_delay_before_starting_(resize_delay_before_starting),
21 duration_(duration), 24 duration_(duration),
22 is_animating_(false), 25 is_animating_(false),
23 currently_scrolling_(false), 26 currently_scrolling_(false),
24 scroll_gesture_has_scrolled_(false), 27 scroll_gesture_has_scrolled_(false),
25 weak_factory_(this) { 28 weak_factory_(this) {
26 } 29 }
27 30
28 ScrollbarAnimationController::~ScrollbarAnimationController() { 31 ScrollbarAnimationController::~ScrollbarAnimationController() {
32 if (is_animating_)
33 client_->StopAnimatingScrollbarAnimationController(this);
29 } 34 }
30 35
31 void ScrollbarAnimationController::Animate(base::TimeTicks now) { 36 void ScrollbarAnimationController::Animate(base::TimeTicks now) {
32 if (!is_animating_) 37 if (!is_animating_)
33 return; 38 return;
34 39
35 if (last_awaken_time_.is_null()) 40 if (last_awaken_time_.is_null())
36 last_awaken_time_ = now; 41 last_awaken_time_ = now;
37 42
38 float progress = AnimationProgressAtTime(now); 43 float progress = AnimationProgressAtTime(now);
39 RunAnimationFrame(progress); 44 RunAnimationFrame(progress);
40
41 if (is_animating_) {
42 delayed_scrollbar_fade_.Cancel();
43 client_->SetNeedsScrollbarAnimationFrame();
44 }
45 } 45 }
46 46
47 float ScrollbarAnimationController::AnimationProgressAtTime( 47 float ScrollbarAnimationController::AnimationProgressAtTime(
48 base::TimeTicks now) { 48 base::TimeTicks now) {
49 base::TimeDelta delta = now - last_awaken_time_; 49 base::TimeDelta delta = now - last_awaken_time_;
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(); 60 delayed_scrollbar_fade_.Cancel();
61 61
62 // As an optimization, we avoid spamming fade delay tasks during active fast 62 // 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. 63 // scrolls. But if we're not within one, we need to post every scroll update.
64 if (!currently_scrolling_) 64 if (!currently_scrolling_)
65 PostDelayedFade(on_resize); 65 PostDelayedAnimationTask(on_resize);
66 else 66 else
67 scroll_gesture_has_scrolled_ = true; 67 scroll_gesture_has_scrolled_ = true;
68 } 68 }
69 69
70 void ScrollbarAnimationController::DidScrollEnd() { 70 void ScrollbarAnimationController::DidScrollEnd() {
71 if (scroll_gesture_has_scrolled_) { 71 if (scroll_gesture_has_scrolled_) {
72 PostDelayedFade(false); 72 PostDelayedAnimationTask(false);
73 scroll_gesture_has_scrolled_ = false; 73 scroll_gesture_has_scrolled_ = false;
74 } 74 }
75 75
76 currently_scrolling_ = false; 76 currently_scrolling_ = false;
77 } 77 }
78 78
79 void ScrollbarAnimationController::PostDelayedFade(bool on_resize) { 79 void ScrollbarAnimationController::PostDelayedAnimationTask(bool on_resize) {
80 base::TimeDelta delay = 80 base::TimeDelta delay =
81 on_resize ? resize_delay_before_starting_ : delay_before_starting_; 81 on_resize ? resize_delay_before_starting_ : delay_before_starting_;
82 delayed_scrollbar_fade_.Reset( 82 delayed_scrollbar_fade_.Reset(
83 base::Bind(&ScrollbarAnimationController::StartAnimation, 83 base::Bind(&ScrollbarAnimationController::StartAnimation,
84 weak_factory_.GetWeakPtr())); 84 weak_factory_.GetWeakPtr()));
85 client_->PostDelayedScrollbarFade(delayed_scrollbar_fade_.callback(), delay); 85 client_->PostDelayedScrollbarAnimationTask(delayed_scrollbar_fade_.callback(),
86 delay);
86 } 87 }
87 88
88 void ScrollbarAnimationController::StartAnimation() { 89 void ScrollbarAnimationController::StartAnimation() {
89 delayed_scrollbar_fade_.Cancel(); 90 delayed_scrollbar_fade_.Cancel();
90 is_animating_ = true; 91 is_animating_ = true;
91 last_awaken_time_ = base::TimeTicks(); 92 last_awaken_time_ = base::TimeTicks();
92 client_->SetNeedsScrollbarAnimationFrame(); 93 client_->StartAnimatingScrollbarAnimationController(this);
93 } 94 }
94 95
95 void ScrollbarAnimationController::StopAnimation() { 96 void ScrollbarAnimationController::StopAnimation() {
96 is_animating_ = false; 97 is_animating_ = false;
98 client_->StopAnimatingScrollbarAnimationController(this);
97 } 99 }
98 100
99 } // namespace cc 101 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/scrollbar_animation_controller.h ('k') | cc/animation/scrollbar_animation_controller_linear_fade.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698