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

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

Issue 608223002: [Android]Increase Scrollbar fade delay on Resize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 6 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/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 10
11 namespace cc { 11 namespace cc {
12 12
13 ScrollbarAnimationController::ScrollbarAnimationController( 13 ScrollbarAnimationController::ScrollbarAnimationController(
14 ScrollbarAnimationControllerClient* client, 14 ScrollbarAnimationControllerClient* client,
15 base::TimeDelta delay_before_starting, 15 base::TimeDelta delay_before_starting,
16 base::TimeDelta resize_delay_before_starting,
16 base::TimeDelta duration) 17 base::TimeDelta duration)
17 : client_(client), 18 : client_(client),
18 delay_before_starting_(delay_before_starting), 19 delay_before_starting_(delay_before_starting),
20 resize_delay_before_starting_(resize_delay_before_starting),
19 duration_(duration), 21 duration_(duration),
20 is_animating_(false), 22 is_animating_(false),
21 currently_scrolling_(false), 23 currently_scrolling_(false),
22 scroll_gesture_has_scrolled_(false), 24 scroll_gesture_has_scrolled_(false),
23 weak_factory_(this) { 25 weak_factory_(this) {
24 } 26 }
25 27
26 ScrollbarAnimationController::~ScrollbarAnimationController() { 28 ScrollbarAnimationController::~ScrollbarAnimationController() {
27 } 29 }
28 30
(...skipping 17 matching lines...) Expand all
46 base::TimeTicks now) { 48 base::TimeTicks now) {
47 base::TimeDelta delta = now - last_awaken_time_; 49 base::TimeDelta delta = now - last_awaken_time_;
48 float progress = delta.InSecondsF() / duration_.InSecondsF(); 50 float progress = delta.InSecondsF() / duration_.InSecondsF();
49 return std::max(std::min(progress, 1.f), 0.f); 51 return std::max(std::min(progress, 1.f), 0.f);
50 } 52 }
51 53
52 void ScrollbarAnimationController::DidScrollBegin() { 54 void ScrollbarAnimationController::DidScrollBegin() {
53 currently_scrolling_ = true; 55 currently_scrolling_ = true;
54 } 56 }
55 57
56 void ScrollbarAnimationController::DidScrollUpdate() { 58 void ScrollbarAnimationController::DidScrollUpdate(bool on_resize) {
57 StopAnimation(); 59 StopAnimation();
58 delayed_scrollbar_fade_.Cancel(); 60 delayed_scrollbar_fade_.Cancel();
59 61
60 // 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
61 // 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.
62 if (!currently_scrolling_) 64 if (!currently_scrolling_)
63 PostDelayedFade(); 65 PostDelayedFade(on_resize);
64 else 66 else
65 scroll_gesture_has_scrolled_ = true; 67 scroll_gesture_has_scrolled_ = true;
66 } 68 }
67 69
68 void ScrollbarAnimationController::DidScrollEnd() { 70 void ScrollbarAnimationController::DidScrollEnd() {
69 if (scroll_gesture_has_scrolled_) { 71 if (scroll_gesture_has_scrolled_) {
70 PostDelayedFade(); 72 PostDelayedFade(false);
71 scroll_gesture_has_scrolled_ = false; 73 scroll_gesture_has_scrolled_ = false;
72 } 74 }
73 75
74 currently_scrolling_ = false; 76 currently_scrolling_ = false;
75 } 77 }
76 78
77 void ScrollbarAnimationController::PostDelayedFade() { 79 void ScrollbarAnimationController::PostDelayedFade(bool on_resize) {
80 base::TimeDelta delay =
81 on_resize ? resize_delay_before_starting_ : delay_before_starting_;
78 delayed_scrollbar_fade_.Reset( 82 delayed_scrollbar_fade_.Reset(
79 base::Bind(&ScrollbarAnimationController::StartAnimation, 83 base::Bind(&ScrollbarAnimationController::StartAnimation,
80 weak_factory_.GetWeakPtr())); 84 weak_factory_.GetWeakPtr()));
81 client_->PostDelayedScrollbarFade(delayed_scrollbar_fade_.callback(), 85 client_->PostDelayedScrollbarFade(delayed_scrollbar_fade_.callback(), delay);
82 delay_before_starting_);
83 } 86 }
84 87
85 void ScrollbarAnimationController::StartAnimation() { 88 void ScrollbarAnimationController::StartAnimation() {
86 delayed_scrollbar_fade_.Cancel(); 89 delayed_scrollbar_fade_.Cancel();
87 is_animating_ = true; 90 is_animating_ = true;
88 last_awaken_time_ = base::TimeTicks(); 91 last_awaken_time_ = base::TimeTicks();
89 client_->SetNeedsScrollbarAnimationFrame(); 92 client_->SetNeedsScrollbarAnimationFrame();
90 } 93 }
91 94
92 void ScrollbarAnimationController::StopAnimation() { 95 void ScrollbarAnimationController::StopAnimation() {
93 is_animating_ = false; 96 is_animating_ = false;
94 } 97 }
95 98
96 } // namespace cc 99 } // 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