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 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 child = child_layer.get(); | 801 child = child_layer.get(); |
802 child_layer->SetDrawsContent(true); | 802 child_layer->SetDrawsContent(true); |
803 child_layer->SetPosition(gfx::PointF(0, 20)); | 803 child_layer->SetPosition(gfx::PointF(0, 20)); |
804 child_layer->SetBounds(gfx::Size(50, 50)); | 804 child_layer->SetBounds(gfx::Size(50, 50)); |
805 scroll->test_properties()->AddChild(std::move(child_layer)); | 805 scroll->test_properties()->AddChild(std::move(child_layer)); |
806 host_impl_->active_tree()->BuildPropertyTreesForTesting(); | 806 host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
807 } | 807 } |
808 | 808 |
809 // Touch handler regions determine whether touch events block scroll. | 809 // Touch handler regions determine whether touch events block scroll. |
810 root->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); | 810 root->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); |
811 EXPECT_TRUE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 10))); | 811 EXPECT_EQ(host_impl_->DoTouchHandlersBlockScrollAt(gfx::Point(10, 10)), |
| 812 EventListenerProperties::kBlocking); |
812 | 813 |
813 // But they don't influence the actual handling of the scroll gestures. | 814 // But they don't influence the actual handling of the scroll gestures. |
814 InputHandler::ScrollStatus status = host_impl_->ScrollBegin( | 815 InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
815 BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN); | 816 BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN); |
816 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); | 817 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
817 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, | 818 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
818 status.main_thread_scrolling_reasons); | 819 status.main_thread_scrolling_reasons); |
819 host_impl_->ScrollEnd(EndState().get()); | 820 host_impl_->ScrollEnd(EndState().get()); |
820 | 821 |
821 EXPECT_TRUE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); | 822 EXPECT_EQ(host_impl_->DoTouchHandlersBlockScrollAt(gfx::Point(10, 30)), |
| 823 EventListenerProperties::kBlocking); |
822 root->SetTouchEventHandlerRegion(gfx::Rect()); | 824 root->SetTouchEventHandlerRegion(gfx::Rect()); |
823 EXPECT_FALSE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); | 825 EXPECT_EQ(host_impl_->DoTouchHandlersBlockScrollAt(gfx::Point(10, 30)), |
| 826 EventListenerProperties::kNone); |
824 child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50)); | 827 child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50)); |
825 EXPECT_TRUE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); | 828 EXPECT_EQ(host_impl_->DoTouchHandlersBlockScrollAt(gfx::Point(10, 30)), |
| 829 EventListenerProperties::kBlocking); |
826 } | 830 } |
827 | 831 |
828 TEST_F(LayerTreeHostImplTest, FlingOnlyWhenScrollingTouchscreen) { | 832 TEST_F(LayerTreeHostImplTest, FlingOnlyWhenScrollingTouchscreen) { |
829 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 833 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
830 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 834 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
831 DrawFrame(); | 835 DrawFrame(); |
832 | 836 |
833 // Ignore the fling since no layer is being scrolled | 837 // Ignore the fling since no layer is being scrolled |
834 InputHandler::ScrollStatus status = host_impl_->FlingScrollBegin(); | 838 InputHandler::ScrollStatus status = host_impl_->FlingScrollBegin(); |
835 EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); | 839 EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); |
(...skipping 9095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9931 last_on_draw_frame_.reset(); | 9935 last_on_draw_frame_.reset(); |
9932 | 9936 |
9933 // Different draw params does swap. | 9937 // Different draw params does swap. |
9934 did_request_redraw_ = false; | 9938 did_request_redraw_ = false; |
9935 host_impl_->OnDraw(draw_transform, draw_viewport2, | 9939 host_impl_->OnDraw(draw_transform, draw_viewport2, |
9936 resourceless_software_draw); | 9940 resourceless_software_draw); |
9937 EXPECT_TRUE(did_request_redraw_); | 9941 EXPECT_TRUE(did_request_redraw_); |
9938 EXPECT_FALSE(last_on_draw_frame_->has_no_damage); | 9942 EXPECT_FALSE(last_on_draw_frame_->has_no_damage); |
9939 } | 9943 } |
9940 | 9944 |
| 9945 TEST_F(LayerTreeHostImplTest, TouchInsideOrOutsideFlingLayer) { |
| 9946 gfx::Size surface_size(100, 100); |
| 9947 gfx::Size inner_size(50, 50); |
| 9948 std::unique_ptr<LayerImpl> root = |
| 9949 LayerImpl::Create(host_impl_->active_tree(), 1); |
| 9950 root->test_properties()->force_render_surface = true; |
| 9951 |
| 9952 std::unique_ptr<LayerImpl> root_scrolling_layer = |
| 9953 CreateScrollableLayer(2, surface_size, root.get()); |
| 9954 auto* root_scrolling = root_scrolling_layer.get(); |
| 9955 root->test_properties()->AddChild(std::move(root_scrolling_layer)); |
| 9956 |
| 9957 std::unique_ptr<LayerImpl> child_layer = |
| 9958 CreateScrollableLayer(3, surface_size, root.get()); |
| 9959 auto* child = child_layer.get(); |
| 9960 root_scrolling->test_properties()->AddChild(std::move(child_layer)); |
| 9961 |
| 9962 std::unique_ptr<LayerImpl> grand_child_layer = |
| 9963 CreateScrollableLayer(4, inner_size, root.get()); |
| 9964 child->test_properties()->AddChild(std::move(grand_child_layer)); |
| 9965 |
| 9966 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
| 9967 host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 9968 host_impl_->active_tree()->DidBecomeActive(); |
| 9969 |
| 9970 host_impl_->SetViewportSize(surface_size); |
| 9971 DrawFrame(); |
| 9972 { |
| 9973 std::unique_ptr<ScrollAndScaleSet> scroll_info; |
| 9974 LayerImpl* child = host_impl_->active_tree() |
| 9975 ->root_layer_for_testing() |
| 9976 ->test_properties() |
| 9977 ->children[0] |
| 9978 ->test_properties() |
| 9979 ->children[0]; |
| 9980 LayerImpl* grand_child = child->test_properties()->children[0]; |
| 9981 child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); |
| 9982 grand_child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); |
| 9983 EXPECT_EQ(host_impl_->DoTouchHandlersBlockScrollAt(gfx::Point(10, 10)), |
| 9984 EventListenerProperties::kBlocking); |
| 9985 // Flinging the child layer. |
| 9986 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 9987 host_impl_ |
| 9988 ->ScrollBegin(BeginState(gfx::Point(60, 60)).get(), |
| 9989 InputHandler::TOUCHSCREEN) |
| 9990 .thread); |
| 9991 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 9992 host_impl_->FlingScrollBegin().thread); |
| 9993 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child); |
| 9994 // Touch on the child layer, which is an active fling layer, the touch |
| 9995 // event handler will force to be passive. |
| 9996 EXPECT_EQ(host_impl_->DoTouchHandlersBlockScrollAt(gfx::Point(70, 80)), |
| 9997 EventListenerProperties::kBlockingAndPassiveDueToFling); |
| 9998 // Touch on the grand child layer, which is a descendant of an active fling |
| 9999 // layer, the touch event handler will force to be passive. |
| 10000 EXPECT_EQ(host_impl_->DoTouchHandlersBlockScrollAt(gfx::Point(20, 30)), |
| 10001 EventListenerProperties::kBlockingAndPassiveDueToFling); |
| 10002 |
| 10003 // Now flinging on the grand child layer. |
| 10004 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10005 host_impl_ |
| 10006 ->ScrollBegin(BeginState(gfx::Point(10, 10)).get(), |
| 10007 InputHandler::TOUCHSCREEN) |
| 10008 .thread); |
| 10009 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10010 host_impl_->FlingScrollBegin().thread); |
| 10011 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
| 10012 // Touch on the child layer, the touch event handler will still be blocking. |
| 10013 EXPECT_EQ(host_impl_->DoTouchHandlersBlockScrollAt(gfx::Point(60, 60)), |
| 10014 EventListenerProperties::kBlocking); |
| 10015 } |
| 10016 } |
| 10017 |
9941 class ResourcelessSoftwareLayerTreeHostImplTest : public LayerTreeHostImplTest { | 10018 class ResourcelessSoftwareLayerTreeHostImplTest : public LayerTreeHostImplTest { |
9942 protected: | 10019 protected: |
9943 std::unique_ptr<CompositorFrameSink> CreateCompositorFrameSink() override { | 10020 std::unique_ptr<CompositorFrameSink> CreateCompositorFrameSink() override { |
9944 return FakeCompositorFrameSink::Create3d(); | 10021 return FakeCompositorFrameSink::Create3d(); |
9945 } | 10022 } |
9946 }; | 10023 }; |
9947 | 10024 |
9948 TEST_F(ResourcelessSoftwareLayerTreeHostImplTest, | 10025 TEST_F(ResourcelessSoftwareLayerTreeHostImplTest, |
9949 ResourcelessSoftwareSetNeedsRedraw) { | 10026 ResourcelessSoftwareSetNeedsRedraw) { |
9950 SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); | 10027 SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); |
(...skipping 1679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11630 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); | 11707 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); |
11631 host_impl_->MouseMoveAt(gfx::Point(10, 150)); | 11708 host_impl_->MouseMoveAt(gfx::Point(10, 150)); |
11632 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); | 11709 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); |
11633 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); | 11710 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); |
11634 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_near_scrollbar()); | 11711 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_near_scrollbar()); |
11635 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); | 11712 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); |
11636 } | 11713 } |
11637 | 11714 |
11638 } // namespace | 11715 } // namespace |
11639 } // namespace cc | 11716 } // namespace cc |
OLD | NEW |