OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/layers/layer_impl.h" | 5 #include "cc/layers/layer_impl.h" |
6 | 6 |
7 #include "cc/layers/painted_scrollbar_layer_impl.h" | 7 #include "cc/layers/painted_scrollbar_layer_impl.h" |
| 8 #include "cc/layers/solid_color_scrollbar_layer_impl.h" |
8 #include "cc/output/filter_operation.h" | 9 #include "cc/output/filter_operation.h" |
9 #include "cc/output/filter_operations.h" | 10 #include "cc/output/filter_operations.h" |
10 #include "cc/test/fake_impl_proxy.h" | 11 #include "cc/test/fake_impl_proxy.h" |
11 #include "cc/test/fake_layer_tree_host_impl.h" | 12 #include "cc/test/fake_layer_tree_host_impl.h" |
12 #include "cc/test/fake_output_surface.h" | 13 #include "cc/test/fake_output_surface.h" |
13 #include "cc/test/geometry_test_utils.h" | 14 #include "cc/test/geometry_test_utils.h" |
14 #include "cc/test/test_shared_bitmap_manager.h" | 15 #include "cc/test/test_shared_bitmap_manager.h" |
15 #include "cc/trees/layer_tree_impl.h" | 16 #include "cc/trees/layer_tree_impl.h" |
16 #include "cc/trees/single_thread_proxy.h" | 17 #include "cc/trees/single_thread_proxy.h" |
| 18 #include "cc/trees/tree_synchronizer.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 21 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
20 | 22 |
21 namespace cc { | 23 namespace cc { |
22 namespace { | 24 namespace { |
23 | 25 |
24 #define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(code_to_test) \ | 26 #define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(code_to_test) \ |
25 root->ResetAllChangeTrackingForSubtree(); \ | 27 root->ResetAllChangeTrackingForSubtree(); \ |
26 code_to_test; \ | 28 code_to_test; \ |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 PaintedScrollbarLayerImpl::Create(tree(), 101, HORIZONTAL)); | 731 PaintedScrollbarLayerImpl::Create(tree(), 101, HORIZONTAL)); |
730 horizontal_scrollbar->SetScrollLayerAndClipLayerByIds( | 732 horizontal_scrollbar->SetScrollLayerAndClipLayerByIds( |
731 layer()->id(), tree()->root_layer()->id()); | 733 layer()->id(), tree()->root_layer()->id()); |
732 | 734 |
733 int expected_horizontal_maximum = | 735 int expected_horizontal_maximum = |
734 layer()->bounds().width() - tree()->root_layer()->bounds().width(); | 736 layer()->bounds().width() - tree()->root_layer()->bounds().width(); |
735 EXPECT_EQ(expected_horizontal_maximum, horizontal_scrollbar->maximum()); | 737 EXPECT_EQ(expected_horizontal_maximum, horizontal_scrollbar->maximum()); |
736 EXPECT_EQ(scroll_offset.x(), horizontal_scrollbar->current_pos()); | 738 EXPECT_EQ(scroll_offset.x(), horizontal_scrollbar->current_pos()); |
737 } | 739 } |
738 | 740 |
| 741 class LayerImplScrollbarSyncTest : public testing::Test { |
| 742 public: |
| 743 enum { |
| 744 ROOT = 1, |
| 745 IV_CLIP = 2, |
| 746 PAGE = 3, |
| 747 IV_SCROLL = 4, |
| 748 SCROLLBAR = 5, |
| 749 OLD_ROOT = 6, |
| 750 OV_CLIP = 7, |
| 751 OV_SCROLL = 8, |
| 752 }; |
| 753 enum TreeID { |
| 754 PENDING, |
| 755 ACTIVE |
| 756 }; |
| 757 |
| 758 LayerImplScrollbarSyncTest() |
| 759 : host_impl_(settings(), &proxy_, &shared_bitmap_manager_) { |
| 760 host_impl_.CreatePendingTree(); |
| 761 |
| 762 CreateLayers(host_impl_.pending_tree()); |
| 763 CreateLayers(host_impl_.active_tree()); |
| 764 } |
| 765 |
| 766 void CreateLayers(LayerTreeImpl * tree) { |
| 767 tree->SetRootLayer(LayerImpl::Create(tree, ROOT)); |
| 768 LayerImpl * root = tree->root_layer(); |
| 769 ASSERT_TRUE(root != nullptr); |
| 770 |
| 771 int hierarchy[] = {IV_CLIP, PAGE, IV_SCROLL, OLD_ROOT, OV_CLIP, OV_SCROLL}; |
| 772 LayerImpl * parent = root; |
| 773 for (int child_id : hierarchy) { |
| 774 parent->AddChild(LayerImpl::Create(tree, child_id)); |
| 775 parent = tree->LayerById(child_id); |
| 776 ASSERT_TRUE(parent != nullptr); |
| 777 } |
| 778 |
| 779 root->AddChild( |
| 780 SolidColorScrollbarLayerImpl::Create(tree, SCROLLBAR, HORIZONTAL, |
| 781 5, 5, false, true)); |
| 782 } |
| 783 |
| 784 LayerImpl* layer(int id, TreeID tree_id) { |
| 785 LayerTreeImpl* tree = |
| 786 ((tree_id == PENDING) ? |
| 787 host_impl_.pending_tree() : host_impl_.active_tree()); |
| 788 |
| 789 assert(tree); |
| 790 return tree->LayerById(id); |
| 791 } |
| 792 |
| 793 bool LayerHasScrollbar(int id, TreeID tree_id) { |
| 794 return layer(id, tree_id)->HasScrollbar(HORIZONTAL); |
| 795 } |
| 796 |
| 797 ScrollbarLayerImplBase* pending_scrollbar() { |
| 798 LayerImpl* layer_impl = layer(SCROLLBAR, PENDING); |
| 799 assert(layer_impl); |
| 800 return layer_impl->ToScrollbarLayer(); |
| 801 } |
| 802 |
| 803 LayerImpl* pending_root() { |
| 804 LayerImpl * result = layer(ROOT, PENDING); |
| 805 assert(result); |
| 806 return result; |
| 807 } |
| 808 |
| 809 LayerImpl* active_root() { |
| 810 LayerImpl * result = layer(ROOT, ACTIVE); |
| 811 assert(result); |
| 812 return result; |
| 813 } |
| 814 |
| 815 LayerTreeSettings settings() { |
| 816 LayerTreeSettings settings; |
| 817 settings.use_pinch_virtual_viewport = true; |
| 818 return settings; |
| 819 } |
| 820 |
| 821 private: |
| 822 FakeImplProxy proxy_; |
| 823 TestSharedBitmapManager shared_bitmap_manager_; |
| 824 FakeLayerTreeHostImpl host_impl_; |
| 825 }; |
| 826 |
| 827 TEST_F(LayerImplScrollbarSyncTest, LayerImplBecomesScrollable) { |
| 828 // In the beginning IV_SCROLL layer is not scrollable. |
| 829 ASSERT_FALSE(layer(IV_SCROLL, PENDING)->scrollable()); |
| 830 |
| 831 // For pinch virtual viewport the clip layer is the inner viewport |
| 832 // clip layer (IV_CLIP) and the scroll one is the outer viewport |
| 833 // scroll layer (OV_SCROLL). |
| 834 pending_scrollbar()->SetScrollLayerAndClipLayerByIds(OV_SCROLL, IV_CLIP); |
| 835 |
| 836 ASSERT_TRUE(LayerHasScrollbar(OV_SCROLL, PENDING)); |
| 837 ASSERT_TRUE(LayerHasScrollbar(IV_CLIP, PENDING)); |
| 838 |
| 839 // Synchronize with the active tree. |
| 840 TreeSynchronizer::PushProperties(pending_root(), active_root()); |
| 841 |
| 842 ASSERT_TRUE(LayerHasScrollbar(OV_SCROLL, ACTIVE)); |
| 843 ASSERT_TRUE(LayerHasScrollbar(IV_CLIP, ACTIVE)); |
| 844 |
| 845 // Make IV_SCROLL layer scrollable. |
| 846 layer(IV_SCROLL, PENDING)->SetScrollClipLayer(IV_CLIP); |
| 847 layer(IV_SCROLL, PENDING)->SetNeedsPushProperties(); |
| 848 ASSERT_TRUE(layer(IV_SCROLL, PENDING)->scrollable()); |
| 849 |
| 850 pending_scrollbar()->SetScrollLayerAndClipLayerByIds(OV_SCROLL, IV_CLIP); |
| 851 |
| 852 // Now IV_CLIP layer should also receive the scrollbar. |
| 853 ASSERT_TRUE(LayerHasScrollbar(OV_SCROLL, PENDING)); |
| 854 ASSERT_TRUE(LayerHasScrollbar(IV_CLIP, PENDING)); |
| 855 ASSERT_TRUE(LayerHasScrollbar(IV_SCROLL, PENDING)); |
| 856 |
| 857 // Synchronize with the active tree. |
| 858 TreeSynchronizer::PushProperties(pending_root(), active_root()); |
| 859 |
| 860 ASSERT_TRUE(layer(IV_SCROLL, ACTIVE)->scrollable()); |
| 861 |
| 862 ASSERT_TRUE(LayerHasScrollbar(OV_SCROLL, ACTIVE)); |
| 863 ASSERT_TRUE(LayerHasScrollbar(IV_CLIP, ACTIVE)); |
| 864 ASSERT_TRUE(LayerHasScrollbar(IV_SCROLL, ACTIVE)); |
| 865 } |
| 866 |
739 } // namespace | 867 } // namespace |
740 } // namespace cc | 868 } // namespace cc |
OLD | NEW |