| 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, UpdatePropertiesOfScrollBarWhenThumbRemoved) { | 199 TEST(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { |
| 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 23 matching lines...) Expand all Loading... |
| 230 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 235 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 231 | 236 |
| 232 scrollbar_layer->fake_scrollbar()->set_has_thumb(false); | 237 scrollbar_layer->fake_scrollbar()->set_has_thumb(false); |
| 233 | 238 |
| 234 UPDATE_AND_EXTRACT_LAYER_POINTERS(); | 239 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
| 235 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(), | 240 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(), |
| 236 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 241 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 237 } | 242 } |
| 238 | 243 |
| 239 TEST(ScrollbarLayerTest, ThumbRect) { | 244 TEST(ScrollbarLayerTest, ThumbRect) { |
| 240 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 245 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
| 246 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); |
| 241 scoped_refptr<Layer> root_clip_layer = Layer::Create(); | 247 scoped_refptr<Layer> root_clip_layer = Layer::Create(); |
| 242 scoped_refptr<Layer> root_layer = Layer::Create(); | 248 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 243 scoped_refptr<Layer> content_layer = Layer::Create(); | 249 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 244 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 250 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 245 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); | 251 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); |
| 246 | 252 |
| 247 root_layer->SetScrollClipLayerId(root_clip_layer->id()); | 253 root_layer->SetScrollClipLayerId(root_clip_layer->id()); |
| 248 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). | 254 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). |
| 249 root_clip_layer->SetBounds(gfx::Size(20, 50)); | 255 root_clip_layer->SetBounds(gfx::Size(20, 50)); |
| 250 root_layer->SetBounds(gfx::Size(100, 50)); | 256 root_layer->SetBounds(gfx::Size(100, 50)); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 UPDATE_AND_EXTRACT_LAYER_POINTERS(); | 320 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
| 315 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), | 321 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), |
| 316 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 322 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 317 } | 323 } |
| 318 | 324 |
| 319 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { | 325 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { |
| 320 const int kThumbThickness = 3; | 326 const int kThumbThickness = 3; |
| 321 const int kTrackStart = 1; | 327 const int kTrackStart = 1; |
| 322 const int kTrackLength = 100; | 328 const int kTrackLength = 100; |
| 323 | 329 |
| 330 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
| 324 LayerTreeSettings layer_tree_settings; | 331 LayerTreeSettings layer_tree_settings; |
| 325 scoped_ptr<FakeLayerTreeHost> host = | 332 scoped_ptr<FakeLayerTreeHost> host = |
| 326 FakeLayerTreeHost::Create(layer_tree_settings); | 333 FakeLayerTreeHost::Create(&client, layer_tree_settings); |
| 327 | 334 |
| 328 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 335 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| 329 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 336 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 330 host.get(), scrollbar.Pass(), false, true, kThumbThickness, kTrackStart); | 337 host.get(), scrollbar.Pass(), false, true, kThumbThickness, kTrackStart); |
| 331 ScrollbarLayerImplBase* scrollbar_layer_impl = | 338 ScrollbarLayerImplBase* scrollbar_layer_impl = |
| 332 static_cast<SolidColorScrollbarLayerImpl*>( | 339 static_cast<SolidColorScrollbarLayerImpl*>( |
| 333 layer_impl_tree_root->children()[1]); | 340 layer_impl_tree_root->children()[1]); |
| 334 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); | 341 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
| 335 scrollbar_layer_impl->SetCurrentPos(10.f); | 342 scrollbar_layer_impl->SetCurrentPos(10.f); |
| 336 scrollbar_layer_impl->SetMaximum(100); | 343 scrollbar_layer_impl->SetMaximum(100); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); | 406 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); |
| 400 EXPECT_RECT_EQ(gfx::Rect(1, 0, 19, 3), quads[0]->rect); | 407 EXPECT_RECT_EQ(gfx::Rect(1, 0, 19, 3), quads[0]->rect); |
| 401 } | 408 } |
| 402 } | 409 } |
| 403 | 410 |
| 404 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { | 411 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { |
| 405 const int kThumbThickness = 3; | 412 const int kThumbThickness = 3; |
| 406 const int kTrackStart = 0; | 413 const int kTrackStart = 0; |
| 407 const int kTrackLength = 10; | 414 const int kTrackLength = 10; |
| 408 | 415 |
| 416 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
| 409 LayerTreeSettings layer_tree_settings; | 417 LayerTreeSettings layer_tree_settings; |
| 410 scoped_ptr<FakeLayerTreeHost> host = | 418 scoped_ptr<FakeLayerTreeHost> host = |
| 411 FakeLayerTreeHost::Create(layer_tree_settings); | 419 FakeLayerTreeHost::Create(&client, layer_tree_settings); |
| 412 | 420 |
| 413 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 421 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| 414 | 422 |
| 415 { | 423 { |
| 416 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 424 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 417 scoped_refptr<Layer> scroll_layer = Layer::Create(); | 425 scoped_refptr<Layer> scroll_layer = Layer::Create(); |
| 418 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); | 426 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); |
| 419 scoped_refptr<Layer> child1 = Layer::Create(); | 427 scoped_refptr<Layer> child1 = Layer::Create(); |
| 420 scoped_refptr<Layer> child2; | 428 scoped_refptr<Layer> child2; |
| 421 const bool kIsLeftSideVerticalScrollbar = false; | 429 const bool kIsLeftSideVerticalScrollbar = false; |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1095 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); | 1103 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); |
| 1096 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); | 1104 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); |
| 1097 | 1105 |
| 1098 // Horizontal Scrollbars. | 1106 // Horizontal Scrollbars. |
| 1099 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); | 1107 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); |
| 1100 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); | 1108 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); |
| 1101 } | 1109 } |
| 1102 | 1110 |
| 1103 } // namespace | 1111 } // namespace |
| 1104 } // namespace cc | 1112 } // namespace cc |
| OLD | NEW |