| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "base/containers/hash_tables.h" | 5 #include "base/containers/hash_tables.h" |
| 6 #include "cc/animation/scrollbar_animation_controller.h" | 6 #include "cc/animation/scrollbar_animation_controller.h" |
| 7 #include "cc/debug/test_web_graphics_context_3d.h" | 7 #include "cc/debug/test_web_graphics_context_3d.h" |
| 8 #include "cc/layers/append_quads_data.h" | 8 #include "cc/layers/append_quads_data.h" |
| 9 #include "cc/layers/painted_scrollbar_layer.h" | 9 #include "cc/layers/painted_scrollbar_layer.h" |
| 10 #include "cc/layers/painted_scrollbar_layer_impl.h" | 10 #include "cc/layers/painted_scrollbar_layer_impl.h" |
| 11 #include "cc/layers/scrollbar_layer_interface.h" |
| 12 #include "cc/layers/solid_color_scrollbar_layer.h" |
| 13 #include "cc/layers/solid_color_scrollbar_layer_impl.h" |
| 11 #include "cc/quads/solid_color_draw_quad.h" | 14 #include "cc/quads/solid_color_draw_quad.h" |
| 12 #include "cc/resources/resource_update_queue.h" | 15 #include "cc/resources/resource_update_queue.h" |
| 13 #include "cc/test/fake_impl_proxy.h" | 16 #include "cc/test/fake_impl_proxy.h" |
| 14 #include "cc/test/fake_layer_tree_host.h" | 17 #include "cc/test/fake_layer_tree_host.h" |
| 15 #include "cc/test/fake_layer_tree_host_client.h" | 18 #include "cc/test/fake_layer_tree_host_client.h" |
| 16 #include "cc/test/fake_layer_tree_host_impl.h" | 19 #include "cc/test/fake_layer_tree_host_impl.h" |
| 17 #include "cc/test/fake_painted_scrollbar_layer.h" | 20 #include "cc/test/fake_painted_scrollbar_layer.h" |
| 18 #include "cc/test/fake_scrollbar.h" | 21 #include "cc/test/fake_scrollbar.h" |
| 19 #include "cc/test/geometry_test_utils.h" | 22 #include "cc/test/geometry_test_utils.h" |
| 20 #include "cc/test/layer_tree_test.h" | 23 #include "cc/test/layer_tree_test.h" |
| 21 #include "cc/test/mock_quad_culler.h" | 24 #include "cc/test/mock_quad_culler.h" |
| 22 #include "cc/trees/layer_tree_host.h" | 25 #include "cc/trees/layer_tree_host.h" |
| 23 #include "cc/trees/layer_tree_impl.h" | 26 #include "cc/trees/layer_tree_impl.h" |
| 24 #include "cc/trees/single_thread_proxy.h" | 27 #include "cc/trees/single_thread_proxy.h" |
| 25 #include "cc/trees/tree_synchronizer.h" | 28 #include "cc/trees/tree_synchronizer.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 31 |
| 29 namespace cc { | 32 namespace cc { |
| 30 namespace { | 33 namespace { |
| 31 | 34 |
| 32 LayerImpl* LayerImplForScrollAreaAndScrollbar( | 35 LayerImpl* LayerImplForScrollAreaAndScrollbar( |
| 33 FakeLayerTreeHost* host, | 36 FakeLayerTreeHost* host, |
| 34 scoped_ptr<Scrollbar> scrollbar, | 37 scoped_ptr<Scrollbar> scrollbar, |
| 35 bool reverse_order) { | 38 bool reverse_order, |
| 39 bool use_solid_color_scrollbar, |
| 40 int thumb_thickness) { |
| 36 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 41 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 37 scoped_refptr<Layer> child1 = Layer::Create(); | 42 scoped_refptr<Layer> child1 = Layer::Create(); |
| 38 scoped_refptr<Layer> child2 = | 43 scoped_refptr<Layer> child2; |
| 39 PaintedScrollbarLayer::Create(scrollbar.Pass(), child1->id()); | 44 if (use_solid_color_scrollbar) { |
| 45 child2 = SolidColorScrollbarLayer::Create( |
| 46 scrollbar->Orientation(), thumb_thickness, child1->id()); |
| 47 } else { |
| 48 child2 = PaintedScrollbarLayer::Create(scrollbar.Pass(), child1->id()); |
| 49 } |
| 40 layer_tree_root->AddChild(child1); | 50 layer_tree_root->AddChild(child1); |
| 41 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); | 51 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); |
| 42 host->SetRootLayer(layer_tree_root); | 52 host->SetRootLayer(layer_tree_root); |
| 43 return host->CommitAndCreateLayerImplTree(); | 53 return host->CommitAndCreateLayerImplTree(); |
| 44 } | 54 } |
| 45 | 55 |
| 46 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) { | 56 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) { |
| 47 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 57 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 48 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 58 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 49 LayerImpl* layer_impl_tree_root = | 59 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 50 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); | 60 host.get(), scrollbar.Pass(), false, false, 0); |
| 51 | 61 |
| 52 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; | 62 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; |
| 53 PaintedScrollbarLayerImpl* cc_child2 = | 63 PaintedScrollbarLayerImpl* cc_child2 = |
| 54 static_cast<PaintedScrollbarLayerImpl*>( | 64 static_cast<PaintedScrollbarLayerImpl*>( |
| 55 layer_impl_tree_root->children()[1]); | 65 layer_impl_tree_root->children()[1]); |
| 56 | 66 |
| 57 EXPECT_EQ(cc_child1->horizontal_scrollbar_layer(), cc_child2); | 67 EXPECT_EQ(cc_child1->horizontal_scrollbar_layer(), cc_child2); |
| 58 } | 68 } |
| 59 | 69 |
| 60 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { | 70 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { |
| 61 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 71 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 62 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 72 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 63 LayerImpl* layer_impl_tree_root = | 73 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 64 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), true); | 74 host.get(), scrollbar.Pass(), true, false, 0); |
| 65 | 75 |
| 66 PaintedScrollbarLayerImpl* cc_child1 = | 76 PaintedScrollbarLayerImpl* cc_child1 = |
| 67 static_cast<PaintedScrollbarLayerImpl*>( | 77 static_cast<PaintedScrollbarLayerImpl*>( |
| 68 layer_impl_tree_root->children()[0]); | 78 layer_impl_tree_root->children()[0]); |
| 69 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; | 79 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; |
| 70 | 80 |
| 71 EXPECT_EQ(cc_child2->horizontal_scrollbar_layer(), cc_child1); | 81 EXPECT_EQ(cc_child2->horizontal_scrollbar_layer(), cc_child1); |
| 72 } | 82 } |
| 73 | 83 |
| 74 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { | 84 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { |
| 75 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 85 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 76 | 86 |
| 77 // Create and attach a non-overlay scrollbar. | 87 // Create and attach a non-overlay scrollbar. |
| 78 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 88 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 79 LayerImpl* layer_impl_tree_root = | 89 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 80 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); | 90 host.get(), scrollbar.Pass(), false, false, 0); |
| 81 PaintedScrollbarLayerImpl* scrollbar_layer_impl = | 91 PaintedScrollbarLayerImpl* scrollbar_layer_impl = |
| 82 static_cast<PaintedScrollbarLayerImpl*>( | 92 static_cast<PaintedScrollbarLayerImpl*>( |
| 83 layer_impl_tree_root->children()[1]); | 93 layer_impl_tree_root->children()[1]); |
| 84 | 94 |
| 85 // When the scrollbar is not an overlay scrollbar, the scroll should be | 95 // When the scrollbar is not an overlay scrollbar, the scroll should be |
| 86 // responded to on the main thread as the compositor does not yet implement | 96 // responded to on the main thread as the compositor does not yet implement |
| 87 // scrollbar scrolling. | 97 // scrollbar scrolling. |
| 88 EXPECT_EQ(InputHandler::ScrollOnMainThread, | 98 EXPECT_EQ(InputHandler::ScrollOnMainThread, |
| 89 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), | 99 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), |
| 90 InputHandler::Gesture)); | 100 InputHandler::Gesture)); |
| 91 | 101 |
| 92 // Create and attach an overlay scrollbar. | 102 // Create and attach an overlay scrollbar. |
| 93 scrollbar.reset(new FakeScrollbar(false, false, true)); | 103 scrollbar.reset(new FakeScrollbar(false, false, true)); |
| 94 | 104 |
| 95 layer_impl_tree_root = | 105 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 96 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); | 106 host.get(), scrollbar.Pass(), false, false, 0); |
| 97 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( | 107 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( |
| 98 layer_impl_tree_root->children()[1]); | 108 layer_impl_tree_root->children()[1]); |
| 99 | 109 |
| 100 // The user shouldn't be able to drag an overlay scrollbar and the scroll | 110 // The user shouldn't be able to drag an overlay scrollbar and the scroll |
| 101 // may be handled in the compositor. | 111 // may be handled in the compositor. |
| 102 EXPECT_EQ(InputHandler::ScrollIgnored, | 112 EXPECT_EQ(InputHandler::ScrollIgnored, |
| 103 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), | 113 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), |
| 104 InputHandler::Gesture)); | 114 InputHandler::Gesture)); |
| 105 } | 115 } |
| 106 | 116 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 121 | 131 |
| 122 host->SetRootLayer(layer_tree_root); | 132 host->SetRootLayer(layer_tree_root); |
| 123 layer_tree_root->AddChild(content_layer); | 133 layer_tree_root->AddChild(content_layer); |
| 124 layer_tree_root->AddChild(scrollbar_layer); | 134 layer_tree_root->AddChild(scrollbar_layer); |
| 125 | 135 |
| 126 layer_tree_root->SavePaintProperties(); | 136 layer_tree_root->SavePaintProperties(); |
| 127 content_layer->SavePaintProperties(); | 137 content_layer->SavePaintProperties(); |
| 128 | 138 |
| 129 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); | 139 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); |
| 130 | 140 |
| 131 PaintedScrollbarLayerImpl* cc_scrollbar_layer = | 141 ScrollbarLayerImplBase* cc_scrollbar_layer = |
| 132 static_cast<PaintedScrollbarLayerImpl*>( | 142 static_cast<PaintedScrollbarLayerImpl*>( |
| 133 layer_impl_tree_root->children()[1]); | 143 layer_impl_tree_root->children()[1]); |
| 134 | 144 |
| 135 EXPECT_EQ(10.f, cc_scrollbar_layer->CurrentPos()); | 145 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos()); |
| 136 EXPECT_EQ(30, cc_scrollbar_layer->Maximum()); | 146 EXPECT_EQ(30, cc_scrollbar_layer->maximum()); |
| 137 | 147 |
| 138 layer_tree_root->SetScrollOffset(gfx::Vector2d(100, 200)); | 148 layer_tree_root->SetScrollOffset(gfx::Vector2d(100, 200)); |
| 139 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(300, 500)); | 149 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(300, 500)); |
| 140 layer_tree_root->SetBounds(gfx::Size(1000, 2000)); | 150 layer_tree_root->SetBounds(gfx::Size(1000, 2000)); |
| 141 layer_tree_root->SavePaintProperties(); | 151 layer_tree_root->SavePaintProperties(); |
| 142 content_layer->SetBounds(gfx::Size(1000, 2000)); | 152 content_layer->SetBounds(gfx::Size(1000, 2000)); |
| 143 content_layer->SavePaintProperties(); | 153 content_layer->SavePaintProperties(); |
| 144 | 154 |
| 145 ScrollbarAnimationController* scrollbar_controller = | 155 ScrollbarAnimationController* scrollbar_controller = |
| 146 layer_impl_tree_root->scrollbar_animation_controller(); | 156 layer_impl_tree_root->scrollbar_animation_controller(); |
| 147 layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); | 157 layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); |
| 148 EXPECT_EQ(scrollbar_controller, | 158 EXPECT_EQ(scrollbar_controller, |
| 149 layer_impl_tree_root->scrollbar_animation_controller()); | 159 layer_impl_tree_root->scrollbar_animation_controller()); |
| 150 | 160 |
| 151 EXPECT_EQ(100.f, cc_scrollbar_layer->CurrentPos()); | 161 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos()); |
| 152 EXPECT_EQ(300, cc_scrollbar_layer->Maximum()); | 162 EXPECT_EQ(300, cc_scrollbar_layer->maximum()); |
| 153 | 163 |
| 154 layer_impl_tree_root->ScrollBy(gfx::Vector2d(12, 34)); | 164 layer_impl_tree_root->ScrollBy(gfx::Vector2d(12, 34)); |
| 155 | 165 |
| 156 EXPECT_EQ(112.f, cc_scrollbar_layer->CurrentPos()); | 166 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos()); |
| 157 EXPECT_EQ(300, cc_scrollbar_layer->Maximum()); | 167 EXPECT_EQ(300, cc_scrollbar_layer->maximum()); |
| 158 } | 168 } |
| 159 | 169 |
| 160 TEST(ScrollbarLayerTest, ThumbRect) { | 170 TEST(ScrollbarLayerTest, ThumbRect) { |
| 161 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 171 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 162 scoped_refptr<Layer> root_layer = Layer::Create(); | 172 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 163 scoped_refptr<Layer> content_layer = Layer::Create(); | 173 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 164 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 174 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 165 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); | 175 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); |
| 166 | 176 |
| 167 root_layer->SetScrollable(true); | 177 root_layer->SetScrollable(true); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 253 |
| 244 scrollbar_layer->UpdateThumbAndTrackGeometry(); | 254 scrollbar_layer->UpdateThumbAndTrackGeometry(); |
| 245 root_layer_impl = host->CommitAndCreateLayerImplTree(); | 255 root_layer_impl = host->CommitAndCreateLayerImplTree(); |
| 246 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( | 256 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( |
| 247 root_layer_impl->children()[1]); | 257 root_layer_impl->children()[1]); |
| 248 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), | 258 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), |
| 249 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 259 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 250 } | 260 } |
| 251 | 261 |
| 252 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { | 262 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { |
| 263 const int kThumbThickness = 3; |
| 264 const int kTrackLength = 100; |
| 265 |
| 253 LayerTreeSettings layer_tree_settings; | 266 LayerTreeSettings layer_tree_settings; |
| 254 layer_tree_settings.solid_color_scrollbars = true; | |
| 255 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3; | 267 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3; |
| 256 scoped_ptr<FakeLayerTreeHost> host = | 268 scoped_ptr<FakeLayerTreeHost> host = |
| 257 FakeLayerTreeHost::Create(layer_tree_settings); | 269 FakeLayerTreeHost::Create(layer_tree_settings); |
| 258 | 270 |
| 259 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 271 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| 260 LayerImpl* layer_impl_tree_root = | 272 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 261 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); | 273 host.get(), scrollbar.Pass(), false, true, kThumbThickness); |
| 262 PaintedScrollbarLayerImpl* scrollbar_layer_impl = | 274 ScrollbarLayerImplBase* scrollbar_layer_impl = |
| 263 static_cast<PaintedScrollbarLayerImpl*>( | 275 static_cast<SolidColorScrollbarLayerImpl*>( |
| 264 layer_impl_tree_root->children()[1]); | 276 layer_impl_tree_root->children()[1]); |
| 265 scrollbar_layer_impl->SetThumbThickness(3); | 277 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
| 266 scrollbar_layer_impl->SetCurrentPos(10.f); | 278 scrollbar_layer_impl->SetCurrentPos(10.f); |
| 267 scrollbar_layer_impl->SetMaximum(100); | 279 scrollbar_layer_impl->SetMaximum(100); |
| 268 scrollbar_layer_impl->SetTrackLength(100); | |
| 269 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f); | 280 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f); |
| 270 | 281 |
| 271 // Thickness should be overridden to 3. | 282 // Thickness should be overridden to 3. |
| 272 { | 283 { |
| 273 MockQuadCuller quad_culler; | 284 MockQuadCuller quad_culler; |
| 274 AppendQuadsData data; | 285 AppendQuadsData data; |
| 275 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); | 286 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); |
| 276 | 287 |
| 277 const QuadList& quads = quad_culler.quad_list(); | 288 const QuadList& quads = quad_culler.quad_list(); |
| 278 ASSERT_EQ(1u, quads.size()); | 289 ASSERT_EQ(1u, quads.size()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 305 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); | 316 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); |
| 306 | 317 |
| 307 const QuadList& quads = quad_culler.quad_list(); | 318 const QuadList& quads = quad_culler.quad_list(); |
| 308 ASSERT_EQ(1u, quads.size()); | 319 ASSERT_EQ(1u, quads.size()); |
| 309 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); | 320 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); |
| 310 EXPECT_RECT_EQ(gfx::Rect(8, 0, 20, 3), quads[0]->rect); | 321 EXPECT_RECT_EQ(gfx::Rect(8, 0, 20, 3), quads[0]->rect); |
| 311 } | 322 } |
| 312 } | 323 } |
| 313 | 324 |
| 314 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { | 325 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { |
| 326 const int kThumbThickness = 3; |
| 327 const int kTrackLength = 10; |
| 328 |
| 315 LayerTreeSettings layer_tree_settings; | 329 LayerTreeSettings layer_tree_settings; |
| 316 layer_tree_settings.solid_color_scrollbars = true; | |
| 317 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3; | 330 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3; |
| 318 scoped_ptr<FakeLayerTreeHost> host = | 331 scoped_ptr<FakeLayerTreeHost> host = |
| 319 FakeLayerTreeHost::Create(layer_tree_settings); | 332 FakeLayerTreeHost::Create(layer_tree_settings); |
| 320 | 333 |
| 321 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 334 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| 322 LayerImpl* layer_impl_tree_root = | 335 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 323 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); | 336 host.get(), scrollbar.Pass(), false, true, kThumbThickness); |
| 324 PaintedScrollbarLayerImpl* scrollbar_layer_impl = | 337 ScrollbarLayerImplBase* scrollbar_layer_impl = |
| 325 static_cast<PaintedScrollbarLayerImpl*>( | 338 static_cast<PaintedScrollbarLayerImpl*>( |
| 326 layer_impl_tree_root->children()[1]); | 339 layer_impl_tree_root->children()[1]); |
| 327 | 340 |
| 328 scrollbar_layer_impl->SetThumbThickness(3); | 341 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
| 329 scrollbar_layer_impl->SetTrackLength(10); | |
| 330 scrollbar_layer_impl->SetCurrentPos(4.f); | 342 scrollbar_layer_impl->SetCurrentPos(4.f); |
| 331 scrollbar_layer_impl->SetMaximum(8); | 343 scrollbar_layer_impl->SetMaximum(8); |
| 332 | 344 |
| 333 layer_impl_tree_root->SetScrollable(true); | 345 layer_impl_tree_root->SetScrollable(true); |
| 334 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl); | 346 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl); |
| 335 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8)); | 347 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8)); |
| 336 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); | 348 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); |
| 337 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f)); | 349 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f)); |
| 338 | 350 |
| 339 { | 351 { |
| 340 MockQuadCuller quad_culler; | 352 MockQuadCuller quad_culler; |
| 341 AppendQuadsData data; | 353 AppendQuadsData data; |
| 342 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); | 354 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); |
| 343 | 355 |
| 344 const QuadList& quads = quad_culler.quad_list(); | 356 const QuadList& quads = quad_culler.quad_list(); |
| 345 ASSERT_EQ(1u, quads.size()); | 357 ASSERT_EQ(1u, quads.size()); |
| 346 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); | 358 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); |
| 347 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect); | 359 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect); |
| 348 } | 360 } |
| 349 } | 361 } |
| 350 | 362 |
| 351 class ScrollbarLayerSolidColorThumbTest : public testing::Test { | 363 class ScrollbarLayerSolidColorThumbTest : public testing::Test { |
| 352 public: | 364 public: |
| 353 ScrollbarLayerSolidColorThumbTest() { | 365 ScrollbarLayerSolidColorThumbTest() { |
| 354 LayerTreeSettings layer_tree_settings; | 366 LayerTreeSettings layer_tree_settings; |
| 355 layer_tree_settings.solid_color_scrollbars = true; | 367 layer_tree_settings.solid_color_scrollbars = true; |
| 356 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_)); | 368 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_)); |
| 357 | 369 |
| 358 horizontal_scrollbar_layer_ = PaintedScrollbarLayerImpl::Create( | 370 const int kThumbThickness = 3; |
| 359 host_impl_->active_tree(), 1, HORIZONTAL); | 371 |
| 360 vertical_scrollbar_layer_ = PaintedScrollbarLayerImpl::Create( | 372 horizontal_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( |
| 361 host_impl_->active_tree(), 2, VERTICAL); | 373 host_impl_->active_tree(), 1, HORIZONTAL, kThumbThickness); |
| 374 vertical_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( |
| 375 host_impl_->active_tree(), 2, VERTICAL, kThumbThickness); |
| 362 } | 376 } |
| 363 | 377 |
| 364 protected: | 378 protected: |
| 365 FakeImplProxy proxy_; | 379 FakeImplProxy proxy_; |
| 366 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; | 380 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; |
| 367 scoped_ptr<PaintedScrollbarLayerImpl> horizontal_scrollbar_layer_; | 381 scoped_ptr<SolidColorScrollbarLayerImpl> horizontal_scrollbar_layer_; |
| 368 scoped_ptr<PaintedScrollbarLayerImpl> vertical_scrollbar_layer_; | 382 scoped_ptr<SolidColorScrollbarLayerImpl> vertical_scrollbar_layer_; |
| 369 }; | 383 }; |
| 370 | 384 |
| 371 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { | 385 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { |
| 372 horizontal_scrollbar_layer_->SetCurrentPos(0); | 386 horizontal_scrollbar_layer_->SetCurrentPos(0); |
| 373 horizontal_scrollbar_layer_->SetMaximum(10); | 387 horizontal_scrollbar_layer_->SetMaximum(10); |
| 374 horizontal_scrollbar_layer_->SetThumbThickness(3); | |
| 375 | 388 |
| 376 // Simple case - one third of the scrollable area is visible, so the thumb | 389 // Simple case - one third of the scrollable area is visible, so the thumb |
| 377 // should be one third as long as the track. | 390 // should be one third as long as the track. |
| 378 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.33f); | 391 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.33f); |
| 379 horizontal_scrollbar_layer_->SetTrackLength(100); | 392 horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3)); |
| 380 EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); | 393 EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); |
| 381 | 394 |
| 382 // The thumb's length should never be less than its thickness. | 395 // The thumb's length should never be less than its thickness. |
| 383 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.01f); | 396 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.01f); |
| 384 horizontal_scrollbar_layer_->SetTrackLength(100); | 397 horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3)); |
| 385 EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); | 398 EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); |
| 386 } | 399 } |
| 387 | 400 |
| 388 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) { | 401 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) { |
| 389 horizontal_scrollbar_layer_->SetTrackLength(100); | 402 horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3)); |
| 390 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.1f); | 403 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.1f); |
| 391 horizontal_scrollbar_layer_->SetThumbThickness(3); | |
| 392 | 404 |
| 393 horizontal_scrollbar_layer_->SetCurrentPos(0); | 405 horizontal_scrollbar_layer_->SetCurrentPos(0); |
| 394 horizontal_scrollbar_layer_->SetMaximum(100); | 406 horizontal_scrollbar_layer_->SetMaximum(100); |
| 395 EXPECT_EQ(0, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); | 407 EXPECT_EQ(0, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); |
| 396 EXPECT_EQ(10, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); | 408 EXPECT_EQ(10, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); |
| 397 | 409 |
| 398 horizontal_scrollbar_layer_->SetCurrentPos(100); | 410 horizontal_scrollbar_layer_->SetCurrentPos(100); |
| 399 // The thumb is 10px long and the track is 100px, so the maximum thumb | 411 // The thumb is 10px long and the track is 100px, so the maximum thumb |
| 400 // position is 90px. | 412 // position is 90px. |
| 401 EXPECT_EQ(90, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); | 413 EXPECT_EQ(90, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); |
| 402 | 414 |
| 403 horizontal_scrollbar_layer_->SetCurrentPos(80); | 415 horizontal_scrollbar_layer_->SetCurrentPos(80); |
| 404 // The scroll position is 80% of the maximum, so the thumb's position should | 416 // The scroll position is 80% of the maximum, so the thumb's position should |
| 405 // be at 80% of its maximum or 72px. | 417 // be at 80% of its maximum or 72px. |
| 406 EXPECT_EQ(72, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); | 418 EXPECT_EQ(72, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); |
| 407 } | 419 } |
| 408 | 420 |
| 409 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) { | 421 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) { |
| 410 PaintedScrollbarLayerImpl* layers[2] = | 422 SolidColorScrollbarLayerImpl* layers[2] = |
| 411 { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() }; | 423 { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() }; |
| 412 for (size_t i = 0; i < 2; ++i) { | 424 for (size_t i = 0; i < 2; ++i) { |
| 413 layers[i]->SetTrackLength(100); | |
| 414 layers[i]->SetVisibleToTotalLengthRatio(0.2f); | 425 layers[i]->SetVisibleToTotalLengthRatio(0.2f); |
| 415 layers[i]->SetThumbThickness(3); | |
| 416 layers[i]->SetCurrentPos(25); | 426 layers[i]->SetCurrentPos(25); |
| 417 layers[i]->SetMaximum(100); | 427 layers[i]->SetMaximum(100); |
| 418 } | 428 } |
| 429 layers[0]->SetBounds(gfx::Size(100, 3)); |
| 430 layers[1]->SetBounds(gfx::Size(3, 100)); |
| 419 | 431 |
| 420 EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f), | 432 EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f), |
| 421 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); | 433 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); |
| 422 EXPECT_RECT_EQ(gfx::RectF(0.f, 20.f, 3.f, 20.f), | 434 EXPECT_RECT_EQ(gfx::RectF(0.f, 20.f, 3.f, 20.f), |
| 423 vertical_scrollbar_layer_->ComputeThumbQuadRect()); | 435 vertical_scrollbar_layer_->ComputeThumbQuadRect()); |
| 424 | 436 |
| 425 horizontal_scrollbar_layer_->SetVerticalAdjust(10.f); | 437 horizontal_scrollbar_layer_->SetVerticalAdjust(10.f); |
| 426 vertical_scrollbar_layer_->SetVerticalAdjust(10.f); | 438 vertical_scrollbar_layer_->SetVerticalAdjust(10.f); |
| 427 | 439 |
| 428 // The vertical adjustment factor has two effects: | 440 // The vertical adjustment factor has two effects: |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 | 558 |
| 547 | 559 |
| 548 class ScrollbarLayerTestResourceCreation : public testing::Test { | 560 class ScrollbarLayerTestResourceCreation : public testing::Test { |
| 549 public: | 561 public: |
| 550 ScrollbarLayerTestResourceCreation() | 562 ScrollbarLayerTestResourceCreation() |
| 551 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} | 563 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} |
| 552 | 564 |
| 553 void TestResourceUpload(int num_updates, | 565 void TestResourceUpload(int num_updates, |
| 554 size_t expected_resources, | 566 size_t expected_resources, |
| 555 int expected_created, | 567 int expected_created, |
| 556 int expected_deleted) { | 568 int expected_deleted, |
| 569 bool use_solid_color_scrollbar) { |
| 557 layer_tree_host_.reset( | 570 layer_tree_host_.reset( |
| 558 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); | 571 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); |
| 559 | 572 |
| 560 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); | 573 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); |
| 561 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 574 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 562 scoped_refptr<Layer> content_layer = Layer::Create(); | 575 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 563 scoped_refptr<Layer> scrollbar_layer = | 576 scoped_refptr<Layer> scrollbar_layer; |
| 564 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); | 577 if (use_solid_color_scrollbar) { |
| 578 const int kThumbThickness = 3; |
| 579 scrollbar_layer = |
| 580 SolidColorScrollbarLayer::Create(scrollbar->Orientation(), |
| 581 kThumbThickness, |
| 582 layer_tree_root->id()); |
| 583 } else { |
| 584 scrollbar_layer = PaintedScrollbarLayer::Create(scrollbar.Pass(), |
| 585 layer_tree_root->id()); |
| 586 } |
| 565 layer_tree_root->AddChild(content_layer); | 587 layer_tree_root->AddChild(content_layer); |
| 566 layer_tree_root->AddChild(scrollbar_layer); | 588 layer_tree_root->AddChild(scrollbar_layer); |
| 567 | 589 |
| 568 layer_tree_host_->InitializeOutputSurfaceIfNeeded(); | 590 layer_tree_host_->InitializeOutputSurfaceIfNeeded(); |
| 569 layer_tree_host_->SetRootLayer(layer_tree_root); | 591 layer_tree_host_->SetRootLayer(layer_tree_root); |
| 570 | 592 |
| 571 scrollbar_layer->SetIsDrawable(true); | 593 scrollbar_layer->SetIsDrawable(true); |
| 572 scrollbar_layer->SetBounds(gfx::Size(100, 100)); | 594 scrollbar_layer->SetBounds(gfx::Size(100, 100)); |
| 573 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); | 595 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); |
| 574 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50)); | 596 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 600 scrollbar_layer->ClearRenderSurface(); | 622 scrollbar_layer->ClearRenderSurface(); |
| 601 } | 623 } |
| 602 | 624 |
| 603 protected: | 625 protected: |
| 604 FakeLayerTreeHostClient fake_client_; | 626 FakeLayerTreeHostClient fake_client_; |
| 605 LayerTreeSettings layer_tree_settings_; | 627 LayerTreeSettings layer_tree_settings_; |
| 606 scoped_ptr<MockLayerTreeHost> layer_tree_host_; | 628 scoped_ptr<MockLayerTreeHost> layer_tree_host_; |
| 607 }; | 629 }; |
| 608 | 630 |
| 609 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) { | 631 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) { |
| 610 layer_tree_settings_.solid_color_scrollbars = false; | 632 bool use_solid_color_scrollbars = false; |
| 611 TestResourceUpload(0, 0, 0, 0); | 633 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); |
| 612 int num_updates[3] = {1, 5, 10}; | 634 int num_updates[3] = {1, 5, 10}; |
| 613 for (int j = 0; j < 3; j++) { | 635 for (int j = 0; j < 3; j++) { |
| 614 TestResourceUpload( | 636 TestResourceUpload(num_updates[j], |
| 615 num_updates[j], 2, num_updates[j] * 2, (num_updates[j] - 1) * 2); | 637 2, |
| 638 num_updates[j] * 2, |
| 639 (num_updates[j] - 1) * 2, |
| 640 use_solid_color_scrollbars); |
| 616 } | 641 } |
| 617 } | 642 } |
| 618 | 643 |
| 619 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) { | 644 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) { |
| 620 layer_tree_settings_.solid_color_scrollbars = true; | 645 bool use_solid_color_scrollbars = true; |
| 621 TestResourceUpload(0, 0, 0, 0); | 646 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); |
| 622 TestResourceUpload(1, 0, 0, 0); | 647 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars); |
| 623 } | 648 } |
| 624 | 649 |
| 625 class ScaledScrollbarLayerTestResourceCreation : public testing::Test { | 650 class ScaledScrollbarLayerTestResourceCreation : public testing::Test { |
| 626 public: | 651 public: |
| 627 ScaledScrollbarLayerTestResourceCreation() | 652 ScaledScrollbarLayerTestResourceCreation() |
| 628 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} | 653 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} |
| 629 | 654 |
| 630 void TestResourceUpload(const float test_scale) { | 655 void TestResourceUpload(const float test_scale) { |
| 631 layer_tree_host_.reset( | 656 layer_tree_host_.reset( |
| 632 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); | 657 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 scrollbar_layer->ClearRenderSurface(); | 715 scrollbar_layer->ClearRenderSurface(); |
| 691 } | 716 } |
| 692 | 717 |
| 693 protected: | 718 protected: |
| 694 FakeLayerTreeHostClient fake_client_; | 719 FakeLayerTreeHostClient fake_client_; |
| 695 LayerTreeSettings layer_tree_settings_; | 720 LayerTreeSettings layer_tree_settings_; |
| 696 scoped_ptr<MockLayerTreeHost> layer_tree_host_; | 721 scoped_ptr<MockLayerTreeHost> layer_tree_host_; |
| 697 }; | 722 }; |
| 698 | 723 |
| 699 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { | 724 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { |
| 700 layer_tree_settings_.solid_color_scrollbars = false; | |
| 701 // Pick a test scale that moves the scrollbar's (non-zero) position to | 725 // Pick a test scale that moves the scrollbar's (non-zero) position to |
| 702 // a non-pixel-aligned location. | 726 // a non-pixel-aligned location. |
| 703 TestResourceUpload(.041f); | 727 TestResourceUpload(.041f); |
| 704 TestResourceUpload(1.41f); | 728 TestResourceUpload(1.41f); |
| 705 TestResourceUpload(4.1f); | 729 TestResourceUpload(4.1f); |
| 706 } | 730 } |
| 707 | 731 |
| 708 } // namespace | 732 } // namespace |
| 709 } // namespace cc | 733 } // namespace cc |
| OLD | NEW |