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

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: Testing more points on the boundaries and also added test for deviceScaleFactor and pageScaleFactor 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
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 228ce2b6e5b7cf4cc4e8f5a6a7bf61e73cde12c3..0fad36308354682d4b23005db7264d85a025c4e5 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,422 @@ 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);
+
+ // 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);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ testPoint = gfx::Point(34, 34);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ testPoint = gfx::Point(65, 65);
+ 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(35, 35);
+ 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, verifyHitCheckingTouchHandlerRegionsForSingleLayerWithDeviceScale)
+{
+ // The layer's deviceScalefactor should scale the contentRect and we should be able to hit the touch handler region
+ // by scaling the points accordingly.
danakj 2012/11/13 00:42:04 This sounds like actually the opposite of what we
Yusuf 2012/11/13 01:17:49 Looking at scrollBegin(), we also scale the incomi
danakj 2012/11/13 01:25:05 The incoming point goes through these transformati
Yusuf 2012/11/13 01:41:39 Then since the viewport space to deviceViewPort sp
danakj 2012/11/13 01:54:00 Ahhh. I see. I forgot this was not going through L
+ DebugScopedSetImplThread thisScopeIsOnImplThread;
+
+ scoped_ptr<LayerImpl> root = LayerImpl::create(1);
+
+ WebTransformationMatrix identityMatrix;
+ gfx::PointF anchor(0, 0);
+ // Set the bounds of the root layer big enough to fit the child when scaled.
+ setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, gfx::PointF(0, 0), gfx::Size(250, 250), false);
danakj 2012/11/13 00:50:43 Don't change the bounds of the root. Layer space s
Yusuf 2012/11/13 01:17:49 Done.
+
+ {
+ 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);
+
+ testLayer->setDrawsContent(true);
+ testLayer->setTouchEventHandlerRegion(touchHandlerRegion);
+ root->addChild(testLayer.Pass());
+ }
+
+ std::vector<LayerImpl*> renderSurfaceLayerList;
+ int dummyMaxTextureSize = 512;
+ float deviceScaleFactor = 3.0f;
+ float pageScaleFactor = 5.0f; // pageScaleFactor shouldn't factor into this for LayerImpl.
danakj 2012/11/13 00:50:43 I'm not sure what you mean by this comment here. T
Yusuf 2012/11/13 00:57:36 I may be misinterpreting the code I think, but cal
danakj 2012/11/13 01:07:45 Oh! Okay, right. Since there's no main thread to s
danakj 2012/11/13 01:12:39 Actually, sorry, I confused myself. The pageScaleF
+ LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), deviceScaleFactor, pageScaleFactor, 0, dummyMaxTextureSize, renderSurfaceLayerList);
danakj 2012/11/13 00:50:43 The 2nd argument is the deviceViewportSize, ie the
Yusuf 2012/11/13 01:17:49 Using gfx::ToCeiledSize(root->bounds().Scale(devic
+
+ // Sanity check the scenario we just created.
+ // The visibleContentRect for testLayer is actually 100x100, even though its layout size is 50x50, positioned at 25x25.
danakj 2012/11/13 00:50:43 I don't see a check related to this comment.
Yusuf 2012/11/13 01:17:49 Sorry meant to swap this check with the one about
+ LayerImpl* testLayer = root->children()[0];
+ ASSERT_EQ(1u, renderSurfaceLayerList.size());
+ ASSERT_EQ(1u, root->renderSurface()->layerList().size());
+
+ // Check whether the child layer fits into the root after scaled.
+ EXPECT_RECT_EQ(gfx::Rect(gfx::Point(), gfx::Size(50, 50)), testLayer->visibleContentRect());
danakj 2012/11/13 00:50:43 The root layer is 250,250 now, so this seems off?
Yusuf 2012/11/13 01:17:49 Done.
+
+ // 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::PointF testPoint(76, 76);
+ testPoint = testPoint.Scale(deviceScaleFactor);
+ 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);
+ testPoint = testPoint.Scale(deviceScaleFactor);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ testPoint = gfx::Point(34, 34);
+ testPoint = testPoint.Scale(deviceScaleFactor);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ testPoint = gfx::Point(65, 65);
+ testPoint = testPoint.Scale(deviceScaleFactor);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ EXPECT_FALSE(resultLayer);
+
+ testPoint = gfx::Point(74, 74);
+ testPoint = testPoint.Scale(deviceScaleFactor);
+ 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(35, 35);
+ testPoint = testPoint.Scale(deviceScaleFactor);
+ resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(testPoint, renderSurfaceLayerList);
+ ASSERT_TRUE(resultLayer);
+ EXPECT_EQ(12345, resultLayer->id());
+
+ testPoint = gfx::Point(64, 64);
+ testPoint = testPoint.Scale(deviceScaleFactor);
+ 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(35, 35);
+ 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(25, 25);
+ 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:

Powered by Google App Engine
This is Rietveld 408576698