Chromium Code Reviews| 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 cc { | 12 namespace cc { |
| 13 | 13 |
| 14 namespace { | |
| 15 | |
| 16 float DistanceToScrollbarTrack(const gfx::PointF& device_viewport_point, | |
| 17 const ScrollbarLayerImplBase* scrollbar) { | |
| 18 if (!scrollbar) | |
| 19 return std::numeric_limits<float>::max(); | |
| 20 | |
| 21 gfx::Rect scrollbar_bounds(scrollbar->bounds()); | |
| 22 | |
| 23 gfx::RectF device_viewport_scrollbar_bounds = MathUtil::MapClippedRect( | |
| 24 scrollbar->ScreenSpaceTransform(), gfx::RectF(scrollbar_bounds)); | |
| 25 | |
| 26 return device_viewport_scrollbar_bounds.ManhattanDistanceToPoint( | |
| 27 device_viewport_point) / | |
| 28 scrollbar->layer_tree_impl()->device_scale_factor(); | |
| 29 } | |
| 30 | |
| 31 float DistanceToScrollbarThumb(const gfx::PointF& device_viewport_point, | |
| 32 const ScrollbarLayerImplBase* scrollbar) { | |
| 33 if (!scrollbar) | |
| 34 return std::numeric_limits<float>::max(); | |
| 35 | |
| 36 gfx::Rect thumb_bounds(scrollbar->ComputeExpandedThumbQuadRect()); | |
| 37 | |
| 38 gfx::RectF device_viewport_scrollbar_thumb_bounds = MathUtil::MapClippedRect( | |
| 39 scrollbar->ScreenSpaceTransform(), gfx::RectF(thumb_bounds)); | |
| 40 | |
| 41 return device_viewport_scrollbar_thumb_bounds.ManhattanDistanceToPoint( | |
| 42 device_viewport_point) / | |
| 43 scrollbar->layer_tree_impl()->device_scale_factor(); | |
| 44 } | |
| 45 | |
| 46 const ScrollbarOrientation orientations[] = {HORIZONTAL, VERTICAL}; | |
|
bokan
2017/04/28 14:15:17
This is only used for one loop. Move this into the
| |
| 47 | |
| 48 } // namespace | |
| 49 | |
| 14 std::unique_ptr<ScrollbarAnimationController> | 50 std::unique_ptr<ScrollbarAnimationController> |
| 15 ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid( | 51 ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid( |
| 16 ElementId scroll_element_id, | 52 ElementId scroll_element_id, |
| 17 ScrollbarAnimationControllerClient* client, | 53 ScrollbarAnimationControllerClient* client, |
| 18 base::TimeDelta fade_delay, | 54 base::TimeDelta fade_delay, |
| 19 base::TimeDelta fade_out_resize_delay, | 55 base::TimeDelta fade_out_resize_delay, |
| 20 base::TimeDelta fade_duration) { | 56 base::TimeDelta fade_duration) { |
| 21 return base::WrapUnique( | 57 return base::WrapUnique( |
| 22 new ScrollbarAnimationController(scroll_element_id, client, fade_delay, | 58 new ScrollbarAnimationController(scroll_element_id, client, fade_delay, |
| 23 fade_out_resize_delay, fade_duration)); | 59 fade_out_resize_delay, fade_duration)); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 39 ScrollbarAnimationController::ScrollbarAnimationController( | 75 ScrollbarAnimationController::ScrollbarAnimationController( |
| 40 ElementId scroll_element_id, | 76 ElementId scroll_element_id, |
| 41 ScrollbarAnimationControllerClient* client, | 77 ScrollbarAnimationControllerClient* client, |
| 42 base::TimeDelta fade_delay, | 78 base::TimeDelta fade_delay, |
| 43 base::TimeDelta fade_out_resize_delay, | 79 base::TimeDelta fade_out_resize_delay, |
| 44 base::TimeDelta fade_duration) | 80 base::TimeDelta fade_duration) |
| 45 : client_(client), | 81 : client_(client), |
| 46 fade_delay_(fade_delay), | 82 fade_delay_(fade_delay), |
| 47 fade_out_resize_delay_(fade_out_resize_delay), | 83 fade_out_resize_delay_(fade_out_resize_delay), |
| 48 fade_duration_(fade_duration), | 84 fade_duration_(fade_duration), |
| 49 need_trigger_scrollbar_show_(false), | 85 need_trigger_scrollbar_fade_in_(false), |
| 50 is_animating_(false), | 86 is_animating_(false), |
| 51 animation_change_(NONE), | 87 animation_change_(NONE), |
| 52 scroll_element_id_(scroll_element_id), | 88 scroll_element_id_(scroll_element_id), |
| 53 currently_scrolling_(false), | 89 currently_scrolling_(false), |
| 54 show_in_fast_scroll_(false), | 90 show_in_fast_scroll_(false), |
| 55 opacity_(0.0f), | 91 opacity_(0.0f), |
| 56 show_scrollbars_on_scroll_gesture_(false), | 92 show_scrollbars_on_scroll_gesture_(false), |
| 57 need_thinning_animation_(false), | 93 need_thinning_animation_(false), |
| 58 weak_factory_(this) { | 94 weak_factory_(this) { |
| 59 ApplyOpacityToScrollbars(0.0f); | 95 ApplyOpacityToScrollbars(0.0f); |
| 60 } | 96 } |
| 61 | 97 |
| 62 ScrollbarAnimationController::ScrollbarAnimationController( | 98 ScrollbarAnimationController::ScrollbarAnimationController( |
| 63 ElementId scroll_element_id, | 99 ElementId scroll_element_id, |
| 64 ScrollbarAnimationControllerClient* client, | 100 ScrollbarAnimationControllerClient* client, |
| 65 base::TimeDelta fade_delay, | 101 base::TimeDelta fade_delay, |
| 66 base::TimeDelta fade_out_resize_delay, | 102 base::TimeDelta fade_out_resize_delay, |
| 67 base::TimeDelta fade_duration, | 103 base::TimeDelta fade_duration, |
| 68 base::TimeDelta thinning_duration) | 104 base::TimeDelta thinning_duration) |
| 69 : client_(client), | 105 : client_(client), |
| 70 fade_delay_(fade_delay), | 106 fade_delay_(fade_delay), |
| 71 fade_out_resize_delay_(fade_out_resize_delay), | 107 fade_out_resize_delay_(fade_out_resize_delay), |
| 72 fade_duration_(fade_duration), | 108 fade_duration_(fade_duration), |
| 73 need_trigger_scrollbar_show_(false), | 109 need_trigger_scrollbar_fade_in_(false), |
| 74 is_animating_(false), | 110 is_animating_(false), |
| 75 animation_change_(NONE), | 111 animation_change_(NONE), |
| 76 scroll_element_id_(scroll_element_id), | 112 scroll_element_id_(scroll_element_id), |
| 77 currently_scrolling_(false), | 113 currently_scrolling_(false), |
| 78 show_in_fast_scroll_(false), | 114 show_in_fast_scroll_(false), |
| 79 opacity_(0.0f), | 115 opacity_(0.0f), |
| 80 show_scrollbars_on_scroll_gesture_(true), | 116 show_scrollbars_on_scroll_gesture_(true), |
| 81 need_thinning_animation_(true), | 117 need_thinning_animation_(true), |
| 82 weak_factory_(this) { | 118 weak_factory_(this) { |
| 83 vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create( | 119 scrollbar_controllers_[ScrollbarOrientation::HORIZONTAL] = |
| 84 scroll_element_id, ScrollbarOrientation::VERTICAL, client, | 120 SingleScrollbarAnimationControllerThinning::Create( |
| 85 thinning_duration); | 121 scroll_element_id, ScrollbarOrientation::HORIZONTAL, client, |
| 86 horizontal_controller_ = SingleScrollbarAnimationControllerThinning::Create( | 122 thinning_duration); |
| 87 scroll_element_id, ScrollbarOrientation::HORIZONTAL, client, | 123 scrollbar_controllers_[ScrollbarOrientation::VERTICAL] = |
| 88 thinning_duration); | 124 SingleScrollbarAnimationControllerThinning::Create( |
| 125 scroll_element_id, ScrollbarOrientation::VERTICAL, client, | |
| 126 thinning_duration); | |
| 127 | |
| 128 mouse_is_near_scrollbar_[ScrollbarOrientation::HORIZONTAL] = false; | |
| 129 mouse_is_near_scrollbar_[ScrollbarOrientation::VERTICAL] = false; | |
| 130 | |
| 89 ApplyOpacityToScrollbars(0.0f); | 131 ApplyOpacityToScrollbars(0.0f); |
| 90 } | 132 } |
| 91 | 133 |
| 92 ScrollbarAnimationController::~ScrollbarAnimationController() {} | 134 ScrollbarAnimationController::~ScrollbarAnimationController() {} |
| 93 | 135 |
| 94 ScrollbarSet ScrollbarAnimationController::Scrollbars() const { | 136 ScrollbarSet ScrollbarAnimationController::Scrollbars() const { |
| 95 return client_->ScrollbarsFor(scroll_element_id_); | 137 return client_->ScrollbarsFor(scroll_element_id_); |
| 96 } | 138 } |
| 97 | 139 |
| 140 ScrollbarLayerImplBase* ScrollbarAnimationController::GetScrollbar( | |
| 141 ScrollbarOrientation orientation) const { | |
| 142 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { | |
| 143 if (!scrollbar->is_overlay_scrollbar()) | |
| 144 continue; | |
| 145 | |
| 146 if (scrollbar->orientation() == orientation) | |
| 147 return scrollbar; | |
| 148 } | |
| 149 | |
| 150 return nullptr; | |
| 151 } | |
| 152 | |
| 98 SingleScrollbarAnimationControllerThinning& | 153 SingleScrollbarAnimationControllerThinning& |
| 99 ScrollbarAnimationController::GetScrollbarAnimationController( | 154 ScrollbarAnimationController::GetScrollbarAnimationController( |
| 100 ScrollbarOrientation orientation) const { | 155 ScrollbarOrientation orientation) const { |
| 101 DCHECK(need_thinning_animation_); | 156 DCHECK(need_thinning_animation_); |
| 102 if (orientation == ScrollbarOrientation::VERTICAL) | 157 return *scrollbar_controllers_[orientation].get(); |
| 103 return *(vertical_controller_.get()); | |
| 104 else | |
| 105 return *(horizontal_controller_.get()); | |
| 106 } | 158 } |
| 107 | 159 |
| 108 void ScrollbarAnimationController::StartAnimation() { | 160 void ScrollbarAnimationController::StartAnimation() { |
| 109 DCHECK(animation_change_ != NONE); | 161 DCHECK(animation_change_ != NONE); |
| 110 delayed_scrollbar_animation_.Cancel(); | 162 delayed_scrollbar_animation_.Cancel(); |
| 111 is_animating_ = true; | 163 is_animating_ = true; |
| 112 last_awaken_time_ = base::TimeTicks(); | 164 last_awaken_time_ = base::TimeTicks(); |
| 113 client_->SetNeedsAnimateForScrollbarAnimation(); | 165 client_->SetNeedsAnimateForScrollbarAnimation(); |
| 114 } | 166 } |
| 115 | 167 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 144 | 196 |
| 145 float progress = AnimationProgressAtTime(now); | 197 float progress = AnimationProgressAtTime(now); |
| 146 RunAnimationFrame(progress); | 198 RunAnimationFrame(progress); |
| 147 | 199 |
| 148 if (is_animating_) | 200 if (is_animating_) |
| 149 client_->SetNeedsAnimateForScrollbarAnimation(); | 201 client_->SetNeedsAnimateForScrollbarAnimation(); |
| 150 animated = true; | 202 animated = true; |
| 151 } | 203 } |
| 152 | 204 |
| 153 if (need_thinning_animation_) { | 205 if (need_thinning_animation_) { |
| 154 animated |= vertical_controller_->Animate(now); | 206 for (auto& controller : scrollbar_controllers_) |
| 155 animated |= horizontal_controller_->Animate(now); | 207 animated |= controller->Animate(now); |
| 156 } | 208 } |
| 157 | 209 |
| 158 return animated; | 210 return animated; |
| 159 } | 211 } |
| 160 | 212 |
| 161 float ScrollbarAnimationController::AnimationProgressAtTime( | 213 float ScrollbarAnimationController::AnimationProgressAtTime( |
| 162 base::TimeTicks now) { | 214 base::TimeTicks now) { |
| 163 base::TimeDelta delta = now - last_awaken_time_; | 215 base::TimeDelta delta = now - last_awaken_time_; |
| 164 float progress = delta.InSecondsF() / fade_duration_.InSecondsF(); | 216 float progress = delta.InSecondsF() / fade_duration_.InSecondsF(); |
| 165 return std::max(std::min(progress, 1.f), 0.f); | 217 return std::max(std::min(progress, 1.f), 0.f); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 if (!currently_scrolling_) { | 264 if (!currently_scrolling_) { |
| 213 // We don't fade out scrollbar if they need thinning animation and mouse is | 265 // We don't fade out scrollbar if they need thinning animation and mouse is |
| 214 // near. | 266 // near. |
| 215 if (!need_thinning_animation_ || !MouseIsNearAnyScrollbar()) | 267 if (!need_thinning_animation_ || !MouseIsNearAnyScrollbar()) |
| 216 PostDelayedAnimation(FADE_OUT, false); | 268 PostDelayedAnimation(FADE_OUT, false); |
| 217 } else { | 269 } else { |
| 218 show_in_fast_scroll_ = true; | 270 show_in_fast_scroll_ = true; |
| 219 } | 271 } |
| 220 | 272 |
| 221 if (need_thinning_animation_) { | 273 if (need_thinning_animation_) { |
| 222 vertical_controller_->UpdateThumbThicknessScale(); | 274 for (auto& controller : scrollbar_controllers_) |
| 223 horizontal_controller_->UpdateThumbThicknessScale(); | 275 controller->UpdateThumbThicknessScale(); |
| 224 } | 276 } |
| 225 } | 277 } |
| 226 | 278 |
| 227 void ScrollbarAnimationController::WillUpdateScroll() { | 279 void ScrollbarAnimationController::WillUpdateScroll() { |
| 228 if (show_scrollbars_on_scroll_gesture_) | 280 if (show_scrollbars_on_scroll_gesture_) |
| 229 DidScrollUpdate(); | 281 DidScrollUpdate(); |
| 230 } | 282 } |
| 231 | 283 |
| 232 void ScrollbarAnimationController::DidRequestShowFromMainThread() { | 284 void ScrollbarAnimationController::DidRequestShowFromMainThread() { |
| 233 // TODO(skobes): Call DidScrollUpdate here (suppressed for crbug.com/706927). | 285 // TODO(skobes): Call DidScrollUpdate here (suppressed for crbug.com/706927). |
| 234 } | 286 } |
| 235 | 287 |
| 236 void ScrollbarAnimationController::DidResize() { | 288 void ScrollbarAnimationController::DidResize() { |
| 237 StopAnimation(); | 289 StopAnimation(); |
| 238 Show(); | 290 Show(); |
| 239 | 291 |
| 240 // As an optimization, we avoid spamming fade delay tasks during active fast | 292 // As an optimization, we avoid spamming fade delay tasks during active fast |
| 241 // scrolls. | 293 // scrolls. |
| 242 if (!currently_scrolling_) { | 294 if (!currently_scrolling_) { |
| 243 PostDelayedAnimation(FADE_OUT, true); | 295 PostDelayedAnimation(FADE_OUT, true); |
| 244 } else { | 296 } else { |
| 245 show_in_fast_scroll_ = true; | 297 show_in_fast_scroll_ = true; |
| 246 } | 298 } |
| 247 } | 299 } |
| 248 | 300 |
| 249 void ScrollbarAnimationController::DidMouseDown() { | 301 void ScrollbarAnimationController::DidMouseDown() { |
| 250 if (!need_thinning_animation_ || ScrollbarsHidden()) | 302 if (!need_thinning_animation_ || ScrollbarsHidden()) |
| 251 return; | 303 return; |
| 252 | 304 |
| 253 vertical_controller_->DidMouseDown(); | 305 for (auto& controller : scrollbar_controllers_) |
| 254 horizontal_controller_->DidMouseDown(); | 306 controller->DidMouseDown(); |
| 255 } | 307 } |
| 256 | 308 |
| 257 void ScrollbarAnimationController::DidMouseUp() { | 309 void ScrollbarAnimationController::DidMouseUp() { |
| 258 if (!need_thinning_animation_ || !Captured()) | 310 if (!need_thinning_animation_ || !Captured()) |
| 259 return; | 311 return; |
| 260 | 312 |
| 261 vertical_controller_->DidMouseUp(); | 313 for (auto& controller : scrollbar_controllers_) |
| 262 horizontal_controller_->DidMouseUp(); | 314 controller->DidMouseUp(); |
| 263 | 315 |
| 264 if (!MouseIsNearAnyScrollbar()) | 316 if (!MouseIsNearAnyScrollbar()) |
| 265 PostDelayedAnimation(FADE_OUT, false); | 317 PostDelayedAnimation(FADE_OUT, false); |
| 266 } | 318 } |
| 267 | 319 |
| 268 void ScrollbarAnimationController::DidMouseLeave() { | 320 void ScrollbarAnimationController::DidMouseLeave() { |
| 269 if (!need_thinning_animation_) | 321 if (!need_thinning_animation_) |
| 270 return; | 322 return; |
| 271 | 323 |
| 272 vertical_controller_->DidMouseLeave(); | 324 for (auto& controller : scrollbar_controllers_) |
| 273 horizontal_controller_->DidMouseLeave(); | 325 controller->DidMouseLeave(); |
| 326 | |
| 327 for (bool& mouse_is_near_scrollbar : mouse_is_near_scrollbar_) | |
| 328 mouse_is_near_scrollbar = false; | |
| 274 | 329 |
| 275 delayed_scrollbar_animation_.Cancel(); | 330 delayed_scrollbar_animation_.Cancel(); |
| 276 need_trigger_scrollbar_show_ = false; | 331 need_trigger_scrollbar_fade_in_ = false; |
| 277 | 332 |
| 278 if (ScrollbarsHidden() || Captured()) | 333 if (ScrollbarsHidden() || Captured()) |
| 279 return; | 334 return; |
| 280 | 335 |
| 281 PostDelayedAnimation(FADE_OUT, false); | 336 PostDelayedAnimation(FADE_OUT, false); |
| 282 } | 337 } |
| 283 | 338 |
| 284 void ScrollbarAnimationController::DidMouseMoveNear( | 339 void ScrollbarAnimationController::DidMouseMove( |
| 285 ScrollbarOrientation orientation, | 340 const gfx::PointF& device_viewport_point) { |
| 286 float distance) { | |
| 287 if (!need_thinning_animation_) | 341 if (!need_thinning_animation_) |
| 288 return; | 342 return; |
| 289 | 343 |
| 290 bool need_trigger_scrollbar_show_before = need_trigger_scrollbar_show_; | 344 bool need_trigger_scrollbar_fade_in_before = need_trigger_scrollbar_fade_in_; |
| 291 | 345 |
| 292 GetScrollbarAnimationController(orientation).DidMouseMoveNear(distance); | 346 for (ScrollbarOrientation orientation : orientations) { |
| 347 ScrollbarLayerImplBase* scrollbar = GetScrollbar(orientation); | |
| 348 float distance_to_scrollbar_track = | |
| 349 DistanceToScrollbarTrack(device_viewport_point, scrollbar); | |
| 350 float distance_to_scrollbar_thumb = | |
| 351 DistanceToScrollbarThumb(device_viewport_point, scrollbar); | |
| 293 | 352 |
| 294 need_trigger_scrollbar_show_ = | 353 GetScrollbarAnimationController(orientation) |
| 295 CalcNeedTriggerScrollbarShow(orientation, distance); | 354 .DidMouseMove(distance_to_scrollbar_thumb); |
| 355 | |
| 356 mouse_is_near_scrollbar_[orientation] = | |
| 357 distance_to_scrollbar_track < kMouseMoveDistanceToTriggerFadeIn; | |
| 358 } | |
| 359 | |
| 360 need_trigger_scrollbar_fade_in_ = MouseIsNearAnyScrollbar(); | |
| 296 | 361 |
| 297 if (Captured()) | 362 if (Captured()) |
| 298 return; | 363 return; |
| 299 | 364 |
| 300 if (ScrollbarsHidden()) { | 365 if (ScrollbarsHidden()) { |
| 301 if (need_trigger_scrollbar_show_before != need_trigger_scrollbar_show_) { | 366 if (need_trigger_scrollbar_fade_in_before != |
| 302 if (need_trigger_scrollbar_show_) { | 367 need_trigger_scrollbar_fade_in_) { |
| 368 if (need_trigger_scrollbar_fade_in_) { | |
| 303 PostDelayedAnimation(FADE_IN, false); | 369 PostDelayedAnimation(FADE_IN, false); |
| 304 } else { | 370 } else { |
| 305 delayed_scrollbar_animation_.Cancel(); | 371 delayed_scrollbar_animation_.Cancel(); |
| 306 } | 372 } |
| 307 } | 373 } |
| 308 } else { | 374 } else { |
| 309 if (MouseIsNearAnyScrollbar()) { | 375 if (MouseIsNearAnyScrollbar()) { |
| 310 Show(); | 376 Show(); |
| 311 StopAnimation(); | 377 StopAnimation(); |
| 312 } else if (!is_animating_) { | 378 } else if (!is_animating_) { |
| 313 PostDelayedAnimation(FADE_OUT, false); | 379 PostDelayedAnimation(FADE_OUT, false); |
| 314 } | 380 } |
| 315 } | 381 } |
| 316 } | 382 } |
| 317 | 383 |
| 318 bool ScrollbarAnimationController::CalcNeedTriggerScrollbarShow( | 384 bool ScrollbarAnimationController::MouseIsOverScrollbarThumb( |
| 319 ScrollbarOrientation orientation, | 385 ScrollbarOrientation orientation) const { |
| 320 float distance) const { | |
| 321 DCHECK(need_thinning_animation_); | 386 DCHECK(need_thinning_animation_); |
| 322 | 387 return GetScrollbarAnimationController(orientation) |
| 323 if (vertical_controller_->mouse_is_over_scrollbar() || | 388 .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 } | 389 } |
| 337 | 390 |
| 338 bool ScrollbarAnimationController::MouseIsOverScrollbar( | 391 bool ScrollbarAnimationController::MouseIsNearScrollbarThumb( |
| 339 ScrollbarOrientation orientation) const { | 392 ScrollbarOrientation orientation) const { |
| 340 DCHECK(need_thinning_animation_); | 393 DCHECK(need_thinning_animation_); |
| 341 return GetScrollbarAnimationController(orientation).mouse_is_over_scrollbar(); | 394 return GetScrollbarAnimationController(orientation) |
| 395 .mouse_is_near_scrollbar_thumb(); | |
| 342 } | 396 } |
| 343 | 397 |
| 344 bool ScrollbarAnimationController::MouseIsNearScrollbar( | 398 bool ScrollbarAnimationController::MouseIsNearScrollbar( |
| 345 ScrollbarOrientation orientation) const { | 399 ScrollbarOrientation orientation) const { |
| 346 DCHECK(need_thinning_animation_); | 400 DCHECK(need_thinning_animation_); |
| 347 return GetScrollbarAnimationController(orientation).mouse_is_near_scrollbar(); | 401 return mouse_is_near_scrollbar_[orientation]; |
| 348 } | 402 } |
| 349 | 403 |
| 350 bool ScrollbarAnimationController::MouseIsNearAnyScrollbar() const { | 404 bool ScrollbarAnimationController::MouseIsNearAnyScrollbar() const { |
| 351 DCHECK(need_thinning_animation_); | 405 DCHECK(need_thinning_animation_); |
| 352 return vertical_controller_->mouse_is_near_scrollbar() || | 406 return MouseIsNearScrollbar(VERTICAL) || MouseIsNearScrollbar(HORIZONTAL); |
| 353 horizontal_controller_->mouse_is_near_scrollbar(); | |
| 354 } | 407 } |
| 355 | 408 |
| 356 bool ScrollbarAnimationController::ScrollbarsHidden() const { | 409 bool ScrollbarAnimationController::ScrollbarsHidden() const { |
| 357 return opacity_ == 0.0f; | 410 return opacity_ == 0.0f; |
| 358 } | 411 } |
| 359 | 412 |
| 360 bool ScrollbarAnimationController::Captured() const { | 413 bool ScrollbarAnimationController::Captured() const { |
| 361 DCHECK(need_thinning_animation_); | 414 DCHECK(need_thinning_animation_); |
| 362 return vertical_controller_->captured() || horizontal_controller_->captured(); | 415 return GetScrollbarAnimationController(VERTICAL).captured() || |
| 416 GetScrollbarAnimationController(HORIZONTAL).captured(); | |
| 363 } | 417 } |
| 364 | 418 |
| 365 void ScrollbarAnimationController::Show() { | 419 void ScrollbarAnimationController::Show() { |
| 366 delayed_scrollbar_animation_.Cancel(); | 420 delayed_scrollbar_animation_.Cancel(); |
| 367 ApplyOpacityToScrollbars(1.0f); | 421 ApplyOpacityToScrollbars(1.0f); |
| 368 } | 422 } |
| 369 | 423 |
| 370 void ScrollbarAnimationController::ApplyOpacityToScrollbars(float opacity) { | 424 void ScrollbarAnimationController::ApplyOpacityToScrollbars(float opacity) { |
| 371 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { | 425 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { |
| 372 if (!scrollbar->is_overlay_scrollbar()) | 426 if (!scrollbar->is_overlay_scrollbar()) |
| 373 continue; | 427 continue; |
| 374 float effective_opacity = scrollbar->CanScrollOrientation() ? opacity : 0; | 428 float effective_opacity = scrollbar->CanScrollOrientation() ? opacity : 0; |
| 375 scrollbar->SetOverlayScrollbarLayerOpacityAnimated(effective_opacity); | 429 scrollbar->SetOverlayScrollbarLayerOpacityAnimated(effective_opacity); |
| 376 } | 430 } |
| 377 | 431 |
| 378 bool previouslyVisible = opacity_ > 0.0f; | 432 bool previouslyVisible = opacity_ > 0.0f; |
| 379 bool currentlyVisible = opacity > 0.0f; | 433 bool currentlyVisible = opacity > 0.0f; |
| 380 | 434 |
| 381 if (opacity_ != opacity) | 435 if (opacity_ != opacity) |
| 382 client_->SetNeedsRedrawForScrollbarAnimation(); | 436 client_->SetNeedsRedrawForScrollbarAnimation(); |
| 383 | 437 |
| 384 opacity_ = opacity; | 438 opacity_ = opacity; |
| 385 | 439 |
| 386 if (previouslyVisible != currentlyVisible) | 440 if (previouslyVisible != currentlyVisible) |
| 387 client_->DidChangeScrollbarVisibility(); | 441 client_->DidChangeScrollbarVisibility(); |
| 388 } | 442 } |
| 389 | 443 |
| 390 } // namespace cc | 444 } // namespace cc |
| OLD | NEW |