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

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 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
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | content/renderer/input/input_handler_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 child = child_layer.get(); 802 child = child_layer.get();
803 child_layer->SetDrawsContent(true); 803 child_layer->SetDrawsContent(true);
804 child_layer->SetPosition(gfx::PointF(0, 20)); 804 child_layer->SetPosition(gfx::PointF(0, 20));
805 child_layer->SetBounds(gfx::Size(50, 50)); 805 child_layer->SetBounds(gfx::Size(50, 50));
806 scroll->test_properties()->AddChild(std::move(child_layer)); 806 scroll->test_properties()->AddChild(std::move(child_layer));
807 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 807 host_impl_->active_tree()->BuildPropertyTreesForTesting();
808 } 808 }
809 809
810 // Touch handler regions determine whether touch events block scroll. 810 // Touch handler regions determine whether touch events block scroll.
811 root->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); 811 root->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
812 EXPECT_TRUE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 10))); 812 EXPECT_EQ(InputHandler::TouchStartEventListenerType::HANDLER,
813 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 10)));
813 814
814 // But they don't influence the actual handling of the scroll gestures. 815 // But they don't influence the actual handling of the scroll gestures.
815 InputHandler::ScrollStatus status = host_impl_->ScrollBegin( 816 InputHandler::ScrollStatus status = host_impl_->ScrollBegin(
816 BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN); 817 BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN);
817 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); 818 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread);
818 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, 819 EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain,
819 status.main_thread_scrolling_reasons); 820 status.main_thread_scrolling_reasons);
820 host_impl_->ScrollEnd(EndState().get()); 821 host_impl_->ScrollEnd(EndState().get());
821 822
822 EXPECT_TRUE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); 823 EXPECT_EQ(InputHandler::TouchStartEventListenerType::HANDLER,
824 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 30)));
823 root->SetTouchEventHandlerRegion(gfx::Rect()); 825 root->SetTouchEventHandlerRegion(gfx::Rect());
824 EXPECT_FALSE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); 826 EXPECT_EQ(InputHandler::TouchStartEventListenerType::NO_HANDLER,
827 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 30)));
825 child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50)); 828 child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50));
826 EXPECT_TRUE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); 829 EXPECT_EQ(InputHandler::TouchStartEventListenerType::HANDLER,
830 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 30)));
827 } 831 }
828 832
829 TEST_F(LayerTreeHostImplTest, FlingOnlyWhenScrollingTouchscreen) { 833 TEST_F(LayerTreeHostImplTest, FlingOnlyWhenScrollingTouchscreen) {
830 SetupScrollAndContentsLayers(gfx::Size(100, 100)); 834 SetupScrollAndContentsLayers(gfx::Size(100, 100));
831 host_impl_->SetViewportSize(gfx::Size(50, 50)); 835 host_impl_->SetViewportSize(gfx::Size(50, 50));
832 DrawFrame(); 836 DrawFrame();
833 837
834 // Ignore the fling since no layer is being scrolled 838 // Ignore the fling since no layer is being scrolled
835 InputHandler::ScrollStatus status = host_impl_->FlingScrollBegin(); 839 InputHandler::ScrollStatus status = host_impl_->FlingScrollBegin();
836 EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); 840 EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread);
(...skipping 9133 matching lines...) Expand 10 before | Expand all | Expand 10 after
9970 last_on_draw_frame_.reset(); 9974 last_on_draw_frame_.reset();
9971 9975
9972 // Different draw params does swap. 9976 // Different draw params does swap.
9973 did_request_redraw_ = false; 9977 did_request_redraw_ = false;
9974 host_impl_->OnDraw(draw_transform, draw_viewport2, 9978 host_impl_->OnDraw(draw_transform, draw_viewport2,
9975 resourceless_software_draw); 9979 resourceless_software_draw);
9976 EXPECT_TRUE(did_request_redraw_); 9980 EXPECT_TRUE(did_request_redraw_);
9977 EXPECT_FALSE(last_on_draw_frame_->has_no_damage); 9981 EXPECT_FALSE(last_on_draw_frame_->has_no_damage);
9978 } 9982 }
9979 9983
9984 // We will force the touch event handler to be passive if we touch on a
9985 // layer which is the current scrolling layer or its descendant.
9986 TEST_F(LayerTreeHostImplTest, TouchInsideOrOutsideFlingLayer) {
9987 gfx::Size surface_size(100, 100);
9988 gfx::Size inner_size(50, 50);
9989
9990 LayerImpl* root =
9991 CreateBasicVirtualViewportLayers(surface_size, surface_size);
9992 root->test_properties()->force_render_surface = true;
9993
9994 std::unique_ptr<LayerImpl> child =
9995 CreateScrollableLayer(26, surface_size, root);
9996 LayerImpl* child_layer = child.get();
9997
9998 std::unique_ptr<LayerImpl> grand_child =
9999 CreateScrollableLayer(27, inner_size, root);
10000 LayerImpl* grand_child_layer = grand_child.get();
10001 child->test_properties()->AddChild(std::move(grand_child));
10002 root->test_properties()->AddChild(std::move(child));
10003
10004 host_impl_->active_tree()->BuildPropertyTreesForTesting();
10005 host_impl_->active_tree()->DidBecomeActive();
10006 DrawFrame();
10007
10008 {
10009 // Touch on a layer which does not have a handler will return kNone.
10010 EXPECT_EQ(InputHandler::TouchStartEventListenerType::NO_HANDLER,
10011 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 10)));
10012 child_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
10013 grand_child_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
10014 EXPECT_EQ(InputHandler::TouchStartEventListenerType::HANDLER,
10015 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 10)));
10016 // Flinging the child layer.
10017 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
10018 host_impl_
10019 ->ScrollBegin(BeginState(gfx::Point(60, 60)).get(),
10020 InputHandler::TOUCHSCREEN)
10021 .thread);
10022 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
10023 host_impl_->FlingScrollBegin().thread);
10024 EXPECT_EQ(child_layer, host_impl_->CurrentlyScrollingLayer());
10025 // Touch on the child layer, which is an active fling layer, the touch
10026 // event handler will force to be passive.
10027 EXPECT_EQ(
10028 InputHandler::TouchStartEventListenerType::HANDLER_ON_SCROLLING_LAYER,
10029 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(70, 80)));
10030 // Touch on the grand child layer, which is a descendant of an active fling
10031 // layer, the touch event handler will force to be passive.
10032 EXPECT_EQ(
10033 InputHandler::TouchStartEventListenerType::HANDLER_ON_SCROLLING_LAYER,
10034 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(20, 30)));
10035
10036 // Now flinging on the grand child layer.
10037 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
10038 host_impl_
10039 ->ScrollBegin(BeginState(gfx::Point(10, 10)).get(),
10040 InputHandler::TOUCHSCREEN)
10041 .thread);
10042 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
10043 host_impl_->FlingScrollBegin().thread);
10044 EXPECT_EQ(grand_child_layer, host_impl_->CurrentlyScrollingLayer());
10045 // Touch on the child layer, the touch event handler will still be blocking.
10046 EXPECT_EQ(InputHandler::TouchStartEventListenerType::HANDLER,
10047 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(60, 60)));
10048 }
10049 }
10050
9980 class ResourcelessSoftwareLayerTreeHostImplTest : public LayerTreeHostImplTest { 10051 class ResourcelessSoftwareLayerTreeHostImplTest : public LayerTreeHostImplTest {
9981 protected: 10052 protected:
9982 std::unique_ptr<CompositorFrameSink> CreateCompositorFrameSink() override { 10053 std::unique_ptr<CompositorFrameSink> CreateCompositorFrameSink() override {
9983 return FakeCompositorFrameSink::Create3d(); 10054 return FakeCompositorFrameSink::Create3d();
9984 } 10055 }
9985 }; 10056 };
9986 10057
9987 TEST_F(ResourcelessSoftwareLayerTreeHostImplTest, 10058 TEST_F(ResourcelessSoftwareLayerTreeHostImplTest,
9988 ResourcelessSoftwareSetNeedsRedraw) { 10059 ResourcelessSoftwareSetNeedsRedraw) {
9989 SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); 10060 SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1));
(...skipping 1679 matching lines...) Expand 10 before | Expand all | Expand 10 after
11669 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); 11740 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar());
11670 host_impl_->MouseMoveAt(gfx::Point(10, 150)); 11741 host_impl_->MouseMoveAt(gfx::Point(10, 150));
11671 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); 11742 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar());
11672 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); 11743 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_over_scrollbar());
11673 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_near_scrollbar()); 11744 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_near_scrollbar());
11674 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); 11745 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar());
11675 } 11746 }
11676 11747
11677 } // namespace 11748 } // namespace
11678 } // namespace cc 11749 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | content/renderer/input/input_handler_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698