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

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

Issue 2838053002: Remove resize fade delay plumbing. (Closed)
Patch Set: rebase 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"
11 11
12 namespace cc { 12 namespace cc {
13 13
14 std::unique_ptr<ScrollbarAnimationController> 14 std::unique_ptr<ScrollbarAnimationController>
15 ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid( 15 ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid(
16 ElementId scroll_element_id, 16 ElementId scroll_element_id,
17 ScrollbarAnimationControllerClient* client, 17 ScrollbarAnimationControllerClient* client,
18 base::TimeDelta fade_delay, 18 base::TimeDelta fade_delay,
19 base::TimeDelta fade_out_resize_delay,
20 base::TimeDelta fade_duration) { 19 base::TimeDelta fade_duration) {
21 return base::WrapUnique( 20 return base::WrapUnique(new ScrollbarAnimationController(
22 new ScrollbarAnimationController(scroll_element_id, client, fade_delay, 21 scroll_element_id, client, fade_delay, fade_duration));
23 fade_out_resize_delay, fade_duration));
24 } 22 }
25 23
26 std::unique_ptr<ScrollbarAnimationController> 24 std::unique_ptr<ScrollbarAnimationController>
27 ScrollbarAnimationController::CreateScrollbarAnimationControllerAuraOverlay( 25 ScrollbarAnimationController::CreateScrollbarAnimationControllerAuraOverlay(
28 ElementId scroll_element_id, 26 ElementId scroll_element_id,
29 ScrollbarAnimationControllerClient* client, 27 ScrollbarAnimationControllerClient* client,
30 base::TimeDelta fade_delay, 28 base::TimeDelta fade_delay,
31 base::TimeDelta fade_out_resize_delay,
32 base::TimeDelta fade_duration, 29 base::TimeDelta fade_duration,
33 base::TimeDelta thinning_duration) { 30 base::TimeDelta thinning_duration) {
34 return base::WrapUnique(new ScrollbarAnimationController( 31 return base::WrapUnique(new ScrollbarAnimationController(
35 scroll_element_id, client, fade_delay, fade_out_resize_delay, 32 scroll_element_id, client, fade_delay, fade_duration, thinning_duration));
36 fade_duration, thinning_duration));
37 } 33 }
38 34
39 ScrollbarAnimationController::ScrollbarAnimationController( 35 ScrollbarAnimationController::ScrollbarAnimationController(
40 ElementId scroll_element_id, 36 ElementId scroll_element_id,
41 ScrollbarAnimationControllerClient* client, 37 ScrollbarAnimationControllerClient* client,
42 base::TimeDelta fade_delay, 38 base::TimeDelta fade_delay,
43 base::TimeDelta fade_out_resize_delay,
44 base::TimeDelta fade_duration) 39 base::TimeDelta fade_duration)
45 : client_(client), 40 : client_(client),
46 fade_delay_(fade_delay), 41 fade_delay_(fade_delay),
47 fade_out_resize_delay_(fade_out_resize_delay),
48 fade_duration_(fade_duration), 42 fade_duration_(fade_duration),
49 need_trigger_scrollbar_show_(false), 43 need_trigger_scrollbar_show_(false),
50 is_animating_(false), 44 is_animating_(false),
51 animation_change_(NONE), 45 animation_change_(NONE),
52 scroll_element_id_(scroll_element_id), 46 scroll_element_id_(scroll_element_id),
53 currently_scrolling_(false), 47 currently_scrolling_(false),
54 show_in_fast_scroll_(false), 48 show_in_fast_scroll_(false),
55 opacity_(0.0f), 49 opacity_(0.0f),
56 show_scrollbars_on_scroll_gesture_(false), 50 show_scrollbars_on_scroll_gesture_(false),
57 need_thinning_animation_(false), 51 need_thinning_animation_(false),
58 weak_factory_(this) { 52 weak_factory_(this) {
59 ApplyOpacityToScrollbars(0.0f); 53 ApplyOpacityToScrollbars(0.0f);
60 } 54 }
61 55
62 ScrollbarAnimationController::ScrollbarAnimationController( 56 ScrollbarAnimationController::ScrollbarAnimationController(
63 ElementId scroll_element_id, 57 ElementId scroll_element_id,
64 ScrollbarAnimationControllerClient* client, 58 ScrollbarAnimationControllerClient* client,
65 base::TimeDelta fade_delay, 59 base::TimeDelta fade_delay,
66 base::TimeDelta fade_out_resize_delay,
67 base::TimeDelta fade_duration, 60 base::TimeDelta fade_duration,
68 base::TimeDelta thinning_duration) 61 base::TimeDelta thinning_duration)
69 : client_(client), 62 : client_(client),
70 fade_delay_(fade_delay), 63 fade_delay_(fade_delay),
71 fade_out_resize_delay_(fade_out_resize_delay),
72 fade_duration_(fade_duration), 64 fade_duration_(fade_duration),
73 need_trigger_scrollbar_show_(false), 65 need_trigger_scrollbar_show_(false),
74 is_animating_(false), 66 is_animating_(false),
75 animation_change_(NONE), 67 animation_change_(NONE),
76 scroll_element_id_(scroll_element_id), 68 scroll_element_id_(scroll_element_id),
77 currently_scrolling_(false), 69 currently_scrolling_(false),
78 show_in_fast_scroll_(false), 70 show_in_fast_scroll_(false),
79 opacity_(0.0f), 71 opacity_(0.0f),
80 show_scrollbars_on_scroll_gesture_(true), 72 show_scrollbars_on_scroll_gesture_(true),
81 need_thinning_animation_(true), 73 need_thinning_animation_(true),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 client_->SetNeedsAnimateForScrollbarAnimation(); 105 client_->SetNeedsAnimateForScrollbarAnimation();
114 } 106 }
115 107
116 void ScrollbarAnimationController::StopAnimation() { 108 void ScrollbarAnimationController::StopAnimation() {
117 delayed_scrollbar_animation_.Cancel(); 109 delayed_scrollbar_animation_.Cancel();
118 is_animating_ = false; 110 is_animating_ = false;
119 animation_change_ = NONE; 111 animation_change_ = NONE;
120 } 112 }
121 113
122 void ScrollbarAnimationController::PostDelayedAnimation( 114 void ScrollbarAnimationController::PostDelayedAnimation(
123 AnimationChange animation_change, 115 AnimationChange animation_change) {
124 bool on_resize) {
125 animation_change_ = animation_change; 116 animation_change_ = animation_change;
126
127 base::TimeDelta delay = on_resize ? fade_out_resize_delay_ : fade_delay_;
128
129 delayed_scrollbar_animation_.Cancel(); 117 delayed_scrollbar_animation_.Cancel();
130 delayed_scrollbar_animation_.Reset( 118 delayed_scrollbar_animation_.Reset(
131 base::Bind(&ScrollbarAnimationController::StartAnimation, 119 base::Bind(&ScrollbarAnimationController::StartAnimation,
132 weak_factory_.GetWeakPtr())); 120 weak_factory_.GetWeakPtr()));
133 client_->PostDelayedScrollbarAnimationTask( 121 client_->PostDelayedScrollbarAnimationTask(
134 delayed_scrollbar_animation_.callback(), delay); 122 delayed_scrollbar_animation_.callback(), fade_delay_);
135 } 123 }
136 124
137 bool ScrollbarAnimationController::Animate(base::TimeTicks now) { 125 bool ScrollbarAnimationController::Animate(base::TimeTicks now) {
138 bool animated = false; 126 bool animated = false;
139 127
140 if (is_animating_) { 128 if (is_animating_) {
141 DCHECK(animation_change_ != NONE); 129 DCHECK(animation_change_ != NONE);
142 if (last_awaken_time_.is_null()) 130 if (last_awaken_time_.is_null())
143 last_awaken_time_ = now; 131 last_awaken_time_ = now;
144 132
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 show_in_fast_scroll_ = false; 177 show_in_fast_scroll_ = false;
190 178
191 currently_scrolling_ = false; 179 currently_scrolling_ = false;
192 180
193 // We don't fade out scrollbar if they need thinning animation and mouse is 181 // We don't fade out scrollbar if they need thinning animation and mouse is
194 // near. 182 // near.
195 if (need_thinning_animation_ && MouseIsNearAnyScrollbar()) 183 if (need_thinning_animation_ && MouseIsNearAnyScrollbar())
196 return; 184 return;
197 185
198 if (has_scrolled) 186 if (has_scrolled)
199 PostDelayedAnimation(FADE_OUT, false); 187 PostDelayedAnimation(FADE_OUT);
200 } 188 }
201 189
202 void ScrollbarAnimationController::DidScrollUpdate() { 190 void ScrollbarAnimationController::DidScrollUpdate() {
203 if (need_thinning_animation_ && Captured()) 191 if (need_thinning_animation_ && Captured())
204 return; 192 return;
205 193
206 StopAnimation(); 194 StopAnimation();
207 195
208 Show(); 196 Show();
209 197
210 // As an optimization, we avoid spamming fade delay tasks during active fast 198 // As an optimization, we avoid spamming fade delay tasks during active fast
211 // scrolls. But if we're not within one, we need to post every scroll update. 199 // scrolls. But if we're not within one, we need to post every scroll update.
212 if (!currently_scrolling_) { 200 if (!currently_scrolling_) {
213 // We don't fade out scrollbar if they need thinning animation and mouse is 201 // We don't fade out scrollbar if they need thinning animation and mouse is
214 // near. 202 // near.
215 if (!need_thinning_animation_ || !MouseIsNearAnyScrollbar()) 203 if (!need_thinning_animation_ || !MouseIsNearAnyScrollbar())
216 PostDelayedAnimation(FADE_OUT, false); 204 PostDelayedAnimation(FADE_OUT);
217 } else { 205 } else {
218 show_in_fast_scroll_ = true; 206 show_in_fast_scroll_ = true;
219 } 207 }
220 208
221 if (need_thinning_animation_) { 209 if (need_thinning_animation_) {
222 vertical_controller_->UpdateThumbThicknessScale(); 210 vertical_controller_->UpdateThumbThicknessScale();
223 horizontal_controller_->UpdateThumbThicknessScale(); 211 horizontal_controller_->UpdateThumbThicknessScale();
224 } 212 }
225 } 213 }
226 214
227 void ScrollbarAnimationController::WillUpdateScroll() { 215 void ScrollbarAnimationController::WillUpdateScroll() {
228 if (show_scrollbars_on_scroll_gesture_) 216 if (show_scrollbars_on_scroll_gesture_)
229 DidScrollUpdate(); 217 DidScrollUpdate();
230 } 218 }
231 219
232 void ScrollbarAnimationController::DidRequestShowFromMainThread() { 220 void ScrollbarAnimationController::DidRequestShowFromMainThread() {
233 DidScrollUpdate(); 221 DidScrollUpdate();
234 } 222 }
235 223
236 void ScrollbarAnimationController::DidResize() {
237 StopAnimation();
238 Show();
239
240 // As an optimization, we avoid spamming fade delay tasks during active fast
241 // scrolls.
242 if (!currently_scrolling_) {
243 PostDelayedAnimation(FADE_OUT, true);
244 } else {
245 show_in_fast_scroll_ = true;
246 }
247 }
248
249 void ScrollbarAnimationController::DidMouseDown() { 224 void ScrollbarAnimationController::DidMouseDown() {
250 if (!need_thinning_animation_ || ScrollbarsHidden()) 225 if (!need_thinning_animation_ || ScrollbarsHidden())
251 return; 226 return;
252 227
253 vertical_controller_->DidMouseDown(); 228 vertical_controller_->DidMouseDown();
254 horizontal_controller_->DidMouseDown(); 229 horizontal_controller_->DidMouseDown();
255 } 230 }
256 231
257 void ScrollbarAnimationController::DidMouseUp() { 232 void ScrollbarAnimationController::DidMouseUp() {
258 if (!need_thinning_animation_ || !Captured()) 233 if (!need_thinning_animation_ || !Captured())
259 return; 234 return;
260 235
261 vertical_controller_->DidMouseUp(); 236 vertical_controller_->DidMouseUp();
262 horizontal_controller_->DidMouseUp(); 237 horizontal_controller_->DidMouseUp();
263 238
264 if (!MouseIsNearAnyScrollbar()) 239 if (!MouseIsNearAnyScrollbar())
265 PostDelayedAnimation(FADE_OUT, false); 240 PostDelayedAnimation(FADE_OUT);
266 } 241 }
267 242
268 void ScrollbarAnimationController::DidMouseLeave() { 243 void ScrollbarAnimationController::DidMouseLeave() {
269 if (!need_thinning_animation_) 244 if (!need_thinning_animation_)
270 return; 245 return;
271 246
272 vertical_controller_->DidMouseLeave(); 247 vertical_controller_->DidMouseLeave();
273 horizontal_controller_->DidMouseLeave(); 248 horizontal_controller_->DidMouseLeave();
274 249
275 delayed_scrollbar_animation_.Cancel(); 250 delayed_scrollbar_animation_.Cancel();
276 need_trigger_scrollbar_show_ = false; 251 need_trigger_scrollbar_show_ = false;
277 252
278 if (ScrollbarsHidden() || Captured()) 253 if (ScrollbarsHidden() || Captured())
279 return; 254 return;
280 255
281 PostDelayedAnimation(FADE_OUT, false); 256 PostDelayedAnimation(FADE_OUT);
282 } 257 }
283 258
284 void ScrollbarAnimationController::DidMouseMoveNear( 259 void ScrollbarAnimationController::DidMouseMoveNear(
285 ScrollbarOrientation orientation, 260 ScrollbarOrientation orientation,
286 float distance) { 261 float distance) {
287 if (!need_thinning_animation_) 262 if (!need_thinning_animation_)
288 return; 263 return;
289 264
290 bool need_trigger_scrollbar_show_before = need_trigger_scrollbar_show_; 265 bool need_trigger_scrollbar_show_before = need_trigger_scrollbar_show_;
291 266
292 GetScrollbarAnimationController(orientation).DidMouseMoveNear(distance); 267 GetScrollbarAnimationController(orientation).DidMouseMoveNear(distance);
293 268
294 need_trigger_scrollbar_show_ = 269 need_trigger_scrollbar_show_ =
295 CalcNeedTriggerScrollbarShow(orientation, distance); 270 CalcNeedTriggerScrollbarShow(orientation, distance);
296 271
297 if (Captured()) 272 if (Captured())
298 return; 273 return;
299 274
300 if (ScrollbarsHidden()) { 275 if (ScrollbarsHidden()) {
301 if (need_trigger_scrollbar_show_before != need_trigger_scrollbar_show_) { 276 if (need_trigger_scrollbar_show_before != need_trigger_scrollbar_show_) {
302 if (need_trigger_scrollbar_show_) { 277 if (need_trigger_scrollbar_show_) {
303 PostDelayedAnimation(FADE_IN, false); 278 PostDelayedAnimation(FADE_IN);
304 } else { 279 } else {
305 delayed_scrollbar_animation_.Cancel(); 280 delayed_scrollbar_animation_.Cancel();
306 } 281 }
307 } 282 }
308 } else { 283 } else {
309 if (MouseIsNearAnyScrollbar()) { 284 if (MouseIsNearAnyScrollbar()) {
310 Show(); 285 Show();
311 StopAnimation(); 286 StopAnimation();
312 } else if (!is_animating_) { 287 } else if (!is_animating_) {
313 PostDelayedAnimation(FADE_OUT, false); 288 PostDelayedAnimation(FADE_OUT);
314 } 289 }
315 } 290 }
316 } 291 }
317 292
318 bool ScrollbarAnimationController::CalcNeedTriggerScrollbarShow( 293 bool ScrollbarAnimationController::CalcNeedTriggerScrollbarShow(
319 ScrollbarOrientation orientation, 294 ScrollbarOrientation orientation,
320 float distance) const { 295 float distance) const {
321 DCHECK(need_thinning_animation_); 296 DCHECK(need_thinning_animation_);
322 297
323 if (vertical_controller_->mouse_is_over_scrollbar() || 298 if (vertical_controller_->mouse_is_over_scrollbar() ||
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 if (opacity_ != opacity) 356 if (opacity_ != opacity)
382 client_->SetNeedsRedrawForScrollbarAnimation(); 357 client_->SetNeedsRedrawForScrollbarAnimation();
383 358
384 opacity_ = opacity; 359 opacity_ = opacity;
385 360
386 if (previouslyVisible != currentlyVisible) 361 if (previouslyVisible != currentlyVisible)
387 client_->DidChangeScrollbarVisibility(); 362 client_->DidChangeScrollbarVisibility();
388 } 363 }
389 364
390 } // namespace cc 365 } // 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