| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <unordered_map> | 7 #include <unordered_map> |
| 8 | 8 |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "cc/animation/animation_host.h" | 10 #include "cc/animation/animation_host.h" |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 // Shrink the track in the non-scrolling dimension so that it only covers the | 394 // Shrink the track in the non-scrolling dimension so that it only covers the |
| 395 // middle third of the scrollbar layer (this does not affect the thumb | 395 // middle third of the scrollbar layer (this does not affect the thumb |
| 396 // position). | 396 // position). |
| 397 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 12, 50, 6)); | 397 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 12, 50, 6)); |
| 398 | 398 |
| 399 UPDATE_AND_EXTRACT_LAYER_POINTERS(); | 399 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
| 400 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), | 400 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), |
| 401 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 401 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 402 } | 402 } |
| 403 | 403 |
| 404 TEST_F(ScrollbarLayerTest, ThumbRectForOverlayLeftSideVerticalScrollbar) { |
| 405 scoped_refptr<Layer> root_clip_layer = Layer::Create(); |
| 406 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 407 // Create an overlay left side vertical scrollbar. |
| 408 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 409 FakePaintedScrollbarLayer::Create(false, true, VERTICAL, true, true, |
| 410 root_layer->id()); |
| 411 root_layer->SetScrollClipLayerId(root_clip_layer->id()); |
| 412 root_clip_layer->SetBounds(gfx::Size(50, 20)); |
| 413 root_layer->SetBounds(gfx::Size(50, 100)); |
| 414 |
| 415 layer_tree_->SetRootLayer(root_clip_layer); |
| 416 root_clip_layer->AddChild(root_layer); |
| 417 root_layer->AddChild(scrollbar_layer); |
| 418 |
| 419 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); |
| 420 scrollbar_layer->SetBounds(gfx::Size(10, 20)); |
| 421 scrollbar_layer->SetScrollLayer(root_layer->id()); |
| 422 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(0, 0, 10, 20)); |
| 423 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); |
| 424 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); |
| 425 layer_tree_host_->UpdateLayers(); |
| 426 LayerImpl* root_clip_layer_impl = nullptr; |
| 427 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr; |
| 428 |
| 429 // Thumb is at the edge of the scrollbar (should be inset to |
| 430 // the start of the track within the scrollbar layer's |
| 431 // position). |
| 432 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
| 433 EXPECT_EQ(gfx::Rect(0, 0, 10, 4).ToString(), |
| 434 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 435 |
| 436 // Change thumb thickness scale factor. |
| 437 scrollbar_layer_impl->SetThumbThicknessScaleFactor(0.5); |
| 438 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
| 439 // For overlay scrollbars thumb_rect.width = thumb_thickness * |
| 440 // thumb_thickness_scale_factor. |
| 441 EXPECT_EQ(gfx::Rect(0, 0, 5, 4).ToString(), |
| 442 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 443 |
| 444 // Change thumb thickness and length. |
| 445 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(4); |
| 446 scrollbar_layer->fake_scrollbar()->set_thumb_length(6); |
| 447 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
| 448 // For left side vertical scrollbars thumb_rect.x = bounds.width() - |
| 449 // thumb_thickness. |
| 450 EXPECT_EQ(gfx::Rect(6, 0, 2, 6).ToString(), |
| 451 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 452 } |
| 453 |
| 404 TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) { | 454 TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) { |
| 405 const int kThumbThickness = 3; | 455 const int kThumbThickness = 3; |
| 406 const int kTrackStart = 1; | 456 const int kTrackStart = 1; |
| 407 const int kTrackLength = 100; | 457 const int kTrackLength = 100; |
| 408 | 458 |
| 409 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 459 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| 410 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 460 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 411 layer_tree_host_.get(), std::move(scrollbar), false, true, | 461 layer_tree_host_.get(), std::move(scrollbar), false, true, |
| 412 kThumbThickness, kTrackStart); | 462 kThumbThickness, kTrackStart); |
| 413 ScrollbarLayerImplBase* scrollbar_layer_impl = | 463 ScrollbarLayerImplBase* scrollbar_layer_impl = |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); | 1167 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); |
| 1118 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); | 1168 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); |
| 1119 | 1169 |
| 1120 // Horizontal Scrollbars. | 1170 // Horizontal Scrollbars. |
| 1121 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); | 1171 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); |
| 1122 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); | 1172 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); |
| 1123 } | 1173 } |
| 1124 | 1174 |
| 1125 } // namespace | 1175 } // namespace |
| 1126 } // namespace cc | 1176 } // namespace cc |
| OLD | NEW |