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/layers/append_quads_data.h" | 7 #include "cc/layers/append_quads_data.h" |
8 #include "cc/layers/painted_scrollbar_layer.h" | 8 #include "cc/layers/painted_scrollbar_layer.h" |
9 #include "cc/layers/painted_scrollbar_layer_impl.h" | 9 #include "cc/layers/painted_scrollbar_layer_impl.h" |
10 #include "cc/layers/scrollbar_layer_interface.h" | 10 #include "cc/layers/scrollbar_layer_interface.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 child2 = PaintedScrollbarLayer::Create(scrollbar.Pass(), child1->id()); | 53 child2 = PaintedScrollbarLayer::Create(scrollbar.Pass(), child1->id()); |
54 } | 54 } |
55 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); | 55 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); |
56 layer_tree_root->AddChild(child1); | 56 layer_tree_root->AddChild(child1); |
57 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); | 57 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); |
58 host->SetRootLayer(layer_tree_root); | 58 host->SetRootLayer(layer_tree_root); |
59 return host->CommitAndCreateLayerImplTree(); | 59 return host->CommitAndCreateLayerImplTree(); |
60 } | 60 } |
61 | 61 |
62 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) { | 62 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) { |
63 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 63 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
| 64 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); |
64 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 65 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
65 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 66 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
66 host.get(), scrollbar.Pass(), false, false, 0, 0); | 67 host.get(), scrollbar.Pass(), false, false, 0, 0); |
67 | 68 |
68 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; | 69 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; |
69 PaintedScrollbarLayerImpl* cc_child2 = | 70 PaintedScrollbarLayerImpl* cc_child2 = |
70 static_cast<PaintedScrollbarLayerImpl*>( | 71 static_cast<PaintedScrollbarLayerImpl*>( |
71 layer_impl_tree_root->children()[1]); | 72 layer_impl_tree_root->children()[1]); |
72 | 73 |
73 EXPECT_EQ(cc_child1->scrollbars()->size(), 1UL); | 74 EXPECT_EQ(cc_child1->scrollbars()->size(), 1UL); |
74 EXPECT_EQ(*(cc_child1->scrollbars()->begin()), cc_child2); | 75 EXPECT_EQ(*(cc_child1->scrollbars()->begin()), cc_child2); |
75 } | 76 } |
76 | 77 |
77 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { | 78 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { |
78 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 79 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
| 80 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); |
79 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 81 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
80 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 82 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
81 host.get(), scrollbar.Pass(), true, false, 0, 0); | 83 host.get(), scrollbar.Pass(), true, false, 0, 0); |
82 | 84 |
83 PaintedScrollbarLayerImpl* cc_child1 = | 85 PaintedScrollbarLayerImpl* cc_child1 = |
84 static_cast<PaintedScrollbarLayerImpl*>( | 86 static_cast<PaintedScrollbarLayerImpl*>( |
85 layer_impl_tree_root->children()[0]); | 87 layer_impl_tree_root->children()[0]); |
86 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; | 88 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; |
87 | 89 |
88 EXPECT_EQ(cc_child2->scrollbars()->size(), 1UL); | 90 EXPECT_EQ(cc_child2->scrollbars()->size(), 1UL); |
89 EXPECT_EQ(*(cc_child2->scrollbars()->begin()), cc_child1); | 91 EXPECT_EQ(*(cc_child2->scrollbars()->begin()), cc_child1); |
90 } | 92 } |
91 | 93 |
92 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { | 94 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { |
93 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 95 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
| 96 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); |
94 | 97 |
95 // Create and attach a non-overlay scrollbar. | 98 // Create and attach a non-overlay scrollbar. |
96 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 99 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
97 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 100 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
98 host.get(), scrollbar.Pass(), false, false, 0, 0); | 101 host.get(), scrollbar.Pass(), false, false, 0, 0); |
99 PaintedScrollbarLayerImpl* scrollbar_layer_impl = | 102 PaintedScrollbarLayerImpl* scrollbar_layer_impl = |
100 static_cast<PaintedScrollbarLayerImpl*>( | 103 static_cast<PaintedScrollbarLayerImpl*>( |
101 layer_impl_tree_root->children()[1]); | 104 layer_impl_tree_root->children()[1]); |
102 | 105 |
103 // When the scrollbar is not an overlay scrollbar, the scroll should be | 106 // When the scrollbar is not an overlay scrollbar, the scroll should be |
(...skipping 12 matching lines...) Expand all Loading... |
116 layer_impl_tree_root->children()[1]); | 119 layer_impl_tree_root->children()[1]); |
117 | 120 |
118 // The user shouldn't be able to drag an overlay scrollbar and the scroll | 121 // The user shouldn't be able to drag an overlay scrollbar and the scroll |
119 // may be handled in the compositor. | 122 // may be handled in the compositor. |
120 EXPECT_EQ(InputHandler::ScrollIgnored, | 123 EXPECT_EQ(InputHandler::ScrollIgnored, |
121 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), | 124 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), |
122 InputHandler::Gesture)); | 125 InputHandler::Gesture)); |
123 } | 126 } |
124 | 127 |
125 TEST(PaintedScrollbarLayerTest, ScrollOffsetSynchronization) { | 128 TEST(PaintedScrollbarLayerTest, ScrollOffsetSynchronization) { |
126 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 129 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
| 130 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); |
127 | 131 |
128 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 132 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
129 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 133 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
130 scoped_refptr<Layer> scroll_layer = Layer::Create(); | 134 scoped_refptr<Layer> scroll_layer = Layer::Create(); |
131 scoped_refptr<Layer> content_layer = Layer::Create(); | 135 scoped_refptr<Layer> content_layer = Layer::Create(); |
132 scoped_refptr<Layer> scrollbar_layer = | 136 scoped_refptr<Layer> scrollbar_layer = |
133 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); | 137 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); |
134 | 138 |
135 // Choose bounds to give max_scroll_offset = (30, 50). | 139 // Choose bounds to give max_scroll_offset = (30, 50). |
136 layer_tree_root->SetBounds(gfx::Size(70, 150)); | 140 layer_tree_root->SetBounds(gfx::Size(70, 150)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 do { \ | 190 do { \ |
187 scrollbar_layer->UpdateThumbAndTrackGeometry(); \ | 191 scrollbar_layer->UpdateThumbAndTrackGeometry(); \ |
188 root_clip_layer_impl = host->CommitAndCreateLayerImplTree(); \ | 192 root_clip_layer_impl = host->CommitAndCreateLayerImplTree(); \ |
189 root_layer_impl = root_clip_layer_impl->children()[0]; \ | 193 root_layer_impl = root_clip_layer_impl->children()[0]; \ |
190 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ | 194 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ |
191 root_layer_impl->children()[1]); \ | 195 root_layer_impl->children()[1]); \ |
192 scrollbar_layer_impl->ScrollbarParametersDidChange(); \ | 196 scrollbar_layer_impl->ScrollbarParametersDidChange(); \ |
193 } while (false) | 197 } while (false) |
194 | 198 |
195 TEST(ScrollbarLayerTest, ThumbRect) { | 199 TEST(ScrollbarLayerTest, ThumbRect) { |
196 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 200 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
| 201 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); |
197 scoped_refptr<Layer> root_clip_layer = Layer::Create(); | 202 scoped_refptr<Layer> root_clip_layer = Layer::Create(); |
198 scoped_refptr<Layer> root_layer = Layer::Create(); | 203 scoped_refptr<Layer> root_layer = Layer::Create(); |
199 scoped_refptr<Layer> content_layer = Layer::Create(); | 204 scoped_refptr<Layer> content_layer = Layer::Create(); |
200 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 205 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
201 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); | 206 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); |
202 | 207 |
203 root_layer->SetScrollClipLayerId(root_clip_layer->id()); | 208 root_layer->SetScrollClipLayerId(root_clip_layer->id()); |
204 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). | 209 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). |
205 root_clip_layer->SetBounds(gfx::Size(20, 50)); | 210 root_clip_layer->SetBounds(gfx::Size(20, 50)); |
206 root_layer->SetBounds(gfx::Size(100, 50)); | 211 root_layer->SetBounds(gfx::Size(100, 50)); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 UPDATE_AND_EXTRACT_LAYER_POINTERS(); | 275 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
271 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), | 276 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), |
272 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 277 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
273 } | 278 } |
274 | 279 |
275 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { | 280 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { |
276 const int kThumbThickness = 3; | 281 const int kThumbThickness = 3; |
277 const int kTrackStart = 0; | 282 const int kTrackStart = 0; |
278 const int kTrackLength = 100; | 283 const int kTrackLength = 100; |
279 | 284 |
| 285 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
280 LayerTreeSettings layer_tree_settings; | 286 LayerTreeSettings layer_tree_settings; |
281 scoped_ptr<FakeLayerTreeHost> host = | 287 scoped_ptr<FakeLayerTreeHost> host = |
282 FakeLayerTreeHost::Create(layer_tree_settings); | 288 FakeLayerTreeHost::Create(&client, layer_tree_settings); |
283 | 289 |
284 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 290 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
285 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 291 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
286 host.get(), scrollbar.Pass(), false, true, kThumbThickness, kTrackStart); | 292 host.get(), scrollbar.Pass(), false, true, kThumbThickness, kTrackStart); |
287 ScrollbarLayerImplBase* scrollbar_layer_impl = | 293 ScrollbarLayerImplBase* scrollbar_layer_impl = |
288 static_cast<SolidColorScrollbarLayerImpl*>( | 294 static_cast<SolidColorScrollbarLayerImpl*>( |
289 layer_impl_tree_root->children()[1]); | 295 layer_impl_tree_root->children()[1]); |
290 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); | 296 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
291 scrollbar_layer_impl->SetCurrentPos(10.f); | 297 scrollbar_layer_impl->SetCurrentPos(10.f); |
292 scrollbar_layer_impl->SetMaximum(100); | 298 scrollbar_layer_impl->SetMaximum(100); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); | 345 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); |
340 EXPECT_RECT_EQ(gfx::Rect(8, 0, 20, 3), quads[0]->rect); | 346 EXPECT_RECT_EQ(gfx::Rect(8, 0, 20, 3), quads[0]->rect); |
341 } | 347 } |
342 } | 348 } |
343 | 349 |
344 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { | 350 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { |
345 const int kThumbThickness = 3; | 351 const int kThumbThickness = 3; |
346 const int kTrackStart = 0; | 352 const int kTrackStart = 0; |
347 const int kTrackLength = 10; | 353 const int kTrackLength = 10; |
348 | 354 |
| 355 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
349 LayerTreeSettings layer_tree_settings; | 356 LayerTreeSettings layer_tree_settings; |
350 scoped_ptr<FakeLayerTreeHost> host = | 357 scoped_ptr<FakeLayerTreeHost> host = |
351 FakeLayerTreeHost::Create(layer_tree_settings); | 358 FakeLayerTreeHost::Create(&client, layer_tree_settings); |
352 | 359 |
353 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 360 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
354 | 361 |
355 { | 362 { |
356 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 363 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
357 scoped_refptr<Layer> scroll_layer = Layer::Create(); | 364 scoped_refptr<Layer> scroll_layer = Layer::Create(); |
358 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); | 365 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); |
359 scoped_refptr<Layer> child1 = Layer::Create(); | 366 scoped_refptr<Layer> child1 = Layer::Create(); |
360 scoped_refptr<Layer> child2; | 367 scoped_refptr<Layer> child2; |
361 const bool kIsLeftSideVerticalScrollbar = false; | 368 const bool kIsLeftSideVerticalScrollbar = false; |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); | 900 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); |
894 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); | 901 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); |
895 | 902 |
896 // Horizontal Scrollbars. | 903 // Horizontal Scrollbars. |
897 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); | 904 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); |
898 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); | 905 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); |
899 } | 906 } |
900 | 907 |
901 } // namespace | 908 } // namespace |
902 } // namespace cc | 909 } // namespace cc |
OLD | NEW |