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.h" | 5 #include "cc/input/scrollbar_animation_controller.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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 : host_impl_(&task_runner_provider_, &task_graph_runner_), | 64 : host_impl_(&task_runner_provider_, &task_graph_runner_), |
65 client_(&host_impl_) {} | 65 client_(&host_impl_) {} |
66 | 66 |
67 void ExpectScrollbarsOpacity(float opacity) { | 67 void ExpectScrollbarsOpacity(float opacity) { |
68 EXPECT_FLOAT_EQ(opacity, v_scrollbar_layer_->Opacity()); | 68 EXPECT_FLOAT_EQ(opacity, v_scrollbar_layer_->Opacity()); |
69 EXPECT_FLOAT_EQ(opacity, h_scrollbar_layer_->Opacity()); | 69 EXPECT_FLOAT_EQ(opacity, h_scrollbar_layer_->Opacity()); |
70 } | 70 } |
71 | 71 |
72 protected: | 72 protected: |
73 const base::TimeDelta kFadeDelay = base::TimeDelta::FromSeconds(4); | 73 const base::TimeDelta kFadeDelay = base::TimeDelta::FromSeconds(4); |
74 const base::TimeDelta kResizeFadeOutDelay = base::TimeDelta::FromSeconds(5); | |
75 const base::TimeDelta kFadeDuration = base::TimeDelta::FromSeconds(3); | 74 const base::TimeDelta kFadeDuration = base::TimeDelta::FromSeconds(3); |
76 const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2); | 75 const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2); |
77 | 76 |
78 void SetUp() override { | 77 void SetUp() override { |
79 std::unique_ptr<LayerImpl> scroll_layer = | 78 std::unique_ptr<LayerImpl> scroll_layer = |
80 LayerImpl::Create(host_impl_.active_tree(), 1); | 79 LayerImpl::Create(host_impl_.active_tree(), 1); |
81 std::unique_ptr<LayerImpl> clip = | 80 std::unique_ptr<LayerImpl> clip = |
82 LayerImpl::Create(host_impl_.active_tree(), 2); | 81 LayerImpl::Create(host_impl_.active_tree(), 2); |
83 clip_layer_ = clip.get(); | 82 clip_layer_ = clip.get(); |
84 scroll_layer->SetElementId( | 83 scroll_layer->SetElementId( |
(...skipping 24 matching lines...) Expand all Loading... |
109 v_scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); | 108 v_scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); |
110 h_scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); | 109 h_scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); |
111 v_scrollbar_layer_->test_properties()->opacity_can_animate = true; | 110 v_scrollbar_layer_->test_properties()->opacity_can_animate = true; |
112 h_scrollbar_layer_->test_properties()->opacity_can_animate = true; | 111 h_scrollbar_layer_->test_properties()->opacity_can_animate = true; |
113 clip_layer_->SetBounds(gfx::Size(100, 100)); | 112 clip_layer_->SetBounds(gfx::Size(100, 100)); |
114 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); | 113 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); |
115 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); | 114 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
116 | 115 |
117 scrollbar_controller_ = ScrollbarAnimationController:: | 116 scrollbar_controller_ = ScrollbarAnimationController:: |
118 CreateScrollbarAnimationControllerAuraOverlay( | 117 CreateScrollbarAnimationControllerAuraOverlay( |
119 scroll_layer_ptr->element_id(), &client_, kFadeDelay, | 118 scroll_layer_ptr->element_id(), &client_, kFadeDelay, kFadeDuration, |
120 kResizeFadeOutDelay, kFadeDuration, kThinningDuration); | 119 kThinningDuration); |
121 } | 120 } |
122 | 121 |
123 FakeImplTaskRunnerProvider task_runner_provider_; | 122 FakeImplTaskRunnerProvider task_runner_provider_; |
124 TestTaskGraphRunner task_graph_runner_; | 123 TestTaskGraphRunner task_graph_runner_; |
125 FakeLayerTreeHostImpl host_impl_; | 124 FakeLayerTreeHostImpl host_impl_; |
126 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_; | 125 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_; |
127 LayerImpl* clip_layer_; | 126 LayerImpl* clip_layer_; |
128 SolidColorScrollbarLayerImpl* v_scrollbar_layer_; | 127 SolidColorScrollbarLayerImpl* v_scrollbar_layer_; |
129 SolidColorScrollbarLayerImpl* h_scrollbar_layer_; | 128 SolidColorScrollbarLayerImpl* h_scrollbar_layer_; |
130 NiceMock<MockScrollbarAnimationControllerClient> client_; | 129 NiceMock<MockScrollbarAnimationControllerClient> client_; |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 // If we got a ScrollBegin, we shouldn't schedule the fade out animation until | 687 // If we got a ScrollBegin, we shouldn't schedule the fade out animation until |
689 // we get a corresponding ScrollEnd. | 688 // we get a corresponding ScrollEnd. |
690 scrollbar_controller_->DidScrollBegin(); | 689 scrollbar_controller_->DidScrollBegin(); |
691 scrollbar_controller_->DidScrollUpdate(); | 690 scrollbar_controller_->DidScrollUpdate(); |
692 EXPECT_TRUE(client_.start_fade().is_null()); | 691 EXPECT_TRUE(client_.start_fade().is_null()); |
693 scrollbar_controller_->DidScrollEnd(); | 692 scrollbar_controller_->DidScrollEnd(); |
694 EXPECT_FALSE(client_.start_fade().is_null()); | 693 EXPECT_FALSE(client_.start_fade().is_null()); |
695 EXPECT_EQ(kFadeDelay, client_.delay()); | 694 EXPECT_EQ(kFadeDelay, client_.delay()); |
696 } | 695 } |
697 | 696 |
698 // Make sure that if the scroll update is as a result of a resize, we use the | |
699 // resize delay time instead of the default one. | |
700 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, ResizeFadeDuration) { | |
701 ASSERT_TRUE(client_.delay().is_zero()); | |
702 | |
703 scrollbar_controller_->DidResize(); | |
704 EXPECT_FALSE(client_.start_fade().is_null()); | |
705 EXPECT_EQ(kResizeFadeOutDelay, client_.delay()); | |
706 | |
707 client_.delay() = base::TimeDelta(); | |
708 | |
709 // We should use the gesture delay rather than the resize delay if we're in a | |
710 // gesture scroll, even if it is resizing. | |
711 scrollbar_controller_->DidScrollBegin(); | |
712 scrollbar_controller_->DidResize(); | |
713 scrollbar_controller_->DidScrollEnd(); | |
714 | |
715 EXPECT_FALSE(client_.start_fade().is_null()); | |
716 EXPECT_EQ(kFadeDelay, client_.delay()); | |
717 } | |
718 | |
719 // Tests that the fade effect is animated. | 697 // Tests that the fade effect is animated. |
720 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAnimated) { | 698 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAnimated) { |
721 base::TimeTicks time; | 699 base::TimeTicks time; |
722 time += base::TimeDelta::FromSeconds(1); | 700 time += base::TimeDelta::FromSeconds(1); |
723 | 701 |
724 // Scroll to make the scrollbars visible. | 702 // Scroll to make the scrollbars visible. |
725 scrollbar_controller_->DidScrollBegin(); | 703 scrollbar_controller_->DidScrollBegin(); |
726 scrollbar_controller_->DidScrollUpdate(); | 704 scrollbar_controller_->DidScrollUpdate(); |
727 scrollbar_controller_->DidScrollEnd(); | 705 scrollbar_controller_->DidScrollEnd(); |
728 | 706 |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); | 1159 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); |
1182 | 1160 |
1183 scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); | 1161 scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); |
1184 clip_layer_->SetBounds(gfx::Size(100, 100)); | 1162 clip_layer_->SetBounds(gfx::Size(100, 100)); |
1185 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); | 1163 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); |
1186 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); | 1164 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
1187 | 1165 |
1188 scrollbar_controller_ = | 1166 scrollbar_controller_ = |
1189 ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid( | 1167 ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid( |
1190 scroll_layer_ptr->element_id(), this, | 1168 scroll_layer_ptr->element_id(), this, |
1191 base::TimeDelta::FromSeconds(2), base::TimeDelta::FromSeconds(5), | 1169 base::TimeDelta::FromSeconds(2), base::TimeDelta::FromSeconds(3)); |
1192 base::TimeDelta::FromSeconds(3)); | |
1193 } | 1170 } |
1194 | 1171 |
1195 virtual ScrollbarOrientation orientation() const { return HORIZONTAL; } | 1172 virtual ScrollbarOrientation orientation() const { return HORIZONTAL; } |
1196 | 1173 |
1197 FakeImplTaskRunnerProvider task_runner_provider_; | 1174 FakeImplTaskRunnerProvider task_runner_provider_; |
1198 TestTaskGraphRunner task_graph_runner_; | 1175 TestTaskGraphRunner task_graph_runner_; |
1199 FakeLayerTreeHostImpl host_impl_; | 1176 FakeLayerTreeHostImpl host_impl_; |
1200 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_; | 1177 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_; |
1201 LayerImpl* clip_layer_; | 1178 LayerImpl* clip_layer_; |
1202 SolidColorScrollbarLayerImpl* scrollbar_layer_; | 1179 SolidColorScrollbarLayerImpl* scrollbar_layer_; |
1203 | 1180 |
1204 base::Closure start_fade_; | 1181 base::Closure start_fade_; |
1205 base::TimeDelta delay_; | 1182 base::TimeDelta delay_; |
1206 bool did_request_redraw_; | 1183 bool did_request_redraw_; |
1207 bool did_request_animate_; | 1184 bool did_request_animate_; |
1208 }; | 1185 }; |
1209 | 1186 |
1210 class VerticalScrollbarAnimationControllerAndroidTest | 1187 class VerticalScrollbarAnimationControllerAndroidTest |
1211 : public ScrollbarAnimationControllerAndroidTest { | 1188 : public ScrollbarAnimationControllerAndroidTest { |
1212 protected: | 1189 protected: |
1213 ScrollbarOrientation orientation() const override { return VERTICAL; } | 1190 ScrollbarOrientation orientation() const override { return VERTICAL; } |
1214 }; | 1191 }; |
1215 | 1192 |
1216 TEST_F(ScrollbarAnimationControllerAndroidTest, DelayAnimationOnResize) { | |
1217 scrollbar_layer_->SetOverlayScrollbarLayerOpacityAnimated(0.f); | |
1218 // We should use the gesture delay rather than the resize delay if we're in a | |
1219 // gesture scroll, even if it is resizing. | |
1220 scrollbar_controller_->DidScrollBegin(); | |
1221 scrollbar_controller_->DidResize(); | |
1222 scrollbar_controller_->DidScrollEnd(); | |
1223 // Normal Animation delay of 2 seconds. | |
1224 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | |
1225 EXPECT_EQ(delay_, base::TimeDelta::FromSeconds(2)); | |
1226 | |
1227 scrollbar_layer_->SetOverlayScrollbarLayerOpacityAnimated(0.f); | |
1228 scrollbar_controller_->DidResize(); | |
1229 // Delay animation on resize to 5 seconds. | |
1230 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | |
1231 EXPECT_EQ(delay_, base::TimeDelta::FromSeconds(5)); | |
1232 } | |
1233 | |
1234 TEST_F(ScrollbarAnimationControllerAndroidTest, HiddenInBegin) { | 1193 TEST_F(ScrollbarAnimationControllerAndroidTest, HiddenInBegin) { |
1235 scrollbar_layer_->SetOverlayScrollbarLayerOpacityAnimated(0.f); | 1194 scrollbar_layer_->SetOverlayScrollbarLayerOpacityAnimated(0.f); |
1236 scrollbar_controller_->Animate(base::TimeTicks()); | 1195 scrollbar_controller_->Animate(base::TimeTicks()); |
1237 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 1196 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
1238 } | 1197 } |
1239 | 1198 |
1240 TEST_F(ScrollbarAnimationControllerAndroidTest, | 1199 TEST_F(ScrollbarAnimationControllerAndroidTest, |
1241 HiddenAfterNonScrollingGesture) { | 1200 HiddenAfterNonScrollingGesture) { |
1242 scrollbar_layer_->SetOverlayScrollbarLayerOpacityAnimated(0.f); | 1201 scrollbar_layer_->SetOverlayScrollbarLayerOpacityAnimated(0.f); |
1243 scrollbar_controller_->DidScrollBegin(); | 1202 scrollbar_controller_->DidScrollBegin(); |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1616 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); | 1575 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); |
1617 | 1576 |
1618 time += base::TimeDelta::FromSeconds(1); | 1577 time += base::TimeDelta::FromSeconds(1); |
1619 scrollbar_controller_->DidScrollEnd(); | 1578 scrollbar_controller_->DidScrollEnd(); |
1620 EXPECT_FALSE(did_request_animate_); | 1579 EXPECT_FALSE(did_request_animate_); |
1621 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); | 1580 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); |
1622 } | 1581 } |
1623 | 1582 |
1624 } // namespace | 1583 } // namespace |
1625 } // namespace cc | 1584 } // namespace cc |
OLD | NEW |