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 "cc/layers/scrollbar_layer.h" | 5 #include "cc/layers/scrollbar_layer.h" |
6 | 6 |
7 #include "cc/animation/scrollbar_animation_controller.h" | 7 #include "cc/animation/scrollbar_animation_controller.h" |
8 #include "cc/layers/append_quads_data.h" | 8 #include "cc/layers/append_quads_data.h" |
| 9 #include "cc/layers/scrollbar_layer_base.h" |
9 #include "cc/layers/scrollbar_layer_impl.h" | 10 #include "cc/layers/scrollbar_layer_impl.h" |
| 11 #include "cc/layers/solid_color_scrollbar_layer.h" |
| 12 #include "cc/layers/solid_color_scrollbar_layer_impl.h" |
10 #include "cc/quads/solid_color_draw_quad.h" | 13 #include "cc/quads/solid_color_draw_quad.h" |
11 #include "cc/resources/prioritized_resource_manager.h" | 14 #include "cc/resources/prioritized_resource_manager.h" |
12 #include "cc/resources/priority_calculator.h" | 15 #include "cc/resources/priority_calculator.h" |
13 #include "cc/resources/resource_update_queue.h" | 16 #include "cc/resources/resource_update_queue.h" |
14 #include "cc/test/fake_impl_proxy.h" | 17 #include "cc/test/fake_impl_proxy.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_scrollbar.h" | 20 #include "cc/test/fake_scrollbar.h" |
18 #include "cc/test/geometry_test_utils.h" | 21 #include "cc/test/geometry_test_utils.h" |
19 #include "cc/test/layer_tree_test.h" | 22 #include "cc/test/layer_tree_test.h" |
20 #include "cc/test/mock_quad_culler.h" | 23 #include "cc/test/mock_quad_culler.h" |
21 #include "cc/test/test_web_graphics_context_3d.h" | 24 #include "cc/test/test_web_graphics_context_3d.h" |
22 #include "cc/trees/layer_tree_impl.h" | 25 #include "cc/trees/layer_tree_impl.h" |
23 #include "cc/trees/single_thread_proxy.h" | 26 #include "cc/trees/single_thread_proxy.h" |
24 #include "cc/trees/tree_synchronizer.h" | 27 #include "cc/trees/tree_synchronizer.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
27 | 30 |
28 namespace cc { | 31 namespace cc { |
29 namespace { | 32 namespace { |
30 | 33 |
31 scoped_ptr<LayerImpl> LayerImplForScrollAreaAndScrollbar( | 34 scoped_ptr<LayerImpl> LayerImplForScrollAreaAndScrollbar( |
32 FakeLayerTreeHostImpl* host_impl, | 35 FakeLayerTreeHostImpl* host_impl, |
33 scoped_ptr<Scrollbar> scrollbar, | 36 scoped_ptr<Scrollbar> scrollbar, |
34 bool reverse_order) { | 37 bool reverse_order, |
| 38 bool use_solid_color_scrollbar, |
| 39 int thumb_thickness) { |
35 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 40 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
36 scoped_refptr<Layer> child1 = Layer::Create(); | 41 scoped_refptr<Layer> child1 = Layer::Create(); |
37 scoped_refptr<Layer> child2 = | 42 scoped_refptr<Layer> child2; |
38 ScrollbarLayer::Create(scrollbar.Pass(), | 43 if (use_solid_color_scrollbar) { |
39 child1->id()); | 44 SkColor color = SkColorSetARGB(128, 128, 128, 128); |
| 45 child2 = SolidColorScrollbarLayer::Create( |
| 46 scrollbar->Orientation(), thumb_thickness, color, child1->id()); |
| 47 } else { |
| 48 child2 = ScrollbarLayer::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 scoped_ptr<LayerImpl> layer_impl = | 52 scoped_ptr<LayerImpl> layer_impl = |
43 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), | 53 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), |
44 scoped_ptr<LayerImpl>(), | 54 scoped_ptr<LayerImpl>(), |
45 host_impl->active_tree()); | 55 host_impl->active_tree()); |
46 TreeSynchronizer::PushProperties(layer_tree_root.get(), layer_impl.get()); | 56 TreeSynchronizer::PushProperties(layer_tree_root.get(), layer_impl.get()); |
47 return layer_impl.Pass(); | 57 return layer_impl.Pass(); |
48 } | 58 } |
49 | 59 |
50 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) { | 60 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) { |
51 FakeImplProxy proxy; | 61 FakeImplProxy proxy; |
52 FakeLayerTreeHostImpl host_impl(&proxy); | 62 FakeLayerTreeHostImpl host_impl(&proxy); |
53 | 63 |
54 { | 64 { |
55 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 65 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
56 scoped_ptr<LayerImpl> layer_impl_tree_root = | 66 scoped_ptr<LayerImpl> layer_impl_tree_root = |
57 LayerImplForScrollAreaAndScrollbar( | 67 LayerImplForScrollAreaAndScrollbar( |
58 &host_impl, scrollbar.Pass(), false); | 68 &host_impl, scrollbar.Pass(), false, false, 0); |
59 | 69 |
60 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; | 70 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; |
61 ScrollbarLayerImpl* cc_child2 = static_cast<ScrollbarLayerImpl*>( | 71 ScrollbarLayerImpl* cc_child2 = static_cast<ScrollbarLayerImpl*>( |
62 layer_impl_tree_root->children()[1]); | 72 layer_impl_tree_root->children()[1]); |
63 | 73 |
64 EXPECT_EQ(cc_child1->horizontal_scrollbar_layer(), cc_child2); | 74 EXPECT_EQ(cc_child1->horizontal_scrollbar_layer(), cc_child2); |
65 } | 75 } |
66 { | 76 { |
67 // another traverse order | 77 // another traverse order |
68 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 78 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
69 scoped_ptr<LayerImpl> layer_impl_tree_root = | 79 scoped_ptr<LayerImpl> layer_impl_tree_root = |
70 LayerImplForScrollAreaAndScrollbar( | 80 LayerImplForScrollAreaAndScrollbar( |
71 &host_impl, scrollbar.Pass(), true); | 81 &host_impl, scrollbar.Pass(), true, false, 0); |
72 | 82 |
73 ScrollbarLayerImpl* cc_child1 = static_cast<ScrollbarLayerImpl*>( | 83 ScrollbarLayerImpl* cc_child1 = static_cast<ScrollbarLayerImpl*>( |
74 layer_impl_tree_root->children()[0]); | 84 layer_impl_tree_root->children()[0]); |
75 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; | 85 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; |
76 | 86 |
77 EXPECT_EQ(cc_child2->horizontal_scrollbar_layer(), cc_child1); | 87 EXPECT_EQ(cc_child2->horizontal_scrollbar_layer(), cc_child1); |
78 } | 88 } |
79 } | 89 } |
80 | 90 |
81 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { | 91 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { |
82 FakeImplProxy proxy; | 92 FakeImplProxy proxy; |
83 FakeLayerTreeHostImpl host_impl(&proxy); | 93 FakeLayerTreeHostImpl host_impl(&proxy); |
84 | 94 |
85 // Create and attach a non-overlay scrollbar. | 95 // Create and attach a non-overlay scrollbar. |
86 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 96 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
87 scoped_ptr<LayerImpl> layer_impl_tree_root = | 97 scoped_ptr<LayerImpl> layer_impl_tree_root = |
88 LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false); | 98 LayerImplForScrollAreaAndScrollbar( |
| 99 &host_impl, scrollbar.Pass(), false, false, 0); |
89 ScrollbarLayerImpl* scrollbar_layer_impl = | 100 ScrollbarLayerImpl* scrollbar_layer_impl = |
90 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); | 101 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); |
91 | 102 |
92 // When the scrollbar is not an overlay scrollbar, the scroll should be | 103 // When the scrollbar is not an overlay scrollbar, the scroll should be |
93 // responded to on the main thread as the compositor does not yet implement | 104 // responded to on the main thread as the compositor does not yet implement |
94 // scrollbar scrolling. | 105 // scrollbar scrolling. |
95 EXPECT_EQ(InputHandler::ScrollOnMainThread, | 106 EXPECT_EQ(InputHandler::ScrollOnMainThread, |
96 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), | 107 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), |
97 InputHandler::Gesture)); | 108 InputHandler::Gesture)); |
98 | 109 |
99 // Create and attach an overlay scrollbar. | 110 // Create and attach an overlay scrollbar. |
100 scrollbar.reset(new FakeScrollbar(false, false, true)); | 111 scrollbar.reset(new FakeScrollbar(false, false, true)); |
101 | 112 |
102 layer_impl_tree_root = | 113 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
103 LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false); | 114 &host_impl, scrollbar.Pass(), false, false, 0); |
104 scrollbar_layer_impl = | 115 scrollbar_layer_impl = |
105 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); | 116 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); |
106 | 117 |
107 // The user shouldn't be able to drag an overlay scrollbar and the scroll | 118 // The user shouldn't be able to drag an overlay scrollbar and the scroll |
108 // may be handled in the compositor. | 119 // may be handled in the compositor. |
109 EXPECT_EQ(InputHandler::ScrollIgnored, | 120 EXPECT_EQ(InputHandler::ScrollIgnored, |
110 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), | 121 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), |
111 InputHandler::Gesture)); | 122 InputHandler::Gesture)); |
112 } | 123 } |
113 | 124 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 EXPECT_EQ(100.f, cc_scrollbar_layer->CurrentPos()); | 176 EXPECT_EQ(100.f, cc_scrollbar_layer->CurrentPos()); |
166 EXPECT_EQ(300, cc_scrollbar_layer->Maximum()); | 177 EXPECT_EQ(300, cc_scrollbar_layer->Maximum()); |
167 | 178 |
168 layer_impl_tree_root->ScrollBy(gfx::Vector2d(12, 34)); | 179 layer_impl_tree_root->ScrollBy(gfx::Vector2d(12, 34)); |
169 | 180 |
170 EXPECT_EQ(112.f, cc_scrollbar_layer->CurrentPos()); | 181 EXPECT_EQ(112.f, cc_scrollbar_layer->CurrentPos()); |
171 EXPECT_EQ(300, cc_scrollbar_layer->Maximum()); | 182 EXPECT_EQ(300, cc_scrollbar_layer->Maximum()); |
172 } | 183 } |
173 | 184 |
174 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { | 185 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { |
| 186 const int thumb_thickness = 3; |
| 187 const int track_length = 100; |
| 188 |
175 LayerTreeSettings layer_tree_settings; | 189 LayerTreeSettings layer_tree_settings; |
176 layer_tree_settings.solid_color_scrollbars = true; | |
177 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3; | |
178 FakeImplProxy proxy; | 190 FakeImplProxy proxy; |
179 FakeLayerTreeHostImpl host_impl(layer_tree_settings, &proxy); | 191 FakeLayerTreeHostImpl host_impl(layer_tree_settings, &proxy); |
180 | 192 |
181 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 193 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
182 scoped_ptr<LayerImpl> layer_impl_tree_root = | 194 scoped_ptr<LayerImpl> layer_impl_tree_root = |
183 LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false); | 195 LayerImplForScrollAreaAndScrollbar( |
184 ScrollbarLayerImpl* scrollbar_layer_impl = | 196 &host_impl, scrollbar.Pass(), false, true, thumb_thickness); |
185 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); | 197 ScrollbarLayerImplBase* scrollbar_layer_impl = |
186 scrollbar_layer_impl->set_thumb_thickness(3); | 198 static_cast<ScrollbarLayerImplBase*>(layer_impl_tree_root->children()[1]); |
| 199 scrollbar_layer_impl->SetBounds(gfx::Size(track_length, thumb_thickness)); |
187 scrollbar_layer_impl->SetCurrentPos(10.f); | 200 scrollbar_layer_impl->SetCurrentPos(10.f); |
188 scrollbar_layer_impl->SetMaximum(100); | 201 scrollbar_layer_impl->SetMaximum(100); |
189 scrollbar_layer_impl->set_track_length(100); | |
190 scrollbar_layer_impl->set_visible_to_total_length_ratio(0.4f); | 202 scrollbar_layer_impl->set_visible_to_total_length_ratio(0.4f); |
191 | 203 |
192 // Thickness should be overridden to 3. | 204 // Thickness should be overridden to 3. |
193 { | 205 { |
194 MockQuadCuller quad_culler; | 206 MockQuadCuller quad_culler; |
195 AppendQuadsData data; | 207 AppendQuadsData data; |
196 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); | 208 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); |
197 | 209 |
198 const QuadList& quads = quad_culler.quad_list(); | 210 const QuadList& quads = quad_culler.quad_list(); |
199 ASSERT_EQ(1u, quads.size()); | 211 ASSERT_EQ(1u, quads.size()); |
(...skipping 26 matching lines...) Expand all Loading... |
226 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); | 238 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); |
227 | 239 |
228 const QuadList& quads = quad_culler.quad_list(); | 240 const QuadList& quads = quad_culler.quad_list(); |
229 ASSERT_EQ(1u, quads.size()); | 241 ASSERT_EQ(1u, quads.size()); |
230 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); | 242 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); |
231 EXPECT_RECT_EQ(gfx::Rect(8, 0, 20, 3), quads[0]->rect); | 243 EXPECT_RECT_EQ(gfx::Rect(8, 0, 20, 3), quads[0]->rect); |
232 } | 244 } |
233 } | 245 } |
234 | 246 |
235 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { | 247 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { |
| 248 const int thumb_thickness = 3; |
| 249 const int track_length = 10; |
| 250 |
236 LayerTreeSettings layer_tree_settings; | 251 LayerTreeSettings layer_tree_settings; |
237 layer_tree_settings.solid_color_scrollbars = true; | |
238 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3; | |
239 FakeImplProxy proxy; | 252 FakeImplProxy proxy; |
240 FakeLayerTreeHostImpl host_impl(layer_tree_settings, &proxy); | 253 FakeLayerTreeHostImpl host_impl(layer_tree_settings, &proxy); |
241 | 254 |
242 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 255 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
243 scoped_ptr<LayerImpl> layer_impl_tree_root = | 256 scoped_ptr<LayerImpl> layer_impl_tree_root = |
244 LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false); | 257 LayerImplForScrollAreaAndScrollbar( |
245 ScrollbarLayerImpl* scrollbar_layer_impl = | 258 &host_impl, scrollbar.Pass(), false, true, thumb_thickness); |
246 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); | 259 ScrollbarLayerImplBase* scrollbar_layer_impl = |
| 260 static_cast<ScrollbarLayerImplBase*>(layer_impl_tree_root->children()[1]); |
247 | 261 |
248 scrollbar_layer_impl->set_thumb_thickness(3); | 262 scrollbar_layer_impl->SetBounds(gfx::Size(track_length, thumb_thickness)); |
249 scrollbar_layer_impl->set_track_length(10); | |
250 scrollbar_layer_impl->SetCurrentPos(4.f); | 263 scrollbar_layer_impl->SetCurrentPos(4.f); |
251 scrollbar_layer_impl->SetMaximum(8); | 264 scrollbar_layer_impl->SetMaximum(8); |
252 | 265 |
253 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl); | 266 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl); |
254 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8)); | 267 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8)); |
255 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); | 268 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); |
256 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f)); | 269 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f)); |
257 | 270 |
258 { | 271 { |
259 MockQuadCuller quad_culler; | 272 MockQuadCuller quad_culler; |
260 AppendQuadsData data; | 273 AppendQuadsData data; |
261 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); | 274 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); |
262 | 275 |
263 const QuadList& quads = quad_culler.quad_list(); | 276 const QuadList& quads = quad_culler.quad_list(); |
264 ASSERT_EQ(1u, quads.size()); | 277 ASSERT_EQ(1u, quads.size()); |
265 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); | 278 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); |
266 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect); | 279 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect); |
267 } | 280 } |
268 } | 281 } |
269 | 282 |
270 class ScrollbarLayerSolidColorThumbTest : public testing::Test { | 283 class ScrollbarLayerSolidColorThumbTest : public testing::Test { |
271 public: | 284 public: |
272 ScrollbarLayerSolidColorThumbTest() { | 285 ScrollbarLayerSolidColorThumbTest() { |
273 LayerTreeSettings layer_tree_settings; | 286 LayerTreeSettings layer_tree_settings; |
274 layer_tree_settings.solid_color_scrollbars = true; | |
275 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_)); | 287 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_)); |
276 | 288 |
277 horizontal_scrollbar_layer_ = ScrollbarLayerImpl::Create( | 289 const int thumb_thickness = 3; |
278 host_impl_->active_tree(), 1, HORIZONTAL); | 290 const SkColor color = SkColorSetARGB(128, 128, 128, 128); |
279 vertical_scrollbar_layer_ = ScrollbarLayerImpl::Create( | 291 |
280 host_impl_->active_tree(), 2, VERTICAL); | 292 horizontal_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( |
| 293 host_impl_->active_tree(), 1, HORIZONTAL, thumb_thickness, color); |
| 294 vertical_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( |
| 295 host_impl_->active_tree(), |
| 296 2, |
| 297 VERTICAL, |
| 298 thumb_thickness, color); |
281 } | 299 } |
282 | 300 |
283 protected: | 301 protected: |
284 FakeImplProxy proxy_; | 302 FakeImplProxy proxy_; |
285 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; | 303 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; |
286 scoped_ptr<ScrollbarLayerImpl> horizontal_scrollbar_layer_; | 304 scoped_ptr<SolidColorScrollbarLayerImpl> horizontal_scrollbar_layer_; |
287 scoped_ptr<ScrollbarLayerImpl> vertical_scrollbar_layer_; | 305 scoped_ptr<SolidColorScrollbarLayerImpl> vertical_scrollbar_layer_; |
288 }; | 306 }; |
289 | 307 |
290 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { | 308 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { |
291 horizontal_scrollbar_layer_->SetCurrentPos(0); | 309 horizontal_scrollbar_layer_->SetCurrentPos(0); |
292 horizontal_scrollbar_layer_->SetMaximum(10); | 310 horizontal_scrollbar_layer_->SetMaximum(10); |
293 horizontal_scrollbar_layer_->set_thumb_thickness(3); | |
294 | 311 |
295 // Simple case - one third of the scrollable area is visible, so the thumb | 312 // Simple case - one third of the scrollable area is visible, so the thumb |
296 // should be one third as long as the track. | 313 // should be one third as long as the track. |
297 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.33f); | 314 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.33f); |
298 horizontal_scrollbar_layer_->set_track_length(100); | 315 horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3)); |
299 EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); | 316 EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); |
300 | 317 |
301 // The thumb's length should never be less than its thickness. | 318 // The thumb's length should never be less than its thickness. |
302 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.01f); | 319 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.01f); |
303 horizontal_scrollbar_layer_->set_track_length(100); | 320 horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3)); |
304 EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); | 321 EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); |
305 } | 322 } |
306 | 323 |
307 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) { | 324 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) { |
308 horizontal_scrollbar_layer_->set_track_length(100); | 325 horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3)); |
309 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.1f); | 326 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.1f); |
310 horizontal_scrollbar_layer_->set_thumb_thickness(3); | |
311 | 327 |
312 horizontal_scrollbar_layer_->SetCurrentPos(0); | 328 horizontal_scrollbar_layer_->SetCurrentPos(0); |
313 horizontal_scrollbar_layer_->SetMaximum(100); | 329 horizontal_scrollbar_layer_->SetMaximum(100); |
314 EXPECT_EQ(0, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); | 330 EXPECT_EQ(0, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); |
315 EXPECT_EQ(10, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); | 331 EXPECT_EQ(10, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); |
316 | 332 |
317 horizontal_scrollbar_layer_->SetCurrentPos(100); | 333 horizontal_scrollbar_layer_->SetCurrentPos(100); |
318 // The thumb is 10px long and the track is 100px, so the maximum thumb | 334 // The thumb is 10px long and the track is 100px, so the maximum thumb |
319 // position is 90px. | 335 // position is 90px. |
320 EXPECT_EQ(90, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); | 336 EXPECT_EQ(90, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); |
321 | 337 |
322 horizontal_scrollbar_layer_->SetCurrentPos(80); | 338 horizontal_scrollbar_layer_->SetCurrentPos(80); |
323 // The scroll position is 80% of the maximum, so the thumb's position should | 339 // The scroll position is 80% of the maximum, so the thumb's position should |
324 // be at 80% of its maximum or 72px. | 340 // be at 80% of its maximum or 72px. |
325 EXPECT_EQ(72, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); | 341 EXPECT_EQ(72, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); |
326 } | 342 } |
327 | 343 |
328 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) { | 344 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) { |
329 ScrollbarLayerImpl* layers[2] = | 345 SolidColorScrollbarLayerImpl* layers[2] = |
330 { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() }; | 346 { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() }; |
331 for (size_t i = 0; i < 2; ++i) { | 347 for (size_t i = 0; i < 2; ++i) { |
332 layers[i]->set_track_length(100); | |
333 layers[i]->set_visible_to_total_length_ratio(0.2f); | 348 layers[i]->set_visible_to_total_length_ratio(0.2f); |
334 layers[i]->set_thumb_thickness(3); | |
335 layers[i]->SetCurrentPos(25); | 349 layers[i]->SetCurrentPos(25); |
336 layers[i]->SetMaximum(100); | 350 layers[i]->SetMaximum(100); |
337 } | 351 } |
| 352 layers[0]->SetBounds(gfx::Size(100, 3)); |
| 353 layers[1]->SetBounds(gfx::Size(3, 100)); |
338 | 354 |
339 EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f), | 355 EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f), |
340 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); | 356 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); |
341 EXPECT_RECT_EQ(gfx::RectF(0.f, 20.f, 3.f, 20.f), | 357 EXPECT_RECT_EQ(gfx::RectF(0.f, 20.f, 3.f, 20.f), |
342 vertical_scrollbar_layer_->ComputeThumbQuadRect()); | 358 vertical_scrollbar_layer_->ComputeThumbQuadRect()); |
343 | 359 |
344 horizontal_scrollbar_layer_->set_vertical_adjust(10.f); | 360 horizontal_scrollbar_layer_->set_vertical_adjust(10.f); |
345 vertical_scrollbar_layer_->set_vertical_adjust(10.f); | 361 vertical_scrollbar_layer_->set_vertical_adjust(10.f); |
346 | 362 |
347 // The vertical adjustment factor has two effects: | 363 // The vertical adjustment factor has two effects: |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 Initialize(NULL); | 439 Initialize(NULL); |
424 } | 440 } |
425 }; | 441 }; |
426 | 442 |
427 | 443 |
428 class ScrollbarLayerTestResourceCreation : public testing::Test { | 444 class ScrollbarLayerTestResourceCreation : public testing::Test { |
429 public: | 445 public: |
430 ScrollbarLayerTestResourceCreation() | 446 ScrollbarLayerTestResourceCreation() |
431 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} | 447 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} |
432 | 448 |
433 void TestResourceUpload(size_t expected_resources) { | 449 void TestResourceUpload(size_t expected_resources, |
| 450 bool use_solid_color_scrollbar) { |
434 layer_tree_host_.reset( | 451 layer_tree_host_.reset( |
435 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); | 452 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); |
436 | 453 |
437 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); | 454 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); |
438 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 455 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
439 scoped_refptr<Layer> content_layer = Layer::Create(); | 456 scoped_refptr<Layer> content_layer = Layer::Create(); |
440 scoped_refptr<Layer> scrollbar_layer = | 457 scoped_refptr<Layer> scrollbar_layer; |
441 ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); | 458 if (use_solid_color_scrollbar) { |
| 459 SkColor color = SkColorSetARGB(128, 128, 128, 128); |
| 460 int thumb_thickness = 3; |
| 461 scrollbar_layer = |
| 462 SolidColorScrollbarLayer::Create(scrollbar->Orientation(), |
| 463 thumb_thickness, |
| 464 color, |
| 465 layer_tree_root->id()); |
| 466 } else { |
| 467 scrollbar_layer = |
| 468 ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); |
| 469 } |
442 layer_tree_root->AddChild(content_layer); | 470 layer_tree_root->AddChild(content_layer); |
443 layer_tree_root->AddChild(scrollbar_layer); | 471 layer_tree_root->AddChild(scrollbar_layer); |
444 | 472 |
445 layer_tree_host_->InitializeOutputSurfaceIfNeeded(); | 473 layer_tree_host_->InitializeOutputSurfaceIfNeeded(); |
446 layer_tree_host_->contents_texture_manager()-> | 474 layer_tree_host_->contents_texture_manager()-> |
447 SetMaxMemoryLimitBytes(1024 * 1024); | 475 SetMaxMemoryLimitBytes(1024 * 1024); |
448 layer_tree_host_->SetRootLayer(layer_tree_root); | 476 layer_tree_host_->SetRootLayer(layer_tree_root); |
449 | 477 |
450 scrollbar_layer->SetIsDrawable(true); | 478 scrollbar_layer->SetIsDrawable(true); |
451 scrollbar_layer->SetBounds(gfx::Size(100, 100)); | 479 scrollbar_layer->SetBounds(gfx::Size(100, 100)); |
(...skipping 23 matching lines...) Expand all Loading... |
475 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 503 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
476 } | 504 } |
477 | 505 |
478 protected: | 506 protected: |
479 FakeLayerTreeHostClient fake_client_; | 507 FakeLayerTreeHostClient fake_client_; |
480 LayerTreeSettings layer_tree_settings_; | 508 LayerTreeSettings layer_tree_settings_; |
481 scoped_ptr<MockLayerTreeHost> layer_tree_host_; | 509 scoped_ptr<MockLayerTreeHost> layer_tree_host_; |
482 }; | 510 }; |
483 | 511 |
484 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) { | 512 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) { |
485 layer_tree_settings_.solid_color_scrollbars = false; | 513 TestResourceUpload(2, false); |
486 TestResourceUpload(2); | |
487 } | 514 } |
488 | 515 |
489 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) { | 516 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) { |
490 layer_tree_settings_.solid_color_scrollbars = true; | 517 TestResourceUpload(0, true); |
491 TestResourceUpload(0); | |
492 } | 518 } |
493 | 519 |
494 class ScaledScrollbarLayerTestResourceCreation : public testing::Test { | 520 class ScaledScrollbarLayerTestResourceCreation : public testing::Test { |
495 public: | 521 public: |
496 ScaledScrollbarLayerTestResourceCreation() | 522 ScaledScrollbarLayerTestResourceCreation() |
497 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} | 523 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} |
498 | 524 |
499 void TestResourceUpload(size_t expected_resources, const float test_scale) { | 525 void TestResourceUpload(size_t expected_resources, const float test_scale) { |
500 layer_tree_host_.reset( | 526 layer_tree_host_.reset( |
501 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); | 527 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 594 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
569 } | 595 } |
570 | 596 |
571 protected: | 597 protected: |
572 FakeLayerTreeHostClient fake_client_; | 598 FakeLayerTreeHostClient fake_client_; |
573 LayerTreeSettings layer_tree_settings_; | 599 LayerTreeSettings layer_tree_settings_; |
574 scoped_ptr<MockLayerTreeHost> layer_tree_host_; | 600 scoped_ptr<MockLayerTreeHost> layer_tree_host_; |
575 }; | 601 }; |
576 | 602 |
577 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { | 603 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { |
578 layer_tree_settings_.solid_color_scrollbars = false; | |
579 // Pick a test scale that moves the scrollbar's (non-zero) position to | 604 // Pick a test scale that moves the scrollbar's (non-zero) position to |
580 // a non-pixel-aligned location. | 605 // a non-pixel-aligned location. |
581 TestResourceUpload(2, 1.41f); | 606 TestResourceUpload(2, 1.41f); |
582 } | 607 } |
583 | 608 |
584 } // namespace | 609 } // namespace |
585 } // namespace cc | 610 } // namespace cc |
OLD | NEW |