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

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

Issue 26112002: cc: Fix hit-testing in zero-opacity layers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 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 | Annotate | Revision Log
« no previous file with comments | « cc/trees/layer_tree_host_common.cc ('k') | cc/trees/layer_tree_host_impl.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_common.h" 5 #include "cc/trees/layer_tree_host_common.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "cc/animation/layer_animation_controller.h" 9 #include "cc/animation/layer_animation_controller.h"
10 #include "cc/base/math_util.h" 10 #include "cc/base/math_util.h"
(...skipping 5370 matching lines...) Expand 10 before | Expand all | Expand 10 after
5381 LayerImplList render_surface_layer_list; 5381 LayerImplList render_surface_layer_list;
5382 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 5382 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5383 root.get(), root->bounds(), &render_surface_layer_list); 5383 root.get(), root->bounds(), &render_surface_layer_list);
5384 inputs.can_adjust_raster_scales = true; 5384 inputs.can_adjust_raster_scales = true;
5385 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 5385 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5386 5386
5387 // Verify that the root layer and empty layers with touch/wheel handlers 5387 // Verify that the root layer and empty layers with touch/wheel handlers
5388 // (but not the empty layer without a touch handler) are in the RSSL. 5388 // (but not the empty layer without a touch handler) are in the RSSL.
5389 ASSERT_EQ(1u, render_surface_layer_list.size()); 5389 ASSERT_EQ(1u, render_surface_layer_list.size());
5390 EXPECT_EQ(1, render_surface_layer_list[0]->id()); 5390 EXPECT_EQ(1, render_surface_layer_list[0]->id());
5391 ASSERT_EQ(3u, root->render_surface()->layer_list().size()); 5391 ASSERT_EQ(4u, root->render_surface()->layer_list().size());
5392 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); 5392 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
5393 EXPECT_EQ(3, root->render_surface()->layer_list().at(1)->id()); 5393 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
5394 EXPECT_EQ(4, root->render_surface()->layer_list().at(2)->id()); 5394 EXPECT_EQ(3, root->render_surface()->layer_list().at(2)->id());
5395 EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id());
5395 5396
5396 // Hit testing for a point inside the empty no-handlers layer should return 5397 // Hit testing for a point inside the empty no-handlers layer should return
5397 // the root layer. 5398 // the root layer.
5398 gfx::Point test_point = gfx::Point(15, 15); 5399 gfx::Point test_point = gfx::Point(15, 15);
5399 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( 5400 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5400 test_point, render_surface_layer_list); 5401 test_point, render_surface_layer_list);
5401 ASSERT_TRUE(result_layer); 5402 ASSERT_TRUE(result_layer);
5402 EXPECT_EQ(1, result_layer->id()); 5403 EXPECT_EQ(2, result_layer->id());
5403 5404
5404 // Hit testing for a point inside the touch handler layer should return it. 5405 // Hit testing for a point inside the touch handler layer should return it.
5405 test_point = gfx::Point(15, 75); 5406 test_point = gfx::Point(15, 75);
5406 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( 5407 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5407 test_point, render_surface_layer_list); 5408 test_point, render_surface_layer_list);
5408 ASSERT_TRUE(result_layer); 5409 ASSERT_TRUE(result_layer);
5409 EXPECT_EQ(3, result_layer->id()); 5410 EXPECT_EQ(3, result_layer->id());
5410 5411
5411 // Hit testing for a point inside the mousewheel layer should return it. 5412 // Hit testing for a point inside the mousewheel layer should return it.
5412 test_point = gfx::Point(75, 75); 5413 test_point = gfx::Point(75, 75);
5413 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( 5414 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5414 test_point, render_surface_layer_list); 5415 test_point, render_surface_layer_list);
5415 ASSERT_TRUE(result_layer); 5416 ASSERT_TRUE(result_layer);
5416 EXPECT_EQ(4, result_layer->id()); 5417 EXPECT_EQ(4, result_layer->id());
5417 } 5418 }
5418 5419
5420 TEST_F(LayerTreeHostCommonTest, HitTestForZeroOpacityLayers) {
5421 FakeImplProxy proxy;
5422 FakeLayerTreeHostImpl host_impl(&proxy);
5423 const int kRootId = 1;
5424 const int kTouchHandlerId = 2;
5425 const int kWheelHandlerId = 3;
5426 const int kNoHandlerId = 4;
5427 const int kGrandChildWithEventId = 5;
5428
5429 scoped_ptr<LayerImpl> root =
5430 LayerImpl::Create(host_impl.active_tree(), 1);
5431 gfx::Transform identity_matrix;
5432 gfx::PointF anchor;
5433 gfx::PointF position;
5434 gfx::Size bounds(100, 100);
5435 SetLayerPropertiesForTesting(root.get(),
5436 identity_matrix,
5437 identity_matrix,
5438 anchor,
5439 position,
5440 bounds,
5441 false);
5442 root->SetDrawsContent(true);
5443
5444 {
5445 // Child 1 - Zero opacity, without any event handler.
5446 gfx::PointF position(10.f, 10.f);
5447 gfx::Size bounds(30, 30);
5448 scoped_ptr<LayerImpl> child =
5449 LayerImpl::Create(host_impl.active_tree(), kNoHandlerId);
5450 SetLayerPropertiesForTesting(child.get(),
5451 identity_matrix,
5452 identity_matrix,
5453 anchor,
5454 position,
5455 bounds,
5456 false);
5457 child->SetOpacity(0.f);
5458
5459 // Grandchild - with a wheel handler.
5460 scoped_ptr<LayerImpl> grand_child =
5461 LayerImpl::Create(host_impl.active_tree(), kGrandChildWithEventId);
5462 SetLayerPropertiesForTesting(grand_child.get(),
5463 identity_matrix,
5464 identity_matrix,
5465 gfx::PointF(),
5466 gfx::PointF(10, 10),
5467 gfx::Size(10, 10),
5468 false);
5469 grand_child->SetHaveWheelEventHandlers(true);
5470 child->AddChild(grand_child.Pass());
5471 root->AddChild(child.Pass());
5472 }
5473
5474 {
5475 // Child 2 - Zero opacity, with touch event handler.
5476 gfx::PointF position(70.f, 10.f);
5477 gfx::Size bounds(30, 30);
5478 scoped_ptr<LayerImpl> child =
5479 LayerImpl::Create(host_impl.active_tree(), kTouchHandlerId);
5480 SetLayerPropertiesForTesting(child.get(),
5481 identity_matrix,
5482 identity_matrix,
5483 anchor,
5484 position,
5485 bounds,
5486 false);
5487 child->SetOpacity(0.f);
5488 child->SetTouchEventHandlerRegion(gfx::Rect(10, 10, 10, 10));
5489 root->AddChild(child.Pass());
5490 }
5491
5492 {
5493 // Child 3 - Zero opacity, with wheel event handler.
5494 gfx::PointF position(10.f, 50.f);
5495 gfx::Size bounds(30, 30);
5496 scoped_ptr<LayerImpl> child =
5497 LayerImpl::Create(host_impl.active_tree(), kWheelHandlerId);
5498 SetLayerPropertiesForTesting(child.get(),
5499 identity_matrix,
5500 identity_matrix,
5501 anchor,
5502 position,
5503 bounds,
5504 false);
5505 child->SetOpacity(0.f);
5506 child->SetHaveWheelEventHandlers(true);
5507 root->AddChild(child.Pass());
5508 }
5509
5510 LayerImplList render_surface_layer_list;
5511 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5512 root.get(), root->bounds(), &render_surface_layer_list);
5513 inputs.can_adjust_raster_scales = true;
5514 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5515
5516 // Verify that the root layer and zero-opacity layers with touch/wheel
5517 // handlers (but not the zero-opacity layer without a touch handler) are in
5518 // the RSSL.
5519 ASSERT_EQ(1u, render_surface_layer_list.size());
5520 EXPECT_EQ(kRootId, render_surface_layer_list[0]->id());
5521 ASSERT_EQ(5u, root->render_surface()->layer_list().size());
5522 EXPECT_EQ(kRootId, root->render_surface()->layer_list().at(0)->id());
5523 EXPECT_EQ(kNoHandlerId, root->render_surface()->layer_list().at(1)->id());
5524 EXPECT_EQ(kGrandChildWithEventId,
5525 root->render_surface()->layer_list().at(2)->id());
5526 EXPECT_EQ(kTouchHandlerId, root->render_surface()->layer_list().at(3)->id());
5527 EXPECT_EQ(kWheelHandlerId, root->render_surface()->layer_list().at(4)->id());
5528
5529 // Hit testing for a point inside the zero-opacity no-handler layer should
5530 // return the root layer.
5531 gfx::Point test_point = gfx::Point(15, 15);
5532 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5533 test_point, render_surface_layer_list);
5534 ASSERT_TRUE(result_layer);
5535 EXPECT_EQ(kNoHandlerId, result_layer->id());
5536
5537 // Hit testing for a point inside the child of the zero-opacity no-handler
5538 // layer should return the child layer, since that layer has mousewheel
5539 // handler.
5540 test_point = gfx::Point(25, 25);
5541 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5542 test_point, render_surface_layer_list);
5543 ASSERT_TRUE(result_layer);
5544 EXPECT_EQ(kGrandChildWithEventId, result_layer->id());
5545
5546 // Hit testing for a point inside the touch handler layer should return it.
5547 test_point = gfx::Point(85, 25);
5548 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5549 test_point, render_surface_layer_list);
5550 ASSERT_TRUE(result_layer);
5551 EXPECT_EQ(kTouchHandlerId, result_layer->id());
5552
5553 // Hit testing for a point inside the mousewheel layer should return it.
5554 test_point = gfx::Point(15, 55);
5555 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5556 test_point, render_surface_layer_list);
5557 ASSERT_TRUE(result_layer);
5558 EXPECT_EQ(kWheelHandlerId, result_layer->id());
5559 }
5560
5419 TEST_F(LayerTreeHostCommonTest, 5561 TEST_F(LayerTreeHostCommonTest,
5420 HitCheckingTouchHandlerRegionsForEmptyLayerList) { 5562 HitCheckingTouchHandlerRegionsForEmptyLayerList) {
5421 // Hit checking on an empty render_surface_layer_list should return a null 5563 // Hit checking on an empty render_surface_layer_list should return a null
5422 // pointer. 5564 // pointer.
5423 LayerImplList render_surface_layer_list; 5565 LayerImplList render_surface_layer_list;
5424 5566
5425 gfx::Point test_point(0, 0); 5567 gfx::Point test_point(0, 0);
5426 LayerImpl* result_layer = 5568 LayerImpl* result_layer =
5427 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( 5569 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5428 test_point, render_surface_layer_list); 5570 test_point, render_surface_layer_list);
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
5734 root.get(), root->bounds(), &render_surface_layer_list); 5876 root.get(), root->bounds(), &render_surface_layer_list);
5735 inputs.can_adjust_raster_scales = true; 5877 inputs.can_adjust_raster_scales = true;
5736 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 5878 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5737 5879
5738 // Sanity check the scenario we just created. 5880 // Sanity check the scenario we just created.
5739 // The visible content rect for test_layer is actually 100x100, even though 5881 // The visible content rect for test_layer is actually 100x100, even though
5740 // its layout size is 50x50, positioned at 25x25. 5882 // its layout size is 50x50, positioned at 25x25.
5741 LayerImpl* test_layer = root->children()[0]; 5883 LayerImpl* test_layer = root->children()[0];
5742 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), test_layer->visible_content_rect()); 5884 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), test_layer->visible_content_rect());
5743 ASSERT_EQ(1u, render_surface_layer_list.size()); 5885 ASSERT_EQ(1u, render_surface_layer_list.size());
5744 ASSERT_EQ(1u, root->render_surface()->layer_list().size()); 5886 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
5745 5887
5746 // Hit checking for a point outside the layer should return a null pointer 5888 // Hit checking for a point outside the layer should return a null pointer
5747 // (the root layer does not draw content, so it will not be tested either). 5889 // (the root layer does not draw content, so it will not be tested either).
5748 gfx::Point test_point(76, 76); 5890 gfx::Point test_point(76, 76);
5749 LayerImpl* result_layer = 5891 LayerImpl* result_layer =
5750 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( 5892 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5751 test_point, render_surface_layer_list); 5893 test_point, render_surface_layer_list);
5752 EXPECT_FALSE(result_layer); 5894 EXPECT_FALSE(result_layer);
5753 5895
5754 // Hit checking for a point inside the layer, but outside the touch handler 5896 // Hit checking for a point inside the layer, but outside the touch handler
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
5844 inputs.page_scale_factor = page_scale_factor; 5986 inputs.page_scale_factor = page_scale_factor;
5845 inputs.page_scale_application_layer = root.get(); 5987 inputs.page_scale_application_layer = root.get();
5846 inputs.can_adjust_raster_scales = true; 5988 inputs.can_adjust_raster_scales = true;
5847 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 5989 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5848 5990
5849 // Sanity check the scenario we just created. 5991 // Sanity check the scenario we just created.
5850 // The visible content rect for test_layer is actually 100x100, even though 5992 // The visible content rect for test_layer is actually 100x100, even though
5851 // its layout size is 50x50, positioned at 25x25. 5993 // its layout size is 50x50, positioned at 25x25.
5852 LayerImpl* test_layer = root->children()[0]; 5994 LayerImpl* test_layer = root->children()[0];
5853 ASSERT_EQ(1u, render_surface_layer_list.size()); 5995 ASSERT_EQ(1u, render_surface_layer_list.size());
5854 ASSERT_EQ(1u, root->render_surface()->layer_list().size()); 5996 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
5855 5997
5856 // Check whether the child layer fits into the root after scaled. 5998 // Check whether the child layer fits into the root after scaled.
5857 EXPECT_RECT_EQ(gfx::Rect(test_layer->content_bounds()), 5999 EXPECT_RECT_EQ(gfx::Rect(test_layer->content_bounds()),
5858 test_layer->visible_content_rect()); 6000 test_layer->visible_content_rect());
5859 6001
5860 // Hit checking for a point outside the layer should return a null pointer 6002 // Hit checking for a point outside the layer should return a null pointer
5861 // (the root layer does not draw content, so it will not be tested either). 6003 // (the root layer does not draw content, so it will not be tested either).
5862 gfx::PointF test_point(76.f, 76.f); 6004 gfx::PointF test_point(76.f, 76.f);
5863 test_point = 6005 test_point =
5864 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); 6006 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
5975 } 6117 }
5976 6118
5977 LayerImplList render_surface_layer_list; 6119 LayerImplList render_surface_layer_list;
5978 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 6120 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5979 root.get(), root->bounds(), &render_surface_layer_list); 6121 root.get(), root->bounds(), &render_surface_layer_list);
5980 inputs.can_adjust_raster_scales = true; 6122 inputs.can_adjust_raster_scales = true;
5981 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 6123 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5982 6124
5983 // Sanity check the scenario we just created. 6125 // Sanity check the scenario we just created.
5984 ASSERT_EQ(1u, render_surface_layer_list.size()); 6126 ASSERT_EQ(1u, render_surface_layer_list.size());
5985 ASSERT_EQ(1u, root->render_surface()->layer_list().size()); 6127 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
5986 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id()); 6128 ASSERT_EQ(1, root->render_surface()->layer_list().at(0)->id());
6129 ASSERT_EQ(123, root->render_surface()->layer_list().at(1)->id());
6130 ASSERT_EQ(456, root->render_surface()->layer_list().at(2)->id());
5987 6131
5988 // Hit checking for a point outside the layer should return a null pointer. 6132 // Hit checking for a point outside the layer should return a null pointer.
5989 // Despite the child layer being very large, it should be clipped to the root 6133 // Despite the child layer being very large, it should be clipped to the root
5990 // layer's bounds. 6134 // layer's bounds.
5991 gfx::Point test_point(24, 24); 6135 gfx::Point test_point(24, 24);
5992 LayerImpl* result_layer = 6136 LayerImpl* result_layer =
5993 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( 6137 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5994 test_point, render_surface_layer_list); 6138 test_point, render_surface_layer_list);
5995 EXPECT_FALSE(result_layer); 6139 EXPECT_FALSE(result_layer);
5996 6140
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
6078 } 6222 }
6079 6223
6080 LayerImplList render_surface_layer_list; 6224 LayerImplList render_surface_layer_list;
6081 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 6225 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6082 root.get(), root->bounds(), &render_surface_layer_list); 6226 root.get(), root->bounds(), &render_surface_layer_list);
6083 inputs.can_adjust_raster_scales = true; 6227 inputs.can_adjust_raster_scales = true;
6084 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 6228 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6085 6229
6086 // Sanity check the scenario we just created. 6230 // Sanity check the scenario we just created.
6087 ASSERT_EQ(1u, render_surface_layer_list.size()); 6231 ASSERT_EQ(1u, render_surface_layer_list.size());
6088 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); 6232 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
6089 ASSERT_EQ(123, root->render_surface()->layer_list().at(0)->id()); 6233 ASSERT_EQ(1, root->render_surface()->layer_list().at(0)->id());
6090 ASSERT_EQ(1234, root->render_surface()->layer_list().at(1)->id()); 6234 ASSERT_EQ(123, root->render_surface()->layer_list().at(1)->id());
6235 ASSERT_EQ(1234, root->render_surface()->layer_list().at(2)->id());
6091 6236
6092 gfx::Point test_point(35, 35); 6237 gfx::Point test_point(35, 35);
6093 LayerImpl* result_layer = 6238 LayerImpl* result_layer =
6094 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( 6239 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6095 test_point, render_surface_layer_list); 6240 test_point, render_surface_layer_list);
6096 EXPECT_FALSE(result_layer); 6241 EXPECT_FALSE(result_layer);
6097 6242
6098 test_point = gfx::Point(35, 15); 6243 test_point = gfx::Point(35, 15);
6099 result_layer = 6244 result_layer =
6100 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( 6245 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
(...skipping 3639 matching lines...) Expand 10 before | Expand all | Expand 10 after
9740 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), 9885 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
9741 container_offset); 9886 container_offset);
9742 EXPECT_VECTOR_EQ(scroll_layer->draw_properties() 9887 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
9743 .screen_space_transform.To2dTranslation(), 9888 .screen_space_transform.To2dTranslation(),
9744 container_offset - rounded_scroll_delta); 9889 container_offset - rounded_scroll_delta);
9745 } 9890 }
9746 } 9891 }
9747 9892
9748 } // namespace 9893 } // namespace
9749 } // namespace cc 9894 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_common.cc ('k') | cc/trees/layer_tree_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698