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 #ifndef CC_INPUT_SCROLLBAR_ANIMATION_CONTROLLER_H_ | 5 #ifndef CC_INPUT_SCROLLBAR_ANIMATION_CONTROLLER_H_ |
6 #define CC_INPUT_SCROLLBAR_ANIMATION_CONTROLLER_H_ | 6 #define CC_INPUT_SCROLLBAR_ANIMATION_CONTROLLER_H_ |
7 | 7 |
8 #include "base/cancelable_callback.h" | 8 #include "base/cancelable_callback.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 // SingleScrollbarAnimationControllerThinnings. | 37 // SingleScrollbarAnimationControllerThinnings. |
38 class CC_EXPORT ScrollbarAnimationController { | 38 class CC_EXPORT ScrollbarAnimationController { |
39 public: | 39 public: |
40 // ScrollbarAnimationController for Android. It only has show & fade out | 40 // ScrollbarAnimationController for Android. It only has show & fade out |
41 // animation. | 41 // animation. |
42 static std::unique_ptr<ScrollbarAnimationController> | 42 static std::unique_ptr<ScrollbarAnimationController> |
43 CreateScrollbarAnimationControllerAndroid( | 43 CreateScrollbarAnimationControllerAndroid( |
44 ElementId scroll_element_id, | 44 ElementId scroll_element_id, |
45 ScrollbarAnimationControllerClient* client, | 45 ScrollbarAnimationControllerClient* client, |
46 base::TimeDelta fade_delay, | 46 base::TimeDelta fade_delay, |
47 base::TimeDelta fade_out_resize_delay, | |
48 base::TimeDelta fade_duration); | 47 base::TimeDelta fade_duration); |
49 | 48 |
50 // ScrollbarAnimationController for Desktop Overlay Scrollbar. It has show & | 49 // ScrollbarAnimationController for Desktop Overlay Scrollbar. It has show & |
51 // fade out animation and thinning animation. | 50 // fade out animation and thinning animation. |
52 static std::unique_ptr<ScrollbarAnimationController> | 51 static std::unique_ptr<ScrollbarAnimationController> |
53 CreateScrollbarAnimationControllerAuraOverlay( | 52 CreateScrollbarAnimationControllerAuraOverlay( |
54 ElementId scroll_element_id, | 53 ElementId scroll_element_id, |
55 ScrollbarAnimationControllerClient* client, | 54 ScrollbarAnimationControllerClient* client, |
56 base::TimeDelta fade_delay, | 55 base::TimeDelta fade_delay, |
57 base::TimeDelta fade_out_resize_delay, | |
58 base::TimeDelta fade_duration, | 56 base::TimeDelta fade_duration, |
59 base::TimeDelta thinning_duration); | 57 base::TimeDelta thinning_duration); |
60 | 58 |
61 ~ScrollbarAnimationController(); | 59 ~ScrollbarAnimationController(); |
62 | 60 |
63 bool ScrollbarsHidden() const; | 61 bool ScrollbarsHidden() const; |
64 | 62 |
65 bool Animate(base::TimeTicks now); | 63 bool Animate(base::TimeTicks now); |
66 | 64 |
67 // WillUpdateScroll expects to be called even if the scroll position won't | 65 // WillUpdateScroll expects to be called even if the scroll position won't |
68 // change as a result of the scroll. Only effect Aura Overlay Scrollbar. | 66 // change as a result of the scroll. Only effect Aura Overlay Scrollbar. |
69 void WillUpdateScroll(); | 67 void WillUpdateScroll(); |
70 | 68 |
71 // DidScrollUpdate expects to be called only if the scroll position change. | 69 // DidScrollUpdate expects to be called only if the scroll position change. |
72 // Effect both Android and Aura Overlay Scrollbar. | 70 // Effect both Android and Aura Overlay Scrollbar. |
73 void DidScrollUpdate(); | 71 void DidScrollUpdate(); |
74 | 72 |
75 // DidResize expects to be called when clip layer size changed or scroll layer | |
76 // size changed. | |
77 void DidResize(); | |
78 | |
79 void DidScrollBegin(); | 73 void DidScrollBegin(); |
80 void DidScrollEnd(); | 74 void DidScrollEnd(); |
81 | 75 |
82 void DidMouseDown(); | 76 void DidMouseDown(); |
83 void DidMouseUp(); | 77 void DidMouseUp(); |
84 void DidMouseLeave(); | 78 void DidMouseLeave(); |
85 void DidMouseMoveNear(ScrollbarOrientation, float); | 79 void DidMouseMoveNear(ScrollbarOrientation, float); |
86 | 80 |
87 // Called when Blink wants to show the scrollbars (via | 81 // Called when Blink wants to show the scrollbars (via |
88 // ScrollableArea::showOverlayScrollbars). | 82 // ScrollableArea::showOverlayScrollbars). |
89 void DidRequestShowFromMainThread(); | 83 void DidRequestShowFromMainThread(); |
90 | 84 |
91 bool MouseIsOverScrollbar(ScrollbarOrientation orientation) const; | 85 bool MouseIsOverScrollbar(ScrollbarOrientation orientation) const; |
92 bool MouseIsNearScrollbar(ScrollbarOrientation orientation) const; | 86 bool MouseIsNearScrollbar(ScrollbarOrientation orientation) const; |
93 bool MouseIsNearAnyScrollbar() const; | 87 bool MouseIsNearAnyScrollbar() const; |
94 | 88 |
95 static constexpr float kMouseMoveDistanceToTriggerFadeIn = 30.0f; | 89 static constexpr float kMouseMoveDistanceToTriggerFadeIn = 30.0f; |
96 | 90 |
97 private: | 91 private: |
98 // Describes whether the current animation should FadeIn or FadeOut. | 92 // Describes whether the current animation should FadeIn or FadeOut. |
99 enum AnimationChange { NONE, FADE_IN, FADE_OUT }; | 93 enum AnimationChange { NONE, FADE_IN, FADE_OUT }; |
100 | 94 |
101 ScrollbarAnimationController(ElementId scroll_element_id, | 95 ScrollbarAnimationController(ElementId scroll_element_id, |
102 ScrollbarAnimationControllerClient* client, | 96 ScrollbarAnimationControllerClient* client, |
103 base::TimeDelta fade_delay, | 97 base::TimeDelta fade_delay, |
104 base::TimeDelta fade_out_resize_delay, | |
105 base::TimeDelta fade_duration); | 98 base::TimeDelta fade_duration); |
106 | 99 |
107 ScrollbarAnimationController(ElementId scroll_element_id, | 100 ScrollbarAnimationController(ElementId scroll_element_id, |
108 ScrollbarAnimationControllerClient* client, | 101 ScrollbarAnimationControllerClient* client, |
109 base::TimeDelta fade_delay, | 102 base::TimeDelta fade_delay, |
110 base::TimeDelta fade_out_resize_delay, | |
111 base::TimeDelta fade_duration, | 103 base::TimeDelta fade_duration, |
112 base::TimeDelta thinning_duration); | 104 base::TimeDelta thinning_duration); |
113 | 105 |
114 ScrollbarSet Scrollbars() const; | 106 ScrollbarSet Scrollbars() const; |
115 SingleScrollbarAnimationControllerThinning& GetScrollbarAnimationController( | 107 SingleScrollbarAnimationControllerThinning& GetScrollbarAnimationController( |
116 ScrollbarOrientation) const; | 108 ScrollbarOrientation) const; |
117 | 109 |
118 // Returns how far through the animation we are as a progress value from | 110 // Returns how far through the animation we are as a progress value from |
119 // 0 to 1. | 111 // 0 to 1. |
120 float AnimationProgressAtTime(base::TimeTicks now); | 112 float AnimationProgressAtTime(base::TimeTicks now); |
121 void RunAnimationFrame(float progress); | 113 void RunAnimationFrame(float progress); |
122 | 114 |
123 void StartAnimation(); | 115 void StartAnimation(); |
124 void StopAnimation(); | 116 void StopAnimation(); |
125 | 117 |
126 void Show(); | 118 void Show(); |
127 | 119 |
128 void PostDelayedAnimation(AnimationChange animation_change, bool on_resize); | 120 void PostDelayedAnimation(AnimationChange animation_change); |
129 | 121 |
130 bool Captured() const; | 122 bool Captured() const; |
131 | 123 |
132 bool CalcNeedTriggerScrollbarShow(ScrollbarOrientation orientation, | 124 bool CalcNeedTriggerScrollbarShow(ScrollbarOrientation orientation, |
133 float distance) const; | 125 float distance) const; |
134 | 126 |
135 void ApplyOpacityToScrollbars(float opacity); | 127 void ApplyOpacityToScrollbars(float opacity); |
136 | 128 |
137 ScrollbarAnimationControllerClient* client_; | 129 ScrollbarAnimationControllerClient* client_; |
138 | 130 |
139 base::TimeTicks last_awaken_time_; | 131 base::TimeTicks last_awaken_time_; |
140 | 132 |
141 base::TimeDelta fade_delay_; | 133 base::TimeDelta fade_delay_; |
142 base::TimeDelta fade_out_resize_delay_; | |
143 | 134 |
144 base::TimeDelta fade_duration_; | 135 base::TimeDelta fade_duration_; |
145 | 136 |
146 bool need_trigger_scrollbar_show_; | 137 bool need_trigger_scrollbar_show_; |
147 | 138 |
148 bool is_animating_; | 139 bool is_animating_; |
149 AnimationChange animation_change_; | 140 AnimationChange animation_change_; |
150 | 141 |
151 const ElementId scroll_element_id_; | 142 const ElementId scroll_element_id_; |
152 bool currently_scrolling_; | 143 bool currently_scrolling_; |
153 bool show_in_fast_scroll_; | 144 bool show_in_fast_scroll_; |
154 | 145 |
155 base::CancelableClosure delayed_scrollbar_animation_; | 146 base::CancelableClosure delayed_scrollbar_animation_; |
156 | 147 |
157 float opacity_; | 148 float opacity_; |
158 | 149 |
159 const bool show_scrollbars_on_scroll_gesture_; | 150 const bool show_scrollbars_on_scroll_gesture_; |
160 const bool need_thinning_animation_; | 151 const bool need_thinning_animation_; |
161 std::unique_ptr<SingleScrollbarAnimationControllerThinning> | 152 std::unique_ptr<SingleScrollbarAnimationControllerThinning> |
162 vertical_controller_; | 153 vertical_controller_; |
163 std::unique_ptr<SingleScrollbarAnimationControllerThinning> | 154 std::unique_ptr<SingleScrollbarAnimationControllerThinning> |
164 horizontal_controller_; | 155 horizontal_controller_; |
165 | 156 |
166 base::WeakPtrFactory<ScrollbarAnimationController> weak_factory_; | 157 base::WeakPtrFactory<ScrollbarAnimationController> weak_factory_; |
167 }; | 158 }; |
168 | 159 |
169 } // namespace cc | 160 } // namespace cc |
170 | 161 |
171 #endif // CC_INPUT_SCROLLBAR_ANIMATION_CONTROLLER_H_ | 162 #endif // CC_INPUT_SCROLLBAR_ANIMATION_CONTROLLER_H_ |
OLD | NEW |