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 scoped_ptr<FakeLayerTreeHost> host = | 267 scoped_ptr<FakeLayerTreeHost> host = |
256 FakeLayerTreeHost::Create(layer_tree_settings); | 268 FakeLayerTreeHost::Create(layer_tree_settings); |
257 | 269 |
258 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 270 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
259 LayerImpl* layer_impl_tree_root = | 271 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
260 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); | 272 host.get(), scrollbar.Pass(), false, true, kThumbThickness); |
261 PaintedScrollbarLayerImpl* scrollbar_layer_impl = | 273 ScrollbarLayerImplBase* scrollbar_layer_impl = |
262 static_cast<PaintedScrollbarLayerImpl*>( | 274 static_cast<SolidColorScrollbarLayerImpl*>( |
263 layer_impl_tree_root->children()[1]); | 275 layer_impl_tree_root->children()[1]); |
264 scrollbar_layer_impl->SetThumbThickness(3); | 276 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
265 scrollbar_layer_impl->SetCurrentPos(10.f); | 277 scrollbar_layer_impl->SetCurrentPos(10.f); |
266 scrollbar_layer_impl->SetMaximum(100); | 278 scrollbar_layer_impl->SetMaximum(100); |
267 scrollbar_layer_impl->SetTrackLength(100); | |
268 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f); | 279 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f); |
269 | 280 |
270 // Thickness should be overridden to 3. | 281 // Thickness should be overridden to 3. |
271 { | 282 { |
272 MockQuadCuller quad_culler; | 283 MockQuadCuller quad_culler; |
273 AppendQuadsData data; | 284 AppendQuadsData data; |
274 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); | 285 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); |
275 | 286 |
276 const QuadList& quads = quad_culler.quad_list(); | 287 const QuadList& quads = quad_culler.quad_list(); |
277 ASSERT_EQ(1u, quads.size()); | 288 ASSERT_EQ(1u, quads.size()); |
(...skipping 26 matching lines...) Expand all Loading... |
304 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); | 315 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); |
305 | 316 |
306 const QuadList& quads = quad_culler.quad_list(); | 317 const QuadList& quads = quad_culler.quad_list(); |
307 ASSERT_EQ(1u, quads.size()); | 318 ASSERT_EQ(1u, quads.size()); |
308 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); | 319 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); |
309 EXPECT_RECT_EQ(gfx::Rect(8, 0, 20, 3), quads[0]->rect); | 320 EXPECT_RECT_EQ(gfx::Rect(8, 0, 20, 3), quads[0]->rect); |
310 } | 321 } |
311 } | 322 } |
312 | 323 |
313 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { | 324 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { |
| 325 const int kThumbThickness = 3; |
| 326 const int kTrackLength = 10; |
| 327 |
314 LayerTreeSettings layer_tree_settings; | 328 LayerTreeSettings layer_tree_settings; |
315 layer_tree_settings.solid_color_scrollbars = true; | 329 // layer_tree_settings.solid_color_scrollbars = true; // WJM ?? |
316 scoped_ptr<FakeLayerTreeHost> host = | 330 scoped_ptr<FakeLayerTreeHost> host = |
317 FakeLayerTreeHost::Create(layer_tree_settings); | 331 FakeLayerTreeHost::Create(layer_tree_settings); |
318 | 332 |
319 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 333 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
320 LayerImpl* layer_impl_tree_root = | 334 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
321 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); | 335 host.get(), scrollbar.Pass(), false, true, kThumbThickness); |
322 PaintedScrollbarLayerImpl* scrollbar_layer_impl = | 336 ScrollbarLayerImplBase* scrollbar_layer_impl = |
323 static_cast<PaintedScrollbarLayerImpl*>( | 337 static_cast<PaintedScrollbarLayerImpl*>( |
324 layer_impl_tree_root->children()[1]); | 338 layer_impl_tree_root->children()[1]); |
325 | 339 |
326 scrollbar_layer_impl->SetThumbThickness(3); | 340 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
327 scrollbar_layer_impl->SetTrackLength(10); | |
328 scrollbar_layer_impl->SetCurrentPos(4.f); | 341 scrollbar_layer_impl->SetCurrentPos(4.f); |
329 scrollbar_layer_impl->SetMaximum(8); | 342 scrollbar_layer_impl->SetMaximum(8); |
330 | 343 |
331 layer_impl_tree_root->SetScrollable(true); | 344 layer_impl_tree_root->SetScrollable(true); |
332 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl); | 345 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl); |
333 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8)); | 346 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8)); |
334 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); | 347 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); |
335 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f)); | 348 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f)); |
336 | 349 |
337 { | 350 { |
338 MockQuadCuller quad_culler; | 351 MockQuadCuller quad_culler; |
339 AppendQuadsData data; | 352 AppendQuadsData data; |
340 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); | 353 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); |
341 | 354 |
342 const QuadList& quads = quad_culler.quad_list(); | 355 const QuadList& quads = quad_culler.quad_list(); |
343 ASSERT_EQ(1u, quads.size()); | 356 ASSERT_EQ(1u, quads.size()); |
344 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); | 357 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); |
345 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect); | 358 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect); |
346 } | 359 } |
347 } | 360 } |
348 | 361 |
349 class ScrollbarLayerSolidColorThumbTest : public testing::Test { | 362 class ScrollbarLayerSolidColorThumbTest : public testing::Test { |
350 public: | 363 public: |
351 ScrollbarLayerSolidColorThumbTest() { | 364 ScrollbarLayerSolidColorThumbTest() { |
352 LayerTreeSettings layer_tree_settings; | 365 LayerTreeSettings layer_tree_settings; |
353 layer_tree_settings.solid_color_scrollbars = true; | 366 layer_tree_settings.solid_color_scrollbars = true; |
354 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_)); | 367 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_)); |
355 | 368 |
356 horizontal_scrollbar_layer_ = PaintedScrollbarLayerImpl::Create( | 369 const int kThumbThickness = 3; |
357 host_impl_->active_tree(), 1, HORIZONTAL); | 370 |
358 vertical_scrollbar_layer_ = PaintedScrollbarLayerImpl::Create( | 371 horizontal_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( |
359 host_impl_->active_tree(), 2, VERTICAL); | 372 host_impl_->active_tree(), 1, HORIZONTAL, kThumbThickness); |
| 373 vertical_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( |
| 374 host_impl_->active_tree(), 2, VERTICAL, kThumbThickness); |
360 } | 375 } |
361 | 376 |
362 protected: | 377 protected: |
363 FakeImplProxy proxy_; | 378 FakeImplProxy proxy_; |
364 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; | 379 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; |
365 scoped_ptr<PaintedScrollbarLayerImpl> horizontal_scrollbar_layer_; | 380 scoped_ptr<SolidColorScrollbarLayerImpl> horizontal_scrollbar_layer_; |
366 scoped_ptr<PaintedScrollbarLayerImpl> vertical_scrollbar_layer_; | 381 scoped_ptr<SolidColorScrollbarLayerImpl> vertical_scrollbar_layer_; |
367 }; | 382 }; |
368 | 383 |
369 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { | 384 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { |
370 horizontal_scrollbar_layer_->SetCurrentPos(0); | 385 horizontal_scrollbar_layer_->SetCurrentPos(0); |
371 horizontal_scrollbar_layer_->SetMaximum(10); | 386 horizontal_scrollbar_layer_->SetMaximum(10); |
372 horizontal_scrollbar_layer_->SetThumbThickness(3); | |
373 | 387 |
374 // Simple case - one third of the scrollable area is visible, so the thumb | 388 // Simple case - one third of the scrollable area is visible, so the thumb |
375 // should be one third as long as the track. | 389 // should be one third as long as the track. |
376 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.33f); | 390 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.33f); |
377 horizontal_scrollbar_layer_->SetTrackLength(100); | 391 horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3)); |
378 EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); | 392 EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); |
379 | 393 |
380 // The thumb's length should never be less than its thickness. | 394 // The thumb's length should never be less than its thickness. |
381 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.01f); | 395 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.01f); |
382 horizontal_scrollbar_layer_->SetTrackLength(100); | 396 horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3)); |
383 EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); | 397 EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); |
384 } | 398 } |
385 | 399 |
386 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) { | 400 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) { |
387 horizontal_scrollbar_layer_->SetTrackLength(100); | 401 horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3)); |
388 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.1f); | 402 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.1f); |
389 horizontal_scrollbar_layer_->SetThumbThickness(3); | |
390 | 403 |
391 horizontal_scrollbar_layer_->SetCurrentPos(0); | 404 horizontal_scrollbar_layer_->SetCurrentPos(0); |
392 horizontal_scrollbar_layer_->SetMaximum(100); | 405 horizontal_scrollbar_layer_->SetMaximum(100); |
393 EXPECT_EQ(0, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); | 406 EXPECT_EQ(0, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); |
394 EXPECT_EQ(10, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); | 407 EXPECT_EQ(10, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); |
395 | 408 |
396 horizontal_scrollbar_layer_->SetCurrentPos(100); | 409 horizontal_scrollbar_layer_->SetCurrentPos(100); |
397 // The thumb is 10px long and the track is 100px, so the maximum thumb | 410 // The thumb is 10px long and the track is 100px, so the maximum thumb |
398 // position is 90px. | 411 // position is 90px. |
399 EXPECT_EQ(90, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); | 412 EXPECT_EQ(90, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); |
400 | 413 |
401 horizontal_scrollbar_layer_->SetCurrentPos(80); | 414 horizontal_scrollbar_layer_->SetCurrentPos(80); |
402 // The scroll position is 80% of the maximum, so the thumb's position should | 415 // The scroll position is 80% of the maximum, so the thumb's position should |
403 // be at 80% of its maximum or 72px. | 416 // be at 80% of its maximum or 72px. |
404 EXPECT_EQ(72, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); | 417 EXPECT_EQ(72, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); |
405 } | 418 } |
406 | 419 |
407 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) { | 420 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) { |
408 PaintedScrollbarLayerImpl* layers[2] = | 421 SolidColorScrollbarLayerImpl* layers[2] = |
409 { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() }; | 422 { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() }; |
410 for (size_t i = 0; i < 2; ++i) { | 423 for (size_t i = 0; i < 2; ++i) { |
411 layers[i]->SetTrackLength(100); | |
412 layers[i]->SetVisibleToTotalLengthRatio(0.2f); | 424 layers[i]->SetVisibleToTotalLengthRatio(0.2f); |
413 layers[i]->SetThumbThickness(3); | |
414 layers[i]->SetCurrentPos(25); | 425 layers[i]->SetCurrentPos(25); |
415 layers[i]->SetMaximum(100); | 426 layers[i]->SetMaximum(100); |
416 } | 427 } |
| 428 layers[0]->SetBounds(gfx::Size(100, 3)); |
| 429 layers[1]->SetBounds(gfx::Size(3, 100)); |
417 | 430 |
418 EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f), | 431 EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f), |
419 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); | 432 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); |
420 EXPECT_RECT_EQ(gfx::RectF(0.f, 20.f, 3.f, 20.f), | 433 EXPECT_RECT_EQ(gfx::RectF(0.f, 20.f, 3.f, 20.f), |
421 vertical_scrollbar_layer_->ComputeThumbQuadRect()); | 434 vertical_scrollbar_layer_->ComputeThumbQuadRect()); |
422 | 435 |
423 horizontal_scrollbar_layer_->SetVerticalAdjust(10.f); | 436 horizontal_scrollbar_layer_->SetVerticalAdjust(10.f); |
424 vertical_scrollbar_layer_->SetVerticalAdjust(10.f); | 437 vertical_scrollbar_layer_->SetVerticalAdjust(10.f); |
425 | 438 |
426 // The vertical adjustment factor has two effects: | 439 // The vertical adjustment factor has two effects: |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 | 557 |
545 | 558 |
546 class ScrollbarLayerTestResourceCreation : public testing::Test { | 559 class ScrollbarLayerTestResourceCreation : public testing::Test { |
547 public: | 560 public: |
548 ScrollbarLayerTestResourceCreation() | 561 ScrollbarLayerTestResourceCreation() |
549 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} | 562 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} |
550 | 563 |
551 void TestResourceUpload(int num_updates, | 564 void TestResourceUpload(int num_updates, |
552 size_t expected_resources, | 565 size_t expected_resources, |
553 int expected_created, | 566 int expected_created, |
554 int expected_deleted) { | 567 int expected_deleted, |
| 568 bool use_solid_color_scrollbar) { |
555 layer_tree_host_.reset( | 569 layer_tree_host_.reset( |
556 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); | 570 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); |
557 | 571 |
558 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); | 572 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); |
559 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 573 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
560 scoped_refptr<Layer> content_layer = Layer::Create(); | 574 scoped_refptr<Layer> content_layer = Layer::Create(); |
561 scoped_refptr<Layer> scrollbar_layer = | 575 scoped_refptr<Layer> scrollbar_layer; |
562 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); | 576 if (use_solid_color_scrollbar) { |
| 577 const int kThumbThickness = 3; |
| 578 scrollbar_layer = |
| 579 SolidColorScrollbarLayer::Create(scrollbar->Orientation(), |
| 580 kThumbThickness, |
| 581 layer_tree_root->id()); |
| 582 } else { |
| 583 scrollbar_layer = PaintedScrollbarLayer::Create(scrollbar.Pass(), |
| 584 layer_tree_root->id()); |
| 585 } |
563 layer_tree_root->AddChild(content_layer); | 586 layer_tree_root->AddChild(content_layer); |
564 layer_tree_root->AddChild(scrollbar_layer); | 587 layer_tree_root->AddChild(scrollbar_layer); |
565 | 588 |
566 layer_tree_host_->InitializeOutputSurfaceIfNeeded(); | 589 layer_tree_host_->InitializeOutputSurfaceIfNeeded(); |
567 layer_tree_host_->SetRootLayer(layer_tree_root); | 590 layer_tree_host_->SetRootLayer(layer_tree_root); |
568 | 591 |
569 scrollbar_layer->SetIsDrawable(true); | 592 scrollbar_layer->SetIsDrawable(true); |
570 scrollbar_layer->SetBounds(gfx::Size(100, 100)); | 593 scrollbar_layer->SetBounds(gfx::Size(100, 100)); |
571 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); | 594 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); |
572 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50)); | 595 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50)); |
(...skipping 25 matching lines...) Expand all Loading... |
598 scrollbar_layer->ClearRenderSurface(); | 621 scrollbar_layer->ClearRenderSurface(); |
599 } | 622 } |
600 | 623 |
601 protected: | 624 protected: |
602 FakeLayerTreeHostClient fake_client_; | 625 FakeLayerTreeHostClient fake_client_; |
603 LayerTreeSettings layer_tree_settings_; | 626 LayerTreeSettings layer_tree_settings_; |
604 scoped_ptr<MockLayerTreeHost> layer_tree_host_; | 627 scoped_ptr<MockLayerTreeHost> layer_tree_host_; |
605 }; | 628 }; |
606 | 629 |
607 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) { | 630 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) { |
608 layer_tree_settings_.solid_color_scrollbars = false; | 631 bool use_solid_color_scrollbars = false; |
609 TestResourceUpload(0, 0, 0, 0); | 632 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); |
610 int num_updates[3] = {1, 5, 10}; | 633 int num_updates[3] = {1, 5, 10}; |
611 for (int j = 0; j < 3; j++) { | 634 for (int j = 0; j < 3; j++) { |
612 TestResourceUpload( | 635 TestResourceUpload(num_updates[j], |
613 num_updates[j], 2, num_updates[j] * 2, (num_updates[j] - 1) * 2); | 636 2, |
| 637 num_updates[j] * 2, |
| 638 (num_updates[j] - 1) * 2, |
| 639 use_solid_color_scrollbars); |
614 } | 640 } |
615 } | 641 } |
616 | 642 |
617 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) { | 643 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) { |
618 layer_tree_settings_.solid_color_scrollbars = true; | 644 bool use_solid_color_scrollbars = true; |
619 TestResourceUpload(0, 0, 0, 0); | 645 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); |
620 TestResourceUpload(1, 0, 0, 0); | 646 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars); |
621 } | 647 } |
622 | 648 |
623 class ScaledScrollbarLayerTestResourceCreation : public testing::Test { | 649 class ScaledScrollbarLayerTestResourceCreation : public testing::Test { |
624 public: | 650 public: |
625 ScaledScrollbarLayerTestResourceCreation() | 651 ScaledScrollbarLayerTestResourceCreation() |
626 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} | 652 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} |
627 | 653 |
628 void TestResourceUpload(const float test_scale) { | 654 void TestResourceUpload(const float test_scale) { |
629 layer_tree_host_.reset( | 655 layer_tree_host_.reset( |
630 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); | 656 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 scrollbar_layer->ClearRenderSurface(); | 714 scrollbar_layer->ClearRenderSurface(); |
689 } | 715 } |
690 | 716 |
691 protected: | 717 protected: |
692 FakeLayerTreeHostClient fake_client_; | 718 FakeLayerTreeHostClient fake_client_; |
693 LayerTreeSettings layer_tree_settings_; | 719 LayerTreeSettings layer_tree_settings_; |
694 scoped_ptr<MockLayerTreeHost> layer_tree_host_; | 720 scoped_ptr<MockLayerTreeHost> layer_tree_host_; |
695 }; | 721 }; |
696 | 722 |
697 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { | 723 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { |
698 layer_tree_settings_.solid_color_scrollbars = false; | |
699 // Pick a test scale that moves the scrollbar's (non-zero) position to | 724 // Pick a test scale that moves the scrollbar's (non-zero) position to |
700 // a non-pixel-aligned location. | 725 // a non-pixel-aligned location. |
701 TestResourceUpload(.041f); | 726 TestResourceUpload(.041f); |
702 TestResourceUpload(1.41f); | 727 TestResourceUpload(1.41f); |
703 TestResourceUpload(4.1f); | 728 TestResourceUpload(4.1f); |
704 } | 729 } |
705 | 730 |
706 } // namespace | 731 } // namespace |
707 } // namespace cc | 732 } // namespace cc |
OLD | NEW |