| 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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 | 345 |
| 346 // Thickness should be overridden to 3. | 346 // Thickness should be overridden to 3. |
| 347 { | 347 { |
| 348 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 348 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 349 AppendQuadsData data; | 349 AppendQuadsData data; |
| 350 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); | 350 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); |
| 351 | 351 |
| 352 const QuadList& quads = render_pass->quad_list; | 352 const QuadList& quads = render_pass->quad_list; |
| 353 ASSERT_EQ(1u, quads.size()); | 353 ASSERT_EQ(1u, quads.size()); |
| 354 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); | 354 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); |
| 355 EXPECT_RECT_EQ(gfx::Rect(6, 0, 39, 3), quads.front()->rect); | 355 EXPECT_EQ(gfx::Rect(6, 0, 39, 3), quads.front()->rect); |
| 356 } | 356 } |
| 357 | 357 |
| 358 // Contents scale should scale the draw quad. | 358 // Contents scale should scale the draw quad. |
| 359 scrollbar_layer_impl->draw_properties().contents_scale_x = 2.f; | 359 scrollbar_layer_impl->draw_properties().contents_scale_x = 2.f; |
| 360 scrollbar_layer_impl->draw_properties().contents_scale_y = 2.f; | 360 scrollbar_layer_impl->draw_properties().contents_scale_y = 2.f; |
| 361 { | 361 { |
| 362 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 362 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 363 AppendQuadsData data; | 363 AppendQuadsData data; |
| 364 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); | 364 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); |
| 365 | 365 |
| 366 const QuadList& quads = render_pass->quad_list; | 366 const QuadList& quads = render_pass->quad_list; |
| 367 ASSERT_EQ(1u, quads.size()); | 367 ASSERT_EQ(1u, quads.size()); |
| 368 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); | 368 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); |
| 369 EXPECT_RECT_EQ(gfx::Rect(12, 0, 78, 6), quads.front()->rect); | 369 EXPECT_EQ(gfx::Rect(12, 0, 78, 6), quads.front()->rect); |
| 370 } | 370 } |
| 371 scrollbar_layer_impl->draw_properties().contents_scale_x = 1.f; | 371 scrollbar_layer_impl->draw_properties().contents_scale_x = 1.f; |
| 372 scrollbar_layer_impl->draw_properties().contents_scale_y = 1.f; | 372 scrollbar_layer_impl->draw_properties().contents_scale_y = 1.f; |
| 373 | 373 |
| 374 // For solid color scrollbars, position and size should reflect the | 374 // For solid color scrollbars, position and size should reflect the |
| 375 // current viewport state. | 375 // current viewport state. |
| 376 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.2f); | 376 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.2f); |
| 377 { | 377 { |
| 378 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 378 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 379 AppendQuadsData data; | 379 AppendQuadsData data; |
| 380 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); | 380 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); |
| 381 | 381 |
| 382 const QuadList& quads = render_pass->quad_list; | 382 const QuadList& quads = render_pass->quad_list; |
| 383 ASSERT_EQ(1u, quads.size()); | 383 ASSERT_EQ(1u, quads.size()); |
| 384 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); | 384 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); |
| 385 EXPECT_RECT_EQ(gfx::Rect(8, 0, 19, 3), quads.front()->rect); | 385 EXPECT_EQ(gfx::Rect(8, 0, 19, 3), quads.front()->rect); |
| 386 } | 386 } |
| 387 | 387 |
| 388 // We shouldn't attempt div-by-zero when the maximum is zero. | 388 // We shouldn't attempt div-by-zero when the maximum is zero. |
| 389 scrollbar_layer_impl->SetCurrentPos(0.f); | 389 scrollbar_layer_impl->SetCurrentPos(0.f); |
| 390 scrollbar_layer_impl->SetMaximum(0); | 390 scrollbar_layer_impl->SetMaximum(0); |
| 391 { | 391 { |
| 392 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 392 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 393 AppendQuadsData data; | 393 AppendQuadsData data; |
| 394 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); | 394 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); |
| 395 | 395 |
| 396 const QuadList& quads = render_pass->quad_list; | 396 const QuadList& quads = render_pass->quad_list; |
| 397 ASSERT_EQ(1u, quads.size()); | 397 ASSERT_EQ(1u, quads.size()); |
| 398 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); | 398 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); |
| 399 EXPECT_RECT_EQ(gfx::Rect(1, 0, 19, 3), quads.front()->rect); | 399 EXPECT_EQ(gfx::Rect(1, 0, 19, 3), quads.front()->rect); |
| 400 } | 400 } |
| 401 } | 401 } |
| 402 | 402 |
| 403 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { | 403 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { |
| 404 const int kThumbThickness = 3; | 404 const int kThumbThickness = 3; |
| 405 const int kTrackStart = 0; | 405 const int kTrackStart = 0; |
| 406 const int kTrackLength = 10; | 406 const int kTrackLength = 10; |
| 407 | 407 |
| 408 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 408 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
| 409 LayerTreeSettings layer_tree_settings; | 409 LayerTreeSettings layer_tree_settings; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 | 448 |
| 449 { | 449 { |
| 450 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 450 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 451 | 451 |
| 452 AppendQuadsData data; | 452 AppendQuadsData data; |
| 453 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); | 453 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); |
| 454 | 454 |
| 455 const QuadList& quads = render_pass->quad_list; | 455 const QuadList& quads = render_pass->quad_list; |
| 456 ASSERT_EQ(1u, quads.size()); | 456 ASSERT_EQ(1u, quads.size()); |
| 457 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); | 457 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); |
| 458 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads.front()->rect); | 458 EXPECT_EQ(gfx::Rect(3, 0, 3, 3), quads.front()->rect); |
| 459 } | 459 } |
| 460 } | 460 } |
| 461 | 461 |
| 462 class ScrollbarLayerSolidColorThumbTest : public testing::Test { | 462 class ScrollbarLayerSolidColorThumbTest : public testing::Test { |
| 463 public: | 463 public: |
| 464 ScrollbarLayerSolidColorThumbTest() { | 464 ScrollbarLayerSolidColorThumbTest() { |
| 465 LayerTreeSettings layer_tree_settings; | 465 LayerTreeSettings layer_tree_settings; |
| 466 host_impl_.reset(new FakeLayerTreeHostImpl( | 466 host_impl_.reset(new FakeLayerTreeHostImpl( |
| 467 layer_tree_settings, &proxy_, &shared_bitmap_manager_)); | 467 layer_tree_settings, &proxy_, &shared_bitmap_manager_)); |
| 468 | 468 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 SolidColorScrollbarLayerImpl* layers[2] = | 537 SolidColorScrollbarLayerImpl* layers[2] = |
| 538 { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() }; | 538 { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() }; |
| 539 for (size_t i = 0; i < 2; ++i) { | 539 for (size_t i = 0; i < 2; ++i) { |
| 540 layers[i]->SetVisibleToTotalLengthRatio(0.2f); | 540 layers[i]->SetVisibleToTotalLengthRatio(0.2f); |
| 541 layers[i]->SetCurrentPos(25); | 541 layers[i]->SetCurrentPos(25); |
| 542 layers[i]->SetMaximum(100); | 542 layers[i]->SetMaximum(100); |
| 543 } | 543 } |
| 544 layers[0]->SetBounds(gfx::Size(100, 3)); | 544 layers[0]->SetBounds(gfx::Size(100, 3)); |
| 545 layers[1]->SetBounds(gfx::Size(3, 100)); | 545 layers[1]->SetBounds(gfx::Size(3, 100)); |
| 546 | 546 |
| 547 EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f), | 547 EXPECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f), |
| 548 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); | 548 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); |
| 549 EXPECT_RECT_EQ(gfx::RectF(0.f, 20.f, 3.f, 20.f), | 549 EXPECT_EQ(gfx::RectF(0.f, 20.f, 3.f, 20.f), |
| 550 vertical_scrollbar_layer_->ComputeThumbQuadRect()); | 550 vertical_scrollbar_layer_->ComputeThumbQuadRect()); |
| 551 | 551 |
| 552 horizontal_scrollbar_layer_->SetVerticalAdjust(10.f); | 552 horizontal_scrollbar_layer_->SetVerticalAdjust(10.f); |
| 553 vertical_scrollbar_layer_->SetVerticalAdjust(10.f); | 553 vertical_scrollbar_layer_->SetVerticalAdjust(10.f); |
| 554 | 554 |
| 555 // The vertical adjustment factor has two effects: | 555 // The vertical adjustment factor has two effects: |
| 556 // 1.) Moves the horizontal scrollbar down | 556 // 1.) Moves the horizontal scrollbar down |
| 557 // 2.) Increases the vertical scrollbar's effective track length which both | 557 // 2.) Increases the vertical scrollbar's effective track length which both |
| 558 // increases the thumb's length and its position within the track. | 558 // increases the thumb's length and its position within the track. |
| 559 EXPECT_RECT_EQ(gfx::Rect(20.f, 10.f, 20.f, 3.f), | 559 EXPECT_EQ(gfx::Rect(20.f, 10.f, 20.f, 3.f), |
| 560 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); | 560 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); |
| 561 EXPECT_RECT_EQ(gfx::Rect(0.f, 22, 3.f, 22.f), | 561 EXPECT_EQ(gfx::Rect(0.f, 22, 3.f, 22.f), |
| 562 vertical_scrollbar_layer_->ComputeThumbQuadRect()); | 562 vertical_scrollbar_layer_->ComputeThumbQuadRect()); |
| 563 } | 563 } |
| 564 | 564 |
| 565 class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest { | 565 class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest { |
| 566 public: | 566 public: |
| 567 ScrollbarLayerTestMaxTextureSize() {} | 567 ScrollbarLayerTestMaxTextureSize() {} |
| 568 | 568 |
| 569 void SetScrollbarBounds(const gfx::Size& bounds) { bounds_ = bounds; } | 569 void SetScrollbarBounds(const gfx::Size& bounds) { bounds_ = bounds; } |
| 570 | 570 |
| 571 void BeginTest() override { | 571 void BeginTest() override { |
| 572 scroll_layer_ = Layer::Create(); | 572 scroll_layer_ = Layer::Create(); |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1095 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); | 1095 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); |
| 1096 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); | 1096 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); |
| 1097 | 1097 |
| 1098 // Horizontal Scrollbars. | 1098 // Horizontal Scrollbars. |
| 1099 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); | 1099 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); |
| 1100 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); | 1100 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); |
| 1101 } | 1101 } |
| 1102 | 1102 |
| 1103 } // namespace | 1103 } // namespace |
| 1104 } // namespace cc | 1104 } // namespace cc |
| OLD | NEW |