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

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

Issue 2759523002: Make sure all the touch events during an active fling are uncancelable (Closed)
Patch Set: rebase master Created 3 years, 8 months 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') | no next file » | 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 10170 matching lines...) Expand 10 before | Expand all | Expand 10 after
10181 last_on_draw_frame_.reset(); 10181 last_on_draw_frame_.reset();
10182 10182
10183 // Different draw params does swap. 10183 // Different draw params does swap.
10184 did_request_redraw_ = false; 10184 did_request_redraw_ = false;
10185 host_impl_->OnDraw(draw_transform, draw_viewport2, 10185 host_impl_->OnDraw(draw_transform, draw_viewport2,
10186 resourceless_software_draw); 10186 resourceless_software_draw);
10187 EXPECT_TRUE(did_request_redraw_); 10187 EXPECT_TRUE(did_request_redraw_);
10188 EXPECT_FALSE(last_on_draw_frame_->has_no_damage); 10188 EXPECT_FALSE(last_on_draw_frame_->has_no_damage);
10189 } 10189 }
10190 10190
10191 // We will force the touch event handler to be passive if we touch on a 10191 // We will force the touch event handler to be passive if we touch on a layer
10192 // layer which is the current scrolling layer or its descendant. 10192 // which is the current scrolling layer.
10193 TEST_F(LayerTreeHostImplTest, TouchInsideOrOutsideFlingLayer) { 10193 TEST_F(LayerTreeHostImplTest, TouchInsideFlingLayer) {
10194 gfx::Size surface_size(100, 100); 10194 gfx::Size surface_size(100, 100);
10195 gfx::Size inner_size(50, 50); 10195 gfx::Size content_size(200, 200);
10196 10196
10197 LayerImpl* root = 10197 LayerImpl* root =
10198 CreateBasicVirtualViewportLayers(surface_size, surface_size); 10198 CreateBasicVirtualViewportLayers(surface_size, surface_size);
10199 root->test_properties()->force_render_surface = true; 10199 root->test_properties()->force_render_surface = true;
10200 10200
10201 // A div layer which has an event handler.
10201 std::unique_ptr<LayerImpl> child = 10202 std::unique_ptr<LayerImpl> child =
10202 CreateScrollableLayer(26, surface_size, root); 10203 CreateScrollableLayer(26, surface_size, root);
10203 LayerImpl* child_layer = child.get(); 10204 LayerImpl* child_layer = child.get();
10204 10205
10206 // The layer tree should create a layer for the div layer, which is the
10207 // actual scrolling layer.
10205 std::unique_ptr<LayerImpl> grand_child = 10208 std::unique_ptr<LayerImpl> grand_child =
10206 CreateScrollableLayer(27, inner_size, root); 10209 CreateScrollableLayer(27, content_size, root);
10207 LayerImpl* grand_child_layer = grand_child.get(); 10210 LayerImpl* grand_child_layer = grand_child.get();
10211
10208 child->test_properties()->AddChild(std::move(grand_child)); 10212 child->test_properties()->AddChild(std::move(grand_child));
10209 root->test_properties()->AddChild(std::move(child)); 10213 root->test_properties()->AddChild(std::move(child));
10210 10214
10215 host_impl_->SetViewportSize(surface_size);
10211 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 10216 host_impl_->active_tree()->BuildPropertyTreesForTesting();
10212 host_impl_->active_tree()->DidBecomeActive(); 10217 host_impl_->active_tree()->DidBecomeActive();
10213 DrawFrame(); 10218 DrawFrame();
10214 10219
10215 { 10220 {
10216 // Touch on a layer which does not have a handler will return kNone. 10221 // Touch on a layer which does not have a handler will return kNone.
10217 EXPECT_EQ(InputHandler::TouchStartEventListenerType::NO_HANDLER, 10222 EXPECT_EQ(InputHandler::TouchStartEventListenerType::NO_HANDLER,
10218 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 10))); 10223 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 10)));
10219 child_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); 10224 child_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
10220 grand_child_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
10221 EXPECT_EQ(InputHandler::TouchStartEventListenerType::HANDLER, 10225 EXPECT_EQ(InputHandler::TouchStartEventListenerType::HANDLER,
10222 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 10))); 10226 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 10)));
10223 // Flinging the child layer. 10227 // Flinging the grand_child layer.
10224 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 10228 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
10225 host_impl_ 10229 host_impl_
10226 ->ScrollBegin(BeginState(gfx::Point(60, 60)).get(), 10230 ->ScrollBegin(BeginState(gfx::Point(60, 60)).get(),
10231 InputHandler::TOUCHSCREEN)
10232 .thread);
10233 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
10234 host_impl_->FlingScrollBegin().thread);
10235 EXPECT_EQ(grand_child_layer->scroll_tree_index(),
10236 host_impl_->CurrentlyScrollingNode()->id);
10237 // Touch on the grand_child layer, which is an active fling layer, the touch
10238 // event handler will force to be passive.
10239 EXPECT_EQ(
10240 InputHandler::TouchStartEventListenerType::HANDLER_ON_SCROLLING_LAYER,
10241 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(70, 80)));
10242 }
10243 }
10244
10245 // We will force the touch event handler to be passive if we touch on a layer
10246 // which is a descendant of the current scrolling layer. If we touch on its
10247 // ancestor, then the touch event handler will still be blocked.
10248 TEST_F(LayerTreeHostImplTest, TouchInsideOrOutsideFlingLayer) {
10249 gfx::Size surface_size(100, 100);
10250 gfx::Size content_size(200, 200);
10251 gfx::Size inner_size(50, 50);
10252
10253 LayerImpl* root =
10254 CreateBasicVirtualViewportLayers(surface_size, surface_size);
10255 root->test_properties()->force_render_surface = true;
10256
10257 // A div layer which has an event handler.
10258 std::unique_ptr<LayerImpl> child =
10259 CreateScrollableLayer(26, surface_size, root);
10260 LayerImpl* child_layer = child.get();
10261
10262 // The layer tree should create a layer for the div layer, which is the
10263 // actual scrolling layer.
10264 std::unique_ptr<LayerImpl> grand_child =
10265 CreateScrollableLayer(27, content_size, root);
10266 LayerImpl* grand_child_layer = grand_child.get();
10267
10268 // A child scrollable layer inside grand_child_layer.
10269 std::unique_ptr<LayerImpl> great_grand_child =
10270 CreateScrollableLayer(28, inner_size, root);
10271 LayerImpl* great_grand_child_layer = great_grand_child.get();
10272
10273 grand_child->test_properties()->AddChild(std::move(great_grand_child));
10274 child->test_properties()->AddChild(std::move(grand_child));
10275 root->test_properties()->AddChild(std::move(child));
10276
10277 host_impl_->SetViewportSize(surface_size);
10278 host_impl_->active_tree()->BuildPropertyTreesForTesting();
10279 host_impl_->active_tree()->DidBecomeActive();
10280 DrawFrame();
10281
10282 {
10283 child_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
10284 grand_child_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50));
10285 // Flinging the grand_child layer.
10286 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
10287 host_impl_
10288 ->ScrollBegin(BeginState(gfx::Point(60, 60)).get(),
10227 InputHandler::TOUCHSCREEN) 10289 InputHandler::TOUCHSCREEN)
10228 .thread); 10290 .thread);
10229 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 10291 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
10230 host_impl_->FlingScrollBegin().thread); 10292 host_impl_->FlingScrollBegin().thread);
10231 EXPECT_EQ(child_layer->scroll_tree_index(), 10293 EXPECT_EQ(grand_child_layer->scroll_tree_index(),
10232 host_impl_->CurrentlyScrollingNode()->id); 10294 host_impl_->CurrentlyScrollingNode()->id);
10233 // Touch on the child layer, which is an active fling layer, the touch 10295 // Touch on the grand_child layer, which is an active fling layer, the touch
10234 // event handler will force to be passive. 10296 // event handler will force to be passive.
10235 EXPECT_EQ( 10297 EXPECT_EQ(
10236 InputHandler::TouchStartEventListenerType::HANDLER_ON_SCROLLING_LAYER, 10298 InputHandler::TouchStartEventListenerType::HANDLER_ON_SCROLLING_LAYER,
10237 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(70, 80))); 10299 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(70, 80)));
10238 // Touch on the grand child layer, which is a descendant of an active fling 10300 // Touch on the great_grand_child_layer layer, which is the child of the
10239 // layer, the touch event handler will force to be passive. 10301 // active fling layer, the touch event handler will force to be passive.
10240 EXPECT_EQ( 10302 EXPECT_EQ(
10241 InputHandler::TouchStartEventListenerType::HANDLER_ON_SCROLLING_LAYER, 10303 InputHandler::TouchStartEventListenerType::HANDLER_ON_SCROLLING_LAYER,
10242 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(20, 30))); 10304 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(20, 30)));
10243 10305
10244 // Now flinging on the grand child layer. 10306 // Now flinging on the great_grand_child_layer.
10245 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 10307 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
10246 host_impl_ 10308 host_impl_
10247 ->ScrollBegin(BeginState(gfx::Point(10, 10)).get(), 10309 ->ScrollBegin(BeginState(gfx::Point(10, 10)).get(),
10248 InputHandler::TOUCHSCREEN) 10310 InputHandler::TOUCHSCREEN)
10249 .thread); 10311 .thread);
10250 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 10312 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
10251 host_impl_->FlingScrollBegin().thread); 10313 host_impl_->FlingScrollBegin().thread);
10252 EXPECT_EQ(grand_child_layer->scroll_tree_index(), 10314 EXPECT_EQ(great_grand_child_layer->scroll_tree_index(),
10253 host_impl_->CurrentlyScrollingNode()->id); 10315 host_impl_->CurrentlyScrollingNode()->id);
10254 // Touch on the child layer, the touch event handler will still be blocking. 10316 // Touch on the child layer, the touch event handler will be blocked.
10255 EXPECT_EQ(InputHandler::TouchStartEventListenerType::HANDLER, 10317 EXPECT_EQ(InputHandler::TouchStartEventListenerType::HANDLER,
10256 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(60, 60))); 10318 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(60, 60)));
10257 } 10319 }
10258 } 10320 }
10259 10321
10260 class ResourcelessSoftwareLayerTreeHostImplTest : public LayerTreeHostImplTest { 10322 class ResourcelessSoftwareLayerTreeHostImplTest : public LayerTreeHostImplTest {
10261 protected: 10323 protected:
10262 std::unique_ptr<CompositorFrameSink> CreateCompositorFrameSink() override { 10324 std::unique_ptr<CompositorFrameSink> CreateCompositorFrameSink() override {
10263 return FakeCompositorFrameSink::Create3d(); 10325 return FakeCompositorFrameSink::Create3d();
10264 } 10326 }
(...skipping 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after
12094 else 12156 else
12095 EXPECT_FALSE(tile->HasRasterTask()); 12157 EXPECT_FALSE(tile->HasRasterTask());
12096 } 12158 }
12097 Region expected_invalidation( 12159 Region expected_invalidation(
12098 raster_source->GetRectForImage(checkerable_image->uniqueID())); 12160 raster_source->GetRectForImage(checkerable_image->uniqueID()));
12099 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation())); 12161 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation()));
12100 } 12162 }
12101 12163
12102 } // namespace 12164 } // namespace
12103 } // namespace cc 12165 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698