Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/layer_tree_host_common.h" | 7 #include "cc/layer_tree_host_common.h" |
| 8 | 8 |
| 9 #include "cc/content_layer.h" | 9 #include "cc/content_layer.h" |
| 10 #include "cc/content_layer_client.h" | 10 #include "cc/content_layer_client.h" |
| (...skipping 3091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3102 | 3102 |
| 3103 { | 3103 { |
| 3104 scoped_ptr<LayerImpl> child = LayerImpl::create(456); | 3104 scoped_ptr<LayerImpl> child = LayerImpl::create(456); |
| 3105 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(789); | 3105 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(789); |
| 3106 scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(2468); | 3106 scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(2468); |
| 3107 | 3107 |
| 3108 position = gfx::PointF(10, 10); | 3108 position = gfx::PointF(10, 10); |
| 3109 bounds = gfx::Size(80, 80); | 3109 bounds = gfx::Size(80, 80); |
| 3110 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false); | 3110 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false); |
| 3111 child->setMasksToBounds(true); | 3111 child->setMasksToBounds(true); |
| 3112 | 3112 |
| 3113 WebTransformationMatrix rotation45DegreesAboutCorner; | 3113 WebTransformationMatrix rotation45DegreesAboutCorner; |
| 3114 rotation45DegreesAboutCorner.rotate3d(0, 0, 45); | 3114 rotation45DegreesAboutCorner.rotate3d(0, 0, 45); |
| 3115 | 3115 |
| 3116 position = gfx::PointF(0, 0); // remember, positioned with respect to it s parent which is already at 10, 10 | 3116 position = gfx::PointF(0, 0); // remember, positioned with respect to it s parent which is already at 10, 10 |
| 3117 bounds = gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100. | 3117 bounds = gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100. |
| 3118 setLayerPropertiesForTesting(grandChild.get(), rotation45DegreesAboutCor ner, identityMatrix, anchor, position, bounds, false); | 3118 setLayerPropertiesForTesting(grandChild.get(), rotation45DegreesAboutCor ner, identityMatrix, anchor, position, bounds, false); |
| 3119 grandChild->setMasksToBounds(true); | 3119 grandChild->setMasksToBounds(true); |
| 3120 | 3120 |
| 3121 // Rotates about the center of the layer | 3121 // Rotates about the center of the layer |
| 3122 WebTransformationMatrix rotatedLeafTransform; | 3122 WebTransformationMatrix rotatedLeafTransform; |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3456 ASSERT_TRUE(resultLayer); | 3456 ASSERT_TRUE(resultLayer); |
| 3457 EXPECT_EQ(3, resultLayer->id()); | 3457 EXPECT_EQ(3, resultLayer->id()); |
| 3458 | 3458 |
| 3459 // At (20, 51), child1 and grandChild1 overlap. grandChild1 is expected to b e on top. | 3459 // At (20, 51), child1 and grandChild1 overlap. grandChild1 is expected to b e on top. |
| 3460 testPoint = gfx::Point(20, 51); | 3460 testPoint = gfx::Point(20, 51); |
| 3461 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); | 3461 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); |
| 3462 ASSERT_TRUE(resultLayer); | 3462 ASSERT_TRUE(resultLayer); |
| 3463 EXPECT_EQ(4, resultLayer->id()); | 3463 EXPECT_EQ(4, resultLayer->id()); |
| 3464 } | 3464 } |
| 3465 | 3465 |
| 3466 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForEmptyLayerL ist) | |
| 3467 { | |
| 3468 // Hit checking on an empty renderSurfaceLayerList should return a null poin ter. | |
| 3469 DebugScopedSetImplThread thisScopeIsOnImplThread; | |
| 3470 | |
| 3471 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 3472 | |
| 3473 gfx::Point testPoint(0, 0); | |
| 3474 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTou chHandlerRegion(testPoint, renderSurfaceLayerList); | |
| 3475 EXPECT_FALSE(resultLayer); | |
| 3476 | |
| 3477 testPoint = gfx::Point(10, 20); | |
| 3478 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3479 EXPECT_FALSE(resultLayer); | |
| 3480 } | |
| 3481 | |
| 3482 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSingleLayer ) | |
| 3483 { | |
| 3484 DebugScopedSetImplThread thisScopeIsOnImplThread; | |
| 3485 | |
| 3486 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); | |
| 3487 | |
| 3488 WebTransformationMatrix identityMatrix; | |
| 3489 Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50)); | |
| 3490 gfx::PointF anchor(0, 0); | |
| 3491 gfx::PointF position(0, 0); | |
| 3492 gfx::Size bounds(100, 100); | |
| 3493 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); | |
| 3494 root->setDrawsContent(true); | |
| 3495 | |
| 3496 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 3497 int dummyMaxTextureSize = 512; | |
| 3498 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); | |
| 3499 | |
| 3500 // Sanity check the scenario we just created. | |
| 3501 ASSERT_EQ(1u, renderSurfaceLayerList.size()); | |
| 3502 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); | |
| 3503 | |
| 3504 // Hit checking for any point should return a null pointer for a layer witho ut any touch event handler regions. | |
| 3505 gfx::Point testPoint(11, 11); | |
| 3506 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTou chHandlerRegion(testPoint, renderSurfaceLayerList); | |
| 3507 EXPECT_FALSE(resultLayer); | |
| 3508 | |
| 3509 root->setTouchEventHandlerRegion(touchHandlerRegion); | |
| 3510 // Hit checking for a point outside the layer should return a null pointer. | |
| 3511 testPoint = gfx::Point(101, 101); | |
| 3512 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3513 EXPECT_FALSE(resultLayer); | |
| 3514 | |
| 3515 testPoint = gfx::Point(-1, -1); | |
| 3516 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3517 EXPECT_FALSE(resultLayer); | |
| 3518 | |
| 3519 // Hit checking for a point inside the layer, but outside the touch handler region should return a null pointer. | |
| 3520 testPoint = gfx::Point(1, 1); | |
| 3521 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3522 EXPECT_FALSE(resultLayer); | |
| 3523 | |
| 3524 testPoint = gfx::Point(99, 99); | |
| 3525 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3526 EXPECT_FALSE(resultLayer); | |
| 3527 | |
| 3528 // Hit checking for a point inside the touch event handler region should ret urn the root layer. | |
| 3529 testPoint = gfx::Point(11, 11); | |
| 3530 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3531 ASSERT_TRUE(resultLayer); | |
| 3532 EXPECT_EQ(12345, resultLayer->id()); | |
| 3533 | |
| 3534 testPoint = gfx::Point(59, 59); | |
| 3535 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3536 ASSERT_TRUE(resultLayer); | |
| 3537 EXPECT_EQ(12345, resultLayer->id()); | |
| 3538 } | |
| 3539 | |
| 3540 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForUninvertibl eTransform) | |
| 3541 { | |
| 3542 DebugScopedSetImplThread thisScopeIsOnImplThread; | |
| 3543 | |
| 3544 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); | |
| 3545 | |
| 3546 WebTransformationMatrix uninvertibleTransform; | |
| 3547 uninvertibleTransform.setM11(0); | |
| 3548 uninvertibleTransform.setM22(0); | |
| 3549 uninvertibleTransform.setM33(0); | |
| 3550 uninvertibleTransform.setM44(0); | |
| 3551 ASSERT_FALSE(uninvertibleTransform.isInvertible()); | |
| 3552 | |
| 3553 WebTransformationMatrix identityMatrix; | |
| 3554 Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50)); | |
| 3555 gfx::PointF anchor(0, 0); | |
| 3556 gfx::PointF position(0, 0); | |
| 3557 gfx::Size bounds(100, 100); | |
| 3558 setLayerPropertiesForTesting(root.get(), uninvertibleTransform, identityMatr ix, anchor, position, bounds, false); | |
| 3559 root->setDrawsContent(true); | |
| 3560 root->setTouchEventHandlerRegion(touchHandlerRegion); | |
| 3561 | |
| 3562 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 3563 int dummyMaxTextureSize = 512; | |
| 3564 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); | |
| 3565 | |
| 3566 // Sanity check the scenario we just created. | |
| 3567 ASSERT_EQ(1u, renderSurfaceLayerList.size()); | |
| 3568 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); | |
| 3569 ASSERT_FALSE(root->screenSpaceTransform().isInvertible()); | |
| 3570 | |
| 3571 // Hit checking any point should not hit the touch handler region on the lay er. If the invertible matrix is | |
| 3572 // accidentally ignored and treated like an identity, then the hit testing w ill | |
| 3573 // incorrectly hit the layer when it shouldn't. | |
| 3574 gfx::Point testPoint(1, 1); | |
| 3575 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTou chHandlerRegion(testPoint, renderSurfaceLayerList); | |
| 3576 EXPECT_FALSE(resultLayer); | |
| 3577 | |
| 3578 testPoint = gfx::Point(10, 10); | |
| 3579 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3580 EXPECT_FALSE(resultLayer); | |
| 3581 | |
| 3582 testPoint = gfx::Point(10, 30); | |
| 3583 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3584 EXPECT_FALSE(resultLayer); | |
| 3585 | |
| 3586 testPoint = gfx::Point(50, 50); | |
| 3587 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3588 EXPECT_FALSE(resultLayer); | |
| 3589 | |
| 3590 testPoint = gfx::Point(67, 48); | |
| 3591 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3592 EXPECT_FALSE(resultLayer); | |
| 3593 | |
| 3594 testPoint = gfx::Point(99, 99); | |
| 3595 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3596 EXPECT_FALSE(resultLayer); | |
| 3597 | |
| 3598 testPoint = gfx::Point(-1, -1); | |
| 3599 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3600 EXPECT_FALSE(resultLayer); | |
| 3601 } | |
| 3602 | |
| 3603 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSinglePosit ionedLayer) | |
| 3604 { | |
| 3605 DebugScopedSetImplThread thisScopeIsOnImplThread; | |
| 3606 | |
| 3607 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); | |
| 3608 | |
| 3609 WebTransformationMatrix identityMatrix; | |
| 3610 Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50)); | |
| 3611 gfx::PointF anchor(0, 0); | |
| 3612 gfx::PointF position(50, 50); // this layer is positioned, and hit testing s hould correctly know where the layer is located. | |
| 3613 gfx::Size bounds(100, 100); | |
| 3614 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); | |
| 3615 root->setDrawsContent(true); | |
| 3616 root->setTouchEventHandlerRegion(touchHandlerRegion); | |
| 3617 | |
| 3618 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 3619 int dummyMaxTextureSize = 512; | |
| 3620 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); | |
| 3621 | |
| 3622 // Sanity check the scenario we just created. | |
| 3623 ASSERT_EQ(1u, renderSurfaceLayerList.size()); | |
| 3624 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); | |
| 3625 | |
| 3626 // Hit checking for a point outside the layer should return a null pointer. | |
| 3627 gfx::Point testPoint(49, 49); | |
| 3628 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTou chHandlerRegion(testPoint, renderSurfaceLayerList); | |
| 3629 EXPECT_FALSE(resultLayer); | |
| 3630 | |
| 3631 // Even though the layer has a touch handler region containing (101, 101), i t should not be visible there since the root renderSurface would clamp it. | |
| 3632 testPoint = gfx::Point(101, 101); | |
| 3633 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3634 EXPECT_FALSE(resultLayer); | |
| 3635 | |
| 3636 // Hit checking for a point inside the layer, but outside the touch handler region should return a null pointer. | |
| 3637 testPoint = gfx::Point(51, 51); | |
| 3638 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3639 EXPECT_FALSE(resultLayer); | |
| 3640 | |
| 3641 // Hit checking for a point inside the touch event handler region should ret urn the root layer. | |
| 3642 testPoint = gfx::Point(61, 61); | |
| 3643 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3644 ASSERT_TRUE(resultLayer); | |
| 3645 EXPECT_EQ(12345, resultLayer->id()); | |
| 3646 | |
| 3647 testPoint = gfx::Point(99, 99); | |
| 3648 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3649 ASSERT_TRUE(resultLayer); | |
| 3650 EXPECT_EQ(12345, resultLayer->id()); | |
| 3651 } | |
| 3652 | |
| 3653 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSingleLayer WithScaledContents) | |
| 3654 { | |
| 3655 // A layer's visibleContentRect is actually in the layer's content space. Th e | |
| 3656 // screenSpaceTransform converts from the layer's origin space to screen spa ce. This | |
| 3657 // test makes sure that hit testing works correctly accounts for the content s scale. | |
| 3658 // A contentsScale that is not 1 effectively forces a non-identity transform between | |
| 3659 // layer's content space and layer's origin space. The hit testing code must take this into account. | |
| 3660 // | |
| 3661 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If | |
| 3662 // contentsScale is ignored, then hit checking will mis-interpret the visibl eContentRect | |
| 3663 // as being larger than the actual bounds of the layer. | |
| 3664 // | |
| 3665 DebugScopedSetImplThread thisScopeIsOnImplThread; | |
| 3666 | |
| 3667 scoped_ptr<LayerImpl> root = LayerImpl::create(1); | |
| 3668 | |
| 3669 WebTransformationMatrix identityMatrix; | |
| 3670 gfx::PointF anchor(0, 0); | |
| 3671 | |
| 3672 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false); | |
| 3673 | |
| 3674 { | |
| 3675 Region touchHandlerRegion(gfx::Rect(10, 10, 30, 30)); | |
| 3676 gfx::PointF position(25, 25); | |
| 3677 gfx::Size bounds(50, 50); | |
| 3678 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345); | |
| 3679 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa trix, anchor, position, bounds, false); | |
| 3680 | |
| 3681 // override contentBounds and contentsScale | |
| 3682 testLayer->setContentBounds(gfx::Size(100, 100)); | |
| 3683 testLayer->setContentsScale(2, 2); | |
| 3684 | |
| 3685 testLayer->setDrawsContent(true); | |
| 3686 testLayer->setTouchEventHandlerRegion(touchHandlerRegion); | |
| 3687 root->addChild(testLayer.Pass()); | |
| 3688 } | |
| 3689 | |
| 3690 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 3691 int dummyMaxTextureSize = 512; | |
| 3692 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); | |
| 3693 | |
| 3694 // Sanity check the scenario we just created. | |
| 3695 // The visibleContentRect for testLayer is actually 100x100, even though its layout size is 50x50, positioned at 25x25. | |
| 3696 LayerImpl* testLayer = root->children()[0]; | |
| 3697 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(), gfx::Size(100, 100)), testLayer->visi bleContentRect()); | |
| 3698 ASSERT_EQ(1u, renderSurfaceLayerList.size()); | |
| 3699 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); | |
| 3700 | |
| 3701 // 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). | |
| 3702 gfx::Point testPoint(76, 76); | |
| 3703 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTou chHandlerRegion(testPoint, renderSurfaceLayerList); | |
| 3704 EXPECT_FALSE(resultLayer); | |
| 3705 | |
| 3706 // Hit checking for a point inside the layer, but outside the touch handler region should return a null pointer. | |
| 3707 testPoint = gfx::Point(26, 26); | |
| 3708 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3709 EXPECT_FALSE(resultLayer); | |
| 3710 | |
| 3711 testPoint = gfx::Point(34, 34); | |
| 3712 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3713 EXPECT_FALSE(resultLayer); | |
| 3714 | |
| 3715 testPoint = gfx::Point(65, 65); | |
| 3716 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3717 EXPECT_FALSE(resultLayer); | |
| 3718 | |
| 3719 testPoint = gfx::Point(74, 74); | |
| 3720 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3721 EXPECT_FALSE(resultLayer); | |
| 3722 | |
| 3723 // Hit checking for a point inside the touch event handler region should ret urn the root layer. | |
| 3724 testPoint = gfx::Point(35, 35); | |
| 3725 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3726 ASSERT_TRUE(resultLayer); | |
| 3727 EXPECT_EQ(12345, resultLayer->id()); | |
| 3728 | |
| 3729 testPoint = gfx::Point(64, 64); | |
| 3730 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3731 ASSERT_TRUE(resultLayer); | |
| 3732 EXPECT_EQ(12345, resultLayer->id()); | |
| 3733 } | |
| 3734 | |
| 3735 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSingleLayer WithDeviceScale) | |
| 3736 { | |
| 3737 // The layer's deviceScalefactor should scale the contentRect and we should be able to hit the touch handler region | |
| 3738 // 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
| |
| 3739 DebugScopedSetImplThread thisScopeIsOnImplThread; | |
| 3740 | |
| 3741 scoped_ptr<LayerImpl> root = LayerImpl::create(1); | |
| 3742 | |
| 3743 WebTransformationMatrix identityMatrix; | |
| 3744 gfx::PointF anchor(0, 0); | |
| 3745 // Set the bounds of the root layer big enough to fit the child when scaled. | |
| 3746 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, 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.
| |
| 3747 | |
| 3748 { | |
| 3749 Region touchHandlerRegion(gfx::Rect(10, 10, 30, 30)); | |
| 3750 gfx::PointF position(25, 25); | |
| 3751 gfx::Size bounds(50, 50); | |
| 3752 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345); | |
| 3753 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa trix, anchor, position, bounds, false); | |
| 3754 | |
| 3755 testLayer->setDrawsContent(true); | |
| 3756 testLayer->setTouchEventHandlerRegion(touchHandlerRegion); | |
| 3757 root->addChild(testLayer.Pass()); | |
| 3758 } | |
| 3759 | |
| 3760 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 3761 int dummyMaxTextureSize = 512; | |
| 3762 float deviceScaleFactor = 3.0f; | |
| 3763 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
| |
| 3764 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), dev iceScaleFactor, 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
| |
| 3765 | |
| 3766 // Sanity check the scenario we just created. | |
| 3767 // 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
| |
| 3768 LayerImpl* testLayer = root->children()[0]; | |
| 3769 ASSERT_EQ(1u, renderSurfaceLayerList.size()); | |
| 3770 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); | |
| 3771 | |
| 3772 // Check whether the child layer fits into the root after scaled. | |
| 3773 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(), gfx::Size(50, 50)), testLayer->visibl eContentRect()); | |
|
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.
| |
| 3774 | |
| 3775 // 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). | |
| 3776 gfx::PointF testPoint(76, 76); | |
| 3777 testPoint = testPoint.Scale(deviceScaleFactor); | |
| 3778 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTou chHandlerRegion(testPoint, renderSurfaceLayerList); | |
| 3779 EXPECT_FALSE(resultLayer); | |
| 3780 | |
| 3781 // Hit checking for a point inside the layer, but outside the touch handler region should return a null pointer. | |
| 3782 testPoint = gfx::Point(26, 26); | |
| 3783 testPoint = testPoint.Scale(deviceScaleFactor); | |
| 3784 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3785 EXPECT_FALSE(resultLayer); | |
| 3786 | |
| 3787 testPoint = gfx::Point(34, 34); | |
| 3788 testPoint = testPoint.Scale(deviceScaleFactor); | |
| 3789 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3790 EXPECT_FALSE(resultLayer); | |
| 3791 | |
| 3792 testPoint = gfx::Point(65, 65); | |
| 3793 testPoint = testPoint.Scale(deviceScaleFactor); | |
| 3794 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3795 EXPECT_FALSE(resultLayer); | |
| 3796 | |
| 3797 testPoint = gfx::Point(74, 74); | |
| 3798 testPoint = testPoint.Scale(deviceScaleFactor); | |
| 3799 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3800 EXPECT_FALSE(resultLayer); | |
| 3801 | |
| 3802 // Hit checking for a point inside the touch event handler region should ret urn the root layer. | |
| 3803 testPoint = gfx::Point(35, 35); | |
| 3804 testPoint = testPoint.Scale(deviceScaleFactor); | |
| 3805 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3806 ASSERT_TRUE(resultLayer); | |
| 3807 EXPECT_EQ(12345, resultLayer->id()); | |
| 3808 | |
| 3809 testPoint = gfx::Point(64, 64); | |
| 3810 testPoint = testPoint.Scale(deviceScaleFactor); | |
| 3811 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3812 ASSERT_TRUE(resultLayer); | |
| 3813 EXPECT_EQ(12345, resultLayer->id()); | |
| 3814 } | |
| 3815 | |
| 3816 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSimpleClipp edLayer) | |
| 3817 { | |
| 3818 // Test that hit-checking will only work for the visible portion of a layer, and not | |
| 3819 // the entire layer bounds. Here we just test the simple axis-aligned case. | |
| 3820 DebugScopedSetImplThread thisScopeIsOnImplThread; | |
| 3821 | |
| 3822 WebTransformationMatrix identityMatrix; | |
| 3823 gfx::PointF anchor(0, 0); | |
| 3824 | |
| 3825 scoped_ptr<LayerImpl> root = LayerImpl::create(1); | |
| 3826 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false); | |
| 3827 | |
| 3828 { | |
| 3829 scoped_ptr<LayerImpl> clippingLayer = LayerImpl::create(123); | |
| 3830 gfx::PointF position(25, 25); // this layer is positioned, and hit testi ng should correctly know where the layer is located. | |
| 3831 gfx::Size bounds(50, 50); | |
| 3832 setLayerPropertiesForTesting(clippingLayer.get(), identityMatrix, identi tyMatrix, anchor, position, bounds, false); | |
| 3833 clippingLayer->setMasksToBounds(true); | |
| 3834 | |
| 3835 scoped_ptr<LayerImpl> child = LayerImpl::create(456); | |
| 3836 Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50)); | |
| 3837 position = gfx::PointF(-50, -50); | |
| 3838 bounds = gfx::Size(300, 300); | |
| 3839 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false); | |
| 3840 child->setDrawsContent(true); | |
| 3841 child->setTouchEventHandlerRegion(touchHandlerRegion); | |
| 3842 clippingLayer->addChild(child.Pass()); | |
| 3843 root->addChild(clippingLayer.Pass()); | |
| 3844 } | |
| 3845 | |
| 3846 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 3847 int dummyMaxTextureSize = 512; | |
| 3848 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); | |
| 3849 | |
| 3850 // Sanity check the scenario we just created. | |
| 3851 ASSERT_EQ(1u, renderSurfaceLayerList.size()); | |
| 3852 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); | |
| 3853 ASSERT_EQ(456, root->renderSurface()->layerList()[0]->id()); | |
| 3854 | |
| 3855 // Hit checking for a point outside the layer should return a null pointer. | |
| 3856 // Despite the child layer being very large, it should be clipped to the roo t layer's bounds. | |
| 3857 gfx::Point testPoint(24, 24); | |
| 3858 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTou chHandlerRegion(testPoint, renderSurfaceLayerList); | |
| 3859 EXPECT_FALSE(resultLayer); | |
| 3860 | |
| 3861 // Hit checking for a point inside the layer, but outside the touch handler region should return a null pointer. | |
| 3862 testPoint = gfx::Point(35, 35); | |
| 3863 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3864 EXPECT_FALSE(resultLayer); | |
| 3865 | |
| 3866 testPoint = gfx::Point(74, 74); | |
| 3867 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3868 EXPECT_FALSE(resultLayer); | |
| 3869 | |
| 3870 // Hit checking for a point inside the touch event handler region should ret urn the root layer. | |
| 3871 testPoint = gfx::Point(25, 25); | |
| 3872 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3873 ASSERT_TRUE(resultLayer); | |
| 3874 EXPECT_EQ(456, resultLayer->id()); | |
| 3875 | |
| 3876 testPoint = gfx::Point(34, 34); | |
| 3877 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); | |
| 3878 ASSERT_TRUE(resultLayer); | |
| 3879 EXPECT_EQ(456, resultLayer->id()); | |
| 3880 } | |
| 3881 | |
| 3466 class NoScaleContentLayer : public ContentLayer | 3882 class NoScaleContentLayer : public ContentLayer |
| 3467 { | 3883 { |
| 3468 public: | 3884 public: |
| 3469 static scoped_refptr<NoScaleContentLayer> create(ContentLayerClient* client) { return make_scoped_refptr(new NoScaleContentLayer(client)); } | 3885 static scoped_refptr<NoScaleContentLayer> create(ContentLayerClient* client) { return make_scoped_refptr(new NoScaleContentLayer(client)); } |
| 3470 | 3886 |
| 3471 virtual gfx::Size contentBounds() const OVERRIDE { return bounds(); } | 3887 virtual gfx::Size contentBounds() const OVERRIDE { return bounds(); } |
| 3472 virtual float contentsScaleX() const OVERRIDE { return 1.0; } | 3888 virtual float contentsScaleX() const OVERRIDE { return 1.0; } |
| 3473 virtual float contentsScaleY() const OVERRIDE { return 1.0; } | 3889 virtual float contentsScaleY() const OVERRIDE { return 1.0; } |
| 3474 | 3890 |
| 3475 protected: | 3891 protected: |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4039 int nonexistentId = -1; | 4455 int nonexistentId = -1; |
| 4040 EXPECT_EQ(root, LayerTreeHostCommon::findLayerInSubtree(root.get(), root->id ())); | 4456 EXPECT_EQ(root, LayerTreeHostCommon::findLayerInSubtree(root.get(), root->id ())); |
| 4041 EXPECT_EQ(child, LayerTreeHostCommon::findLayerInSubtree(root.get(), child-> id())); | 4457 EXPECT_EQ(child, LayerTreeHostCommon::findLayerInSubtree(root.get(), child-> id())); |
| 4042 EXPECT_EQ(grandChild, LayerTreeHostCommon::findLayerInSubtree(root.get(), gr andChild->id())); | 4458 EXPECT_EQ(grandChild, LayerTreeHostCommon::findLayerInSubtree(root.get(), gr andChild->id())); |
| 4043 EXPECT_EQ(maskLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), mas kLayer->id())); | 4459 EXPECT_EQ(maskLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), mas kLayer->id())); |
| 4044 EXPECT_EQ(replicaLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), replicaLayer->id())); | 4460 EXPECT_EQ(replicaLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), replicaLayer->id())); |
| 4045 EXPECT_EQ(0, LayerTreeHostCommon::findLayerInSubtree(root.get(), nonexistent Id)); | 4461 EXPECT_EQ(0, LayerTreeHostCommon::findLayerInSubtree(root.get(), nonexistent Id)); |
| 4046 } | 4462 } |
| 4047 | 4463 |
| 4048 } // anonymous namespace | 4464 } // anonymous namespace |
| OLD | NEW |