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" |
11 | 11 |
12 namespace { | |
13 | |
14 float DistanceToScrollbar(const gfx::PointF& device_viewport_point, | |
bokan
2017/04/25 19:36:21
This should be called "DistanceToScrollbarTrack"
| |
15 const cc::ScrollbarLayerImplBase* scrollbar) { | |
16 if (!scrollbar) | |
17 return std::numeric_limits<float>::max(); | |
18 | |
19 gfx::Rect scrollbar_bounds(scrollbar->bounds()); | |
20 | |
21 gfx::RectF device_viewport_scrollbar_bounds = cc::MathUtil::MapClippedRect( | |
22 scrollbar->ScreenSpaceTransform(), gfx::RectF(scrollbar_bounds)); | |
23 | |
24 return device_viewport_scrollbar_bounds.ManhattanDistanceToPoint( | |
25 device_viewport_point) / | |
26 scrollbar->layer_tree_impl()->device_scale_factor(); | |
27 } | |
28 | |
29 float DistanceToScrollbarThumb(const gfx::PointF& device_viewport_point, | |
30 const cc::ScrollbarLayerImplBase* scrollbar) { | |
31 if (!scrollbar) | |
32 return std::numeric_limits<float>::max(); | |
33 | |
34 gfx::Rect thumb_bounds(scrollbar->ComputeExpandedThumbQuadRect()); | |
35 | |
36 gfx::RectF device_viewport_scrollbar_bounds = cc::MathUtil::MapClippedRect( | |
37 scrollbar->ScreenSpaceTransform(), gfx::RectF(thumb_bounds)); | |
38 | |
39 return device_viewport_scrollbar_bounds.ManhattanDistanceToPoint( | |
40 device_viewport_point) / | |
41 scrollbar->layer_tree_impl()->device_scale_factor(); | |
42 } | |
43 | |
44 } // namespace | |
45 | |
12 namespace cc { | 46 namespace cc { |
13 | 47 |
14 std::unique_ptr<ScrollbarAnimationController> | 48 std::unique_ptr<ScrollbarAnimationController> |
15 ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid( | 49 ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid( |
16 ElementId scroll_element_id, | 50 ElementId scroll_element_id, |
17 ScrollbarAnimationControllerClient* client, | 51 ScrollbarAnimationControllerClient* client, |
18 base::TimeDelta fade_delay, | 52 base::TimeDelta fade_delay, |
19 base::TimeDelta fade_out_resize_delay, | 53 base::TimeDelta fade_out_resize_delay, |
20 base::TimeDelta fade_duration) { | 54 base::TimeDelta fade_duration) { |
21 return base::WrapUnique( | 55 return base::WrapUnique( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 thinning_duration); | 122 thinning_duration); |
89 ApplyOpacityToScrollbars(0.0f); | 123 ApplyOpacityToScrollbars(0.0f); |
90 } | 124 } |
91 | 125 |
92 ScrollbarAnimationController::~ScrollbarAnimationController() {} | 126 ScrollbarAnimationController::~ScrollbarAnimationController() {} |
93 | 127 |
94 ScrollbarSet ScrollbarAnimationController::Scrollbars() const { | 128 ScrollbarSet ScrollbarAnimationController::Scrollbars() const { |
95 return client_->ScrollbarsFor(scroll_element_id_); | 129 return client_->ScrollbarsFor(scroll_element_id_); |
96 } | 130 } |
97 | 131 |
132 ScrollbarLayerImplBase* ScrollbarAnimationController::GetScrollbar( | |
133 ScrollbarOrientation orientation) const { | |
134 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { | |
135 if (!scrollbar->is_overlay_scrollbar()) | |
136 continue; | |
137 | |
138 if (scrollbar->orientation() == orientation) | |
139 return scrollbar; | |
140 } | |
141 | |
142 NOTREACHED(); | |
143 return nullptr; | |
144 } | |
145 | |
98 SingleScrollbarAnimationControllerThinning& | 146 SingleScrollbarAnimationControllerThinning& |
99 ScrollbarAnimationController::GetScrollbarAnimationController( | 147 ScrollbarAnimationController::GetScrollbarAnimationController( |
100 ScrollbarOrientation orientation) const { | 148 ScrollbarOrientation orientation) const { |
101 DCHECK(need_thinning_animation_); | 149 DCHECK(need_thinning_animation_); |
102 if (orientation == ScrollbarOrientation::VERTICAL) | 150 if (orientation == ScrollbarOrientation::VERTICAL) |
103 return *(vertical_controller_.get()); | 151 return *(vertical_controller_.get()); |
104 else | 152 else |
105 return *(horizontal_controller_.get()); | 153 return *(horizontal_controller_.get()); |
106 } | 154 } |
107 | 155 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 | 322 |
275 delayed_scrollbar_animation_.Cancel(); | 323 delayed_scrollbar_animation_.Cancel(); |
276 need_trigger_scrollbar_show_ = false; | 324 need_trigger_scrollbar_show_ = false; |
277 | 325 |
278 if (ScrollbarsHidden() || Captured()) | 326 if (ScrollbarsHidden() || Captured()) |
279 return; | 327 return; |
280 | 328 |
281 PostDelayedAnimation(FADE_OUT, false); | 329 PostDelayedAnimation(FADE_OUT, false); |
282 } | 330 } |
283 | 331 |
284 void ScrollbarAnimationController::DidMouseMoveNear( | 332 void ScrollbarAnimationController::DidMouseMoveNear( |
bokan
2017/04/25 19:36:21
This no longer cares about distance - lets just ca
| |
285 ScrollbarOrientation orientation, | 333 ScrollbarOrientation orientation, |
286 float distance) { | 334 const gfx::PointF& device_viewport_point) { |
287 if (!need_thinning_animation_) | 335 if (!need_thinning_animation_) |
288 return; | 336 return; |
289 | 337 |
290 bool need_trigger_scrollbar_show_before = need_trigger_scrollbar_show_; | 338 bool need_trigger_scrollbar_show_before = need_trigger_scrollbar_show_; |
291 | 339 |
292 GetScrollbarAnimationController(orientation).DidMouseMoveNear(distance); | 340 ScrollbarLayerImplBase* scrollbar = GetScrollbar(orientation); |
341 | |
342 float distance_to_scrollbar = | |
343 DistanceToScrollbar(device_viewport_point, scrollbar); | |
344 float distance_to_thumb = | |
345 DistanceToScrollbarThumb(device_viewport_point, scrollbar); | |
346 | |
347 GetScrollbarAnimationController(orientation) | |
348 .DidMouseMoveNear(distance_to_scrollbar, distance_to_thumb); | |
293 | 349 |
294 need_trigger_scrollbar_show_ = | 350 need_trigger_scrollbar_show_ = |
295 CalcNeedTriggerScrollbarShow(orientation, distance); | 351 CalcNeedTriggerScrollbarShow(orientation, distance_to_scrollbar); |
296 | 352 |
297 if (Captured()) | 353 if (Captured()) |
298 return; | 354 return; |
299 | 355 |
300 if (ScrollbarsHidden()) { | 356 if (ScrollbarsHidden()) { |
301 if (need_trigger_scrollbar_show_before != need_trigger_scrollbar_show_) { | 357 if (need_trigger_scrollbar_show_before != need_trigger_scrollbar_show_) { |
302 if (need_trigger_scrollbar_show_) { | 358 if (need_trigger_scrollbar_show_) { |
303 PostDelayedAnimation(FADE_IN, false); | 359 PostDelayedAnimation(FADE_IN, false); |
304 } else { | 360 } else { |
305 delayed_scrollbar_animation_.Cancel(); | 361 delayed_scrollbar_animation_.Cancel(); |
306 } | 362 } |
307 } | 363 } |
308 } else { | 364 } else { |
309 if (MouseIsNearAnyScrollbar()) { | 365 if (MouseIsNearAnyScrollbar()) { |
310 Show(); | 366 Show(); |
311 StopAnimation(); | 367 StopAnimation(); |
312 } else if (!is_animating_) { | 368 } else if (!is_animating_) { |
313 PostDelayedAnimation(FADE_OUT, false); | 369 PostDelayedAnimation(FADE_OUT, false); |
314 } | 370 } |
315 } | 371 } |
316 } | 372 } |
317 | 373 |
318 bool ScrollbarAnimationController::CalcNeedTriggerScrollbarShow( | 374 bool ScrollbarAnimationController::CalcNeedTriggerScrollbarShow( |
319 ScrollbarOrientation orientation, | 375 ScrollbarOrientation orientation, |
320 float distance) const { | 376 float distance) const { |
321 DCHECK(need_thinning_animation_); | 377 DCHECK(need_thinning_animation_); |
322 | 378 |
323 if (vertical_controller_->mouse_is_over_scrollbar() || | 379 if (vertical_controller_->mouse_is_over_scrollbar_thumb() || |
bokan
2017/04/25 19:36:21
I think the show should still happen for "over the
| |
324 horizontal_controller_->mouse_is_over_scrollbar()) | 380 horizontal_controller_->mouse_is_over_scrollbar_thumb()) |
325 return true; | 381 return true; |
326 | 382 |
327 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { | 383 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { |
328 if (scrollbar->orientation() != orientation) | 384 if (scrollbar->orientation() != orientation) |
329 continue; | 385 continue; |
330 | 386 |
331 if (distance < kMouseMoveDistanceToTriggerFadeIn) | 387 if (distance < kMouseMoveDistanceToTriggerFadeIn) |
332 return true; | 388 return true; |
333 } | 389 } |
334 | 390 |
335 return false; | 391 return false; |
336 } | 392 } |
337 | 393 |
338 bool ScrollbarAnimationController::MouseIsOverScrollbar( | 394 bool ScrollbarAnimationController::MouseIsOverScrollbarThumb( |
339 ScrollbarOrientation orientation) const { | 395 ScrollbarOrientation orientation) const { |
340 DCHECK(need_thinning_animation_); | 396 DCHECK(need_thinning_animation_); |
341 return GetScrollbarAnimationController(orientation).mouse_is_over_scrollbar(); | 397 return GetScrollbarAnimationController(orientation) |
398 .mouse_is_over_scrollbar_thumb(); | |
399 } | |
400 | |
401 bool ScrollbarAnimationController::MouseIsNearScrollbarThumb( | |
402 ScrollbarOrientation orientation) const { | |
403 DCHECK(need_thinning_animation_); | |
404 return GetScrollbarAnimationController(orientation) | |
405 .mouse_is_near_scrollbar_thumb(); | |
342 } | 406 } |
343 | 407 |
344 bool ScrollbarAnimationController::MouseIsNearScrollbar( | 408 bool ScrollbarAnimationController::MouseIsNearScrollbar( |
345 ScrollbarOrientation orientation) const { | 409 ScrollbarOrientation orientation) const { |
346 DCHECK(need_thinning_animation_); | 410 DCHECK(need_thinning_animation_); |
347 return GetScrollbarAnimationController(orientation).mouse_is_near_scrollbar(); | 411 return GetScrollbarAnimationController(orientation).mouse_is_near_scrollbar(); |
348 } | 412 } |
349 | 413 |
350 bool ScrollbarAnimationController::MouseIsNearAnyScrollbar() const { | 414 bool ScrollbarAnimationController::MouseIsNearAnyScrollbar() const { |
351 DCHECK(need_thinning_animation_); | 415 DCHECK(need_thinning_animation_); |
(...skipping 29 matching lines...) Expand all Loading... | |
381 if (opacity_ != opacity) | 445 if (opacity_ != opacity) |
382 client_->SetNeedsRedrawForScrollbarAnimation(); | 446 client_->SetNeedsRedrawForScrollbarAnimation(); |
383 | 447 |
384 opacity_ = opacity; | 448 opacity_ = opacity; |
385 | 449 |
386 if (previouslyVisible != currentlyVisible) | 450 if (previouslyVisible != currentlyVisible) |
387 client_->DidChangeScrollbarVisibility(); | 451 client_->DidChangeScrollbarVisibility(); |
388 } | 452 } |
389 | 453 |
390 } // namespace cc | 454 } // namespace cc |
OLD | NEW |