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

Unified 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, 2 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 side-by-side diff with in-line comments
Download patch
« cc/trees/layer_tree_host_common.cc ('K') | « cc/trees/layer_tree_host_common.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/trees/layer_tree_host_common_unittest.cc
diff --git a/cc/trees/layer_tree_host_common_unittest.cc b/cc/trees/layer_tree_host_common_unittest.cc
index 40cc92a72fe89b9f1486119ec9ecb088c75afbea..fec6da10bf7dec0dad02e2a3af53f4867c219a69 100644
--- a/cc/trees/layer_tree_host_common_unittest.cc
+++ b/cc/trees/layer_tree_host_common_unittest.cc
@@ -5569,6 +5569,164 @@ TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayers) {
EXPECT_EQ(4, result_layer->id());
}
+TEST_F(LayerTreeHostCommonTest, HitTestForZeroOpacityLayers) {
+ FakeImplProxy proxy;
+ FakeLayerTreeHostImpl host_impl(&proxy);
+ const int kRootId = 1;
+ const int kTouchHandlerId = 2;
+ const int kWheelHandlerId = 3;
+ const int kNoHandlerId = 4;
+ const int kGrandChildWithEventId = 5;
+ const int kGrandChildWithoutEventId = 6;
+
+ scoped_ptr<LayerImpl> root =
+ LayerImpl::Create(host_impl.active_tree(), 1);
+ gfx::Transform identity_matrix;
+ gfx::PointF anchor;
+ gfx::PointF position;
+ gfx::Size bounds(100, 100);
+ SetLayerPropertiesForTesting(root.get(),
+ identity_matrix,
+ identity_matrix,
+ anchor,
+ position,
+ bounds,
+ false);
+ root->SetDrawsContent(true);
+
+ {
+ // Child 1 - Zero opacity, without any event handler.
+ gfx::PointF position(10.f, 10.f);
+ gfx::Size bounds(30, 30);
+ scoped_ptr<LayerImpl> child =
+ LayerImpl::Create(host_impl.active_tree(), kNoHandlerId);
+ SetLayerPropertiesForTesting(child.get(),
+ identity_matrix,
+ identity_matrix,
+ anchor,
+ position,
+ bounds,
+ false);
+ child->SetOpacity(0.f);
+
+ // Grandchild - with a wheel handler.
+ {
+ scoped_ptr<LayerImpl> grand_child =
+ LayerImpl::Create(host_impl.active_tree(), kGrandChildWithEventId);
+ SetLayerPropertiesForTesting(grand_child.get(),
+ identity_matrix,
+ identity_matrix,
+ gfx::PointF(),
+ gfx::PointF(10, 10),
+ gfx::Size(10, 10),
+ false);
+ grand_child->SetHaveWheelEventHandlers(true);
+ child->AddChild(grand_child.Pass());
+ }
+
+ // Grandchild - without any event handlers.
+ {
+ scoped_ptr<LayerImpl> grand_child =
+ LayerImpl::Create(host_impl.active_tree(), kGrandChildWithoutEventId);
+ SetLayerPropertiesForTesting(grand_child.get(),
+ identity_matrix,
+ identity_matrix,
+ gfx::PointF(),
+ gfx::PointF(20, 10),
+ gfx::Size(10, 10),
+ false);
+ child->AddChild(grand_child.Pass());
+ }
+ root->AddChild(child.Pass());
+ }
+
+ {
+ // Child 2 - Zero opacity, with touch event handler.
+ gfx::PointF position(70.f, 10.f);
+ gfx::Size bounds(30, 30);
+ scoped_ptr<LayerImpl> child =
+ LayerImpl::Create(host_impl.active_tree(), kTouchHandlerId);
+ SetLayerPropertiesForTesting(child.get(),
+ identity_matrix,
+ identity_matrix,
+ anchor,
+ position,
+ bounds,
+ false);
+ child->SetOpacity(0.f);
+ child->SetTouchEventHandlerRegion(gfx::Rect(10, 10, 10, 10));
+ root->AddChild(child.Pass());
+ }
+
+ {
+ // Child 3 - Zero opacity, with wheel event handler.
+ gfx::PointF position(10.f, 50.f);
+ gfx::Size bounds(30, 30);
+ scoped_ptr<LayerImpl> child =
+ LayerImpl::Create(host_impl.active_tree(), kWheelHandlerId);
+ SetLayerPropertiesForTesting(child.get(),
+ identity_matrix,
+ identity_matrix,
+ anchor,
+ position,
+ bounds,
+ false);
+ child->SetOpacity(0.f);
+ child->SetHaveWheelEventHandlers(true);
+ root->AddChild(child.Pass());
+ }
+
+ LayerImplList render_surface_layer_list;
+ LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
+ root.get(), root->bounds(), &render_surface_layer_list);
+ inputs.can_adjust_raster_scales = true;
+ LayerTreeHostCommon::CalculateDrawProperties(&inputs);
+
+ // Verify that the root layer and zero-opacity layers with touch/wheel
+ // handlers (but not the zero-opacity layer without a touch handler) are in
+ // the RSSL.
+ ASSERT_EQ(1u, render_surface_layer_list.size());
+ EXPECT_EQ(kRootId, render_surface_layer_list[0]->id());
+ ASSERT_EQ(4u, root->render_surface()->layer_list().size());
+
+ EXPECT_EQ(kRootId, root->render_surface()->layer_list().at(0)->id());
+ EXPECT_EQ(kGrandChildWithEventId,
+ root->render_surface()->layer_list().at(1)->id());
+ EXPECT_EQ(kTouchHandlerId, root->render_surface()->layer_list().at(2)->id());
+ EXPECT_EQ(kWheelHandlerId, root->render_surface()->layer_list().at(3)->id());
+
+ // Hit testing for a point inside the zero-opacity no-handler layer should
+ // return the root layer.
+ gfx::Point test_point = gfx::Point(15, 15);
+ LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
+ test_point, render_surface_layer_list);
+ ASSERT_TRUE(result_layer);
+ EXPECT_EQ(kRootId, result_layer->id());
+
+ // Hit testing for a point inside the child of the zero-opacity no-handler
+ // layer should return the child layer, since that layer has mousewheel
+ // handler.
+ test_point = gfx::Point(25, 25);
+ result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
+ test_point, render_surface_layer_list);
+ ASSERT_TRUE(result_layer);
+ EXPECT_EQ(kGrandChildWithEventId, result_layer->id());
+
+ // Hit testing for a point inside the touch handler layer should return it.
+ test_point = gfx::Point(85, 25);
+ result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
+ test_point, render_surface_layer_list);
+ ASSERT_TRUE(result_layer);
+ EXPECT_EQ(kTouchHandlerId, result_layer->id());
+
+ // Hit testing for a point inside the mousewheel layer should return it.
+ test_point = gfx::Point(15, 55);
+ result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
+ test_point, render_surface_layer_list);
+ ASSERT_TRUE(result_layer);
+ EXPECT_EQ(kWheelHandlerId, result_layer->id());
+}
+
TEST_F(LayerTreeHostCommonTest,
HitCheckingTouchHandlerRegionsForEmptyLayerList) {
// Hit checking on an empty render_surface_layer_list should return a null
« cc/trees/layer_tree_host_common.cc ('K') | « cc/trees/layer_tree_host_common.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698