OLD | NEW |
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/input/scrollbar_animation_controller.h" | 5 #include "cc/input/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 #include "cc/trees/layer_tree_impl.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 return animated; | 155 return animated; |
156 } | 156 } |
157 | 157 |
158 float ScrollbarAnimationController::AnimationProgressAtTime( | 158 float ScrollbarAnimationController::AnimationProgressAtTime( |
159 base::TimeTicks now) { | 159 base::TimeTicks now) { |
160 base::TimeDelta delta = now - last_awaken_time_; | 160 base::TimeDelta delta = now - last_awaken_time_; |
161 float progress = delta.InSecondsF() / fade_out_duration_.InSecondsF(); | 161 float progress = delta.InSecondsF() / fade_out_duration_.InSecondsF(); |
162 return std::max(std::min(progress, 1.f), 0.f); | 162 return std::max(std::min(progress, 1.f), 0.f); |
163 } | 163 } |
164 | 164 |
165 void ScrollbarAnimationController::DidScrollBegin() { | |
166 currently_scrolling_ = true; | |
167 } | |
168 | |
169 void ScrollbarAnimationController::RunAnimationFrame(float progress) { | 165 void ScrollbarAnimationController::RunAnimationFrame(float progress) { |
170 ApplyOpacityToScrollbars(1.f - progress); | 166 ApplyOpacityToScrollbars(1.f - progress); |
171 client_->SetNeedsRedrawForScrollbarAnimation(); | 167 client_->SetNeedsRedrawForScrollbarAnimation(); |
172 if (progress == 1.f) | 168 if (progress == 1.f) |
173 StopAnimation(); | 169 StopAnimation(); |
174 } | 170 } |
175 | 171 |
176 void ScrollbarAnimationController::DidScrollUpdate(bool on_resize) { | 172 void ScrollbarAnimationController::DidScrollBegin() { |
| 173 currently_scrolling_ = true; |
| 174 } |
| 175 |
| 176 void ScrollbarAnimationController::DidScrollEnd() { |
| 177 bool has_scrolled = scroll_gesture_has_scrolled_; |
| 178 scroll_gesture_has_scrolled_ = false; |
| 179 |
| 180 currently_scrolling_ = false; |
| 181 |
| 182 // We don't fade out scrollbar if they need thinning animation and mouse is |
| 183 // near. |
| 184 if (need_thinning_animation_ && mouse_is_near_any_scrollbar()) |
| 185 return; |
| 186 |
| 187 if (has_scrolled) |
| 188 PostDelayedFadeOut(false); |
| 189 } |
| 190 |
| 191 void ScrollbarAnimationController::WillUpdateScroll() { |
177 if (need_thinning_animation_ && Captured()) | 192 if (need_thinning_animation_ && Captured()) |
178 return; | 193 return; |
179 | 194 |
180 StopAnimation(); | 195 StopAnimation(); |
181 | 196 |
182 // As an optimization, we avoid spamming fade delay tasks during active fast | 197 // As an optimization, we avoid spamming fade delay tasks during active fast |
183 // scrolls. But if we're not within one, we need to post every scroll update. | 198 // scrolls. But if we're not within one, we need to post every scroll update. |
184 if (!currently_scrolling_) { | 199 if (!currently_scrolling_) { |
185 // We don't fade out scrollbar if they need thinning animation and mouse is | 200 // We don't fade out scrollbar if they need thinning animation and mouse is |
186 // near. | 201 // near. |
187 if (!need_thinning_animation_ || !mouse_is_near_any_scrollbar()) | 202 if (!need_thinning_animation_ || !mouse_is_near_any_scrollbar()) |
188 PostDelayedFadeOut(on_resize); | 203 PostDelayedFadeOut(false); |
189 } else { | 204 } else { |
190 scroll_gesture_has_scrolled_ = true; | 205 scroll_gesture_has_scrolled_ = true; |
191 } | 206 } |
192 | 207 |
193 FadeIn(); | 208 FadeIn(); |
194 | 209 |
195 if (need_thinning_animation_) { | 210 if (need_thinning_animation_) { |
196 vertical_controller_->UpdateThumbThicknessScale(); | 211 vertical_controller_->UpdateThumbThicknessScale(); |
197 horizontal_controller_->UpdateThumbThicknessScale(); | 212 horizontal_controller_->UpdateThumbThicknessScale(); |
198 } | 213 } |
199 } | 214 } |
200 | 215 |
201 void ScrollbarAnimationController::DidScrollEnd() { | 216 void ScrollbarAnimationController::DidResize() { |
202 bool has_scrolled = scroll_gesture_has_scrolled_; | 217 StopAnimation(); |
203 scroll_gesture_has_scrolled_ = false; | 218 FadeIn(); |
204 | 219 // We should use the gesture delay rather than the resize delay if we're in a |
205 currently_scrolling_ = false; | 220 // gesture scroll, even if it is resizing. |
206 | 221 PostDelayedFadeOut(!currently_scrolling_); |
207 // We don't fade out scrollbar if they need thinning animation and mouse is | |
208 // near. | |
209 if (need_thinning_animation_ && mouse_is_near_any_scrollbar()) | |
210 return; | |
211 | |
212 if (has_scrolled) | |
213 PostDelayedFadeOut(false); | |
214 } | 222 } |
215 | 223 |
216 void ScrollbarAnimationController::DidMouseDown() { | 224 void ScrollbarAnimationController::DidMouseDown() { |
217 if (!need_thinning_animation_ || ScrollbarsHidden()) | 225 if (!need_thinning_animation_ || ScrollbarsHidden()) |
218 return; | 226 return; |
219 | 227 |
220 vertical_controller_->DidMouseDown(); | 228 vertical_controller_->DidMouseDown(); |
221 horizontal_controller_->DidMouseDown(); | 229 horizontal_controller_->DidMouseDown(); |
222 } | 230 } |
223 | 231 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 bool previouslyVisible = opacity_ > 0.0f; | 346 bool previouslyVisible = opacity_ > 0.0f; |
339 bool currentlyVisible = opacity > 0.0f; | 347 bool currentlyVisible = opacity > 0.0f; |
340 | 348 |
341 opacity_ = opacity; | 349 opacity_ = opacity; |
342 | 350 |
343 if (previouslyVisible != currentlyVisible) | 351 if (previouslyVisible != currentlyVisible) |
344 client_->DidChangeScrollbarVisibility(); | 352 client_->DidChangeScrollbarVisibility(); |
345 } | 353 } |
346 | 354 |
347 } // namespace cc | 355 } // namespace cc |
OLD | NEW |