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

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

Issue 2931703002: Don't fade in overlay scrollbar when user interacting the content under scrollbar. (Closed)
Patch Set: bokan comments addressed Created 3 years, 6 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 fade_duration_(fade_duration), 46 fade_duration_(fade_duration),
47 need_trigger_scrollbar_fade_in_(false), 47 need_trigger_scrollbar_fade_in_(false),
48 is_animating_(false), 48 is_animating_(false),
49 animation_change_(NONE), 49 animation_change_(NONE),
50 scroll_element_id_(scroll_element_id), 50 scroll_element_id_(scroll_element_id),
51 currently_scrolling_(false), 51 currently_scrolling_(false),
52 show_in_fast_scroll_(false), 52 show_in_fast_scroll_(false),
53 opacity_(initial_opacity), 53 opacity_(initial_opacity),
54 show_scrollbars_on_scroll_gesture_(false), 54 show_scrollbars_on_scroll_gesture_(false),
55 need_thinning_animation_(false), 55 need_thinning_animation_(false),
56 is_mouse_down_(false),
56 weak_factory_(this) {} 57 weak_factory_(this) {}
57 58
58 ScrollbarAnimationController::ScrollbarAnimationController( 59 ScrollbarAnimationController::ScrollbarAnimationController(
59 ElementId scroll_element_id, 60 ElementId scroll_element_id,
60 ScrollbarAnimationControllerClient* client, 61 ScrollbarAnimationControllerClient* client,
61 base::TimeDelta fade_delay, 62 base::TimeDelta fade_delay,
62 base::TimeDelta fade_duration, 63 base::TimeDelta fade_duration,
63 base::TimeDelta thinning_duration, 64 base::TimeDelta thinning_duration,
64 float initial_opacity) 65 float initial_opacity)
65 : client_(client), 66 : client_(client),
66 fade_delay_(fade_delay), 67 fade_delay_(fade_delay),
67 fade_duration_(fade_duration), 68 fade_duration_(fade_duration),
68 need_trigger_scrollbar_fade_in_(false), 69 need_trigger_scrollbar_fade_in_(false),
69 is_animating_(false), 70 is_animating_(false),
70 animation_change_(NONE), 71 animation_change_(NONE),
71 scroll_element_id_(scroll_element_id), 72 scroll_element_id_(scroll_element_id),
72 currently_scrolling_(false), 73 currently_scrolling_(false),
73 show_in_fast_scroll_(false), 74 show_in_fast_scroll_(false),
74 opacity_(initial_opacity), 75 opacity_(initial_opacity),
75 show_scrollbars_on_scroll_gesture_(true), 76 show_scrollbars_on_scroll_gesture_(true),
76 need_thinning_animation_(true), 77 need_thinning_animation_(true),
78 is_mouse_down_(false),
77 weak_factory_(this) { 79 weak_factory_(this) {
78 vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create( 80 vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create(
79 scroll_element_id, ScrollbarOrientation::VERTICAL, client, 81 scroll_element_id, ScrollbarOrientation::VERTICAL, client,
80 thinning_duration); 82 thinning_duration);
81 horizontal_controller_ = SingleScrollbarAnimationControllerThinning::Create( 83 horizontal_controller_ = SingleScrollbarAnimationControllerThinning::Create(
82 scroll_element_id, ScrollbarOrientation::HORIZONTAL, client, 84 scroll_element_id, ScrollbarOrientation::HORIZONTAL, client,
83 thinning_duration); 85 thinning_duration);
84 } 86 }
85 87
86 ScrollbarAnimationController::~ScrollbarAnimationController() {} 88 ScrollbarAnimationController::~ScrollbarAnimationController() {}
87 89
88 ScrollbarSet ScrollbarAnimationController::Scrollbars() const { 90 ScrollbarSet ScrollbarAnimationController::Scrollbars() const {
89 return client_->ScrollbarsFor(scroll_element_id_); 91 return client_->ScrollbarsFor(scroll_element_id_);
90 } 92 }
91 93
92 SingleScrollbarAnimationControllerThinning& 94 SingleScrollbarAnimationControllerThinning&
93 ScrollbarAnimationController::GetScrollbarAnimationController( 95 ScrollbarAnimationController::GetScrollbarAnimationController(
94 ScrollbarOrientation orientation) const { 96 ScrollbarOrientation orientation) const {
95 DCHECK(need_thinning_animation_); 97 DCHECK(need_thinning_animation_);
96 if (orientation == ScrollbarOrientation::VERTICAL) 98 if (orientation == ScrollbarOrientation::VERTICAL)
97 return *(vertical_controller_.get()); 99 return *(vertical_controller_.get());
98 else 100 else
99 return *(horizontal_controller_.get()); 101 return *(horizontal_controller_.get());
100 } 102 }
101 103
102 void ScrollbarAnimationController::StartAnimation() { 104 void ScrollbarAnimationController::StartAnimation() {
103 DCHECK(animation_change_ != NONE); 105 DCHECK(animation_change_ != NONE);
104 delayed_scrollbar_animation_.Cancel(); 106 delayed_scrollbar_animation_.Cancel();
107 need_trigger_scrollbar_fade_in_ = false;
105 is_animating_ = true; 108 is_animating_ = true;
106 last_awaken_time_ = base::TimeTicks(); 109 last_awaken_time_ = base::TimeTicks();
107 client_->SetNeedsAnimateForScrollbarAnimation(); 110 client_->SetNeedsAnimateForScrollbarAnimation();
108 } 111 }
109 112
110 void ScrollbarAnimationController::StopAnimation() { 113 void ScrollbarAnimationController::StopAnimation() {
111 delayed_scrollbar_animation_.Cancel(); 114 delayed_scrollbar_animation_.Cancel();
115 need_trigger_scrollbar_fade_in_ = false;
112 is_animating_ = false; 116 is_animating_ = false;
113 animation_change_ = NONE; 117 animation_change_ = NONE;
114 } 118 }
115 119
116 void ScrollbarAnimationController::PostDelayedAnimation( 120 void ScrollbarAnimationController::PostDelayedAnimation(
117 AnimationChange animation_change) { 121 AnimationChange animation_change) {
118 animation_change_ = animation_change; 122 animation_change_ = animation_change;
119 delayed_scrollbar_animation_.Cancel(); 123 delayed_scrollbar_animation_.Cancel();
120 delayed_scrollbar_animation_.Reset( 124 delayed_scrollbar_animation_.Reset(
121 base::Bind(&ScrollbarAnimationController::StartAnimation, 125 base::Bind(&ScrollbarAnimationController::StartAnimation,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 void ScrollbarAnimationController::WillUpdateScroll() { 221 void ScrollbarAnimationController::WillUpdateScroll() {
218 if (show_scrollbars_on_scroll_gesture_) 222 if (show_scrollbars_on_scroll_gesture_)
219 DidScrollUpdate(); 223 DidScrollUpdate();
220 } 224 }
221 225
222 void ScrollbarAnimationController::DidRequestShowFromMainThread() { 226 void ScrollbarAnimationController::DidRequestShowFromMainThread() {
223 DidScrollUpdate(); 227 DidScrollUpdate();
224 } 228 }
225 229
226 void ScrollbarAnimationController::DidMouseDown() { 230 void ScrollbarAnimationController::DidMouseDown() {
227 if (!need_thinning_animation_ || ScrollbarsHidden()) 231 if (!need_thinning_animation_)
228 return; 232 return;
229 233
234 is_mouse_down_ = true;
235
236 if (ScrollbarsHidden()) {
237 if (need_trigger_scrollbar_fade_in_) {
238 delayed_scrollbar_animation_.Cancel();
239 need_trigger_scrollbar_fade_in_ = false;
240 }
241 return;
242 }
243
230 vertical_controller_->DidMouseDown(); 244 vertical_controller_->DidMouseDown();
231 horizontal_controller_->DidMouseDown(); 245 horizontal_controller_->DidMouseDown();
232 } 246 }
233 247
234 void ScrollbarAnimationController::DidMouseUp() { 248 void ScrollbarAnimationController::DidMouseUp() {
235 if (!need_thinning_animation_ || !Captured()) 249 if (!need_thinning_animation_)
236 return; 250 return;
237 251
252 is_mouse_down_ = false;
253
254 if (!Captured()) {
255 if (MouseIsNearAnyScrollbar() && ScrollbarsHidden()) {
256 PostDelayedAnimation(FADE_IN);
257 need_trigger_scrollbar_fade_in_ = true;
258 }
259 return;
260 }
261
238 vertical_controller_->DidMouseUp(); 262 vertical_controller_->DidMouseUp();
239 horizontal_controller_->DidMouseUp(); 263 horizontal_controller_->DidMouseUp();
240 264
241 if (!MouseIsNearAnyScrollbar()) 265 if (!MouseIsNearAnyScrollbar() && !ScrollbarsHidden())
242 PostDelayedAnimation(FADE_OUT); 266 PostDelayedAnimation(FADE_OUT);
243 } 267 }
244 268
245 void ScrollbarAnimationController::DidMouseLeave() { 269 void ScrollbarAnimationController::DidMouseLeave() {
246 if (!need_thinning_animation_) 270 if (!need_thinning_animation_)
247 return; 271 return;
248 272
249 vertical_controller_->DidMouseLeave(); 273 vertical_controller_->DidMouseLeave();
250 horizontal_controller_->DidMouseLeave(); 274 horizontal_controller_->DidMouseLeave();
251 275
252 delayed_scrollbar_animation_.Cancel(); 276 delayed_scrollbar_animation_.Cancel();
253 need_trigger_scrollbar_fade_in_ = false; 277 need_trigger_scrollbar_fade_in_ = false;
254 278
255 if (ScrollbarsHidden() || Captured()) 279 if (ScrollbarsHidden() || Captured())
256 return; 280 return;
257 281
258 PostDelayedAnimation(FADE_OUT); 282 PostDelayedAnimation(FADE_OUT);
259 } 283 }
260 284
261 void ScrollbarAnimationController::DidMouseMove( 285 void ScrollbarAnimationController::DidMouseMove(
262 const gfx::PointF& device_viewport_point) { 286 const gfx::PointF& device_viewport_point) {
263 if (!need_thinning_animation_) 287 if (!need_thinning_animation_)
264 return; 288 return;
265 289
266 bool need_trigger_scrollbar_fade_in_before = need_trigger_scrollbar_fade_in_; 290 bool need_trigger_scrollbar_fade_in_before = need_trigger_scrollbar_fade_in_;
267 291
268 vertical_controller_->DidMouseMove(device_viewport_point); 292 vertical_controller_->DidMouseMove(device_viewport_point);
269 horizontal_controller_->DidMouseMove(device_viewport_point); 293 horizontal_controller_->DidMouseMove(device_viewport_point);
270 294
271 need_trigger_scrollbar_fade_in_ = MouseIsNearAnyScrollbar(); 295 if (Captured()) {
272 296 DCHECK(!ScrollbarsHidden());
273 if (Captured())
274 return; 297 return;
298 }
275 299
276 if (ScrollbarsHidden()) { 300 if (ScrollbarsHidden()) {
301 // Do not fade in scrollbar when user interacting with the content below
302 // scrollbar.
303 if (is_mouse_down_)
304 return;
305 need_trigger_scrollbar_fade_in_ = MouseIsNearAnyScrollbar();
277 if (need_trigger_scrollbar_fade_in_before != 306 if (need_trigger_scrollbar_fade_in_before !=
278 need_trigger_scrollbar_fade_in_) { 307 need_trigger_scrollbar_fade_in_) {
279 if (need_trigger_scrollbar_fade_in_) { 308 if (need_trigger_scrollbar_fade_in_) {
280 PostDelayedAnimation(FADE_IN); 309 PostDelayedAnimation(FADE_IN);
281 } else { 310 } else {
282 delayed_scrollbar_animation_.Cancel(); 311 delayed_scrollbar_animation_.Cancel();
283 } 312 }
284 } 313 }
285 } else { 314 } else {
286 if (MouseIsNearAnyScrollbar()) { 315 if (MouseIsNearAnyScrollbar()) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 if (opacity_ != opacity) 376 if (opacity_ != opacity)
348 client_->SetNeedsRedrawForScrollbarAnimation(); 377 client_->SetNeedsRedrawForScrollbarAnimation();
349 378
350 opacity_ = opacity; 379 opacity_ = opacity;
351 380
352 if (previouslyVisible != currentlyVisible) 381 if (previouslyVisible != currentlyVisible)
353 client_->DidChangeScrollbarVisibility(); 382 client_->DidChangeScrollbarVisibility();
354 } 383 }
355 384
356 } // namespace cc 385 } // namespace cc
OLDNEW
« no previous file with comments | « cc/input/scrollbar_animation_controller.h ('k') | cc/input/scrollbar_animation_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698