OLD | NEW |
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 #include "cc/layers/scrollbar_layer_impl_base.h" | 9 #include "cc/layers/scrollbar_layer_impl_base.h" |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 fadeout_length_(fadeout_length) {} | 30 fadeout_length_(fadeout_length) {} |
31 | 31 |
32 ScrollbarAnimationControllerLinearFade:: | 32 ScrollbarAnimationControllerLinearFade:: |
33 ~ScrollbarAnimationControllerLinearFade() {} | 33 ~ScrollbarAnimationControllerLinearFade() {} |
34 | 34 |
35 bool ScrollbarAnimationControllerLinearFade::IsAnimating() const { | 35 bool ScrollbarAnimationControllerLinearFade::IsAnimating() const { |
36 return !last_awaken_time_.is_null(); | 36 return !last_awaken_time_.is_null(); |
37 } | 37 } |
38 | 38 |
39 base::TimeDelta ScrollbarAnimationControllerLinearFade::DelayBeforeStart( | 39 base::TimeDelta ScrollbarAnimationControllerLinearFade::DelayBeforeStart( |
40 base::TimeTicks now) const { | 40 gfx::FrameTime now) const { |
41 if (now > last_awaken_time_ + fadeout_delay_) | 41 if (now > last_awaken_time_ + fadeout_delay_) |
42 return base::TimeDelta(); | 42 return base::TimeDelta(); |
43 return fadeout_delay_ - (now - last_awaken_time_); | 43 return fadeout_delay_ - (now - last_awaken_time_); |
44 } | 44 } |
45 | 45 |
46 bool ScrollbarAnimationControllerLinearFade::Animate(base::TimeTicks now) { | 46 bool ScrollbarAnimationControllerLinearFade::Animate(gfx::FrameTime now) { |
47 float opacity = OpacityAtTime(now); | 47 float opacity = OpacityAtTime(now); |
48 ApplyOpacityToScrollbars(opacity); | 48 ApplyOpacityToScrollbars(opacity); |
49 if (!opacity) | 49 if (!opacity) |
50 last_awaken_time_ = base::TimeTicks(); | 50 last_awaken_time_ = gfx::FrameTime(); |
51 return IsAnimating() && DelayBeforeStart(now) == base::TimeDelta(); | 51 return IsAnimating() && DelayBeforeStart(now) == base::TimeDelta(); |
52 } | 52 } |
53 | 53 |
54 void ScrollbarAnimationControllerLinearFade::DidScrollGestureBegin() { | 54 void ScrollbarAnimationControllerLinearFade::DidScrollGestureBegin() { |
55 scroll_gesture_in_progress_ = true; | 55 scroll_gesture_in_progress_ = true; |
56 scroll_gesture_has_scrolled_ = false; | 56 scroll_gesture_has_scrolled_ = false; |
57 } | 57 } |
58 | 58 |
59 void ScrollbarAnimationControllerLinearFade::DidScrollGestureEnd( | 59 void ScrollbarAnimationControllerLinearFade::DidScrollGestureEnd( |
60 base::TimeTicks now) { | 60 gfx::FrameTime now) { |
61 // The animation should not be triggered if no scrolling has occurred. | 61 // The animation should not be triggered if no scrolling has occurred. |
62 if (scroll_gesture_has_scrolled_) | 62 if (scroll_gesture_has_scrolled_) |
63 last_awaken_time_ = now; | 63 last_awaken_time_ = now; |
64 scroll_gesture_has_scrolled_ = false; | 64 scroll_gesture_has_scrolled_ = false; |
65 scroll_gesture_in_progress_ = false; | 65 scroll_gesture_in_progress_ = false; |
66 } | 66 } |
67 | 67 |
68 void ScrollbarAnimationControllerLinearFade::DidMouseMoveOffScrollbar( | 68 void ScrollbarAnimationControllerLinearFade::DidMouseMoveOffScrollbar(\ |
69 base::TimeTicks now) { | 69 gfx::FrameTime now) { |
70 // Ignore mouse move events. | 70 // Ignore mouse move events. |
71 } | 71 } |
72 | 72 |
73 bool ScrollbarAnimationControllerLinearFade::DidScrollUpdate( | 73 bool ScrollbarAnimationControllerLinearFade::DidScrollUpdate( |
74 base::TimeTicks now) { | 74 gfx::FrameTime now) { |
75 ApplyOpacityToScrollbars(1.0f); | 75 ApplyOpacityToScrollbars(1.0f); |
76 // The animation should only be activated if the scroll updated occurred | 76 // The animation should only be activated if the scroll updated occurred |
77 // programatically, outside the scope of a scroll gesture. | 77 // programatically, outside the scope of a scroll gesture. |
78 if (scroll_gesture_in_progress_) { | 78 if (scroll_gesture_in_progress_) { |
79 last_awaken_time_ = base::TimeTicks(); | 79 last_awaken_time_ = gfx::FrameTime(); |
80 scroll_gesture_has_scrolled_ = true; | 80 scroll_gesture_has_scrolled_ = true; |
81 return false; | 81 return false; |
82 } | 82 } |
83 | 83 |
84 last_awaken_time_ = now; | 84 last_awaken_time_ = now; |
85 return true; | 85 return true; |
86 } | 86 } |
87 | 87 |
88 bool ScrollbarAnimationControllerLinearFade::DidMouseMoveNear( | 88 bool ScrollbarAnimationControllerLinearFade::DidMouseMoveNear( |
89 base::TimeTicks now, float distance) { | 89 gfx::FrameTime now, float distance) { |
90 // Ignore mouse move events. | 90 // Ignore mouse move events. |
91 return false; | 91 return false; |
92 } | 92 } |
93 | 93 |
94 float ScrollbarAnimationControllerLinearFade::OpacityAtTime( | 94 float ScrollbarAnimationControllerLinearFade::OpacityAtTime( |
95 base::TimeTicks now) { | 95 gfx::FrameTime now) { |
96 if (scroll_gesture_has_scrolled_) | 96 if (scroll_gesture_has_scrolled_) |
97 return 1.0f; | 97 return 1.0f; |
98 | 98 |
99 if (last_awaken_time_.is_null()) | 99 if (last_awaken_time_.is_null()) |
100 return 0.0f; | 100 return 0.0f; |
101 | 101 |
102 base::TimeDelta delta = now - last_awaken_time_; | 102 base::TimeDelta delta = now - last_awaken_time_; |
103 | 103 |
104 if (delta <= fadeout_delay_) | 104 if (delta <= fadeout_delay_) |
105 return 1.0f; | 105 return 1.0f; |
(...skipping 11 matching lines...) Expand all Loading... |
117 if (horizontal_scrollbar) | 117 if (horizontal_scrollbar) |
118 horizontal_scrollbar->SetOpacity(opacity); | 118 horizontal_scrollbar->SetOpacity(opacity); |
119 | 119 |
120 ScrollbarLayerImplBase* vertical_scrollbar = | 120 ScrollbarLayerImplBase* vertical_scrollbar = |
121 scroll_layer_->vertical_scrollbar_layer(); | 121 scroll_layer_->vertical_scrollbar_layer(); |
122 if (vertical_scrollbar) | 122 if (vertical_scrollbar) |
123 vertical_scrollbar->SetOpacity(opacity); | 123 vertical_scrollbar->SetOpacity(opacity); |
124 } | 124 } |
125 | 125 |
126 } // namespace cc | 126 } // namespace cc |
OLD | NEW |