| 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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 ScrollbarLayerImplBase* scrollbar_layer_impl = | 338 ScrollbarLayerImplBase* scrollbar_layer_impl = |
| 339 static_cast<SolidColorScrollbarLayerImpl*>( | 339 static_cast<SolidColorScrollbarLayerImpl*>( |
| 340 layer_impl_tree_root->children()[1]); | 340 layer_impl_tree_root->children()[1]); |
| 341 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); | 341 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
| 342 scrollbar_layer_impl->SetCurrentPos(10.f); | 342 scrollbar_layer_impl->SetCurrentPos(10.f); |
| 343 scrollbar_layer_impl->SetMaximum(100); | 343 scrollbar_layer_impl->SetMaximum(100); |
| 344 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f); | 344 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f); |
| 345 | 345 |
| 346 // Thickness should be overridden to 3. | 346 // Thickness should be overridden to 3. |
| 347 { | 347 { |
| 348 MockOcclusionTracker<LayerImpl> occlusion_tracker; | |
| 349 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 348 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 350 AppendQuadsData data; | 349 AppendQuadsData data; |
| 351 scrollbar_layer_impl->AppendQuads( | 350 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); |
| 352 render_pass.get(), occlusion_tracker, &data); | |
| 353 | 351 |
| 354 const QuadList& quads = render_pass->quad_list; | 352 const QuadList& quads = render_pass->quad_list; |
| 355 ASSERT_EQ(1u, quads.size()); | 353 ASSERT_EQ(1u, quads.size()); |
| 356 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); | 354 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); |
| 357 EXPECT_RECT_EQ(gfx::Rect(6, 0, 39, 3), quads.front()->rect); | 355 EXPECT_RECT_EQ(gfx::Rect(6, 0, 39, 3), quads.front()->rect); |
| 358 } | 356 } |
| 359 | 357 |
| 360 // Contents scale should scale the draw quad. | 358 // Contents scale should scale the draw quad. |
| 361 scrollbar_layer_impl->draw_properties().contents_scale_x = 2.f; | 359 scrollbar_layer_impl->draw_properties().contents_scale_x = 2.f; |
| 362 scrollbar_layer_impl->draw_properties().contents_scale_y = 2.f; | 360 scrollbar_layer_impl->draw_properties().contents_scale_y = 2.f; |
| 363 { | 361 { |
| 364 MockOcclusionTracker<LayerImpl> occlusion_tracker; | |
| 365 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 362 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 366 AppendQuadsData data; | 363 AppendQuadsData data; |
| 367 scrollbar_layer_impl->AppendQuads( | 364 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); |
| 368 render_pass.get(), occlusion_tracker, &data); | |
| 369 | 365 |
| 370 const QuadList& quads = render_pass->quad_list; | 366 const QuadList& quads = render_pass->quad_list; |
| 371 ASSERT_EQ(1u, quads.size()); | 367 ASSERT_EQ(1u, quads.size()); |
| 372 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); | 368 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); |
| 373 EXPECT_RECT_EQ(gfx::Rect(12, 0, 78, 6), quads.front()->rect); | 369 EXPECT_RECT_EQ(gfx::Rect(12, 0, 78, 6), quads.front()->rect); |
| 374 } | 370 } |
| 375 scrollbar_layer_impl->draw_properties().contents_scale_x = 1.f; | 371 scrollbar_layer_impl->draw_properties().contents_scale_x = 1.f; |
| 376 scrollbar_layer_impl->draw_properties().contents_scale_y = 1.f; | 372 scrollbar_layer_impl->draw_properties().contents_scale_y = 1.f; |
| 377 | 373 |
| 378 // For solid color scrollbars, position and size should reflect the | 374 // For solid color scrollbars, position and size should reflect the |
| 379 // current viewport state. | 375 // current viewport state. |
| 380 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.2f); | 376 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.2f); |
| 381 { | 377 { |
| 382 MockOcclusionTracker<LayerImpl> occlusion_tracker; | |
| 383 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 378 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 384 AppendQuadsData data; | 379 AppendQuadsData data; |
| 385 scrollbar_layer_impl->AppendQuads( | 380 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); |
| 386 render_pass.get(), occlusion_tracker, &data); | |
| 387 | 381 |
| 388 const QuadList& quads = render_pass->quad_list; | 382 const QuadList& quads = render_pass->quad_list; |
| 389 ASSERT_EQ(1u, quads.size()); | 383 ASSERT_EQ(1u, quads.size()); |
| 390 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); | 384 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); |
| 391 EXPECT_RECT_EQ(gfx::Rect(8, 0, 19, 3), quads.front()->rect); | 385 EXPECT_RECT_EQ(gfx::Rect(8, 0, 19, 3), quads.front()->rect); |
| 392 } | 386 } |
| 393 | 387 |
| 394 // 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. |
| 395 scrollbar_layer_impl->SetCurrentPos(0.f); | 389 scrollbar_layer_impl->SetCurrentPos(0.f); |
| 396 scrollbar_layer_impl->SetMaximum(0); | 390 scrollbar_layer_impl->SetMaximum(0); |
| 397 { | 391 { |
| 398 MockOcclusionTracker<LayerImpl> occlusion_tracker; | |
| 399 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 392 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 400 AppendQuadsData data; | 393 AppendQuadsData data; |
| 401 scrollbar_layer_impl->AppendQuads( | 394 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); |
| 402 render_pass.get(), occlusion_tracker, &data); | |
| 403 | 395 |
| 404 const QuadList& quads = render_pass->quad_list; | 396 const QuadList& quads = render_pass->quad_list; |
| 405 ASSERT_EQ(1u, quads.size()); | 397 ASSERT_EQ(1u, quads.size()); |
| 406 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); | 398 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); |
| 407 EXPECT_RECT_EQ(gfx::Rect(1, 0, 19, 3), quads.front()->rect); | 399 EXPECT_RECT_EQ(gfx::Rect(1, 0, 19, 3), quads.front()->rect); |
| 408 } | 400 } |
| 409 } | 401 } |
| 410 | 402 |
| 411 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { | 403 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { |
| 412 const int kThumbThickness = 3; | 404 const int kThumbThickness = 3; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 // Choose layer bounds to give max_scroll_offset = (8, 8). | 440 // Choose layer bounds to give max_scroll_offset = (8, 8). |
| 449 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); | 441 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); |
| 450 scroll_layer_impl->SetBounds(gfx::Size(10, 10)); | 442 scroll_layer_impl->SetBounds(gfx::Size(10, 10)); |
| 451 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f)); | 443 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f)); |
| 452 | 444 |
| 453 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); | 445 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
| 454 scrollbar_layer_impl->SetCurrentPos(4.f); | 446 scrollbar_layer_impl->SetCurrentPos(4.f); |
| 455 scrollbar_layer_impl->SetMaximum(8); | 447 scrollbar_layer_impl->SetMaximum(8); |
| 456 | 448 |
| 457 { | 449 { |
| 458 MockOcclusionTracker<LayerImpl> occlusion_tracker; | |
| 459 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 450 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 460 | 451 |
| 461 AppendQuadsData data; | 452 AppendQuadsData data; |
| 462 scrollbar_layer_impl->AppendQuads( | 453 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); |
| 463 render_pass.get(), occlusion_tracker, &data); | |
| 464 | 454 |
| 465 const QuadList& quads = render_pass->quad_list; | 455 const QuadList& quads = render_pass->quad_list; |
| 466 ASSERT_EQ(1u, quads.size()); | 456 ASSERT_EQ(1u, quads.size()); |
| 467 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); | 457 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); |
| 468 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads.front()->rect); | 458 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads.front()->rect); |
| 469 } | 459 } |
| 470 } | 460 } |
| 471 | 461 |
| 472 class ScrollbarLayerSolidColorThumbTest : public testing::Test { | 462 class ScrollbarLayerSolidColorThumbTest : public testing::Test { |
| 473 public: | 463 public: |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); | 1093 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); |
| 1104 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); | 1094 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); |
| 1105 | 1095 |
| 1106 // Horizontal Scrollbars. | 1096 // Horizontal Scrollbars. |
| 1107 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); | 1097 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); |
| 1108 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); | 1098 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); |
| 1109 } | 1099 } |
| 1110 | 1100 |
| 1111 } // namespace | 1101 } // namespace |
| 1112 } // namespace cc | 1102 } // namespace cc |
| OLD | NEW |