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

Side by Side 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: Renamed call to haveTouchEventHandlersAt 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layer_tree_host_common.cc ('k') | cc/layer_tree_host_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "cc/layer_tree_host_common.h" 5 #include "cc/layer_tree_host_common.h"
6 6
7 #include "cc/content_layer.h" 7 #include "cc/content_layer.h"
8 #include "cc/content_layer_client.h" 8 #include "cc/content_layer_client.h"
9 #include "cc/layer.h" 9 #include "cc/layer.h"
10 #include "cc/layer_animation_controller.h" 10 #include "cc/layer_animation_controller.h"
11 #include "cc/layer_impl.h" 11 #include "cc/layer_impl.h"
12 #include "cc/layer_sorter.h" 12 #include "cc/layer_sorter.h"
13 #include "cc/math_util.h" 13 #include "cc/math_util.h"
14 #include "cc/proxy.h" 14 #include "cc/proxy.h"
15 #include "cc/single_thread_proxy.h" 15 #include "cc/single_thread_proxy.h"
16 #include "cc/test/animation_test_common.h" 16 #include "cc/test/animation_test_common.h"
17 #include "cc/test/geometry_test_utils.h" 17 #include "cc/test/geometry_test_utils.h"
18 #include "cc/thread.h" 18 #include "cc/thread.h"
19 #include "ui/gfx/size_conversions.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 #include <public/WebTransformationMatrix.h> 22 #include <public/WebTransformationMatrix.h>
22 23
23 using namespace WebKitTests; 24 using namespace WebKitTests;
24 using WebKit::WebTransformationMatrix; 25 using WebKit::WebTransformationMatrix;
25 26
26 namespace cc { 27 namespace cc {
27 namespace { 28 namespace {
28 29
(...skipping 3033 matching lines...) Expand 10 before | Expand all | Expand 10 after
3062 3063
3063 { 3064 {
3064 scoped_ptr<LayerImpl> child = LayerImpl::create(456); 3065 scoped_ptr<LayerImpl> child = LayerImpl::create(456);
3065 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(789); 3066 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(789);
3066 scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(2468); 3067 scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(2468);
3067 3068
3068 position = gfx::PointF(10, 10); 3069 position = gfx::PointF(10, 10);
3069 bounds = gfx::Size(80, 80); 3070 bounds = gfx::Size(80, 80);
3070 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false); 3071 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false);
3071 child->setMasksToBounds(true); 3072 child->setMasksToBounds(true);
3072 3073
3073 WebTransformationMatrix rotation45DegreesAboutCorner; 3074 WebTransformationMatrix rotation45DegreesAboutCorner;
3074 rotation45DegreesAboutCorner.rotate3d(0, 0, 45); 3075 rotation45DegreesAboutCorner.rotate3d(0, 0, 45);
3075 3076
3076 position = gfx::PointF(0, 0); // remember, positioned with respect to it s parent which is already at 10, 10 3077 position = gfx::PointF(0, 0); // remember, positioned with respect to it s parent which is already at 10, 10
3077 bounds = gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100. 3078 bounds = gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100.
3078 setLayerPropertiesForTesting(grandChild.get(), rotation45DegreesAboutCor ner, identityMatrix, anchor, position, bounds, false); 3079 setLayerPropertiesForTesting(grandChild.get(), rotation45DegreesAboutCor ner, identityMatrix, anchor, position, bounds, false);
3079 grandChild->setMasksToBounds(true); 3080 grandChild->setMasksToBounds(true);
3080 3081
3081 // Rotates about the center of the layer 3082 // Rotates about the center of the layer
3082 WebTransformationMatrix rotatedLeafTransform; 3083 WebTransformationMatrix rotatedLeafTransform;
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
3410 ASSERT_TRUE(resultLayer); 3411 ASSERT_TRUE(resultLayer);
3411 EXPECT_EQ(3, resultLayer->id()); 3412 EXPECT_EQ(3, resultLayer->id());
3412 3413
3413 // At (20, 51), child1 and grandChild1 overlap. grandChild1 is expected to b e on top. 3414 // At (20, 51), child1 and grandChild1 overlap. grandChild1 is expected to b e on top.
3414 testPoint = gfx::Point(20, 51); 3415 testPoint = gfx::Point(20, 51);
3415 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3416 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3416 ASSERT_TRUE(resultLayer); 3417 ASSERT_TRUE(resultLayer);
3417 EXPECT_EQ(4, resultLayer->id()); 3418 EXPECT_EQ(4, resultLayer->id());
3418 } 3419 }
3419 3420
3421 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForEmptyLayerL ist)
3422 {
3423 // Hit checking on an empty renderSurfaceLayerList should return a null poin ter.
3424 std::vector<LayerImpl*> renderSurfaceLayerList;
3425
3426 gfx::Point testPoint(0, 0);
3427 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTou chHandlerRegion(testPoint, renderSurfaceLayerList);
3428 EXPECT_FALSE(resultLayer);
3429
3430 testPoint = gfx::Point(10, 20);
3431 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3432 EXPECT_FALSE(resultLayer);
3433 }
3434
3435 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSingleLayer )
3436 {
3437 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
3438
3439 WebTransformationMatrix identityMatrix;
3440 Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50));
3441 gfx::PointF anchor(0, 0);
3442 gfx::PointF position(0, 0);
3443 gfx::Size bounds(100, 100);
3444 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
3445 root->setDrawsContent(true);
3446
3447 std::vector<LayerImpl*> renderSurfaceLayerList;
3448 int dummyMaxTextureSize = 512;
3449 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
3450
3451 // Sanity check the scenario we just created.
3452 ASSERT_EQ(1u, renderSurfaceLayerList.size());
3453 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
3454
3455 // Hit checking for any point should return a null pointer for a layer witho ut any touch event handler regions.
3456 gfx::Point testPoint(11, 11);
3457 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTou chHandlerRegion(testPoint, renderSurfaceLayerList);
3458 EXPECT_FALSE(resultLayer);
3459
3460 root->setTouchEventHandlerRegion(touchHandlerRegion);
3461 // Hit checking for a point outside the layer should return a null pointer.
3462 testPoint = gfx::Point(101, 101);
3463 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3464 EXPECT_FALSE(resultLayer);
3465
3466 testPoint = gfx::Point(-1, -1);
3467 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3468 EXPECT_FALSE(resultLayer);
3469
3470 // Hit checking for a point inside the layer, but outside the touch handler region should return a null pointer.
3471 testPoint = gfx::Point(1, 1);
3472 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3473 EXPECT_FALSE(resultLayer);
3474
3475 testPoint = gfx::Point(99, 99);
3476 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3477 EXPECT_FALSE(resultLayer);
3478
3479 // Hit checking for a point inside the touch event handler region should ret urn the root layer.
3480 testPoint = gfx::Point(11, 11);
3481 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3482 ASSERT_TRUE(resultLayer);
3483 EXPECT_EQ(12345, resultLayer->id());
3484
3485 testPoint = gfx::Point(59, 59);
3486 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3487 ASSERT_TRUE(resultLayer);
3488 EXPECT_EQ(12345, resultLayer->id());
3489 }
3490
3491 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForUninvertibl eTransform)
3492 {
3493 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
3494
3495 WebTransformationMatrix uninvertibleTransform;
3496 uninvertibleTransform.setM11(0);
3497 uninvertibleTransform.setM22(0);
3498 uninvertibleTransform.setM33(0);
3499 uninvertibleTransform.setM44(0);
3500 ASSERT_FALSE(uninvertibleTransform.isInvertible());
3501
3502 WebTransformationMatrix identityMatrix;
3503 Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50));
3504 gfx::PointF anchor(0, 0);
3505 gfx::PointF position(0, 0);
3506 gfx::Size bounds(100, 100);
3507 setLayerPropertiesForTesting(root.get(), uninvertibleTransform, identityMatr ix, anchor, position, bounds, false);
3508 root->setDrawsContent(true);
3509 root->setTouchEventHandlerRegion(touchHandlerRegion);
3510
3511 std::vector<LayerImpl*> renderSurfaceLayerList;
3512 int dummyMaxTextureSize = 512;
3513 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
3514
3515 // Sanity check the scenario we just created.
3516 ASSERT_EQ(1u, renderSurfaceLayerList.size());
3517 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
3518 ASSERT_FALSE(root->screenSpaceTransform().isInvertible());
3519
3520 // Hit checking any point should not hit the touch handler region on the lay er. If the invertible matrix is
3521 // accidentally ignored and treated like an identity, then the hit testing w ill
3522 // incorrectly hit the layer when it shouldn't.
3523 gfx::Point testPoint(1, 1);
3524 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTou chHandlerRegion(testPoint, renderSurfaceLayerList);
3525 EXPECT_FALSE(resultLayer);
3526
3527 testPoint = gfx::Point(10, 10);
3528 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3529 EXPECT_FALSE(resultLayer);
3530
3531 testPoint = gfx::Point(10, 30);
3532 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3533 EXPECT_FALSE(resultLayer);
3534
3535 testPoint = gfx::Point(50, 50);
3536 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3537 EXPECT_FALSE(resultLayer);
3538
3539 testPoint = gfx::Point(67, 48);
3540 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3541 EXPECT_FALSE(resultLayer);
3542
3543 testPoint = gfx::Point(99, 99);
3544 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3545 EXPECT_FALSE(resultLayer);
3546
3547 testPoint = gfx::Point(-1, -1);
3548 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3549 EXPECT_FALSE(resultLayer);
3550 }
3551
3552 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSinglePosit ionedLayer)
3553 {
3554 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
3555
3556 WebTransformationMatrix identityMatrix;
3557 Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50));
3558 gfx::PointF anchor(0, 0);
3559 gfx::PointF position(50, 50); // this layer is positioned, and hit testing s hould correctly know where the layer is located.
3560 gfx::Size bounds(100, 100);
3561 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
3562 root->setDrawsContent(true);
3563 root->setTouchEventHandlerRegion(touchHandlerRegion);
3564
3565 std::vector<LayerImpl*> renderSurfaceLayerList;
3566 int dummyMaxTextureSize = 512;
3567 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
3568
3569 // Sanity check the scenario we just created.
3570 ASSERT_EQ(1u, renderSurfaceLayerList.size());
3571 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
3572
3573 // Hit checking for a point outside the layer should return a null pointer.
3574 gfx::Point testPoint(49, 49);
3575 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTou chHandlerRegion(testPoint, renderSurfaceLayerList);
3576 EXPECT_FALSE(resultLayer);
3577
3578 // 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.
3579 testPoint = gfx::Point(101, 101);
3580 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3581 EXPECT_FALSE(resultLayer);
3582
3583 // Hit checking for a point inside the layer, but outside the touch handler region should return a null pointer.
3584 testPoint = gfx::Point(51, 51);
3585 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3586 EXPECT_FALSE(resultLayer);
3587
3588 // Hit checking for a point inside the touch event handler region should ret urn the root layer.
3589 testPoint = gfx::Point(61, 61);
3590 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3591 ASSERT_TRUE(resultLayer);
3592 EXPECT_EQ(12345, resultLayer->id());
3593
3594 testPoint = gfx::Point(99, 99);
3595 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3596 ASSERT_TRUE(resultLayer);
3597 EXPECT_EQ(12345, resultLayer->id());
3598 }
3599
3600 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSingleLayer WithScaledContents)
3601 {
3602 // A layer's visibleContentRect is actually in the layer's content space. Th e
3603 // screenSpaceTransform converts from the layer's origin space to screen spa ce. This
3604 // test makes sure that hit testing works correctly accounts for the content s scale.
3605 // A contentsScale that is not 1 effectively forces a non-identity transform between
3606 // layer's content space and layer's origin space. The hit testing code must take this into account.
3607 //
3608 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
3609 // contentsScale is ignored, then hit checking will mis-interpret the visibl eContentRect
3610 // as being larger than the actual bounds of the layer.
3611 //
3612 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
3613
3614 WebTransformationMatrix identityMatrix;
3615 gfx::PointF anchor(0, 0);
3616
3617 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
3618
3619 {
3620 Region touchHandlerRegion(gfx::Rect(10, 10, 30, 30));
3621 gfx::PointF position(25, 25);
3622 gfx::Size bounds(50, 50);
3623 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345);
3624 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa trix, anchor, position, bounds, false);
3625
3626 // override contentBounds and contentsScale
3627 testLayer->setContentBounds(gfx::Size(100, 100));
3628 testLayer->setContentsScale(2, 2);
3629
3630 testLayer->setDrawsContent(true);
3631 testLayer->setTouchEventHandlerRegion(touchHandlerRegion);
3632 root->addChild(testLayer.Pass());
3633 }
3634
3635 std::vector<LayerImpl*> renderSurfaceLayerList;
3636 int dummyMaxTextureSize = 512;
3637 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
3638
3639 // Sanity check the scenario we just created.
3640 // The visibleContentRect for testLayer is actually 100x100, even though its layout size is 50x50, positioned at 25x25.
3641 LayerImpl* testLayer = root->children()[0];
3642 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(), gfx::Size(100, 100)), testLayer->visi bleContentRect());
3643 ASSERT_EQ(1u, renderSurfaceLayerList.size());
3644 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
3645
3646 // 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).
3647 gfx::Point testPoint(76, 76);
3648 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTou chHandlerRegion(testPoint, renderSurfaceLayerList);
3649 EXPECT_FALSE(resultLayer);
3650
3651 // Hit checking for a point inside the layer, but outside the touch handler region should return a null pointer.
3652 testPoint = gfx::Point(26, 26);
3653 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3654 EXPECT_FALSE(resultLayer);
3655
3656 testPoint = gfx::Point(34, 34);
3657 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3658 EXPECT_FALSE(resultLayer);
3659
3660 testPoint = gfx::Point(65, 65);
3661 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3662 EXPECT_FALSE(resultLayer);
3663
3664 testPoint = gfx::Point(74, 74);
3665 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3666 EXPECT_FALSE(resultLayer);
3667
3668 // Hit checking for a point inside the touch event handler region should ret urn the root layer.
3669 testPoint = gfx::Point(35, 35);
3670 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3671 ASSERT_TRUE(resultLayer);
3672 EXPECT_EQ(12345, resultLayer->id());
3673
3674 testPoint = gfx::Point(64, 64);
3675 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3676 ASSERT_TRUE(resultLayer);
3677 EXPECT_EQ(12345, resultLayer->id());
3678 }
3679
3680 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSingleLayer WithDeviceScale)
3681 {
3682 // The layer's deviceScalefactor and pageScaleFactor should scale the conten tRect and we should
3683 // be able to hit the touch handler region by scaling the points accordingly .
3684 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
3685
3686 WebTransformationMatrix identityMatrix;
3687 gfx::PointF anchor(0, 0);
3688 // Set the bounds of the root layer big enough to fit the child when scaled.
3689 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
3690
3691 {
3692 Region touchHandlerRegion(gfx::Rect(10, 10, 30, 30));
3693 gfx::PointF position(25, 25);
3694 gfx::Size bounds(50, 50);
3695 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345);
3696 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa trix, anchor, position, bounds, false);
3697
3698 testLayer->setDrawsContent(true);
3699 testLayer->setTouchEventHandlerRegion(touchHandlerRegion);
3700 root->addChild(testLayer.Pass());
3701 }
3702
3703 std::vector<LayerImpl*> renderSurfaceLayerList;
3704 int dummyMaxTextureSize = 512;
3705 float deviceScaleFactor = 3.0f;
3706 float pageScaleFactor = 5.0f;
3707 WebTransformationMatrix pageScaleTransform;
3708 pageScaleTransform.scale(pageScaleFactor);
3709 root->setImplTransform(pageScaleTransform); // Applying the pageScaleFactor through implTransform.
3710 gfx::Size scaledBoundsForRoot = gfx::ToCeiledSize(gfx::ScaleSize(root->bound s(), deviceScaleFactor * pageScaleFactor));
3711 LayerTreeHostCommon::calculateDrawTransforms(root.get(), scaledBoundsForRoot , deviceScaleFactor, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
3712
3713 // Sanity check the scenario we just created.
3714 // The visibleContentRect for testLayer is actually 100x100, even though its layout size is 50x50, positioned at 25x25.
3715 LayerImpl* testLayer = root->children()[0];
3716 ASSERT_EQ(1u, renderSurfaceLayerList.size());
3717 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
3718
3719 // Check whether the child layer fits into the root after scaled.
3720 EXPECT_RECT_EQ(gfx::Rect(testLayer->contentBounds()), testLayer->visibleCont entRect());;
3721
3722 // 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).
3723 gfx::PointF testPoint(76, 76);
3724 testPoint = gfx::ScalePoint(testPoint, deviceScaleFactor * pageScaleFactor);
3725 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTou chHandlerRegion(testPoint, renderSurfaceLayerList);
3726 EXPECT_FALSE(resultLayer);
3727
3728 // Hit checking for a point inside the layer, but outside the touch handler region should return a null pointer.
3729 testPoint = gfx::Point(26, 26);
3730 testPoint = gfx::ScalePoint(testPoint, deviceScaleFactor * pageScaleFactor);
3731 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3732 EXPECT_FALSE(resultLayer);
3733
3734 testPoint = gfx::Point(34, 34);
3735 testPoint = gfx::ScalePoint(testPoint, deviceScaleFactor * pageScaleFactor);
3736 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3737 EXPECT_FALSE(resultLayer);
3738
3739 testPoint = gfx::Point(65, 65);
3740 testPoint = gfx::ScalePoint(testPoint, deviceScaleFactor * pageScaleFactor);
3741 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3742 EXPECT_FALSE(resultLayer);
3743
3744 testPoint = gfx::Point(74, 74);
3745 testPoint = gfx::ScalePoint(testPoint, deviceScaleFactor * pageScaleFactor);
3746 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3747 EXPECT_FALSE(resultLayer);
3748
3749 // Hit checking for a point inside the touch event handler region should ret urn the root layer.
3750 testPoint = gfx::Point(35, 35);
3751 testPoint = gfx::ScalePoint(testPoint, deviceScaleFactor * pageScaleFactor);
3752 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3753 ASSERT_TRUE(resultLayer);
3754 EXPECT_EQ(12345, resultLayer->id());
3755
3756 testPoint = gfx::Point(64, 64);
3757 testPoint = gfx::ScalePoint(testPoint, deviceScaleFactor * pageScaleFactor);
3758 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3759 ASSERT_TRUE(resultLayer);
3760 EXPECT_EQ(12345, resultLayer->id());
3761 }
3762
3763 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSimpleClipp edLayer)
3764 {
3765 // Test that hit-checking will only work for the visible portion of a layer, and not
3766 // the entire layer bounds. Here we just test the simple axis-aligned case.
3767 WebTransformationMatrix identityMatrix;
3768 gfx::PointF anchor(0, 0);
3769
3770 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
3771 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
3772
3773 {
3774 scoped_ptr<LayerImpl> clippingLayer = LayerImpl::create(123);
3775 gfx::PointF position(25, 25); // this layer is positioned, and hit testi ng should correctly know where the layer is located.
3776 gfx::Size bounds(50, 50);
3777 setLayerPropertiesForTesting(clippingLayer.get(), identityMatrix, identi tyMatrix, anchor, position, bounds, false);
3778 clippingLayer->setMasksToBounds(true);
3779
3780 scoped_ptr<LayerImpl> child = LayerImpl::create(456);
3781 Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50));
3782 position = gfx::PointF(-50, -50);
3783 bounds = gfx::Size(300, 300);
3784 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false);
3785 child->setDrawsContent(true);
3786 child->setTouchEventHandlerRegion(touchHandlerRegion);
3787 clippingLayer->addChild(child.Pass());
3788 root->addChild(clippingLayer.Pass());
3789 }
3790
3791 std::vector<LayerImpl*> renderSurfaceLayerList;
3792 int dummyMaxTextureSize = 512;
3793 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
3794
3795 // Sanity check the scenario we just created.
3796 ASSERT_EQ(1u, renderSurfaceLayerList.size());
3797 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
3798 ASSERT_EQ(456, root->renderSurface()->layerList()[0]->id());
3799
3800 // Hit checking for a point outside the layer should return a null pointer.
3801 // Despite the child layer being very large, it should be clipped to the roo t layer's bounds.
3802 gfx::Point testPoint(24, 24);
3803 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTou chHandlerRegion(testPoint, renderSurfaceLayerList);
3804 EXPECT_FALSE(resultLayer);
3805
3806 // Hit checking for a point inside the layer, but outside the touch handler region should return a null pointer.
3807 testPoint = gfx::Point(35, 35);
3808 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3809 EXPECT_FALSE(resultLayer);
3810
3811 testPoint = gfx::Point(74, 74);
3812 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3813 EXPECT_FALSE(resultLayer);
3814
3815 // Hit checking for a point inside the touch event handler region should ret urn the root layer.
3816 testPoint = gfx::Point(25, 25);
3817 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3818 ASSERT_TRUE(resultLayer);
3819 EXPECT_EQ(456, resultLayer->id());
3820
3821 testPoint = gfx::Point(34, 34);
3822 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3823 ASSERT_TRUE(resultLayer);
3824 EXPECT_EQ(456, resultLayer->id());
3825 }
3826
3420 class NoScaleContentLayer : public ContentLayer 3827 class NoScaleContentLayer : public ContentLayer
3421 { 3828 {
3422 public: 3829 public:
3423 static scoped_refptr<NoScaleContentLayer> create(ContentLayerClient* client) { return make_scoped_refptr(new NoScaleContentLayer(client)); } 3830 static scoped_refptr<NoScaleContentLayer> create(ContentLayerClient* client) { return make_scoped_refptr(new NoScaleContentLayer(client)); }
3424 3831
3425 virtual gfx::Size contentBounds() const OVERRIDE { return bounds(); } 3832 virtual gfx::Size contentBounds() const OVERRIDE { return bounds(); }
3426 virtual float contentsScaleX() const OVERRIDE { return 1.0; } 3833 virtual float contentsScaleX() const OVERRIDE { return 1.0; }
3427 virtual float contentsScaleY() const OVERRIDE { return 1.0; } 3834 virtual float contentsScaleY() const OVERRIDE { return 1.0; }
3428 3835
3429 protected: 3836 protected:
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
4092 EXPECT_EQ(root, LayerTreeHostCommon::findLayerInSubtree(root.get(), root->id ())); 4499 EXPECT_EQ(root, LayerTreeHostCommon::findLayerInSubtree(root.get(), root->id ()));
4093 EXPECT_EQ(child, LayerTreeHostCommon::findLayerInSubtree(root.get(), child-> id())); 4500 EXPECT_EQ(child, LayerTreeHostCommon::findLayerInSubtree(root.get(), child-> id()));
4094 EXPECT_EQ(grandChild, LayerTreeHostCommon::findLayerInSubtree(root.get(), gr andChild->id())); 4501 EXPECT_EQ(grandChild, LayerTreeHostCommon::findLayerInSubtree(root.get(), gr andChild->id()));
4095 EXPECT_EQ(maskLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), mas kLayer->id())); 4502 EXPECT_EQ(maskLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), mas kLayer->id()));
4096 EXPECT_EQ(replicaLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), replicaLayer->id())); 4503 EXPECT_EQ(replicaLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), replicaLayer->id()));
4097 EXPECT_EQ(0, LayerTreeHostCommon::findLayerInSubtree(root.get(), nonexistent Id)); 4504 EXPECT_EQ(0, LayerTreeHostCommon::findLayerInSubtree(root.get(), nonexistent Id));
4098 } 4505 }
4099 4506
4100 } // namespace 4507 } // namespace
4101 } // namespace cc 4508 } // namespace cc
OLDNEW
« 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