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

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: fling layer 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(EventListenerProperties::kBlocking,
812 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 10)));
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(EventListenerProperties::kBlocking,
823 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 30)));
822 root->SetTouchEventHandlerRegion(gfx::Rect()); 824 root->SetTouchEventHandlerRegion(gfx::Rect());
823 EXPECT_FALSE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); 825 EXPECT_EQ(EventListenerProperties::kNone,
826 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 30)));
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(EventListenerProperties::kBlocking,
829 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 30)));
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 // We will force the touch event handler to be passive, only if we touch on a
bokan 2016/11/18 18:41:36 Nit: "passive, only if we touch" -> "passive if we
lanwei 2016/11/23 21:57:38 Done.
9936 // layer which is the current scrolling layer or its descendant.
9937 TEST_F(LayerTreeHostImplTest, TouchInsideOrOutsideFlingLayer) {
9938 gfx::Size surface_size(100, 100);
9939 gfx::Size inner_size(50, 50);
9940
9941 LayerImpl* root =
9942 CreateBasicVirtualViewportLayers(surface_size, surface_size);
9943 root->test_properties()->force_render_surface = true;
9944
9945 std::unique_ptr<LayerImpl> child =
9946 CreateScrollableLayer(26, surface_size, root);
9947 LayerImpl* child_layer = child.get();
9948
9949 std::unique_ptr<LayerImpl> grand_child =
9950 CreateScrollableLayer(27, inner_size, root);
9951 LayerImpl* grand_child_layer = grand_child.get();
9952 child->test_properties()->AddChild(std::move(grand_child));
9953 root->test_properties()->AddChild(std::move(child));
9954
9955 host_impl_->active_tree()->BuildPropertyTreesForTesting();
9956 host_impl_->active_tree()->DidBecomeActive();
9957 DrawFrame();
9958
9959 {
9960 // Touch on a layer which does not have a handler will return kNone.
9961 EXPECT_EQ(EventListenerProperties::kNone,
9962 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 10)));
9963 child_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
9964 grand_child_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
9965 EXPECT_EQ(EventListenerProperties::kBlocking,
9966 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 10)));
9967 // Flinging the child layer.
9968 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9969 host_impl_
9970 ->ScrollBegin(BeginState(gfx::Point(60, 60)).get(),
9971 InputHandler::TOUCHSCREEN)
9972 .thread);
9973 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9974 host_impl_->FlingScrollBegin().thread);
9975 EXPECT_EQ(child_layer, host_impl_->CurrentlyScrollingLayer());
9976 // Touch on the child layer, which is an active fling layer, the touch
9977 // event handler will force to be passive.
9978 EXPECT_EQ(EventListenerProperties::kBlockingAndMaybePassiveDueToFling,
9979 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(70, 80)));
9980 // Touch on the grand child layer, which is a descendant of an active fling
9981 // layer, the touch event handler will force to be passive.
9982 EXPECT_EQ(EventListenerProperties::kBlockingAndMaybePassiveDueToFling,
9983 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(20, 30)));
9984
9985 // Now flinging on the grand child layer.
9986 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9987 host_impl_
9988 ->ScrollBegin(BeginState(gfx::Point(10, 10)).get(),
9989 InputHandler::TOUCHSCREEN)
9990 .thread);
9991 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9992 host_impl_->FlingScrollBegin().thread);
9993 EXPECT_EQ(grand_child_layer, host_impl_->CurrentlyScrollingLayer());
9994 // Touch on the child layer, the touch event handler will still be blocking.
9995 EXPECT_EQ(EventListenerProperties::kBlocking,
9996 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(60, 60)));
9997 }
9998 }
9999
9931 class ResourcelessSoftwareLayerTreeHostImplTest : public LayerTreeHostImplTest { 10000 class ResourcelessSoftwareLayerTreeHostImplTest : public LayerTreeHostImplTest {
9932 protected: 10001 protected:
9933 std::unique_ptr<CompositorFrameSink> CreateCompositorFrameSink() override { 10002 std::unique_ptr<CompositorFrameSink> CreateCompositorFrameSink() override {
9934 return FakeCompositorFrameSink::Create3d(); 10003 return FakeCompositorFrameSink::Create3d();
9935 } 10004 }
9936 }; 10005 };
9937 10006
9938 TEST_F(ResourcelessSoftwareLayerTreeHostImplTest, 10007 TEST_F(ResourcelessSoftwareLayerTreeHostImplTest,
9939 ResourcelessSoftwareSetNeedsRedraw) { 10008 ResourcelessSoftwareSetNeedsRedraw) {
9940 SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); 10009 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()); 11689 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar());
11621 host_impl_->MouseMoveAt(gfx::Point(10, 150)); 11690 host_impl_->MouseMoveAt(gfx::Point(10, 150));
11622 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); 11691 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar());
11623 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); 11692 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_over_scrollbar());
11624 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_near_scrollbar()); 11693 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_near_scrollbar());
11625 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); 11694 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar());
11626 } 11695 }
11627 11696
11628 } // namespace 11697 } // namespace
11629 } // namespace cc 11698 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698