| 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/animation/scrollbar_animation_controller_thinning.h" | 5 #include "cc/animation/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_proxy.h" | 8 #include "cc/test/fake_impl_proxy.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" |
| 11 #include "cc/test/test_shared_bitmap_manager.h" | 11 #include "cc/test/test_shared_bitmap_manager.h" |
| 12 #include "cc/trees/layer_tree_impl.h" | 12 #include "cc/trees/layer_tree_impl.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 namespace cc { | 15 namespace cc { |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 class ScrollbarAnimationControllerThinningTest | 18 class ScrollbarAnimationControllerThinningTest |
| 19 : public testing::Test, | 19 : public testing::Test, |
| 20 public ScrollbarAnimationControllerClient { | 20 public ScrollbarAnimationControllerClient { |
| 21 public: | 21 public: |
| 22 ScrollbarAnimationControllerThinningTest() | 22 ScrollbarAnimationControllerThinningTest() |
| 23 : host_impl_(&proxy_, &shared_bitmap_manager_) {} | 23 : host_impl_(&proxy_, &shared_bitmap_manager_) {} |
| 24 | 24 |
| 25 void PostDelayedScrollbarFade(const base::Closure& start_fade, | 25 void StartAnimatingScrollbarAnimationController( |
| 26 base::TimeDelta delay) override { | 26 ScrollbarAnimationController* controller) override { |
| 27 is_animating_ = true; |
| 28 } |
| 29 void StopAnimatingScrollbarAnimationController( |
| 30 ScrollbarAnimationController* controller) override { |
| 31 is_animating_ = false; |
| 32 } |
| 33 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade, |
| 34 base::TimeDelta delay) override { |
| 27 start_fade_ = start_fade; | 35 start_fade_ = start_fade; |
| 36 delay_ = delay; |
| 28 } | 37 } |
| 29 void SetNeedsScrollbarAnimationFrame() override {} | 38 void SetNeedsRedrawForScrollbarAnimation() override { |
| 39 did_request_redraw_ = true; |
| 40 } |
| 30 | 41 |
| 31 protected: | 42 protected: |
| 32 void SetUp() override { | 43 void SetUp() override { |
| 33 scoped_ptr<LayerImpl> scroll_layer = | 44 scoped_ptr<LayerImpl> scroll_layer = |
| 34 LayerImpl::Create(host_impl_.active_tree(), 1); | 45 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 35 clip_layer_ = LayerImpl::Create(host_impl_.active_tree(), 3); | 46 clip_layer_ = LayerImpl::Create(host_impl_.active_tree(), 3); |
| 36 scroll_layer->SetScrollClipLayer(clip_layer_->id()); | 47 scroll_layer->SetScrollClipLayer(clip_layer_->id()); |
| 37 LayerImpl* scroll_layer_ptr = scroll_layer.get(); | 48 LayerImpl* scroll_layer_ptr = scroll_layer.get(); |
| 38 clip_layer_->AddChild(scroll_layer.Pass()); | 49 clip_layer_->AddChild(scroll_layer.Pass()); |
| 39 | 50 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 50 kTrackStart, | 61 kTrackStart, |
| 51 kIsLeftSideVerticalScrollbar, | 62 kIsLeftSideVerticalScrollbar, |
| 52 kIsOverlayScrollbar); | 63 kIsOverlayScrollbar); |
| 53 | 64 |
| 54 scrollbar_layer_->SetScrollLayerAndClipLayerByIds(scroll_layer_ptr->id(), | 65 scrollbar_layer_->SetScrollLayerAndClipLayerByIds(scroll_layer_ptr->id(), |
| 55 clip_layer_->id()); | 66 clip_layer_->id()); |
| 56 clip_layer_->SetBounds(gfx::Size(100, 100)); | 67 clip_layer_->SetBounds(gfx::Size(100, 100)); |
| 57 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); | 68 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); |
| 58 | 69 |
| 59 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create( | 70 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create( |
| 60 scroll_layer_ptr, | 71 scroll_layer_ptr, this, base::TimeDelta::FromSeconds(2), |
| 61 this, | 72 base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(3)); |
| 62 base::TimeDelta::FromSeconds(2), | |
| 63 base::TimeDelta::FromSeconds(5), | |
| 64 base::TimeDelta::FromSeconds(3)); | |
| 65 } | 73 } |
| 66 | 74 |
| 67 FakeImplProxy proxy_; | 75 FakeImplProxy proxy_; |
| 68 TestSharedBitmapManager shared_bitmap_manager_; | 76 TestSharedBitmapManager shared_bitmap_manager_; |
| 69 FakeLayerTreeHostImpl host_impl_; | 77 FakeLayerTreeHostImpl host_impl_; |
| 70 scoped_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_; | 78 scoped_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_; |
| 71 scoped_ptr<LayerImpl> clip_layer_; | 79 scoped_ptr<LayerImpl> clip_layer_; |
| 72 scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar_layer_; | 80 scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar_layer_; |
| 73 | 81 |
| 74 base::Closure start_fade_; | 82 base::Closure start_fade_; |
| 83 base::TimeDelta delay_; |
| 84 bool is_animating_; |
| 85 bool did_request_redraw_; |
| 75 }; | 86 }; |
| 76 | 87 |
| 77 // Check initialization of scrollbar. | 88 // Check initialization of scrollbar. |
| 78 TEST_F(ScrollbarAnimationControllerThinningTest, Idle) { | 89 TEST_F(ScrollbarAnimationControllerThinningTest, Idle) { |
| 79 scrollbar_controller_->Animate(base::TimeTicks()); | 90 scrollbar_controller_->Animate(base::TimeTicks()); |
| 80 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); | 91 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); |
| 81 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); | 92 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 82 } | 93 } |
| 83 | 94 |
| 84 // Check that scrollbar disappears when the layer becomes non-scrollable. | 95 // Check that scrollbar disappears when the layer becomes non-scrollable. |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 | 376 |
| 366 time += base::TimeDelta::FromSeconds(1); | 377 time += base::TimeDelta::FromSeconds(1); |
| 367 scrollbar_controller_->Animate(time); | 378 scrollbar_controller_->Animate(time); |
| 368 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); | 379 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); |
| 369 // The thickness now gets big again. | 380 // The thickness now gets big again. |
| 370 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 381 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 371 } | 382 } |
| 372 | 383 |
| 373 } // namespace | 384 } // namespace |
| 374 } // namespace cc | 385 } // namespace cc |
| OLD | NEW |