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/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 | 712 |
713 TEST_F(LayerTreeHostImplTest, ScrollBlocksOnWheelEventHandlers) { | 713 TEST_F(LayerTreeHostImplTest, ScrollBlocksOnWheelEventHandlers) { |
714 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 714 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
715 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 715 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
716 DrawFrame(); | 716 DrawFrame(); |
717 LayerImpl* root = host_impl_->active_tree()->root_layer(); | 717 LayerImpl* root = host_impl_->active_tree()->root_layer(); |
718 | 718 |
719 // With registered event handlers, wheel scrolls don't necessarily | 719 // With registered event handlers, wheel scrolls don't necessarily |
720 // have to go to the main thread. | 720 // have to go to the main thread. |
721 root->SetHaveWheelEventHandlers(true); | 721 root->SetHaveWheelEventHandlers(true); |
722 InputHandler::ScrollStatus status = host_impl_->ScrollBegin( | 722 InputHandler::ScrollStatus status = |
723 BeginState(gfx::Point()).get(), InputHandler::WHEEL); | 723 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
724 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); | |
725 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, | |
726 status.main_thread_scrolling_reasons); | |
727 host_impl_->ScrollEnd(EndState().get()); | |
728 | |
729 // But typically the scroll-blocks-on mode will require them to. | |
730 root->SetScrollBlocksOn(SCROLL_BLOCKS_ON_WHEEL_EVENT | | |
731 SCROLL_BLOCKS_ON_START_TOUCH); | |
732 status = host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), | |
733 InputHandler::WHEEL); | 724 InputHandler::WHEEL); |
734 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); | 725 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); |
735 EXPECT_EQ(MainThreadScrollingReason::kEventHandlers, | 726 EXPECT_EQ(MainThreadScrollingReason::kEventHandlers, |
736 status.main_thread_scrolling_reasons); | 727 status.main_thread_scrolling_reasons); |
737 | 728 |
738 // But gesture scrolls can still be handled. | 729 // But gesture scrolls can still be handled. |
739 status = host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), | 730 status = host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
740 InputHandler::GESTURE); | 731 InputHandler::GESTURE); |
741 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); | 732 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
742 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, | 733 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
(...skipping 24 matching lines...) Expand all Loading... |
767 child = child_layer.get(); | 758 child = child_layer.get(); |
768 child_layer->SetDrawsContent(true); | 759 child_layer->SetDrawsContent(true); |
769 child_layer->SetPosition(gfx::PointF(0, 20)); | 760 child_layer->SetPosition(gfx::PointF(0, 20)); |
770 child_layer->SetBounds(gfx::Size(50, 50)); | 761 child_layer->SetBounds(gfx::Size(50, 50)); |
771 scroll->AddChild(std::move(child_layer)); | 762 scroll->AddChild(std::move(child_layer)); |
772 RebuildPropertyTrees(); | 763 RebuildPropertyTrees(); |
773 } | 764 } |
774 | 765 |
775 // Touch handler regions determine whether touch events block scroll. | 766 // Touch handler regions determine whether touch events block scroll. |
776 root->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); | 767 root->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); |
777 EXPECT_FALSE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 10))); | |
778 root->SetScrollBlocksOn(SCROLL_BLOCKS_ON_START_TOUCH | | |
779 SCROLL_BLOCKS_ON_WHEEL_EVENT); | |
780 EXPECT_TRUE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 10))); | 768 EXPECT_TRUE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 10))); |
781 | 769 |
782 // But they don't influence the actual handling of the scroll gestures. | 770 // But they don't influence the actual handling of the scroll gestures. |
783 InputHandler::ScrollStatus status = host_impl_->ScrollBegin( | 771 InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
784 BeginState(gfx::Point()).get(), InputHandler::GESTURE); | 772 BeginState(gfx::Point()).get(), InputHandler::GESTURE); |
785 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); | 773 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
786 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, | 774 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
787 status.main_thread_scrolling_reasons); | 775 status.main_thread_scrolling_reasons); |
788 host_impl_->ScrollEnd(EndState().get()); | 776 host_impl_->ScrollEnd(EndState().get()); |
789 | 777 |
790 // It's the union of scroll-blocks-on mode bits across all layers in the | |
791 // scroll paret chain that matters. | |
792 EXPECT_TRUE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); | 778 EXPECT_TRUE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); |
793 root->SetScrollBlocksOn(SCROLL_BLOCKS_ON_NONE); | 779 root->SetTouchEventHandlerRegion(gfx::Rect()); |
794 EXPECT_FALSE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); | 780 EXPECT_FALSE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); |
795 child->SetScrollBlocksOn(SCROLL_BLOCKS_ON_START_TOUCH); | 781 child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50)); |
796 EXPECT_TRUE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); | 782 EXPECT_TRUE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); |
797 } | 783 } |
798 | 784 |
799 TEST_F(LayerTreeHostImplTest, ScrollBlocksOnScrollEventHandlers) { | |
800 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | |
801 host_impl_->SetViewportSize(gfx::Size(50, 50)); | |
802 DrawFrame(); | |
803 LayerImpl* root = host_impl_->active_tree()->root_layer(); | |
804 | |
805 // With registered scroll handlers, scrolls don't generally have to go | |
806 // to the main thread. | |
807 root->SetHaveScrollEventHandlers(true); | |
808 InputHandler::ScrollStatus status = host_impl_->ScrollBegin( | |
809 BeginState(gfx::Point()).get(), InputHandler::WHEEL); | |
810 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); | |
811 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, | |
812 status.main_thread_scrolling_reasons); | |
813 | |
814 host_impl_->ScrollEnd(EndState().get()); | |
815 | |
816 // Even the default scroll blocks on mode doesn't require this. | |
817 root->SetScrollBlocksOn(SCROLL_BLOCKS_ON_WHEEL_EVENT | | |
818 SCROLL_BLOCKS_ON_START_TOUCH); | |
819 status = host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), | |
820 InputHandler::GESTURE); | |
821 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); | |
822 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, | |
823 status.main_thread_scrolling_reasons); | |
824 | |
825 host_impl_->ScrollEnd(EndState().get()); | |
826 | |
827 // But the page can opt in to blocking on scroll event handlers. | |
828 root->SetScrollBlocksOn(SCROLL_BLOCKS_ON_SCROLL_EVENT); | |
829 status = host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), | |
830 InputHandler::GESTURE); | |
831 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); | |
832 EXPECT_EQ(MainThreadScrollingReason::kEventHandlers, | |
833 status.main_thread_scrolling_reasons); | |
834 | |
835 // GESTURE and WHEEL scrolls behave identically in this regard. | |
836 status = host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), | |
837 InputHandler::WHEEL); | |
838 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); | |
839 EXPECT_EQ(MainThreadScrollingReason::kEventHandlers, | |
840 status.main_thread_scrolling_reasons); | |
841 | |
842 // And if the handlers go away, scrolls can again be processed on impl | |
843 // (despite the scroll-blocks-on mode). | |
844 root->SetHaveScrollEventHandlers(false); | |
845 status = host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), | |
846 InputHandler::GESTURE); | |
847 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); | |
848 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, | |
849 status.main_thread_scrolling_reasons); | |
850 | |
851 host_impl_->ScrollEnd(EndState().get()); | |
852 } | |
853 | |
854 TEST_F(LayerTreeHostImplTest, ScrollBlocksOnLayerTopology) { | |
855 host_impl_->SetViewportSize(gfx::Size(50, 50)); | |
856 | |
857 // Create a normal scrollable root layer | |
858 LayerImpl* root_scroll = SetupScrollAndContentsLayers(gfx::Size(100, 100)); | |
859 LayerImpl* root_child = root_scroll->children()[0].get(); | |
860 LayerImpl* root = host_impl_->active_tree()->root_layer(); | |
861 DrawFrame(); | |
862 | |
863 // Create two child scrollable layers | |
864 LayerImpl* child1 = 0; | |
865 { | |
866 scoped_ptr<LayerImpl> scrollable_child_clip_1 = | |
867 LayerImpl::Create(host_impl_->active_tree(), 6); | |
868 scoped_ptr<LayerImpl> scrollable_child_1 = CreateScrollableLayer( | |
869 7, gfx::Size(10, 10), scrollable_child_clip_1.get()); | |
870 child1 = scrollable_child_1.get(); | |
871 scrollable_child_1->SetPosition(gfx::PointF(5.f, 5.f)); | |
872 scrollable_child_1->SetHaveWheelEventHandlers(true); | |
873 scrollable_child_1->SetHaveScrollEventHandlers(true); | |
874 scrollable_child_clip_1->AddChild(std::move(scrollable_child_1)); | |
875 root_child->AddChild(std::move(scrollable_child_clip_1)); | |
876 RebuildPropertyTrees(); | |
877 } | |
878 | |
879 LayerImpl* child2 = 0; | |
880 { | |
881 scoped_ptr<LayerImpl> scrollable_child_clip_2 = | |
882 LayerImpl::Create(host_impl_->active_tree(), 8); | |
883 scoped_ptr<LayerImpl> scrollable_child_2 = CreateScrollableLayer( | |
884 9, gfx::Size(10, 10), scrollable_child_clip_2.get()); | |
885 child2 = scrollable_child_2.get(); | |
886 scrollable_child_2->SetPosition(gfx::PointF(5.f, 20.f)); | |
887 scrollable_child_2->SetHaveWheelEventHandlers(true); | |
888 scrollable_child_2->SetHaveScrollEventHandlers(true); | |
889 scrollable_child_clip_2->AddChild(std::move(scrollable_child_2)); | |
890 root_child->AddChild(std::move(scrollable_child_clip_2)); | |
891 RebuildPropertyTrees(); | |
892 } | |
893 | |
894 InputHandler::ScrollStatus status = host_impl_->ScrollBegin( | |
895 BeginState(gfx::Point(10, 10)).get(), InputHandler::GESTURE); | |
896 // Scroll-blocks-on on a layer affects scrolls that hit that layer. | |
897 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); | |
898 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, | |
899 status.main_thread_scrolling_reasons); | |
900 host_impl_->ScrollEnd(EndState().get()); | |
901 | |
902 child1->SetScrollBlocksOn(SCROLL_BLOCKS_ON_SCROLL_EVENT); | |
903 status = host_impl_->ScrollBegin(BeginState(gfx::Point(10, 10)).get(), | |
904 InputHandler::GESTURE); | |
905 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); | |
906 EXPECT_EQ(MainThreadScrollingReason::kEventHandlers, | |
907 status.main_thread_scrolling_reasons); | |
908 | |
909 // But not those that hit only other layers. | |
910 status = host_impl_->ScrollBegin(BeginState(gfx::Point(10, 25)).get(), | |
911 InputHandler::GESTURE); | |
912 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); | |
913 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, | |
914 status.main_thread_scrolling_reasons); | |
915 host_impl_->ScrollEnd(EndState().get()); | |
916 | |
917 // It's the union of bits set across the scroll ancestor chain that matters. | |
918 status = host_impl_->ScrollBegin(BeginState(gfx::Point(10, 25)).get(), | |
919 InputHandler::GESTURE); | |
920 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); | |
921 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, | |
922 status.main_thread_scrolling_reasons); | |
923 | |
924 host_impl_->ScrollEnd(EndState().get()); | |
925 status = host_impl_->ScrollBegin(BeginState(gfx::Point(10, 25)).get(), | |
926 InputHandler::WHEEL); | |
927 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); | |
928 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, | |
929 status.main_thread_scrolling_reasons); | |
930 | |
931 host_impl_->ScrollEnd(EndState().get()); | |
932 root->SetScrollBlocksOn(SCROLL_BLOCKS_ON_WHEEL_EVENT); | |
933 status = host_impl_->ScrollBegin(BeginState(gfx::Point(10, 25)).get(), | |
934 InputHandler::GESTURE); | |
935 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); | |
936 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, | |
937 status.main_thread_scrolling_reasons); | |
938 | |
939 host_impl_->ScrollEnd(EndState().get()); | |
940 status = host_impl_->ScrollBegin(BeginState(gfx::Point(10, 25)).get(), | |
941 InputHandler::WHEEL); | |
942 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); | |
943 EXPECT_EQ(MainThreadScrollingReason::kEventHandlers, | |
944 status.main_thread_scrolling_reasons); | |
945 | |
946 child2->SetScrollBlocksOn(SCROLL_BLOCKS_ON_SCROLL_EVENT); | |
947 status = host_impl_->ScrollBegin(BeginState(gfx::Point(10, 25)).get(), | |
948 InputHandler::WHEEL); | |
949 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); | |
950 EXPECT_EQ(MainThreadScrollingReason::kEventHandlers, | |
951 status.main_thread_scrolling_reasons); | |
952 | |
953 status = host_impl_->ScrollBegin(BeginState(gfx::Point(10, 25)).get(), | |
954 InputHandler::GESTURE); | |
955 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); | |
956 EXPECT_EQ(MainThreadScrollingReason::kEventHandlers, | |
957 status.main_thread_scrolling_reasons); | |
958 } | |
959 | |
960 TEST_F(LayerTreeHostImplTest, FlingOnlyWhenScrollingTouchscreen) { | 785 TEST_F(LayerTreeHostImplTest, FlingOnlyWhenScrollingTouchscreen) { |
961 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 786 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
962 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 787 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
963 DrawFrame(); | 788 DrawFrame(); |
964 | 789 |
965 // Ignore the fling since no layer is being scrolled | 790 // Ignore the fling since no layer is being scrolled |
966 InputHandler::ScrollStatus status = host_impl_->FlingScrollBegin(); | 791 InputHandler::ScrollStatus status = host_impl_->FlingScrollBegin(); |
967 EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); | 792 EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); |
968 EXPECT_EQ(MainThreadScrollingReason::kNoScrollingLayer, | 793 EXPECT_EQ(MainThreadScrollingReason::kNoScrollingLayer, |
969 status.main_thread_scrolling_reasons); | 794 status.main_thread_scrolling_reasons); |
(...skipping 9167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10137 // There should not be any jitter measured till we hit the fixed point hits | 9962 // There should not be any jitter measured till we hit the fixed point hits |
10138 // threshold. | 9963 // threshold. |
10139 float expected_jitter = | 9964 float expected_jitter = |
10140 (i == pending_tree->kFixedPointHitsThreshold) ? 500 : 0; | 9965 (i == pending_tree->kFixedPointHitsThreshold) ? 500 : 0; |
10141 EXPECT_EQ(jitter, expected_jitter); | 9966 EXPECT_EQ(jitter, expected_jitter); |
10142 } | 9967 } |
10143 } | 9968 } |
10144 | 9969 |
10145 } // namespace | 9970 } // namespace |
10146 } // namespace cc | 9971 } // namespace cc |
OLD | NEW |