Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(830)

Side by Side Diff: cc/trees/layer_tree_host_impl_unittest.cc

Issue 2471523002: Make touch events uncancelable during fling when they are on the current active scroll layer (Closed)
Patch Set: rename both functions Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 9085 matching lines...) Expand 10 before | Expand all | Expand 10 after
9921 last_on_draw_frame_.reset(); 9925 last_on_draw_frame_.reset();
9922 9926
9923 // Different draw params does swap. 9927 // Different draw params does swap.
9924 did_request_redraw_ = false; 9928 did_request_redraw_ = false;
9925 host_impl_->OnDraw(draw_transform, draw_viewport2, 9929 host_impl_->OnDraw(draw_transform, draw_viewport2,
9926 resourceless_software_draw); 9930 resourceless_software_draw);
9927 EXPECT_TRUE(did_request_redraw_); 9931 EXPECT_TRUE(did_request_redraw_);
9928 EXPECT_FALSE(last_on_draw_frame_->has_no_damage); 9932 EXPECT_FALSE(last_on_draw_frame_->has_no_damage);
9929 } 9933 }
9930 9934
9935 TEST_F(LayerTreeHostImplTest, TouchInsideOrOutsideFlingLayer) {
9936 gfx::Size surface_size(100, 100);
9937 gfx::Size inner_size(50, 50);
bokan 2016/11/15 22:42:40 Please use CreateBasicVirtualViewportLayers to ini
lanwei 2016/11/16 21:13:28 Done.
9938 std::unique_ptr<LayerImpl> root =
9939 LayerImpl::Create(host_impl_->active_tree(), 1);
9940 root->test_properties()->force_render_surface = true;
9941
9942 std::unique_ptr<LayerImpl> root_scrolling_layer =
9943 CreateScrollableLayer(2, surface_size, root.get());
9944 auto* root_scrolling = root_scrolling_layer.get();
9945 root->test_properties()->AddChild(std::move(root_scrolling_layer));
9946
9947 std::unique_ptr<LayerImpl> child_layer =
9948 CreateScrollableLayer(3, surface_size, root.get());
9949 auto* child = child_layer.get();
9950 root_scrolling->test_properties()->AddChild(std::move(child_layer));
9951
9952 std::unique_ptr<LayerImpl> grand_child_layer =
9953 CreateScrollableLayer(4, inner_size, root.get());
9954 child->test_properties()->AddChild(std::move(grand_child_layer));
9955
9956 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root));
9957 host_impl_->active_tree()->BuildPropertyTreesForTesting();
9958 host_impl_->active_tree()->DidBecomeActive();
9959
9960 host_impl_->SetViewportSize(surface_size);
9961 DrawFrame();
9962 {
9963 std::unique_ptr<ScrollAndScaleSet> scroll_info;
9964 LayerImpl* child = host_impl_->active_tree()
bokan 2016/11/15 22:42:40 We've already saved the child and grand_child poin
lanwei 2016/11/16 21:13:28 Done.
9965 ->root_layer_for_testing()
9966 ->test_properties()
9967 ->children[0]
9968 ->test_properties()
9969 ->children[0];
9970 LayerImpl* grand_child = child->test_properties()->children[0];
9971 child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
9972 grand_child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
9973 EXPECT_EQ(host_impl_->DoTouchHandlersBlockScrollAt(gfx::Point(10, 10)),
9974 EventListenerProperties::kBlocking);
9975 // Flinging the child layer.
9976 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9977 host_impl_
9978 ->ScrollBegin(BeginState(gfx::Point(60, 60)).get(),
9979 InputHandler::TOUCHSCREEN)
9980 .thread);
9981 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9982 host_impl_->FlingScrollBegin().thread);
9983 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child);
9984 // Touch on the child layer, which is an active fling layer, the touch
9985 // event handler will force to be passive.
9986 EXPECT_EQ(host_impl_->DoTouchHandlersBlockScrollAt(gfx::Point(70, 80)),
9987 EventListenerProperties::kBlockingAndPassiveDueToFling);
9988 // Touch on the grand child layer, which is a descendant of an active fling
9989 // layer, the touch event handler will force to be passive.
9990 EXPECT_EQ(host_impl_->DoTouchHandlersBlockScrollAt(gfx::Point(20, 30)),
9991 EventListenerProperties::kBlockingAndPassiveDueToFling);
9992
9993 // Now flinging on the grand child layer.
9994 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9995 host_impl_
9996 ->ScrollBegin(BeginState(gfx::Point(10, 10)).get(),
9997 InputHandler::TOUCHSCREEN)
9998 .thread);
9999 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
10000 host_impl_->FlingScrollBegin().thread);
10001 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child);
10002 // Touch on the child layer, the touch event handler will still be blocking.
10003 EXPECT_EQ(host_impl_->DoTouchHandlersBlockScrollAt(gfx::Point(60, 60)),
10004 EventListenerProperties::kBlocking);
10005 }
10006 }
10007
9931 class ResourcelessSoftwareLayerTreeHostImplTest : public LayerTreeHostImplTest { 10008 class ResourcelessSoftwareLayerTreeHostImplTest : public LayerTreeHostImplTest {
9932 protected: 10009 protected:
9933 std::unique_ptr<CompositorFrameSink> CreateCompositorFrameSink() override { 10010 std::unique_ptr<CompositorFrameSink> CreateCompositorFrameSink() override {
9934 return FakeCompositorFrameSink::Create3d(); 10011 return FakeCompositorFrameSink::Create3d();
9935 } 10012 }
9936 }; 10013 };
9937 10014
9938 TEST_F(ResourcelessSoftwareLayerTreeHostImplTest, 10015 TEST_F(ResourcelessSoftwareLayerTreeHostImplTest,
9939 ResourcelessSoftwareSetNeedsRedraw) { 10016 ResourcelessSoftwareSetNeedsRedraw) {
9940 SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); 10017 SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1));
(...skipping 1679 matching lines...) Expand 10 before | Expand all | Expand 10 after
11620 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); 11697 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar());
11621 host_impl_->MouseMoveAt(gfx::Point(10, 150)); 11698 host_impl_->MouseMoveAt(gfx::Point(10, 150));
11622 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); 11699 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar());
11623 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); 11700 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_over_scrollbar());
11624 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_near_scrollbar()); 11701 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_near_scrollbar());
11625 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); 11702 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar());
11626 } 11703 }
11627 11704
11628 } // namespace 11705 } // namespace
11629 } // namespace cc 11706 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698