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 28 matching lines...) Expand all Loading... |
39 ScrollbarAnimationController::ScrollbarAnimationController( | 39 ScrollbarAnimationController::ScrollbarAnimationController( |
40 ElementId scroll_element_id, | 40 ElementId scroll_element_id, |
41 ScrollbarAnimationControllerClient* client, | 41 ScrollbarAnimationControllerClient* client, |
42 base::TimeDelta fade_delay, | 42 base::TimeDelta fade_delay, |
43 base::TimeDelta fade_out_resize_delay, | 43 base::TimeDelta fade_out_resize_delay, |
44 base::TimeDelta fade_duration) | 44 base::TimeDelta fade_duration) |
45 : client_(client), | 45 : client_(client), |
46 fade_delay_(fade_delay), | 46 fade_delay_(fade_delay), |
47 fade_out_resize_delay_(fade_out_resize_delay), | 47 fade_out_resize_delay_(fade_out_resize_delay), |
48 fade_duration_(fade_duration), | 48 fade_duration_(fade_duration), |
49 need_trigger_scrollbar_show_(false), | 49 need_trigger_scrollbar_fade_in_(false), |
50 is_animating_(false), | 50 is_animating_(false), |
51 animation_change_(NONE), | 51 animation_change_(NONE), |
52 scroll_element_id_(scroll_element_id), | 52 scroll_element_id_(scroll_element_id), |
53 currently_scrolling_(false), | 53 currently_scrolling_(false), |
54 show_in_fast_scroll_(false), | 54 show_in_fast_scroll_(false), |
55 opacity_(0.0f), | 55 opacity_(0.0f), |
56 show_scrollbars_on_scroll_gesture_(false), | 56 show_scrollbars_on_scroll_gesture_(false), |
57 need_thinning_animation_(false), | 57 need_thinning_animation_(false), |
58 weak_factory_(this) { | 58 weak_factory_(this) { |
59 ApplyOpacityToScrollbars(0.0f); | 59 ApplyOpacityToScrollbars(0.0f); |
60 } | 60 } |
61 | 61 |
62 ScrollbarAnimationController::ScrollbarAnimationController( | 62 ScrollbarAnimationController::ScrollbarAnimationController( |
63 ElementId scroll_element_id, | 63 ElementId scroll_element_id, |
64 ScrollbarAnimationControllerClient* client, | 64 ScrollbarAnimationControllerClient* client, |
65 base::TimeDelta fade_delay, | 65 base::TimeDelta fade_delay, |
66 base::TimeDelta fade_out_resize_delay, | 66 base::TimeDelta fade_out_resize_delay, |
67 base::TimeDelta fade_duration, | 67 base::TimeDelta fade_duration, |
68 base::TimeDelta thinning_duration) | 68 base::TimeDelta thinning_duration) |
69 : client_(client), | 69 : client_(client), |
70 fade_delay_(fade_delay), | 70 fade_delay_(fade_delay), |
71 fade_out_resize_delay_(fade_out_resize_delay), | 71 fade_out_resize_delay_(fade_out_resize_delay), |
72 fade_duration_(fade_duration), | 72 fade_duration_(fade_duration), |
73 need_trigger_scrollbar_show_(false), | 73 need_trigger_scrollbar_fade_in_(false), |
74 is_animating_(false), | 74 is_animating_(false), |
75 animation_change_(NONE), | 75 animation_change_(NONE), |
76 scroll_element_id_(scroll_element_id), | 76 scroll_element_id_(scroll_element_id), |
77 currently_scrolling_(false), | 77 currently_scrolling_(false), |
78 show_in_fast_scroll_(false), | 78 show_in_fast_scroll_(false), |
79 opacity_(0.0f), | 79 opacity_(0.0f), |
80 show_scrollbars_on_scroll_gesture_(true), | 80 show_scrollbars_on_scroll_gesture_(true), |
81 need_thinning_animation_(true), | 81 need_thinning_animation_(true), |
82 weak_factory_(this) { | 82 weak_factory_(this) { |
83 vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create( | 83 vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create( |
84 scroll_element_id, ScrollbarOrientation::VERTICAL, client, | 84 scroll_element_id, ScrollbarOrientation::VERTICAL, client, |
85 thinning_duration); | 85 thinning_duration); |
86 horizontal_controller_ = SingleScrollbarAnimationControllerThinning::Create( | 86 horizontal_controller_ = SingleScrollbarAnimationControllerThinning::Create( |
87 scroll_element_id, ScrollbarOrientation::HORIZONTAL, client, | 87 scroll_element_id, ScrollbarOrientation::HORIZONTAL, client, |
88 thinning_duration); | 88 thinning_duration); |
| 89 |
89 ApplyOpacityToScrollbars(0.0f); | 90 ApplyOpacityToScrollbars(0.0f); |
90 } | 91 } |
91 | 92 |
92 ScrollbarAnimationController::~ScrollbarAnimationController() {} | 93 ScrollbarAnimationController::~ScrollbarAnimationController() {} |
93 | 94 |
94 ScrollbarSet ScrollbarAnimationController::Scrollbars() const { | 95 ScrollbarSet ScrollbarAnimationController::Scrollbars() const { |
95 return client_->ScrollbarsFor(scroll_element_id_); | 96 return client_->ScrollbarsFor(scroll_element_id_); |
96 } | 97 } |
97 | 98 |
98 SingleScrollbarAnimationControllerThinning& | 99 SingleScrollbarAnimationControllerThinning& |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 } | 267 } |
267 | 268 |
268 void ScrollbarAnimationController::DidMouseLeave() { | 269 void ScrollbarAnimationController::DidMouseLeave() { |
269 if (!need_thinning_animation_) | 270 if (!need_thinning_animation_) |
270 return; | 271 return; |
271 | 272 |
272 vertical_controller_->DidMouseLeave(); | 273 vertical_controller_->DidMouseLeave(); |
273 horizontal_controller_->DidMouseLeave(); | 274 horizontal_controller_->DidMouseLeave(); |
274 | 275 |
275 delayed_scrollbar_animation_.Cancel(); | 276 delayed_scrollbar_animation_.Cancel(); |
276 need_trigger_scrollbar_show_ = false; | 277 need_trigger_scrollbar_fade_in_ = false; |
277 | 278 |
278 if (ScrollbarsHidden() || Captured()) | 279 if (ScrollbarsHidden() || Captured()) |
279 return; | 280 return; |
280 | 281 |
281 PostDelayedAnimation(FADE_OUT, false); | 282 PostDelayedAnimation(FADE_OUT, false); |
282 } | 283 } |
283 | 284 |
284 void ScrollbarAnimationController::DidMouseMoveNear( | 285 void ScrollbarAnimationController::DidMouseMove( |
285 ScrollbarOrientation orientation, | 286 const gfx::PointF& device_viewport_point) { |
286 float distance) { | |
287 if (!need_thinning_animation_) | 287 if (!need_thinning_animation_) |
288 return; | 288 return; |
289 | 289 |
290 bool need_trigger_scrollbar_show_before = need_trigger_scrollbar_show_; | 290 bool need_trigger_scrollbar_fade_in_before = need_trigger_scrollbar_fade_in_; |
291 | 291 |
292 GetScrollbarAnimationController(orientation).DidMouseMoveNear(distance); | 292 vertical_controller_->DidMouseMove(device_viewport_point); |
| 293 horizontal_controller_->DidMouseMove(device_viewport_point); |
293 | 294 |
294 need_trigger_scrollbar_show_ = | 295 need_trigger_scrollbar_fade_in_ = MouseIsNearAnyScrollbar(); |
295 CalcNeedTriggerScrollbarShow(orientation, distance); | |
296 | 296 |
297 if (Captured()) | 297 if (Captured()) |
298 return; | 298 return; |
299 | 299 |
300 if (ScrollbarsHidden()) { | 300 if (ScrollbarsHidden()) { |
301 if (need_trigger_scrollbar_show_before != need_trigger_scrollbar_show_) { | 301 if (need_trigger_scrollbar_fade_in_before != |
302 if (need_trigger_scrollbar_show_) { | 302 need_trigger_scrollbar_fade_in_) { |
| 303 if (need_trigger_scrollbar_fade_in_) { |
303 PostDelayedAnimation(FADE_IN, false); | 304 PostDelayedAnimation(FADE_IN, false); |
304 } else { | 305 } else { |
305 delayed_scrollbar_animation_.Cancel(); | 306 delayed_scrollbar_animation_.Cancel(); |
306 } | 307 } |
307 } | 308 } |
308 } else { | 309 } else { |
309 if (MouseIsNearAnyScrollbar()) { | 310 if (MouseIsNearAnyScrollbar()) { |
310 Show(); | 311 Show(); |
311 StopAnimation(); | 312 StopAnimation(); |
312 } else if (!is_animating_) { | 313 } else if (!is_animating_) { |
313 PostDelayedAnimation(FADE_OUT, false); | 314 PostDelayedAnimation(FADE_OUT, false); |
314 } | 315 } |
315 } | 316 } |
316 } | 317 } |
317 | 318 |
318 bool ScrollbarAnimationController::CalcNeedTriggerScrollbarShow( | 319 bool ScrollbarAnimationController::MouseIsOverScrollbarThumb( |
319 ScrollbarOrientation orientation, | 320 ScrollbarOrientation orientation) const { |
320 float distance) const { | |
321 DCHECK(need_thinning_animation_); | 321 DCHECK(need_thinning_animation_); |
322 | 322 return GetScrollbarAnimationController(orientation) |
323 if (vertical_controller_->mouse_is_over_scrollbar() || | 323 .mouse_is_over_scrollbar_thumb(); |
324 horizontal_controller_->mouse_is_over_scrollbar()) | |
325 return true; | |
326 | |
327 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { | |
328 if (scrollbar->orientation() != orientation) | |
329 continue; | |
330 | |
331 if (distance < kMouseMoveDistanceToTriggerFadeIn) | |
332 return true; | |
333 } | |
334 | |
335 return false; | |
336 } | 324 } |
337 | 325 |
338 bool ScrollbarAnimationController::MouseIsOverScrollbar( | 326 bool ScrollbarAnimationController::MouseIsNearScrollbarThumb( |
339 ScrollbarOrientation orientation) const { | 327 ScrollbarOrientation orientation) const { |
340 DCHECK(need_thinning_animation_); | 328 DCHECK(need_thinning_animation_); |
341 return GetScrollbarAnimationController(orientation).mouse_is_over_scrollbar(); | 329 return GetScrollbarAnimationController(orientation) |
| 330 .mouse_is_near_scrollbar_thumb(); |
342 } | 331 } |
343 | 332 |
344 bool ScrollbarAnimationController::MouseIsNearScrollbar( | 333 bool ScrollbarAnimationController::MouseIsNearScrollbar( |
345 ScrollbarOrientation orientation) const { | 334 ScrollbarOrientation orientation) const { |
346 DCHECK(need_thinning_animation_); | 335 DCHECK(need_thinning_animation_); |
347 return GetScrollbarAnimationController(orientation).mouse_is_near_scrollbar(); | 336 return GetScrollbarAnimationController(orientation) |
| 337 .mouse_is_near_scrollbar_track(); |
348 } | 338 } |
349 | 339 |
350 bool ScrollbarAnimationController::MouseIsNearAnyScrollbar() const { | 340 bool ScrollbarAnimationController::MouseIsNearAnyScrollbar() const { |
351 DCHECK(need_thinning_animation_); | 341 DCHECK(need_thinning_animation_); |
352 return vertical_controller_->mouse_is_near_scrollbar() || | 342 return vertical_controller_->mouse_is_near_scrollbar_track() || |
353 horizontal_controller_->mouse_is_near_scrollbar(); | 343 horizontal_controller_->mouse_is_near_scrollbar_track(); |
354 } | 344 } |
355 | 345 |
356 bool ScrollbarAnimationController::ScrollbarsHidden() const { | 346 bool ScrollbarAnimationController::ScrollbarsHidden() const { |
357 return opacity_ == 0.0f; | 347 return opacity_ == 0.0f; |
358 } | 348 } |
359 | 349 |
360 bool ScrollbarAnimationController::Captured() const { | 350 bool ScrollbarAnimationController::Captured() const { |
361 DCHECK(need_thinning_animation_); | 351 DCHECK(need_thinning_animation_); |
362 return vertical_controller_->captured() || horizontal_controller_->captured(); | 352 return GetScrollbarAnimationController(VERTICAL).captured() || |
| 353 GetScrollbarAnimationController(HORIZONTAL).captured(); |
363 } | 354 } |
364 | 355 |
365 void ScrollbarAnimationController::Show() { | 356 void ScrollbarAnimationController::Show() { |
366 delayed_scrollbar_animation_.Cancel(); | 357 delayed_scrollbar_animation_.Cancel(); |
367 ApplyOpacityToScrollbars(1.0f); | 358 ApplyOpacityToScrollbars(1.0f); |
368 } | 359 } |
369 | 360 |
370 void ScrollbarAnimationController::ApplyOpacityToScrollbars(float opacity) { | 361 void ScrollbarAnimationController::ApplyOpacityToScrollbars(float opacity) { |
371 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { | 362 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { |
372 if (!scrollbar->is_overlay_scrollbar()) | 363 DCHECK(scrollbar->is_overlay_scrollbar()); |
373 continue; | |
374 float effective_opacity = scrollbar->CanScrollOrientation() ? opacity : 0; | 364 float effective_opacity = scrollbar->CanScrollOrientation() ? opacity : 0; |
375 scrollbar->SetOverlayScrollbarLayerOpacityAnimated(effective_opacity); | 365 scrollbar->SetOverlayScrollbarLayerOpacityAnimated(effective_opacity); |
376 } | 366 } |
377 | 367 |
378 bool previouslyVisible = opacity_ > 0.0f; | 368 bool previouslyVisible = opacity_ > 0.0f; |
379 bool currentlyVisible = opacity > 0.0f; | 369 bool currentlyVisible = opacity > 0.0f; |
380 | 370 |
381 if (opacity_ != opacity) | 371 if (opacity_ != opacity) |
382 client_->SetNeedsRedrawForScrollbarAnimation(); | 372 client_->SetNeedsRedrawForScrollbarAnimation(); |
383 | 373 |
384 opacity_ = opacity; | 374 opacity_ = opacity; |
385 | 375 |
386 if (previouslyVisible != currentlyVisible) | 376 if (previouslyVisible != currentlyVisible) |
387 client_->DidChangeScrollbarVisibility(); | 377 client_->DidChangeScrollbarVisibility(); |
388 } | 378 } |
389 | 379 |
390 } // namespace cc | 380 } // namespace cc |
OLD | NEW |