| 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 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 63 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 64 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); | |
| 65 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 64 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 66 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 65 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 67 host.get(), scrollbar.Pass(), false, false, 0, 0); | 66 host.get(), scrollbar.Pass(), false, false, 0, 0); |
| 68 | 67 |
| 69 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; | 68 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; |
| 70 PaintedScrollbarLayerImpl* cc_child2 = | 69 PaintedScrollbarLayerImpl* cc_child2 = |
| 71 static_cast<PaintedScrollbarLayerImpl*>( | 70 static_cast<PaintedScrollbarLayerImpl*>( |
| 72 layer_impl_tree_root->children()[1]); | 71 layer_impl_tree_root->children()[1]); |
| 73 | 72 |
| 74 EXPECT_EQ(cc_child1->scrollbars()->size(), 1UL); | 73 EXPECT_EQ(cc_child1->scrollbars()->size(), 1UL); |
| 75 EXPECT_EQ(*(cc_child1->scrollbars()->begin()), cc_child2); | 74 EXPECT_EQ(*(cc_child1->scrollbars()->begin()), cc_child2); |
| 76 } | 75 } |
| 77 | 76 |
| 78 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { | 77 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { |
| 79 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 78 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 80 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); | |
| 81 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 79 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 82 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 80 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 83 host.get(), scrollbar.Pass(), true, false, 0, 0); | 81 host.get(), scrollbar.Pass(), true, false, 0, 0); |
| 84 | 82 |
| 85 PaintedScrollbarLayerImpl* cc_child1 = | 83 PaintedScrollbarLayerImpl* cc_child1 = |
| 86 static_cast<PaintedScrollbarLayerImpl*>( | 84 static_cast<PaintedScrollbarLayerImpl*>( |
| 87 layer_impl_tree_root->children()[0]); | 85 layer_impl_tree_root->children()[0]); |
| 88 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; | 86 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; |
| 89 | 87 |
| 90 EXPECT_EQ(cc_child2->scrollbars()->size(), 1UL); | 88 EXPECT_EQ(cc_child2->scrollbars()->size(), 1UL); |
| 91 EXPECT_EQ(*(cc_child2->scrollbars()->begin()), cc_child1); | 89 EXPECT_EQ(*(cc_child2->scrollbars()->begin()), cc_child1); |
| 92 } | 90 } |
| 93 | 91 |
| 94 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { | 92 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { |
| 95 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 93 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 96 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); | |
| 97 | 94 |
| 98 // Create and attach a non-overlay scrollbar. | 95 // Create and attach a non-overlay scrollbar. |
| 99 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 96 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 100 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 97 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 101 host.get(), scrollbar.Pass(), false, false, 0, 0); | 98 host.get(), scrollbar.Pass(), false, false, 0, 0); |
| 102 PaintedScrollbarLayerImpl* scrollbar_layer_impl = | 99 PaintedScrollbarLayerImpl* scrollbar_layer_impl = |
| 103 static_cast<PaintedScrollbarLayerImpl*>( | 100 static_cast<PaintedScrollbarLayerImpl*>( |
| 104 layer_impl_tree_root->children()[1]); | 101 layer_impl_tree_root->children()[1]); |
| 105 | 102 |
| 106 // 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 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 119 layer_impl_tree_root->children()[1]); | 116 layer_impl_tree_root->children()[1]); |
| 120 | 117 |
| 121 // 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 |
| 122 // may be handled in the compositor. | 119 // may be handled in the compositor. |
| 123 EXPECT_EQ(InputHandler::ScrollIgnored, | 120 EXPECT_EQ(InputHandler::ScrollIgnored, |
| 124 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), | 121 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), |
| 125 InputHandler::Gesture)); | 122 InputHandler::Gesture)); |
| 126 } | 123 } |
| 127 | 124 |
| 128 TEST(PaintedScrollbarLayerTest, ScrollOffsetSynchronization) { | 125 TEST(PaintedScrollbarLayerTest, ScrollOffsetSynchronization) { |
| 129 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 126 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 130 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); | |
| 131 | 127 |
| 132 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 128 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 133 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 129 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 134 scoped_refptr<Layer> scroll_layer = Layer::Create(); | 130 scoped_refptr<Layer> scroll_layer = Layer::Create(); |
| 135 scoped_refptr<Layer> content_layer = Layer::Create(); | 131 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 136 scoped_refptr<Layer> scrollbar_layer = | 132 scoped_refptr<Layer> scrollbar_layer = |
| 137 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); | 133 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); |
| 138 | 134 |
| 139 // Choose bounds to give max_scroll_offset = (30, 50). | 135 // Choose bounds to give max_scroll_offset = (30, 50). |
| 140 layer_tree_root->SetBounds(gfx::Size(70, 150)); | 136 layer_tree_root->SetBounds(gfx::Size(70, 150)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 do { \ | 186 do { \ |
| 191 scrollbar_layer->UpdateThumbAndTrackGeometry(); \ | 187 scrollbar_layer->UpdateThumbAndTrackGeometry(); \ |
| 192 root_clip_layer_impl = host->CommitAndCreateLayerImplTree(); \ | 188 root_clip_layer_impl = host->CommitAndCreateLayerImplTree(); \ |
| 193 root_layer_impl = root_clip_layer_impl->children()[0]; \ | 189 root_layer_impl = root_clip_layer_impl->children()[0]; \ |
| 194 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ | 190 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ |
| 195 root_layer_impl->children()[1]); \ | 191 root_layer_impl->children()[1]); \ |
| 196 scrollbar_layer_impl->ScrollbarParametersDidChange(); \ | 192 scrollbar_layer_impl->ScrollbarParametersDidChange(); \ |
| 197 } while (false) | 193 } while (false) |
| 198 | 194 |
| 199 TEST(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { | 195 TEST(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { |
| 200 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 196 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 201 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); | |
| 202 scoped_refptr<Layer> root_clip_layer = Layer::Create(); | 197 scoped_refptr<Layer> root_clip_layer = Layer::Create(); |
| 203 scoped_refptr<Layer> root_layer = Layer::Create(); | 198 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 204 scoped_refptr<Layer> content_layer = Layer::Create(); | 199 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 205 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 200 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 206 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); | 201 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); |
| 207 | 202 |
| 208 root_layer->SetScrollClipLayerId(root_clip_layer->id()); | 203 root_layer->SetScrollClipLayerId(root_clip_layer->id()); |
| 209 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). | 204 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). |
| 210 root_clip_layer->SetBounds(gfx::Size(20, 50)); | 205 root_clip_layer->SetBounds(gfx::Size(20, 50)); |
| 211 root_layer->SetBounds(gfx::Size(100, 50)); | 206 root_layer->SetBounds(gfx::Size(100, 50)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 235 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 230 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 236 | 231 |
| 237 scrollbar_layer->fake_scrollbar()->set_has_thumb(false); | 232 scrollbar_layer->fake_scrollbar()->set_has_thumb(false); |
| 238 | 233 |
| 239 UPDATE_AND_EXTRACT_LAYER_POINTERS(); | 234 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
| 240 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(), | 235 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(), |
| 241 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 236 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 242 } | 237 } |
| 243 | 238 |
| 244 TEST(ScrollbarLayerTest, ThumbRect) { | 239 TEST(ScrollbarLayerTest, ThumbRect) { |
| 245 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 240 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 246 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); | |
| 247 scoped_refptr<Layer> root_clip_layer = Layer::Create(); | 241 scoped_refptr<Layer> root_clip_layer = Layer::Create(); |
| 248 scoped_refptr<Layer> root_layer = Layer::Create(); | 242 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 249 scoped_refptr<Layer> content_layer = Layer::Create(); | 243 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 250 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 244 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 251 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); | 245 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); |
| 252 | 246 |
| 253 root_layer->SetScrollClipLayerId(root_clip_layer->id()); | 247 root_layer->SetScrollClipLayerId(root_clip_layer->id()); |
| 254 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). | 248 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). |
| 255 root_clip_layer->SetBounds(gfx::Size(20, 50)); | 249 root_clip_layer->SetBounds(gfx::Size(20, 50)); |
| 256 root_layer->SetBounds(gfx::Size(100, 50)); | 250 root_layer->SetBounds(gfx::Size(100, 50)); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 UPDATE_AND_EXTRACT_LAYER_POINTERS(); | 314 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
| 321 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), | 315 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), |
| 322 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 316 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 323 } | 317 } |
| 324 | 318 |
| 325 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { | 319 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { |
| 326 const int kThumbThickness = 3; | 320 const int kThumbThickness = 3; |
| 327 const int kTrackStart = 1; | 321 const int kTrackStart = 1; |
| 328 const int kTrackLength = 100; | 322 const int kTrackLength = 100; |
| 329 | 323 |
| 330 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | |
| 331 LayerTreeSettings layer_tree_settings; | 324 LayerTreeSettings layer_tree_settings; |
| 332 scoped_ptr<FakeLayerTreeHost> host = | 325 scoped_ptr<FakeLayerTreeHost> host = |
| 333 FakeLayerTreeHost::Create(&client, layer_tree_settings); | 326 FakeLayerTreeHost::Create(layer_tree_settings); |
| 334 | 327 |
| 335 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 328 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| 336 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 329 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 337 host.get(), scrollbar.Pass(), false, true, kThumbThickness, kTrackStart); | 330 host.get(), scrollbar.Pass(), false, true, kThumbThickness, kTrackStart); |
| 338 ScrollbarLayerImplBase* scrollbar_layer_impl = | 331 ScrollbarLayerImplBase* scrollbar_layer_impl = |
| 339 static_cast<SolidColorScrollbarLayerImpl*>( | 332 static_cast<SolidColorScrollbarLayerImpl*>( |
| 340 layer_impl_tree_root->children()[1]); | 333 layer_impl_tree_root->children()[1]); |
| 341 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); | 334 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
| 342 scrollbar_layer_impl->SetCurrentPos(10.f); | 335 scrollbar_layer_impl->SetCurrentPos(10.f); |
| 343 scrollbar_layer_impl->SetMaximum(100); | 336 scrollbar_layer_impl->SetMaximum(100); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); | 399 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); |
| 407 EXPECT_RECT_EQ(gfx::Rect(1, 0, 19, 3), quads[0]->rect); | 400 EXPECT_RECT_EQ(gfx::Rect(1, 0, 19, 3), quads[0]->rect); |
| 408 } | 401 } |
| 409 } | 402 } |
| 410 | 403 |
| 411 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { | 404 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { |
| 412 const int kThumbThickness = 3; | 405 const int kThumbThickness = 3; |
| 413 const int kTrackStart = 0; | 406 const int kTrackStart = 0; |
| 414 const int kTrackLength = 10; | 407 const int kTrackLength = 10; |
| 415 | 408 |
| 416 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | |
| 417 LayerTreeSettings layer_tree_settings; | 409 LayerTreeSettings layer_tree_settings; |
| 418 scoped_ptr<FakeLayerTreeHost> host = | 410 scoped_ptr<FakeLayerTreeHost> host = |
| 419 FakeLayerTreeHost::Create(&client, layer_tree_settings); | 411 FakeLayerTreeHost::Create(layer_tree_settings); |
| 420 | 412 |
| 421 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 413 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| 422 | 414 |
| 423 { | 415 { |
| 424 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 416 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 425 scoped_refptr<Layer> scroll_layer = Layer::Create(); | 417 scoped_refptr<Layer> scroll_layer = Layer::Create(); |
| 426 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); | 418 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); |
| 427 scoped_refptr<Layer> child1 = Layer::Create(); | 419 scoped_refptr<Layer> child1 = Layer::Create(); |
| 428 scoped_refptr<Layer> child2; | 420 scoped_refptr<Layer> child2; |
| 429 const bool kIsLeftSideVerticalScrollbar = false; | 421 const bool kIsLeftSideVerticalScrollbar = false; |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); | 1095 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); |
| 1104 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); | 1096 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); |
| 1105 | 1097 |
| 1106 // Horizontal Scrollbars. | 1098 // Horizontal Scrollbars. |
| 1107 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); | 1099 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); |
| 1108 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); | 1100 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); |
| 1109 } | 1101 } |
| 1110 | 1102 |
| 1111 } // namespace | 1103 } // namespace |
| 1112 } // namespace cc | 1104 } // namespace cc |
| OLD | NEW |