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

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

Issue 2816923002: change overlay scrollbar hover show to hover fade in (Closed)
Patch Set: merge fade-in and fade-out to same code method Created 3 years, 8 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 int scroll_layer_id, 16 int scroll_layer_id,
17 ScrollbarAnimationControllerClient* client, 17 ScrollbarAnimationControllerClient* client,
18 base::TimeDelta fade_out_delay, 18 base::TimeDelta fade_out_delay,
19 base::TimeDelta fade_out_resize_delay, 19 base::TimeDelta fade_out_resize_delay,
20 base::TimeDelta fade_out_duration) { 20 base::TimeDelta fade_out_duration) {
21 return base::WrapUnique(new ScrollbarAnimationController( 21 return base::WrapUnique(new ScrollbarAnimationController(
22 scroll_layer_id, client, fade_out_delay, fade_out_resize_delay, 22 scroll_layer_id, client, fade_out_delay, fade_out_resize_delay,
23 fade_out_duration)); 23 fade_out_duration));
24 } 24 }
25 25
26 std::unique_ptr<ScrollbarAnimationController> 26 std::unique_ptr<ScrollbarAnimationController>
27 ScrollbarAnimationController::CreateScrollbarAnimationControllerAuraOverlay( 27 ScrollbarAnimationController::CreateScrollbarAnimationControllerAuraOverlay(
28 int scroll_layer_id, 28 int scroll_layer_id,
29 ScrollbarAnimationControllerClient* client, 29 ScrollbarAnimationControllerClient* client,
30 base::TimeDelta show_delay, 30 base::TimeDelta fade_in_delay,
31 base::TimeDelta fade_out_delay, 31 base::TimeDelta fade_out_delay,
32 base::TimeDelta fade_out_resize_delay, 32 base::TimeDelta fade_out_resize_delay,
33 base::TimeDelta fade_in_duration,
33 base::TimeDelta fade_out_duration, 34 base::TimeDelta fade_out_duration,
34 base::TimeDelta thinning_duration) { 35 base::TimeDelta thinning_duration) {
35 return base::WrapUnique(new ScrollbarAnimationController( 36 return base::WrapUnique(new ScrollbarAnimationController(
36 scroll_layer_id, client, show_delay, fade_out_delay, 37 scroll_layer_id, client, fade_in_delay, fade_out_delay,
37 fade_out_resize_delay, fade_out_duration, thinning_duration)); 38 fade_out_resize_delay, fade_in_duration, fade_out_duration,
39 thinning_duration));
38 } 40 }
39 41
40 ScrollbarAnimationController::ScrollbarAnimationController( 42 ScrollbarAnimationController::ScrollbarAnimationController(
41 int scroll_layer_id, 43 int scroll_layer_id,
42 ScrollbarAnimationControllerClient* client, 44 ScrollbarAnimationControllerClient* client,
43 base::TimeDelta fade_out_delay, 45 base::TimeDelta fade_out_delay,
44 base::TimeDelta fade_out_resize_delay, 46 base::TimeDelta fade_out_resize_delay,
45 base::TimeDelta fade_out_duration) 47 base::TimeDelta fade_out_duration)
46 : client_(client), 48 : client_(client),
47 fade_out_delay_(fade_out_delay), 49 fade_out_delay_(fade_out_delay),
48 fade_out_resize_delay_(fade_out_resize_delay), 50 fade_out_resize_delay_(fade_out_resize_delay),
51 fade_out_duration_(fade_out_duration),
49 need_trigger_scrollbar_show_(false), 52 need_trigger_scrollbar_show_(false),
50 is_animating_(false), 53 is_animating_(false),
54 animation_change_(NONE),
51 scroll_layer_id_(scroll_layer_id), 55 scroll_layer_id_(scroll_layer_id),
52 currently_scrolling_(false), 56 currently_scrolling_(false),
53 show_in_fast_scroll_(false), 57 show_in_fast_scroll_(false),
54 opacity_(0.0f), 58 opacity_(0.0f),
55 fade_out_duration_(fade_out_duration),
56 show_scrollbars_on_scroll_gesture_(false), 59 show_scrollbars_on_scroll_gesture_(false),
57 need_thinning_animation_(false), 60 need_thinning_animation_(false),
58 weak_factory_(this) { 61 weak_factory_(this) {
59 ApplyOpacityToScrollbars(0.0f); 62 ApplyOpacityToScrollbars(0.0f);
60 } 63 }
61 64
62 ScrollbarAnimationController::ScrollbarAnimationController( 65 ScrollbarAnimationController::ScrollbarAnimationController(
63 int scroll_layer_id, 66 int scroll_layer_id,
64 ScrollbarAnimationControllerClient* client, 67 ScrollbarAnimationControllerClient* client,
65 base::TimeDelta show_delay, 68 base::TimeDelta fade_in_delay,
66 base::TimeDelta fade_out_delay, 69 base::TimeDelta fade_out_delay,
67 base::TimeDelta fade_out_resize_delay, 70 base::TimeDelta fade_out_resize_delay,
71 base::TimeDelta fade_in_duration,
68 base::TimeDelta fade_out_duration, 72 base::TimeDelta fade_out_duration,
69 base::TimeDelta thinning_duration) 73 base::TimeDelta thinning_duration)
70 : client_(client), 74 : client_(client),
71 show_delay_(show_delay), 75 fade_in_delay_(fade_in_delay),
72 fade_out_delay_(fade_out_delay), 76 fade_out_delay_(fade_out_delay),
73 fade_out_resize_delay_(fade_out_resize_delay), 77 fade_out_resize_delay_(fade_out_resize_delay),
78 fade_in_duration_(fade_in_duration),
79 fade_out_duration_(fade_out_duration),
74 need_trigger_scrollbar_show_(false), 80 need_trigger_scrollbar_show_(false),
75 is_animating_(false), 81 is_animating_(false),
82 animation_change_(NONE),
76 scroll_layer_id_(scroll_layer_id), 83 scroll_layer_id_(scroll_layer_id),
77 currently_scrolling_(false), 84 currently_scrolling_(false),
78 show_in_fast_scroll_(false), 85 show_in_fast_scroll_(false),
79 opacity_(0.0f), 86 opacity_(0.0f),
80 fade_out_duration_(fade_out_duration),
81 show_scrollbars_on_scroll_gesture_(true), 87 show_scrollbars_on_scroll_gesture_(true),
82 need_thinning_animation_(true), 88 need_thinning_animation_(true),
83 weak_factory_(this) { 89 weak_factory_(this) {
84 vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create( 90 vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create(
85 scroll_layer_id, ScrollbarOrientation::VERTICAL, client, 91 scroll_layer_id, ScrollbarOrientation::VERTICAL, client,
86 thinning_duration); 92 thinning_duration);
87 horizontal_controller_ = SingleScrollbarAnimationControllerThinning::Create( 93 horizontal_controller_ = SingleScrollbarAnimationControllerThinning::Create(
88 scroll_layer_id, ScrollbarOrientation::HORIZONTAL, client, 94 scroll_layer_id, ScrollbarOrientation::HORIZONTAL, client,
89 thinning_duration); 95 thinning_duration);
90 ApplyOpacityToScrollbars(0.0f); 96 ApplyOpacityToScrollbars(0.0f);
91 } 97 }
92 98
93 ScrollbarAnimationController::~ScrollbarAnimationController() {} 99 ScrollbarAnimationController::~ScrollbarAnimationController() {}
94 100
95 ScrollbarSet ScrollbarAnimationController::Scrollbars() const { 101 ScrollbarSet ScrollbarAnimationController::Scrollbars() const {
96 return client_->ScrollbarsFor(scroll_layer_id_); 102 return client_->ScrollbarsFor(scroll_layer_id_);
97 } 103 }
98 104
99 SingleScrollbarAnimationControllerThinning& 105 SingleScrollbarAnimationControllerThinning&
100 ScrollbarAnimationController::GetScrollbarAnimationController( 106 ScrollbarAnimationController::GetScrollbarAnimationController(
101 ScrollbarOrientation orientation) const { 107 ScrollbarOrientation orientation) const {
102 DCHECK(need_thinning_animation_); 108 DCHECK(need_thinning_animation_);
103 if (orientation == ScrollbarOrientation::VERTICAL) 109 if (orientation == ScrollbarOrientation::VERTICAL)
104 return *(vertical_controller_.get()); 110 return *(vertical_controller_.get());
105 else 111 else
106 return *(horizontal_controller_.get()); 112 return *(horizontal_controller_.get());
107 } 113 }
108 114
109 void ScrollbarAnimationController::StartAnimation() { 115 void ScrollbarAnimationController::StartAnimation() {
110 delayed_scrollbar_show_.Cancel(); 116 DCHECK(animation_change_ != NONE);
111 delayed_scrollbar_fade_out_.Cancel(); 117 delayed_scrollbar_animation_.Cancel();
112 is_animating_ = true; 118 is_animating_ = true;
113 last_awaken_time_ = base::TimeTicks(); 119 last_awaken_time_ = base::TimeTicks();
114 client_->SetNeedsAnimateForScrollbarAnimation(); 120 client_->SetNeedsAnimateForScrollbarAnimation();
115 } 121 }
116 122
117 void ScrollbarAnimationController::StopAnimation() { 123 void ScrollbarAnimationController::StopAnimation() {
118 delayed_scrollbar_show_.Cancel(); 124 delayed_scrollbar_animation_.Cancel();
119 delayed_scrollbar_fade_out_.Cancel();
120 is_animating_ = false; 125 is_animating_ = false;
126 animation_change_ = NONE;
121 } 127 }
122 128
123 void ScrollbarAnimationController::PostDelayedShow() { 129 void ScrollbarAnimationController::PostDelayedAnimation(
124 DCHECK(delayed_scrollbar_fade_out_.IsCancelled()); 130 AnimationChange animation_change,
125 delayed_scrollbar_show_.Cancel(); 131 bool on_resize) {
126 delayed_scrollbar_show_.Reset(base::Bind(&ScrollbarAnimationController::Show, 132 animation_change_ = animation_change;
127 weak_factory_.GetWeakPtr()));
128 client_->PostDelayedScrollbarAnimationTask(delayed_scrollbar_show_.callback(),
129 show_delay_);
130 }
131 133
132 void ScrollbarAnimationController::PostDelayedFadeOut(bool on_resize) { 134 base::TimeDelta delay;
133 DCHECK(delayed_scrollbar_show_.IsCancelled()); 135 if (animation_change == FADE_IN) {
134 base::TimeDelta delay = on_resize ? fade_out_resize_delay_ : fade_out_delay_; 136 delay = fade_in_delay_;
135 delayed_scrollbar_fade_out_.Cancel(); 137 } else {
136 delayed_scrollbar_fade_out_.Reset( 138 delay = on_resize ? fade_out_resize_delay_ : fade_out_delay_;
139 }
140
141 delayed_scrollbar_animation_.Cancel();
142 delayed_scrollbar_animation_.Reset(
137 base::Bind(&ScrollbarAnimationController::StartAnimation, 143 base::Bind(&ScrollbarAnimationController::StartAnimation,
138 weak_factory_.GetWeakPtr())); 144 weak_factory_.GetWeakPtr()));
139 client_->PostDelayedScrollbarAnimationTask( 145 client_->PostDelayedScrollbarAnimationTask(
140 delayed_scrollbar_fade_out_.callback(), delay); 146 delayed_scrollbar_animation_.callback(), delay);
141 } 147 }
142 148
143 bool ScrollbarAnimationController::Animate(base::TimeTicks now) { 149 bool ScrollbarAnimationController::Animate(base::TimeTicks now) {
144 bool animated = false; 150 bool animated = false;
145 151
146 if (is_animating_) { 152 if (is_animating_) {
153 DCHECK(animation_change_ != NONE);
147 if (last_awaken_time_.is_null()) 154 if (last_awaken_time_.is_null())
148 last_awaken_time_ = now; 155 last_awaken_time_ = now;
149 156
150 float progress = AnimationProgressAtTime(now); 157 float progress = AnimationProgressAtTime(now);
151 RunAnimationFrame(progress); 158 RunAnimationFrame(progress);
152 159
153 if (is_animating_) 160 if (is_animating_)
154 client_->SetNeedsAnimateForScrollbarAnimation(); 161 client_->SetNeedsAnimateForScrollbarAnimation();
155 animated = true; 162 animated = true;
156 } 163 }
157 164
158 if (need_thinning_animation_) { 165 if (need_thinning_animation_) {
159 animated |= vertical_controller_->Animate(now); 166 animated |= vertical_controller_->Animate(now);
160 animated |= horizontal_controller_->Animate(now); 167 animated |= horizontal_controller_->Animate(now);
161 } 168 }
162 169
163 return animated; 170 return animated;
164 } 171 }
165 172
166 float ScrollbarAnimationController::AnimationProgressAtTime( 173 float ScrollbarAnimationController::AnimationProgressAtTime(
167 base::TimeTicks now) { 174 base::TimeTicks now) {
168 base::TimeDelta delta = now - last_awaken_time_; 175 base::TimeDelta delta = now - last_awaken_time_;
169 float progress = delta.InSecondsF() / fade_out_duration_.InSecondsF(); 176 base::TimeDelta duration =
177 animation_change_ == FADE_IN ? fade_in_duration_ : fade_out_duration_;
178 float progress = delta.InSecondsF() / duration.InSecondsF();
170 return std::max(std::min(progress, 1.f), 0.f); 179 return std::max(std::min(progress, 1.f), 0.f);
171 } 180 }
172 181
173 void ScrollbarAnimationController::RunAnimationFrame(float progress) { 182 void ScrollbarAnimationController::RunAnimationFrame(float progress) {
174 ApplyOpacityToScrollbars(1.f - progress); 183 float opacity;
184
185 DCHECK(animation_change_ != NONE);
186 if (animation_change_ == FADE_IN) {
187 opacity = std::max(progress, opacity_);
188 } else {
189 opacity = std::min(1.f - progress, opacity_);
190 }
191
192 ApplyOpacityToScrollbars(opacity);
175 if (progress == 1.f) 193 if (progress == 1.f)
176 StopAnimation(); 194 StopAnimation();
177 } 195 }
178 196
179 void ScrollbarAnimationController::DidScrollBegin() { 197 void ScrollbarAnimationController::DidScrollBegin() {
180 currently_scrolling_ = true; 198 currently_scrolling_ = true;
181 } 199 }
182 200
183 void ScrollbarAnimationController::DidScrollEnd() { 201 void ScrollbarAnimationController::DidScrollEnd() {
184 bool has_scrolled = show_in_fast_scroll_; 202 bool has_scrolled = show_in_fast_scroll_;
185 show_in_fast_scroll_ = false; 203 show_in_fast_scroll_ = false;
186 204
187 currently_scrolling_ = false; 205 currently_scrolling_ = false;
188 206
189 // We don't fade out scrollbar if they need thinning animation and mouse is 207 // We don't fade out scrollbar if they need thinning animation and mouse is
190 // near. 208 // near.
191 if (need_thinning_animation_ && MouseIsNearAnyScrollbar()) 209 if (need_thinning_animation_ && MouseIsNearAnyScrollbar())
192 return; 210 return;
193 211
194 if (has_scrolled) 212 if (has_scrolled)
195 PostDelayedFadeOut(false); 213 PostDelayedAnimation(FADE_OUT, false);
196 } 214 }
197 215
198 void ScrollbarAnimationController::DidScrollUpdate() { 216 void ScrollbarAnimationController::DidScrollUpdate() {
199 if (need_thinning_animation_ && Captured()) 217 if (need_thinning_animation_ && Captured())
200 return; 218 return;
201 219
202 StopAnimation(); 220 StopAnimation();
203 221
222 Show();
223
204 // As an optimization, we avoid spamming fade delay tasks during active fast 224 // As an optimization, we avoid spamming fade delay tasks during active fast
205 // scrolls. But if we're not within one, we need to post every scroll update. 225 // scrolls. But if we're not within one, we need to post every scroll update.
206 if (!currently_scrolling_) { 226 if (!currently_scrolling_) {
207 // We don't fade out scrollbar if they need thinning animation and mouse is 227 // We don't fade out scrollbar if they need thinning animation and mouse is
208 // near. 228 // near.
209 if (!need_thinning_animation_ || !MouseIsNearAnyScrollbar()) 229 if (!need_thinning_animation_ || !MouseIsNearAnyScrollbar())
210 PostDelayedFadeOut(false); 230 PostDelayedAnimation(FADE_OUT, false);
211 } else { 231 } else {
212 show_in_fast_scroll_ = true; 232 show_in_fast_scroll_ = true;
213 } 233 }
214 234
215 Show();
216
217 if (need_thinning_animation_) { 235 if (need_thinning_animation_) {
218 vertical_controller_->UpdateThumbThicknessScale(); 236 vertical_controller_->UpdateThumbThicknessScale();
219 horizontal_controller_->UpdateThumbThicknessScale(); 237 horizontal_controller_->UpdateThumbThicknessScale();
220 } 238 }
221 } 239 }
222 240
223 void ScrollbarAnimationController::WillUpdateScroll() { 241 void ScrollbarAnimationController::WillUpdateScroll() {
224 if (show_scrollbars_on_scroll_gesture_) 242 if (show_scrollbars_on_scroll_gesture_)
225 DidScrollUpdate(); 243 DidScrollUpdate();
226 } 244 }
227 245
228 void ScrollbarAnimationController::DidRequestShowFromMainThread() { 246 void ScrollbarAnimationController::DidRequestShowFromMainThread() {
229 DidScrollUpdate(); 247 DidScrollUpdate();
230 } 248 }
231 249
232 void ScrollbarAnimationController::DidResize() { 250 void ScrollbarAnimationController::DidResize() {
233 StopAnimation(); 251 StopAnimation();
234 Show(); 252 Show();
235 253
236 // As an optimization, we avoid spamming fade delay tasks during active fast 254 // As an optimization, we avoid spamming fade delay tasks during active fast
237 // scrolls. 255 // scrolls.
238 if (!currently_scrolling_) { 256 if (!currently_scrolling_) {
239 PostDelayedFadeOut(true); 257 PostDelayedAnimation(FADE_OUT, true);
240 } else { 258 } else {
241 show_in_fast_scroll_ = true; 259 show_in_fast_scroll_ = true;
242 } 260 }
243 } 261 }
244 262
245 void ScrollbarAnimationController::DidMouseDown() { 263 void ScrollbarAnimationController::DidMouseDown() {
246 if (!need_thinning_animation_ || ScrollbarsHidden()) 264 if (!need_thinning_animation_ || ScrollbarsHidden())
247 return; 265 return;
248 266
249 vertical_controller_->DidMouseDown(); 267 vertical_controller_->DidMouseDown();
250 horizontal_controller_->DidMouseDown(); 268 horizontal_controller_->DidMouseDown();
251 } 269 }
252 270
253 void ScrollbarAnimationController::DidMouseUp() { 271 void ScrollbarAnimationController::DidMouseUp() {
254 if (!need_thinning_animation_ || !Captured()) 272 if (!need_thinning_animation_ || !Captured())
255 return; 273 return;
256 274
257 vertical_controller_->DidMouseUp(); 275 vertical_controller_->DidMouseUp();
258 horizontal_controller_->DidMouseUp(); 276 horizontal_controller_->DidMouseUp();
259 277
260 if (!MouseIsNearAnyScrollbar()) 278 if (!MouseIsNearAnyScrollbar())
261 PostDelayedFadeOut(false); 279 PostDelayedAnimation(FADE_OUT, false);
262 } 280 }
263 281
264 void ScrollbarAnimationController::DidMouseLeave() { 282 void ScrollbarAnimationController::DidMouseLeave() {
265 if (!need_thinning_animation_) 283 if (!need_thinning_animation_)
266 return; 284 return;
267 285
268 vertical_controller_->DidMouseLeave(); 286 vertical_controller_->DidMouseLeave();
269 horizontal_controller_->DidMouseLeave(); 287 horizontal_controller_->DidMouseLeave();
270 288
271 delayed_scrollbar_show_.Cancel(); 289 delayed_scrollbar_animation_.Cancel();
272 need_trigger_scrollbar_show_ = false; 290 need_trigger_scrollbar_show_ = false;
273 291
274 if (ScrollbarsHidden() || Captured()) 292 if (ScrollbarsHidden() || Captured())
275 return; 293 return;
276 294
277 PostDelayedFadeOut(false); 295 PostDelayedAnimation(FADE_OUT, false);
278 } 296 }
279 297
280 void ScrollbarAnimationController::DidMouseMoveNear( 298 void ScrollbarAnimationController::DidMouseMoveNear(
281 ScrollbarOrientation orientation, 299 ScrollbarOrientation orientation,
282 float distance) { 300 float distance) {
283 if (!need_thinning_animation_) 301 if (!need_thinning_animation_)
284 return; 302 return;
285 303
286 bool need_trigger_scrollbar_show_before = need_trigger_scrollbar_show_; 304 bool need_trigger_scrollbar_show_before = need_trigger_scrollbar_show_;
287 305
288 GetScrollbarAnimationController(orientation).DidMouseMoveNear(distance); 306 GetScrollbarAnimationController(orientation).DidMouseMoveNear(distance);
289 307
290 need_trigger_scrollbar_show_ = 308 need_trigger_scrollbar_show_ =
291 CalcNeedTriggerScrollbarShow(orientation, distance); 309 CalcNeedTriggerScrollbarShow(orientation, distance);
292 310
293 if (Captured()) 311 if (Captured())
294 return; 312 return;
295 313
296 if (ScrollbarsHidden()) { 314 if (ScrollbarsHidden()) {
297 if (need_trigger_scrollbar_show_before != need_trigger_scrollbar_show_) { 315 if (need_trigger_scrollbar_show_before != need_trigger_scrollbar_show_) {
298 if (need_trigger_scrollbar_show_) { 316 if (need_trigger_scrollbar_show_) {
299 PostDelayedShow(); 317 PostDelayedAnimation(FADE_IN, false);
300 } else { 318 } else {
301 delayed_scrollbar_show_.Cancel(); 319 delayed_scrollbar_animation_.Cancel();
302 } 320 }
303 } 321 }
304 } else { 322 } else {
chaopeng 2017/04/19 16:12:18 when is_animating FadeOut, mouse move would not po
weiliangc 2017/04/19 20:47:08 Ah I see so there is no animation to fade in when
305 if (MouseIsNearAnyScrollbar()) { 323 if (MouseIsNearAnyScrollbar()) {
306 Show(); 324 Show();
307 StopAnimation(); 325 StopAnimation();
308 } else if (!is_animating_) { 326 } else if (!is_animating_) {
309 PostDelayedFadeOut(false); 327 PostDelayedAnimation(FADE_OUT, false);
310 } 328 }
311 } 329 }
312 } 330 }
313 331
314 bool ScrollbarAnimationController::CalcNeedTriggerScrollbarShow( 332 bool ScrollbarAnimationController::CalcNeedTriggerScrollbarShow(
315 ScrollbarOrientation orientation, 333 ScrollbarOrientation orientation,
316 float distance) const { 334 float distance) const {
317 DCHECK(need_thinning_animation_); 335 DCHECK(need_thinning_animation_);
318 336
319 if (vertical_controller_->mouse_is_over_scrollbar() || 337 if (vertical_controller_->mouse_is_over_scrollbar() ||
320 horizontal_controller_->mouse_is_over_scrollbar()) 338 horizontal_controller_->mouse_is_over_scrollbar())
321 return true; 339 return true;
322 340
323 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { 341 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) {
324 if (scrollbar->orientation() != orientation) 342 if (scrollbar->orientation() != orientation)
325 continue; 343 continue;
326 344
327 if (distance < kMouseMoveDistanceToTriggerShow) 345 if (distance < kMouseMoveDistanceToTriggerFadeIn)
328 return true; 346 return true;
329 } 347 }
330 348
331 return false; 349 return false;
332 } 350 }
333 351
334 bool ScrollbarAnimationController::MouseIsOverScrollbar( 352 bool ScrollbarAnimationController::MouseIsOverScrollbar(
335 ScrollbarOrientation orientation) const { 353 ScrollbarOrientation orientation) const {
336 DCHECK(need_thinning_animation_); 354 DCHECK(need_thinning_animation_);
337 return GetScrollbarAnimationController(orientation).mouse_is_over_scrollbar(); 355 return GetScrollbarAnimationController(orientation).mouse_is_over_scrollbar();
(...skipping 14 matching lines...) Expand all
352 bool ScrollbarAnimationController::ScrollbarsHidden() const { 370 bool ScrollbarAnimationController::ScrollbarsHidden() const {
353 return opacity_ == 0.0f; 371 return opacity_ == 0.0f;
354 } 372 }
355 373
356 bool ScrollbarAnimationController::Captured() const { 374 bool ScrollbarAnimationController::Captured() const {
357 DCHECK(need_thinning_animation_); 375 DCHECK(need_thinning_animation_);
358 return vertical_controller_->captured() || horizontal_controller_->captured(); 376 return vertical_controller_->captured() || horizontal_controller_->captured();
359 } 377 }
360 378
361 void ScrollbarAnimationController::Show() { 379 void ScrollbarAnimationController::Show() {
362 delayed_scrollbar_show_.Cancel(); 380 delayed_scrollbar_animation_.Cancel();
363 ApplyOpacityToScrollbars(1.0f); 381 ApplyOpacityToScrollbars(1.0f);
364 } 382 }
365 383
366 void ScrollbarAnimationController::ApplyOpacityToScrollbars(float opacity) { 384 void ScrollbarAnimationController::ApplyOpacityToScrollbars(float opacity) {
367 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { 385 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) {
368 if (!scrollbar->is_overlay_scrollbar()) 386 if (!scrollbar->is_overlay_scrollbar())
369 continue; 387 continue;
370 float effective_opacity = scrollbar->CanScrollOrientation() ? opacity : 0; 388 float effective_opacity = scrollbar->CanScrollOrientation() ? opacity : 0;
371 scrollbar->SetOverlayScrollbarLayerOpacityAnimated(effective_opacity); 389 scrollbar->SetOverlayScrollbarLayerOpacityAnimated(effective_opacity);
372 } 390 }
373 391
374 bool previouslyVisible = opacity_ > 0.0f; 392 bool previouslyVisible = opacity_ > 0.0f;
375 bool currentlyVisible = opacity > 0.0f; 393 bool currentlyVisible = opacity > 0.0f;
376 394
377 if (opacity_ != opacity) 395 if (opacity_ != opacity)
378 client_->SetNeedsRedrawForScrollbarAnimation(); 396 client_->SetNeedsRedrawForScrollbarAnimation();
379 397
380 opacity_ = opacity; 398 opacity_ = opacity;
381 399
382 if (previouslyVisible != currentlyVisible) 400 if (previouslyVisible != currentlyVisible)
383 client_->DidChangeScrollbarVisibility(); 401 client_->DidChangeScrollbarVisibility();
384 } 402 }
385 403
386 } // namespace cc 404 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698