| 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 "base/thread_task_runner_handle.h" | 6 #include "base/thread_task_runner_handle.h" |
| 7 #include "cc/animation/scrollbar_animation_controller.h" | 7 #include "cc/animation/scrollbar_animation_controller.h" |
| 8 #include "cc/layers/append_quads_data.h" | 8 #include "cc/layers/append_quads_data.h" |
| 9 #include "cc/layers/painted_scrollbar_layer.h" | 9 #include "cc/layers/painted_scrollbar_layer.h" |
| 10 #include "cc/layers/painted_scrollbar_layer_impl.h" | 10 #include "cc/layers/painted_scrollbar_layer_impl.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 181 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 182 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, false, | 182 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, false, |
| 183 0, 0); | 183 0, 0); |
| 184 PaintedScrollbarLayerImpl* scrollbar_layer_impl = | 184 PaintedScrollbarLayerImpl* scrollbar_layer_impl = |
| 185 static_cast<PaintedScrollbarLayerImpl*>( | 185 static_cast<PaintedScrollbarLayerImpl*>( |
| 186 layer_impl_tree_root->children()[1]); | 186 layer_impl_tree_root->children()[1]); |
| 187 | 187 |
| 188 // When the scrollbar is not an overlay scrollbar, the scroll should be | 188 // When the scrollbar is not an overlay scrollbar, the scroll should be |
| 189 // responded to on the main thread as the compositor does not yet implement | 189 // responded to on the main thread as the compositor does not yet implement |
| 190 // scrollbar scrolling. | 190 // scrollbar scrolling. |
| 191 EXPECT_EQ( | 191 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, |
| 192 InputHandler::SCROLL_ON_MAIN_THREAD, | 192 scrollbar_layer_impl->TryScroll( |
| 193 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), InputHandler::GESTURE, | 193 gfx::PointF(), InputHandler::GESTURE, SCROLL_BLOCKS_ON_NONE)); |
| 194 SCROLL_BLOCKS_ON_NONE)); | |
| 195 | 194 |
| 196 // Create and attach an overlay scrollbar. | 195 // Create and attach an overlay scrollbar. |
| 197 scrollbar.reset(new FakeScrollbar(false, false, true)); | 196 scrollbar.reset(new FakeScrollbar(false, false, true)); |
| 198 | 197 |
| 199 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 198 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 200 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, false, | 199 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, false, |
| 201 0, 0); | 200 0, 0); |
| 202 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( | 201 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( |
| 203 layer_impl_tree_root->children()[1]); | 202 layer_impl_tree_root->children()[1]); |
| 204 | 203 |
| 205 // The user shouldn't be able to drag an overlay scrollbar and the scroll | 204 // The user shouldn't be able to drag an overlay scrollbar and the scroll |
| 206 // may be handled in the compositor. | 205 // may be handled in the compositor. |
| 207 EXPECT_EQ( | 206 EXPECT_EQ(InputHandler::SCROLL_IGNORED, |
| 208 InputHandler::SCROLL_IGNORED, | 207 scrollbar_layer_impl->TryScroll( |
| 209 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), InputHandler::GESTURE, | 208 gfx::PointF(), InputHandler::GESTURE, SCROLL_BLOCKS_ON_NONE)); |
| 210 SCROLL_BLOCKS_ON_NONE)); | |
| 211 } | 209 } |
| 212 | 210 |
| 213 TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) { | 211 TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) { |
| 214 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 212 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 215 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings()); | 213 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings()); |
| 216 scoped_refptr<Layer> scroll_layer = Layer::Create(layer_settings()); | 214 scoped_refptr<Layer> scroll_layer = Layer::Create(layer_settings()); |
| 217 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings()); | 215 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings()); |
| 218 scoped_refptr<Layer> scrollbar_layer = PaintedScrollbarLayer::Create( | 216 scoped_refptr<Layer> scrollbar_layer = PaintedScrollbarLayer::Create( |
| 219 layer_settings(), scrollbar.Pass(), layer_tree_root->id()); | 217 layer_settings(), scrollbar.Pass(), layer_tree_root->id()); |
| 220 | 218 |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 FakePaintedScrollbarLayer::Create(layer_settings(), false, true, | 757 FakePaintedScrollbarLayer::Create(layer_settings(), false, true, |
| 760 layer_tree_root->id()); | 758 layer_tree_root->id()); |
| 761 | 759 |
| 762 layer_tree_root->AddChild(content_layer); | 760 layer_tree_root->AddChild(content_layer); |
| 763 layer_tree_root->AddChild(scrollbar_layer); | 761 layer_tree_root->AddChild(scrollbar_layer); |
| 764 | 762 |
| 765 layer_tree_host_->SetRootLayer(layer_tree_root); | 763 layer_tree_host_->SetRootLayer(layer_tree_root); |
| 766 | 764 |
| 767 scrollbar_layer->SetIsDrawable(true); | 765 scrollbar_layer->SetIsDrawable(true); |
| 768 scrollbar_layer->SetBounds(gfx::Size(100, 15)); | 766 scrollbar_layer->SetBounds(gfx::Size(100, 15)); |
| 769 scrollbar_layer->SetPosition(scrollbar_location); | 767 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location)); |
| 770 layer_tree_root->SetBounds(gfx::Size(100, 200)); | 768 layer_tree_root->SetBounds(gfx::Size(100, 200)); |
| 771 content_layer->SetBounds(gfx::Size(100, 200)); | 769 content_layer->SetBounds(gfx::Size(100, 200)); |
| 772 scrollbar_layer->set_visible_layer_rect(gfx::Rect(0, 0, 100, 200)); | 770 scrollbar_layer->set_visible_layer_rect(gfx::Rect(0, 0, 100, 200)); |
| 773 | 771 |
| 774 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 772 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 775 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); | 773 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); |
| 776 | 774 |
| 777 size_t resource_count; | 775 size_t resource_count; |
| 778 int expected_created, expected_deleted; | 776 int expected_created, expected_deleted; |
| 779 scrollbar_layer->SavePaintProperties(); | 777 scrollbar_layer->SavePaintProperties(); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 FakePaintedScrollbarLayer::Create(layer_settings(), false, true, | 885 FakePaintedScrollbarLayer::Create(layer_settings(), false, true, |
| 888 layer_tree_root->id()); | 886 layer_tree_root->id()); |
| 889 | 887 |
| 890 layer_tree_root->AddChild(content_layer); | 888 layer_tree_root->AddChild(content_layer); |
| 891 layer_tree_root->AddChild(scrollbar_layer); | 889 layer_tree_root->AddChild(scrollbar_layer); |
| 892 | 890 |
| 893 layer_tree_host_->SetRootLayer(layer_tree_root); | 891 layer_tree_host_->SetRootLayer(layer_tree_root); |
| 894 | 892 |
| 895 scrollbar_layer->SetIsDrawable(true); | 893 scrollbar_layer->SetIsDrawable(true); |
| 896 scrollbar_layer->SetBounds(gfx::Size(100, 15)); | 894 scrollbar_layer->SetBounds(gfx::Size(100, 15)); |
| 897 scrollbar_layer->SetPosition(scrollbar_location); | 895 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location)); |
| 898 layer_tree_root->SetBounds(gfx::Size(100, 200)); | 896 layer_tree_root->SetBounds(gfx::Size(100, 200)); |
| 899 content_layer->SetBounds(gfx::Size(100, 200)); | 897 content_layer->SetBounds(gfx::Size(100, 200)); |
| 900 scrollbar_layer->set_visible_layer_rect( | 898 scrollbar_layer->set_visible_layer_rect( |
| 901 gfx::Rect(scrollbar_location, scrollbar_layer->bounds())); | 899 gfx::Rect(scrollbar_location, scrollbar_layer->bounds())); |
| 902 | 900 |
| 903 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 901 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 904 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); | 902 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); |
| 905 | 903 |
| 906 layer_tree_host_->SetDeviceScaleFactor(test_scale); | 904 layer_tree_host_->SetDeviceScaleFactor(test_scale); |
| 907 | 905 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings()); | 943 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings()); |
| 946 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 944 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 947 FakePaintedScrollbarLayer::Create(layer_settings(), paint_during_update, | 945 FakePaintedScrollbarLayer::Create(layer_settings(), paint_during_update, |
| 948 has_thumb, layer_tree_root->id()); | 946 has_thumb, layer_tree_root->id()); |
| 949 | 947 |
| 950 layer_tree_root->AddChild(scrollbar_layer); | 948 layer_tree_root->AddChild(scrollbar_layer); |
| 951 | 949 |
| 952 layer_tree_host_->SetRootLayer(layer_tree_root); | 950 layer_tree_host_->SetRootLayer(layer_tree_root); |
| 953 | 951 |
| 954 scrollbar_layer->SetBounds(scrollbar_rect.size()); | 952 scrollbar_layer->SetBounds(scrollbar_rect.size()); |
| 955 scrollbar_layer->SetPosition(scrollbar_rect.origin()); | 953 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_rect.origin())); |
| 956 scrollbar_layer->fake_scrollbar()->set_location(scrollbar_rect.origin()); | 954 scrollbar_layer->fake_scrollbar()->set_location(scrollbar_rect.origin()); |
| 957 scrollbar_layer->fake_scrollbar()->set_track_rect(scrollbar_rect); | 955 scrollbar_layer->fake_scrollbar()->set_track_rect(scrollbar_rect); |
| 958 scrollbar_layer->set_visible_layer_rect(scrollbar_rect); | 956 scrollbar_layer->set_visible_layer_rect(scrollbar_rect); |
| 959 | 957 |
| 960 layer_tree_host_->SetDeviceScaleFactor(test_scale); | 958 layer_tree_host_->SetDeviceScaleFactor(test_scale); |
| 961 | 959 |
| 962 gfx::Rect screen_space_clip_rect; | 960 gfx::Rect screen_space_clip_rect; |
| 963 scrollbar_layer->SavePaintProperties(); | 961 scrollbar_layer->SavePaintProperties(); |
| 964 | 962 |
| 965 scrollbar_layer->Update(); | 963 scrollbar_layer->Update(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); | 1007 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); |
| 1010 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); | 1008 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); |
| 1011 | 1009 |
| 1012 // Horizontal Scrollbars. | 1010 // Horizontal Scrollbars. |
| 1013 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); | 1011 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); |
| 1014 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); | 1012 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); |
| 1015 } | 1013 } |
| 1016 | 1014 |
| 1017 } // namespace | 1015 } // namespace |
| 1018 } // namespace cc | 1016 } // namespace cc |
| OLD | NEW |