Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: cc/input/scrollbar_animation_controller.cc

Issue 2841943002: Overlay scrollbars expand only when mouse is near thumb (Closed)
Patch Set: pass point to SingleScrollbarController Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 const ScrollbarOrientation orientations[] = {HORIZONTAL, VERTICAL};
bokan 2017/04/28 18:08:11 No need for loop, just: vertical_controller_->Di
293 for (ScrollbarOrientation orientation : orientations) {
294 GetScrollbarAnimationController(orientation)
295 .DidMouseMove(device_viewport_point);
296 }
293 297
294 need_trigger_scrollbar_show_ = 298 need_trigger_scrollbar_fade_in_ = MouseIsNearAnyScrollbar();
295 CalcNeedTriggerScrollbarShow(orientation, distance);
296 299
297 if (Captured()) 300 if (Captured())
298 return; 301 return;
299 302
300 if (ScrollbarsHidden()) { 303 if (ScrollbarsHidden()) {
301 if (need_trigger_scrollbar_show_before != need_trigger_scrollbar_show_) { 304 if (need_trigger_scrollbar_fade_in_before !=
302 if (need_trigger_scrollbar_show_) { 305 need_trigger_scrollbar_fade_in_) {
306 if (need_trigger_scrollbar_fade_in_) {
303 PostDelayedAnimation(FADE_IN, false); 307 PostDelayedAnimation(FADE_IN, false);
304 } else { 308 } else {
305 delayed_scrollbar_animation_.Cancel(); 309 delayed_scrollbar_animation_.Cancel();
306 } 310 }
307 } 311 }
308 } else { 312 } else {
309 if (MouseIsNearAnyScrollbar()) { 313 if (MouseIsNearAnyScrollbar()) {
310 Show(); 314 Show();
311 StopAnimation(); 315 StopAnimation();
312 } else if (!is_animating_) { 316 } else if (!is_animating_) {
313 PostDelayedAnimation(FADE_OUT, false); 317 PostDelayedAnimation(FADE_OUT, false);
314 } 318 }
315 } 319 }
316 } 320 }
317 321
318 bool ScrollbarAnimationController::CalcNeedTriggerScrollbarShow( 322 bool ScrollbarAnimationController::MouseIsOverScrollbarThumb(
319 ScrollbarOrientation orientation, 323 ScrollbarOrientation orientation) const {
320 float distance) const {
321 DCHECK(need_thinning_animation_); 324 DCHECK(need_thinning_animation_);
322 325 return GetScrollbarAnimationController(orientation)
323 if (vertical_controller_->mouse_is_over_scrollbar() || 326 .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 } 327 }
337 328
338 bool ScrollbarAnimationController::MouseIsOverScrollbar( 329 bool ScrollbarAnimationController::MouseIsNearScrollbarThumb(
339 ScrollbarOrientation orientation) const { 330 ScrollbarOrientation orientation) const {
340 DCHECK(need_thinning_animation_); 331 DCHECK(need_thinning_animation_);
341 return GetScrollbarAnimationController(orientation).mouse_is_over_scrollbar(); 332 return GetScrollbarAnimationController(orientation)
333 .mouse_is_near_scrollbar_thumb();
342 } 334 }
343 335
344 bool ScrollbarAnimationController::MouseIsNearScrollbar( 336 bool ScrollbarAnimationController::MouseIsNearScrollbar(
345 ScrollbarOrientation orientation) const { 337 ScrollbarOrientation orientation) const {
346 DCHECK(need_thinning_animation_); 338 DCHECK(need_thinning_animation_);
347 return GetScrollbarAnimationController(orientation).mouse_is_near_scrollbar(); 339 return GetScrollbarAnimationController(orientation)
340 .mouse_is_near_scrollbar_track();
348 } 341 }
349 342
350 bool ScrollbarAnimationController::MouseIsNearAnyScrollbar() const { 343 bool ScrollbarAnimationController::MouseIsNearAnyScrollbar() const {
351 DCHECK(need_thinning_animation_); 344 DCHECK(need_thinning_animation_);
352 return vertical_controller_->mouse_is_near_scrollbar() || 345 return vertical_controller_->mouse_is_near_scrollbar_track() ||
353 horizontal_controller_->mouse_is_near_scrollbar(); 346 horizontal_controller_->mouse_is_near_scrollbar_track();
354 } 347 }
355 348
356 bool ScrollbarAnimationController::ScrollbarsHidden() const { 349 bool ScrollbarAnimationController::ScrollbarsHidden() const {
357 return opacity_ == 0.0f; 350 return opacity_ == 0.0f;
358 } 351 }
359 352
360 bool ScrollbarAnimationController::Captured() const { 353 bool ScrollbarAnimationController::Captured() const {
361 DCHECK(need_thinning_animation_); 354 DCHECK(need_thinning_animation_);
362 return vertical_controller_->captured() || horizontal_controller_->captured(); 355 return GetScrollbarAnimationController(VERTICAL).captured() ||
356 GetScrollbarAnimationController(HORIZONTAL).captured();
363 } 357 }
364 358
365 void ScrollbarAnimationController::Show() { 359 void ScrollbarAnimationController::Show() {
366 delayed_scrollbar_animation_.Cancel(); 360 delayed_scrollbar_animation_.Cancel();
367 ApplyOpacityToScrollbars(1.0f); 361 ApplyOpacityToScrollbars(1.0f);
368 } 362 }
369 363
370 void ScrollbarAnimationController::ApplyOpacityToScrollbars(float opacity) { 364 void ScrollbarAnimationController::ApplyOpacityToScrollbars(float opacity) {
371 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { 365 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) {
372 if (!scrollbar->is_overlay_scrollbar()) 366 if (!scrollbar->is_overlay_scrollbar())
373 continue; 367 continue;
374 float effective_opacity = scrollbar->CanScrollOrientation() ? opacity : 0; 368 float effective_opacity = scrollbar->CanScrollOrientation() ? opacity : 0;
375 scrollbar->SetOverlayScrollbarLayerOpacityAnimated(effective_opacity); 369 scrollbar->SetOverlayScrollbarLayerOpacityAnimated(effective_opacity);
376 } 370 }
377 371
378 bool previouslyVisible = opacity_ > 0.0f; 372 bool previouslyVisible = opacity_ > 0.0f;
379 bool currentlyVisible = opacity > 0.0f; 373 bool currentlyVisible = opacity > 0.0f;
380 374
381 if (opacity_ != opacity) 375 if (opacity_ != opacity)
382 client_->SetNeedsRedrawForScrollbarAnimation(); 376 client_->SetNeedsRedrawForScrollbarAnimation();
383 377
384 opacity_ = opacity; 378 opacity_ = opacity;
385 379
386 if (previouslyVisible != currentlyVisible) 380 if (previouslyVisible != currentlyVisible)
387 client_->DidChangeScrollbarVisibility(); 381 client_->DidChangeScrollbarVisibility();
388 } 382 }
389 383
390 } // namespace cc 384 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698