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

Unified Diff: cc/layer_tree_host_common_unittest.cc

Issue 11402002: Add API for hit testing layer_impl touchEventHandlerRegions from the host (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added tests and fixed parameters on static call Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/layer_tree_host_common.cc ('k') | cc/layer_tree_host_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/layer_tree_host_common_unittest.cc
diff --git a/cc/layer_tree_host_common_unittest.cc b/cc/layer_tree_host_common_unittest.cc
index e18137a6e5eef92b9d475d765b2f3265224b0191..c5891ab59a7925a911db5a980abf73854f4d750e 100644
--- a/cc/layer_tree_host_common_unittest.cc
+++ b/cc/layer_tree_host_common_unittest.cc
@@ -3109,7 +3109,7 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForMultiClippedRotatedLayer)
bounds = gfx::Size(80, 80);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
child->setMasksToBounds(true);
-
+
WebTransformationMatrix rotation45DegreesAboutCorner;
rotation45DegreesAboutCorner.rotate3d(0, 0, 45);
@@ -3463,6 +3463,333 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayerLists)
EXPECT_EQ(4, resultLayer->id());
}
+TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForEmptyLayerList)
+{
+ // Hit checking on an empty renderSurfaceLayerList should return a null pointer.
+ DebugScopedSetImplThread thisScopeIsOnImplThread;
+
+ std::vector<LayerImpl*> renderSurfaceLayerList;
+
+ gfx::Point testPoint(0, 0);
+ LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ testPoint = gfx::Point(10, 20);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+}
+
+TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSingleLayer)
+{
+ DebugScopedSetImplThread thisScopeIsOnImplThread;
+
+ scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
+
+ WebTransformationMatrix identityMatrix;
+ Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50));
+ gfx::PointF anchor(0, 0);
+ gfx::PointF position(0, 0);
+ gfx::Size bounds(100, 100);
+ setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
+ root->setDrawsContent(true);
+
+ std::vector<LayerImpl*> renderSurfaceLayerList;
+ int dummyMaxTextureSize = 512;
+ LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
+
+ // Sanity check the scenario we just created.
+ ASSERT_EQ(1u, renderSurfaceLayerList.size());
+ ASSERT_EQ(1u, root->renderSurface()->layerList().size());
+
+ // Hit checking for any point should return a null pointer for a layer without any touch event handler regions.
+ gfx::Point testPoint(11, 11);
+ LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ root->setTouchEventHandlerRegion(touchHandlerRegion);
+ // Hit checking for a point outside the layer should return a null pointer.
+ testPoint = gfx::Point(101, 101);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ testPoint = gfx::Point(-1, -1);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ // Hit checking for a point inside the layer, but outside the touch handler region should return a null pointer.
+ testPoint = gfx::Point(1, 1);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ testPoint = gfx::Point(99, 99);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ // Hit checking for a point inside the touch event handler region should return the root layer.
+ testPoint = gfx::Point(11, 11);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ ASSERT_TRUE(resultLayer);
+ EXPECT_EQ(12345, resultLayer->id());
+
+ testPoint = gfx::Point(59, 59);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ ASSERT_TRUE(resultLayer);
+ EXPECT_EQ(12345, resultLayer->id());
+}
+
+TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForUninvertibleTransform)
+{
+ DebugScopedSetImplThread thisScopeIsOnImplThread;
+
+ scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
+
+ WebTransformationMatrix uninvertibleTransform;
+ uninvertibleTransform.setM11(0);
+ uninvertibleTransform.setM22(0);
+ uninvertibleTransform.setM33(0);
+ uninvertibleTransform.setM44(0);
+ ASSERT_FALSE(uninvertibleTransform.isInvertible());
+
+ WebTransformationMatrix identityMatrix;
+ Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50));
+ gfx::PointF anchor(0, 0);
+ gfx::PointF position(0, 0);
+ gfx::Size bounds(100, 100);
+ setLayerPropertiesForTesting(root.get(), uninvertibleTransform, identityMatrix, anchor, position, bounds, false);
+ root->setDrawsContent(true);
+ root->setTouchEventHandlerRegion(touchHandlerRegion);
+
+ std::vector<LayerImpl*> renderSurfaceLayerList;
+ int dummyMaxTextureSize = 512;
+ LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
+
+ // Sanity check the scenario we just created.
+ ASSERT_EQ(1u, renderSurfaceLayerList.size());
+ ASSERT_EQ(1u, root->renderSurface()->layerList().size());
+ ASSERT_FALSE(root->screenSpaceTransform().isInvertible());
+
+ // Hit checking any point should not hit the touch handler region on the layer. If the invertible matrix is
+ // accidentally ignored and treated like an identity, then the hit testing will
+ // incorrectly hit the layer when it shouldn't.
+ gfx::Point testPoint(1, 1);
+ LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ testPoint = gfx::Point(10, 10);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ testPoint = gfx::Point(10, 30);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ testPoint = gfx::Point(50, 50);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ testPoint = gfx::Point(67, 48);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ testPoint = gfx::Point(99, 99);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ testPoint = gfx::Point(-1, -1);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+}
+
+TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSinglePositionedLayer)
+{
+ DebugScopedSetImplThread thisScopeIsOnImplThread;
+
+ scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
+
+ WebTransformationMatrix identityMatrix;
+ Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50));
+ gfx::PointF anchor(0, 0);
+ gfx::PointF position(50, 50); // this layer is positioned, and hit testing should correctly know where the layer is located.
+ gfx::Size bounds(100, 100);
+ setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
+ root->setDrawsContent(true);
+ root->setTouchEventHandlerRegion(touchHandlerRegion);
+
+ std::vector<LayerImpl*> renderSurfaceLayerList;
+ int dummyMaxTextureSize = 512;
+ LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
+
+ // Sanity check the scenario we just created.
+ ASSERT_EQ(1u, renderSurfaceLayerList.size());
+ ASSERT_EQ(1u, root->renderSurface()->layerList().size());
+
+ // Hit checking for a point outside the layer should return a null pointer.
+ gfx::Point testPoint(49, 49);
+ LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ // Even though the layer has a touch handler region containing (101, 101), it should not be visible there since the root renderSurface would clamp it.
+ testPoint = gfx::Point(101, 101);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ // Hit checking for a point inside the layer, but outside the touch handler region should return a null pointer.
+ testPoint = gfx::Point(51, 51);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ // Hit checking for a point inside the touch event handler region should return the root layer.
+ testPoint = gfx::Point(61, 61);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ ASSERT_TRUE(resultLayer);
+ EXPECT_EQ(12345, resultLayer->id());
+
+ testPoint = gfx::Point(99, 99);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ ASSERT_TRUE(resultLayer);
+ EXPECT_EQ(12345, resultLayer->id());
+}
+
+TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSingleLayerWithScaledContents)
+{
+ // A layer's visibleContentRect is actually in the layer's content space. The
+ // screenSpaceTransform converts from the layer's origin space to screen space. This
+ // test makes sure that hit testing works correctly accounts for the contents scale.
+ // A contentsScale that is not 1 effectively forces a non-identity transform between
+ // layer's content space and layer's origin space. The hit testing code must take this into account.
+ //
+ // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
+ // contentsScale is ignored, then hit checking will mis-interpret the visibleContentRect
+ // as being larger than the actual bounds of the layer.
+ //
+ DebugScopedSetImplThread thisScopeIsOnImplThread;
+
+ scoped_ptr<LayerImpl> root = LayerImpl::create(1);
+
+ WebTransformationMatrix identityMatrix;
+ gfx::PointF anchor(0, 0);
+
+ setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
+
+ {
+ Region touchHandlerRegion(gfx::Rect(10, 10, 30, 30));
+ gfx::PointF position(25, 25);
+ gfx::Size bounds(50, 50);
+ scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345);
+ setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
+
+ // override contentBounds and contentsScale
+ testLayer->setContentBounds(gfx::Size(100, 100));
+ testLayer->setContentsScale(2, 2);
+
+ testLayer->setDrawsContent(true);
+ testLayer->setTouchEventHandlerRegion(touchHandlerRegion);
+ root->addChild(testLayer.Pass());
+ }
+
+ std::vector<LayerImpl*> renderSurfaceLayerList;
+ int dummyMaxTextureSize = 512;
+ LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
danakj 2012/11/09 17:02:58 Can you repeat this test but pass something non-1,
Yusuf 2012/11/12 23:57:33 Done.
+
+ // Sanity check the scenario we just created.
+ // The visibleContentRect for testLayer is actually 100x100, even though its layout size is 50x50, positioned at 25x25.
+ LayerImpl* testLayer = root->children()[0];
+ EXPECT_RECT_EQ(gfx::Rect(gfx::Point(), gfx::Size(100, 100)), testLayer->visibleContentRect());
+ ASSERT_EQ(1u, renderSurfaceLayerList.size());
+ ASSERT_EQ(1u, root->renderSurface()->layerList().size());
+
+ // Hit checking for a point outside the layer should return a null pointer (the root layer does not draw content, so it will not be tested either).
+ gfx::Point testPoint(76, 76);
+ LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ // Hit checking for a point inside the layer, but outside the touch handler region should return a null pointer.
+ testPoint = gfx::Point(26, 26);
danakj 2012/11/09 17:02:58 does this also work at 34,34?
Yusuf 2012/11/12 23:57:33 Done.
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ testPoint = gfx::Point(74, 74);
danakj 2012/11/09 17:02:58 does this also work at 65,65?
Yusuf 2012/11/12 23:57:33 Done.
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ // Hit checking for a point inside the touch event handler region should return the root layer.
+ testPoint = gfx::Point(36, 36);
danakj 2012/11/09 17:02:58 does this also work at 35,35?
Yusuf 2012/11/12 23:57:33 Done.
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ ASSERT_TRUE(resultLayer);
+ EXPECT_EQ(12345, resultLayer->id());
+
+ testPoint = gfx::Point(64, 64);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ ASSERT_TRUE(resultLayer);
+ EXPECT_EQ(12345, resultLayer->id());
+}
+
+TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSimpleClippedLayer)
+{
+ // Test that hit-checking will only work for the visible portion of a layer, and not
+ // the entire layer bounds. Here we just test the simple axis-aligned case.
+ DebugScopedSetImplThread thisScopeIsOnImplThread;
+
+ WebTransformationMatrix identityMatrix;
+ gfx::PointF anchor(0, 0);
+
+ scoped_ptr<LayerImpl> root = LayerImpl::create(1);
+ setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
+
+ {
+ scoped_ptr<LayerImpl> clippingLayer = LayerImpl::create(123);
+ gfx::PointF position(25, 25); // this layer is positioned, and hit testing should correctly know where the layer is located.
+ gfx::Size bounds(50, 50);
+ setLayerPropertiesForTesting(clippingLayer.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
+ clippingLayer->setMasksToBounds(true);
+
+ scoped_ptr<LayerImpl> child = LayerImpl::create(456);
+ Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50));
+ position = gfx::PointF(-50, -50);
+ bounds = gfx::Size(300, 300);
+ setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
+ child->setDrawsContent(true);
+ child->setTouchEventHandlerRegion(touchHandlerRegion);
+ clippingLayer->addChild(child.Pass());
+ root->addChild(clippingLayer.Pass());
+ }
+
+ std::vector<LayerImpl*> renderSurfaceLayerList;
+ int dummyMaxTextureSize = 512;
+ LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
+
+ // Sanity check the scenario we just created.
+ ASSERT_EQ(1u, renderSurfaceLayerList.size());
+ ASSERT_EQ(1u, root->renderSurface()->layerList().size());
+ ASSERT_EQ(456, root->renderSurface()->layerList()[0]->id());
+
+ // Hit checking for a point outside the layer should return a null pointer.
+ // Despite the child layer being very large, it should be clipped to the root layer's bounds.
+ gfx::Point testPoint(24, 24);
+ LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ // Hit checking for a point inside the layer, but outside the touch handler region should return a null pointer.
+ testPoint = gfx::Point(36, 36);
danakj 2012/11/09 17:02:58 how about 35,35?
Yusuf 2012/11/12 23:57:33 Done.
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ testPoint = gfx::Point(74, 74);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ // Hit checking for a point inside the touch event handler region should return the root layer.
+ testPoint = gfx::Point(26, 26);
danakj 2012/11/09 17:02:58 how about 25,25?
Yusuf 2012/11/12 23:57:33 Done.
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ ASSERT_TRUE(resultLayer);
+ EXPECT_EQ(456, resultLayer->id());
+
+ testPoint = gfx::Point(34, 34);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ ASSERT_TRUE(resultLayer);
+ EXPECT_EQ(456, resultLayer->id());
+}
+
class NoScaleContentLayer : public ContentLayer
{
public:
« no previous file with comments | « cc/layer_tree_host_common.cc ('k') | cc/layer_tree_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698