| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_thinning.h" | 5 #include "cc/input/scrollbar_animation_controller_thinning.h" |
| 6 | 6 |
| 7 #include "cc/layers/solid_color_scrollbar_layer_impl.h" | 7 #include "cc/layers/solid_color_scrollbar_layer_impl.h" |
| 8 #include "cc/test/fake_impl_task_runner_provider.h" | 8 #include "cc/test/fake_impl_task_runner_provider.h" |
| 9 #include "cc/test/fake_layer_tree_host_impl.h" | 9 #include "cc/test/fake_layer_tree_host_impl.h" |
| 10 #include "cc/test/geometry_test_utils.h" | 10 #include "cc/test/geometry_test_utils.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 did_request_redraw_ = true; | 34 did_request_redraw_ = true; |
| 35 } | 35 } |
| 36 void SetNeedsAnimateForScrollbarAnimation() override { | 36 void SetNeedsAnimateForScrollbarAnimation() override { |
| 37 did_request_animate_ = true; | 37 did_request_animate_ = true; |
| 38 } | 38 } |
| 39 ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override { | 39 ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override { |
| 40 return host_impl_.ScrollbarsFor(scroll_layer_id); | 40 return host_impl_.ScrollbarsFor(scroll_layer_id); |
| 41 } | 41 } |
| 42 | 42 |
| 43 protected: | 43 protected: |
| 44 const int kDelayBeforeStarting = 2; |
| 45 const int kResizeDelayBeforeStarting = 5; |
| 46 const int kDuration = 3; |
| 47 |
| 44 void SetUp() override { | 48 void SetUp() override { |
| 45 std::unique_ptr<LayerImpl> scroll_layer = | 49 std::unique_ptr<LayerImpl> scroll_layer = |
| 46 LayerImpl::Create(host_impl_.active_tree(), 1); | 50 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 47 std::unique_ptr<LayerImpl> clip = | 51 std::unique_ptr<LayerImpl> clip = |
| 48 LayerImpl::Create(host_impl_.active_tree(), 3); | 52 LayerImpl::Create(host_impl_.active_tree(), 3); |
| 49 clip_layer_ = clip.get(); | 53 clip_layer_ = clip.get(); |
| 50 scroll_layer->SetScrollClipLayer(clip_layer_->id()); | 54 scroll_layer->SetScrollClipLayer(clip_layer_->id()); |
| 51 LayerImpl* scroll_layer_ptr = scroll_layer.get(); | 55 LayerImpl* scroll_layer_ptr = scroll_layer.get(); |
| 52 | 56 |
| 53 const int kId = 2; | 57 const int kId = 2; |
| 54 const int kThumbThickness = 10; | 58 const int kThumbThickness = 10; |
| 55 const int kTrackStart = 0; | 59 const int kTrackStart = 0; |
| 56 const bool kIsLeftSideVerticalScrollbar = false; | 60 const bool kIsLeftSideVerticalScrollbar = false; |
| 57 const bool kIsOverlayScrollbar = true; | 61 const bool kIsOverlayScrollbar = true; |
| 62 |
| 58 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = | 63 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
| 59 SolidColorScrollbarLayerImpl::Create( | 64 SolidColorScrollbarLayerImpl::Create( |
| 60 host_impl_.active_tree(), kId, HORIZONTAL, kThumbThickness, | 65 host_impl_.active_tree(), kId, HORIZONTAL, kThumbThickness, |
| 61 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); | 66 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); |
| 62 scrollbar_layer_ = scrollbar.get(); | 67 scrollbar_layer_ = scrollbar.get(); |
| 63 | 68 |
| 64 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); | 69 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); |
| 65 clip_layer_->test_properties()->AddChild(std::move(scroll_layer)); | 70 clip_layer_->test_properties()->AddChild(std::move(scroll_layer)); |
| 66 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); | 71 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); |
| 67 | 72 |
| 68 scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); | 73 scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); |
| 69 scrollbar_layer_->test_properties()->opacity_can_animate = true; | 74 scrollbar_layer_->test_properties()->opacity_can_animate = true; |
| 70 clip_layer_->SetBounds(gfx::Size(100, 100)); | 75 clip_layer_->SetBounds(gfx::Size(100, 100)); |
| 71 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); | 76 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); |
| 72 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); | 77 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 73 | 78 |
| 74 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create( | 79 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create( |
| 75 scroll_layer_ptr->id(), this, base::TimeDelta::FromSeconds(2), | 80 scroll_layer_ptr->id(), this, |
| 76 base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(3)); | 81 base::TimeDelta::FromSeconds(kDelayBeforeStarting), |
| 82 base::TimeDelta::FromSeconds(kResizeDelayBeforeStarting), |
| 83 base::TimeDelta::FromSeconds(kDuration)); |
| 77 } | 84 } |
| 78 | 85 |
| 79 FakeImplTaskRunnerProvider task_runner_provider_; | 86 FakeImplTaskRunnerProvider task_runner_provider_; |
| 80 TestSharedBitmapManager shared_bitmap_manager_; | 87 TestSharedBitmapManager shared_bitmap_manager_; |
| 81 TestTaskGraphRunner task_graph_runner_; | 88 TestTaskGraphRunner task_graph_runner_; |
| 82 FakeLayerTreeHostImpl host_impl_; | 89 FakeLayerTreeHostImpl host_impl_; |
| 83 std::unique_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_; | 90 std::unique_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_; |
| 84 LayerImpl* clip_layer_; | 91 LayerImpl* clip_layer_; |
| 85 SolidColorScrollbarLayerImpl* scrollbar_layer_; | 92 SolidColorScrollbarLayerImpl* scrollbar_layer_; |
| 86 | 93 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 // The thickness now gets big again. | 386 // The thickness now gets big again. |
| 380 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor()); | 387 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 381 | 388 |
| 382 time += base::TimeDelta::FromSeconds(1); | 389 time += base::TimeDelta::FromSeconds(1); |
| 383 scrollbar_controller_->Animate(time); | 390 scrollbar_controller_->Animate(time); |
| 384 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity()); | 391 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity()); |
| 385 // The thickness now gets big again. | 392 // The thickness now gets big again. |
| 386 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 393 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 387 } | 394 } |
| 388 | 395 |
| 396 // First move the pointer on the scrollbar, then press it, then away. |
| 397 // Confirm that the bar gets thick and dark. Then mouse up. Confirm that |
| 398 // the bar gets thin and light. |
| 399 TEST_F(ScrollbarAnimationControllerThinningTest, |
| 400 MouseCaptureAndReleaseOutOfBar) { |
| 401 base::TimeTicks time; |
| 402 time += base::TimeDelta::FromSeconds(1); |
| 403 |
| 404 // Move in |
| 405 scrollbar_controller_->DidMouseMoveNear(0); |
| 406 |
| 407 // Jump X seconds, first we need to make the time not 0, second we need to |
| 408 // call Animate once to start the animation(initial the last_awaken_time_), |
| 409 // now you can jump x seconds. |
| 410 scrollbar_controller_->Animate(time); |
| 411 time += base::TimeDelta::FromSeconds(kDuration); |
| 412 scrollbar_controller_->Animate(time); |
| 413 |
| 414 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 415 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 416 |
| 417 // Capture |
| 418 scrollbar_controller_->DidCaptureScrollbarBegin(); |
| 419 time += base::TimeDelta::FromSeconds(1); |
| 420 scrollbar_controller_->Animate(time); |
| 421 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 422 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 423 |
| 424 // test for 10 seconds, stay thick and dark |
| 425 for (int i = 0; i < 10; ++i) { |
| 426 // move away from bar. |
| 427 scrollbar_controller_->DidMouseMoveNear(26 + i); |
| 428 time += base::TimeDelta::FromSeconds(1); |
| 429 scrollbar_controller_->Animate(time); |
| 430 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 431 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 432 } |
| 433 |
| 434 // release |
| 435 scrollbar_controller_->DidCaptureScrollbarEnd(); |
| 436 |
| 437 // get thickness and light |
| 438 time += base::TimeDelta::FromSeconds(1); |
| 439 scrollbar_controller_->Animate(time); |
| 440 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 441 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 442 |
| 443 time += base::TimeDelta::FromSeconds(1); |
| 444 scrollbar_controller_->Animate(time); |
| 445 EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->Opacity()); |
| 446 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 447 |
| 448 time += base::TimeDelta::FromSeconds(1); |
| 449 scrollbar_controller_->Animate(time); |
| 450 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->Opacity()); |
| 451 EXPECT_FLOAT_EQ(0.6f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 452 |
| 453 time += base::TimeDelta::FromSeconds(1); |
| 454 scrollbar_controller_->Animate(time); |
| 455 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity()); |
| 456 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 457 } |
| 458 |
| 459 // First move the pointer on the scrollbar, then press it, then away. |
| 460 // Confirm that the bar gets thick and dark. Then move point on the |
| 461 // scrollbar and mouse up. Confirm that the bar gets thick and dark. |
| 462 TEST_F(ScrollbarAnimationControllerThinningTest, MouseCaptureAndReleaseOnBar) { |
| 463 base::TimeTicks time; |
| 464 time += base::TimeDelta::FromSeconds(1); |
| 465 |
| 466 // Move in |
| 467 scrollbar_controller_->DidMouseMoveNear(0); |
| 468 |
| 469 scrollbar_controller_->Animate(time); |
| 470 time += base::TimeDelta::FromSeconds(kDuration); |
| 471 scrollbar_controller_->Animate(time); |
| 472 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 473 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 474 |
| 475 // Capture |
| 476 scrollbar_controller_->DidCaptureScrollbarBegin(); |
| 477 time += base::TimeDelta::FromSeconds(1); |
| 478 scrollbar_controller_->Animate(time); |
| 479 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 480 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 481 |
| 482 // test for 10 seconds, stay thick and dark |
| 483 for (int i = 0; i < 10; ++i) { |
| 484 // move away from bar. |
| 485 scrollbar_controller_->DidMouseMoveNear(26 + i); |
| 486 time += base::TimeDelta::FromSeconds(1); |
| 487 scrollbar_controller_->Animate(time); |
| 488 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 489 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 490 } |
| 491 |
| 492 // move to the bar. |
| 493 scrollbar_controller_->DidMouseMoveNear(0); |
| 494 |
| 495 // release |
| 496 scrollbar_controller_->DidCaptureScrollbarEnd(); |
| 497 |
| 498 // stay thick and dark |
| 499 // test for 10 seconds, stay thick and dark |
| 500 for (int i = 0; i < 10; ++i) { |
| 501 time += base::TimeDelta::FromSeconds(1); |
| 502 scrollbar_controller_->Animate(time); |
| 503 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 504 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 505 } |
| 506 } |
| 507 |
| 389 } // namespace | 508 } // namespace |
| 390 } // namespace cc | 509 } // namespace cc |
| OLD | NEW |