cc: Fix touch hit-testing for overlapping layers (in tests).
If a touch-layer is below a non-touch layer, and the two layers overlap,
then the overlapped region should not be treated as a touch-handling region.
This change updates FindLayerThatIsHitByPointInTouchHandlerRegion() to do the
right thing (which is currently used only in tests), and uses this function from
LayerTreeHostImpl::HaveTouchEventHandlersAt() (instead of having its own code).
BUG=none
[email protected]
Review URL: https://codereview.chromium.org/27718006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230578 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/cc/trees/layer_tree_host_common_unittest.cc b/cc/trees/layer_tree_host_common_unittest.cc
index 700bca4..db2181a 100644
--- a/cc/trees/layer_tree_host_common_unittest.cc
+++ b/cc/trees/layer_tree_host_common_unittest.cc
@@ -6025,6 +6025,90 @@
EXPECT_EQ(456, result_layer->id());
}
+TEST_F(LayerTreeHostCommonTest,
+ HitCheckingTouchHandlerOverlappingRegions) {
+ gfx::Transform identity_matrix;
+ gfx::PointF anchor;
+
+ FakeImplProxy proxy;
+ FakeLayerTreeHostImpl host_impl(&proxy);
+ scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
+ SetLayerPropertiesForTesting(root.get(),
+ identity_matrix,
+ identity_matrix,
+ anchor,
+ gfx::PointF(),
+ gfx::Size(100, 100),
+ false);
+ {
+ scoped_ptr<LayerImpl> touch_layer =
+ LayerImpl::Create(host_impl.active_tree(), 123);
+ // this layer is positioned, and hit testing should correctly know where the
+ // layer is located.
+ gfx::PointF position;
+ gfx::Size bounds(50, 50);
+ SetLayerPropertiesForTesting(touch_layer.get(),
+ identity_matrix,
+ identity_matrix,
+ anchor,
+ position,
+ bounds,
+ false);
+ touch_layer->SetDrawsContent(true);
+ touch_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50));
+ root->AddChild(touch_layer.Pass());
+ }
+
+ {
+ scoped_ptr<LayerImpl> notouch_layer =
+ LayerImpl::Create(host_impl.active_tree(), 1234);
+ // this layer is positioned, and hit testing should correctly know where the
+ // layer is located.
+ gfx::PointF position(0, 25);
+ gfx::Size bounds(50, 50);
+ SetLayerPropertiesForTesting(notouch_layer.get(),
+ identity_matrix,
+ identity_matrix,
+ anchor,
+ position,
+ bounds,
+ false);
+ notouch_layer->SetDrawsContent(true);
+ root->AddChild(notouch_layer.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);
+
+ // Sanity check the scenario we just created.
+ ASSERT_EQ(1u, render_surface_layer_list.size());
+ ASSERT_EQ(2u, root->render_surface()->layer_list().size());
+ ASSERT_EQ(123, root->render_surface()->layer_list().at(0)->id());
+ ASSERT_EQ(1234, root->render_surface()->layer_list().at(1)->id());
+
+ gfx::Point test_point(35, 35);
+ LayerImpl* result_layer =
+ LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
+ test_point, render_surface_layer_list);
+ EXPECT_FALSE(result_layer);
+
+ test_point = gfx::Point(35, 15);
+ result_layer =
+ LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
+ test_point, render_surface_layer_list);
+ ASSERT_TRUE(result_layer);
+ EXPECT_EQ(123, result_layer->id());
+
+ test_point = gfx::Point(35, 65);
+ result_layer =
+ LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
+ test_point, render_surface_layer_list);
+ EXPECT_FALSE(result_layer);
+}
+
class NoScaleContentLayer : public ContentLayer {
public:
static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) {