| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 const int kTrackStart = 0; | 88 const int kTrackStart = 0; |
| 89 const int kTrackLength = 100; | 89 const int kTrackLength = 100; |
| 90 const bool kIsLeftSideVerticalScrollbar = false; | 90 const bool kIsLeftSideVerticalScrollbar = false; |
| 91 const bool kIsOverlayScrollbar = true; | 91 const bool kIsOverlayScrollbar = true; |
| 92 | 92 |
| 93 std::unique_ptr<SolidColorScrollbarLayerImpl> h_scrollbar = | 93 std::unique_ptr<SolidColorScrollbarLayerImpl> h_scrollbar = |
| 94 SolidColorScrollbarLayerImpl::Create( | 94 SolidColorScrollbarLayerImpl::Create( |
| 95 host_impl_.active_tree(), 3, HORIZONTAL, kThumbThickness, | 95 host_impl_.active_tree(), 3, HORIZONTAL, kThumbThickness, |
| 96 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); | 96 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); |
| 97 h_scrollbar->test_properties()->opacity = 0.0f; |
| 97 std::unique_ptr<SolidColorScrollbarLayerImpl> v_scrollbar = | 98 std::unique_ptr<SolidColorScrollbarLayerImpl> v_scrollbar = |
| 98 SolidColorScrollbarLayerImpl::Create( | 99 SolidColorScrollbarLayerImpl::Create( |
| 99 host_impl_.active_tree(), 4, VERTICAL, kThumbThickness, kTrackStart, | 100 host_impl_.active_tree(), 4, VERTICAL, kThumbThickness, kTrackStart, |
| 100 kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); | 101 kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); |
| 102 v_scrollbar->test_properties()->opacity = 0.0f; |
| 101 v_scrollbar_layer_ = v_scrollbar.get(); | 103 v_scrollbar_layer_ = v_scrollbar.get(); |
| 102 h_scrollbar_layer_ = h_scrollbar.get(); | 104 h_scrollbar_layer_ = h_scrollbar.get(); |
| 103 | 105 |
| 104 scroll_layer->test_properties()->AddChild(std::move(v_scrollbar)); | 106 scroll_layer->test_properties()->AddChild(std::move(v_scrollbar)); |
| 105 scroll_layer->test_properties()->AddChild(std::move(h_scrollbar)); | 107 scroll_layer->test_properties()->AddChild(std::move(h_scrollbar)); |
| 106 clip_layer_->test_properties()->AddChild(std::move(scroll_layer)); | 108 clip_layer_->test_properties()->AddChild(std::move(scroll_layer)); |
| 107 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); | 109 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); |
| 108 | 110 |
| 109 v_scrollbar_layer_->SetBounds(gfx::Size(kThumbThickness, kTrackLength)); | 111 v_scrollbar_layer_->SetBounds(gfx::Size(kThumbThickness, kTrackLength)); |
| 110 v_scrollbar_layer_->SetPosition(gfx::PointF(90, 0)); | 112 v_scrollbar_layer_->SetPosition(gfx::PointF(90, 0)); |
| 111 v_scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); | 113 v_scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); |
| 112 v_scrollbar_layer_->test_properties()->opacity_can_animate = true; | 114 v_scrollbar_layer_->test_properties()->opacity_can_animate = true; |
| 113 | 115 |
| 114 h_scrollbar_layer_->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); | 116 h_scrollbar_layer_->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
| 115 h_scrollbar_layer_->SetPosition(gfx::PointF(0, 90)); | 117 h_scrollbar_layer_->SetPosition(gfx::PointF(0, 90)); |
| 116 h_scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); | 118 h_scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); |
| 117 h_scrollbar_layer_->test_properties()->opacity_can_animate = true; | 119 h_scrollbar_layer_->test_properties()->opacity_can_animate = true; |
| 118 | 120 |
| 119 clip_layer_->SetBounds(gfx::Size(100, 100)); | 121 clip_layer_->SetBounds(gfx::Size(100, 100)); |
| 120 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); | 122 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); |
| 121 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); | 123 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 122 | 124 |
| 123 scrollbar_controller_ = ScrollbarAnimationController:: | 125 scrollbar_controller_ = ScrollbarAnimationController:: |
| 124 CreateScrollbarAnimationControllerAuraOverlay( | 126 CreateScrollbarAnimationControllerAuraOverlay( |
| 125 scroll_layer_ptr->element_id(), &client_, kFadeDelay, kFadeDuration, | 127 scroll_layer_ptr->element_id(), &client_, kFadeDelay, kFadeDuration, |
| 126 kThinningDuration); | 128 kThinningDuration, 0.0f); |
| 127 v_scrollbar_layer_->SetCurrentPos(0); | 129 v_scrollbar_layer_->SetCurrentPos(0); |
| 128 h_scrollbar_layer_->SetCurrentPos(0); | 130 h_scrollbar_layer_->SetCurrentPos(0); |
| 129 } | 131 } |
| 130 | 132 |
| 131 // Return a point with given offset from the top-left of vertical scrollbar. | 133 // Return a point with given offset from the top-left of vertical scrollbar. |
| 132 gfx::PointF NearVerticalScrollbarBegin(float offset_x, float offset_y) { | 134 gfx::PointF NearVerticalScrollbarBegin(float offset_x, float offset_y) { |
| 133 gfx::PointF p(90, 0); | 135 gfx::PointF p(90, 0); |
| 134 p.Offset(offset_x, offset_y); | 136 p.Offset(offset_x, offset_y); |
| 135 return p; | 137 return p; |
| 136 } | 138 } |
| (...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1233 const int kTrackStart = 0; | 1235 const int kTrackStart = 0; |
| 1234 const bool kIsLeftSideVerticalScrollbar = false; | 1236 const bool kIsLeftSideVerticalScrollbar = false; |
| 1235 const bool kIsOverlayScrollbar = true; // Allow opacity animations. | 1237 const bool kIsOverlayScrollbar = true; // Allow opacity animations. |
| 1236 | 1238 |
| 1237 std::unique_ptr<LayerImpl> scroll_layer = | 1239 std::unique_ptr<LayerImpl> scroll_layer = |
| 1238 LayerImpl::Create(host_impl_.active_tree(), 1); | 1240 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 1239 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = | 1241 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
| 1240 SolidColorScrollbarLayerImpl::Create( | 1242 SolidColorScrollbarLayerImpl::Create( |
| 1241 host_impl_.active_tree(), 2, orientation(), kThumbThickness, | 1243 host_impl_.active_tree(), 2, orientation(), kThumbThickness, |
| 1242 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); | 1244 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); |
| 1245 scrollbar->test_properties()->opacity = 0.0f; |
| 1243 scrollbar_layer_ = scrollbar.get(); | 1246 scrollbar_layer_ = scrollbar.get(); |
| 1244 scrollbar_layer_->test_properties()->opacity_can_animate = true; | 1247 scrollbar_layer_->test_properties()->opacity_can_animate = true; |
| 1245 std::unique_ptr<LayerImpl> clip = | 1248 std::unique_ptr<LayerImpl> clip = |
| 1246 LayerImpl::Create(host_impl_.active_tree(), 3); | 1249 LayerImpl::Create(host_impl_.active_tree(), 3); |
| 1247 clip_layer_ = clip.get(); | 1250 clip_layer_ = clip.get(); |
| 1248 scroll_layer->SetElementId( | 1251 scroll_layer->SetElementId( |
| 1249 LayerIdToElementIdForTesting(scroll_layer->id())); | 1252 LayerIdToElementIdForTesting(scroll_layer->id())); |
| 1250 | 1253 |
| 1251 scroll_layer->SetScrollClipLayer(clip_layer_->id()); | 1254 scroll_layer->SetScrollClipLayer(clip_layer_->id()); |
| 1252 LayerImpl* scroll_layer_ptr = scroll_layer.get(); | 1255 LayerImpl* scroll_layer_ptr = scroll_layer.get(); |
| 1253 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); | 1256 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); |
| 1254 clip->test_properties()->AddChild(std::move(scroll_layer)); | 1257 clip->test_properties()->AddChild(std::move(scroll_layer)); |
| 1255 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); | 1258 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); |
| 1256 | 1259 |
| 1257 scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); | 1260 scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); |
| 1258 clip_layer_->SetBounds(gfx::Size(100, 100)); | 1261 clip_layer_->SetBounds(gfx::Size(100, 100)); |
| 1259 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); | 1262 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); |
| 1260 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); | 1263 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 1261 | 1264 |
| 1262 scrollbar_controller_ = | 1265 scrollbar_controller_ = |
| 1263 ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid( | 1266 ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid( |
| 1264 scroll_layer_ptr->element_id(), this, | 1267 scroll_layer_ptr->element_id(), this, |
| 1265 base::TimeDelta::FromSeconds(2), base::TimeDelta::FromSeconds(3)); | 1268 base::TimeDelta::FromSeconds(2), base::TimeDelta::FromSeconds(3), |
| 1269 0.0f); |
| 1266 } | 1270 } |
| 1267 | 1271 |
| 1268 virtual ScrollbarOrientation orientation() const { return HORIZONTAL; } | 1272 virtual ScrollbarOrientation orientation() const { return HORIZONTAL; } |
| 1269 | 1273 |
| 1270 FakeImplTaskRunnerProvider task_runner_provider_; | 1274 FakeImplTaskRunnerProvider task_runner_provider_; |
| 1271 TestTaskGraphRunner task_graph_runner_; | 1275 TestTaskGraphRunner task_graph_runner_; |
| 1272 FakeLayerTreeHostImpl host_impl_; | 1276 FakeLayerTreeHostImpl host_impl_; |
| 1273 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_; | 1277 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_; |
| 1274 LayerImpl* clip_layer_; | 1278 LayerImpl* clip_layer_; |
| 1275 SolidColorScrollbarLayerImpl* scrollbar_layer_; | 1279 SolidColorScrollbarLayerImpl* scrollbar_layer_; |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1671 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); | 1675 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); |
| 1672 | 1676 |
| 1673 time += base::TimeDelta::FromSeconds(1); | 1677 time += base::TimeDelta::FromSeconds(1); |
| 1674 scrollbar_controller_->DidScrollEnd(); | 1678 scrollbar_controller_->DidScrollEnd(); |
| 1675 EXPECT_FALSE(did_request_animate_); | 1679 EXPECT_FALSE(did_request_animate_); |
| 1676 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); | 1680 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); |
| 1677 } | 1681 } |
| 1678 | 1682 |
| 1679 } // namespace | 1683 } // namespace |
| 1680 } // namespace cc | 1684 } // namespace cc |
| OLD | NEW |