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

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

Issue 23978008: Suppress scrollbar animation if the scroll gesture does not scroll (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix LayerTreeHostImpl unit tests Created 7 years, 3 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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_linear_fade.h" 5 #include "cc/animation/scrollbar_animation_controller_linear_fade.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "cc/layers/layer_impl.h" 8 #include "cc/layers/layer_impl.h"
9 9
10 namespace cc { 10 namespace cc {
11 11
12 scoped_ptr<ScrollbarAnimationControllerLinearFade> 12 scoped_ptr<ScrollbarAnimationControllerLinearFade>
13 ScrollbarAnimationControllerLinearFade::Create(LayerImpl* scroll_layer, 13 ScrollbarAnimationControllerLinearFade::Create(LayerImpl* scroll_layer,
14 base::TimeDelta fadeout_delay, 14 base::TimeDelta fadeout_delay,
15 base::TimeDelta fadeout_length) { 15 base::TimeDelta fadeout_length) {
16 return make_scoped_ptr(new ScrollbarAnimationControllerLinearFade( 16 return make_scoped_ptr(new ScrollbarAnimationControllerLinearFade(
17 scroll_layer, fadeout_delay, fadeout_length)); 17 scroll_layer, fadeout_delay, fadeout_length));
18 } 18 }
19 19
20 ScrollbarAnimationControllerLinearFade::ScrollbarAnimationControllerLinearFade( 20 ScrollbarAnimationControllerLinearFade::ScrollbarAnimationControllerLinearFade(
21 LayerImpl* scroll_layer, 21 LayerImpl* scroll_layer,
22 base::TimeDelta fadeout_delay, 22 base::TimeDelta fadeout_delay,
23 base::TimeDelta fadeout_length) 23 base::TimeDelta fadeout_length)
24 : ScrollbarAnimationController(), 24 : ScrollbarAnimationController(),
25 scroll_layer_(scroll_layer), 25 scroll_layer_(scroll_layer),
26 scroll_gesture_in_progress_(false), 26 scroll_gesture_in_progress_(false),
27 scroll_gesture_has_scrolled_(false),
27 fadeout_delay_(fadeout_delay), 28 fadeout_delay_(fadeout_delay),
28 fadeout_length_(fadeout_length) {} 29 fadeout_length_(fadeout_length) {}
29 30
30 ScrollbarAnimationControllerLinearFade:: 31 ScrollbarAnimationControllerLinearFade::
31 ~ScrollbarAnimationControllerLinearFade() {} 32 ~ScrollbarAnimationControllerLinearFade() {}
32 33
33 bool ScrollbarAnimationControllerLinearFade::IsScrollGestureInProgress() const {
34 return scroll_gesture_in_progress_;
35 }
36
37 bool ScrollbarAnimationControllerLinearFade::IsAnimating() const { 34 bool ScrollbarAnimationControllerLinearFade::IsAnimating() const {
38 return !last_awaken_time_.is_null(); 35 return !last_awaken_time_.is_null();
39 } 36 }
40 37
41 base::TimeDelta ScrollbarAnimationControllerLinearFade::DelayBeforeStart( 38 base::TimeDelta ScrollbarAnimationControllerLinearFade::DelayBeforeStart(
42 base::TimeTicks now) const { 39 base::TimeTicks now) const {
43 if (now > last_awaken_time_ + fadeout_delay_) 40 if (now > last_awaken_time_ + fadeout_delay_)
44 return base::TimeDelta(); 41 return base::TimeDelta();
45 return fadeout_delay_ - (now - last_awaken_time_); 42 return fadeout_delay_ - (now - last_awaken_time_);
46 } 43 }
47 44
48 bool ScrollbarAnimationControllerLinearFade::Animate(base::TimeTicks now) { 45 bool ScrollbarAnimationControllerLinearFade::Animate(base::TimeTicks now) {
49 float opacity = OpacityAtTime(now); 46 float opacity = OpacityAtTime(now);
50 scroll_layer_->SetScrollbarOpacity(opacity); 47 scroll_layer_->SetScrollbarOpacity(opacity);
51 if (!opacity) 48 if (!opacity)
52 last_awaken_time_ = base::TimeTicks(); 49 last_awaken_time_ = base::TimeTicks();
53 return IsAnimating() && DelayBeforeStart(now) == base::TimeDelta(); 50 return IsAnimating() && DelayBeforeStart(now) == base::TimeDelta();
54 } 51 }
55 52
56 void ScrollbarAnimationControllerLinearFade::DidScrollGestureBegin() { 53 void ScrollbarAnimationControllerLinearFade::DidScrollGestureBegin() {
57 scroll_layer_->SetScrollbarOpacity(1.0f);
58 scroll_gesture_in_progress_ = true; 54 scroll_gesture_in_progress_ = true;
59 last_awaken_time_ = base::TimeTicks(); 55 scroll_gesture_has_scrolled_ = false;
60 } 56 }
61 57
62 void ScrollbarAnimationControllerLinearFade::DidScrollGestureEnd( 58 void ScrollbarAnimationControllerLinearFade::DidScrollGestureEnd(
63 base::TimeTicks now) { 59 base::TimeTicks now) {
60 // The animation should not be triggered if no scrolling has occurred.
61 if (scroll_gesture_has_scrolled_)
62 last_awaken_time_ = now;
63 scroll_gesture_has_scrolled_ = false;
64 scroll_gesture_in_progress_ = false; 64 scroll_gesture_in_progress_ = false;
65 last_awaken_time_ = now;
66 } 65 }
67 66
68 void ScrollbarAnimationControllerLinearFade::DidProgrammaticallyUpdateScroll( 67 void ScrollbarAnimationControllerLinearFade::DidScrollUpdate(
69 base::TimeTicks now) { 68 base::TimeTicks now) {
70 // Don't set scroll_gesture_in_progress_ as this scroll is not from a gesture
71 // and we won't receive ScrollEnd.
72 scroll_layer_->SetScrollbarOpacity(1.0f); 69 scroll_layer_->SetScrollbarOpacity(1.0f);
73 last_awaken_time_ = now; 70 // The animation should only be activated if the scroll updated occurred
71 // programatically, outside the scope of a scroll gesture.
72 if (scroll_gesture_in_progress_) {
73 last_awaken_time_ = base::TimeTicks();
74 scroll_gesture_has_scrolled_ = true;
75 } else {
76 last_awaken_time_ = now;
77 }
74 } 78 }
75 79
76 float ScrollbarAnimationControllerLinearFade::OpacityAtTime( 80 float ScrollbarAnimationControllerLinearFade::OpacityAtTime(
77 base::TimeTicks now) { 81 base::TimeTicks now) {
78 if (scroll_gesture_in_progress_) 82 if (scroll_gesture_has_scrolled_)
79 return 1.0f; 83 return 1.0f;
80 84
81 if (last_awaken_time_.is_null()) 85 if (last_awaken_time_.is_null())
82 return 0.0f; 86 return 0.0f;
83 87
84 base::TimeDelta delta = now - last_awaken_time_; 88 base::TimeDelta delta = now - last_awaken_time_;
85 89
86 if (delta <= fadeout_delay_) 90 if (delta <= fadeout_delay_)
87 return 1.0f; 91 return 1.0f;
88 if (delta < fadeout_delay_ + fadeout_length_) { 92 if (delta < fadeout_delay_ + fadeout_length_) {
89 return (fadeout_delay_ + fadeout_length_ - delta).InSecondsF() / 93 return (fadeout_delay_ + fadeout_length_ - delta).InSecondsF() /
90 fadeout_length_.InSecondsF(); 94 fadeout_length_.InSecondsF();
91 } 95 }
92 return 0.0f; 96 return 0.0f;
93 } 97 }
94 98
95 } // namespace cc 99 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698