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 "cc/trees/layer_tree_host_common.h" | 5 #include "cc/trees/layer_tree_host_common.h" |
6 | 6 |
7 #include "cc/animation/layer_animation_controller.h" | 7 #include "cc/animation/layer_animation_controller.h" |
8 #include "cc/base/math_util.h" | 8 #include "cc/base/math_util.h" |
9 #include "cc/layers/content_layer.h" | 9 #include "cc/layers/content_layer.h" |
10 #include "cc/layers/content_layer_client.h" | 10 #include "cc/layers/content_layer_client.h" |
(...skipping 5551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5562 EXPECT_EQ(3, result_layer->id()); | 5562 EXPECT_EQ(3, result_layer->id()); |
5563 | 5563 |
5564 // Hit testing for a point inside the mousewheel layer should return it. | 5564 // Hit testing for a point inside the mousewheel layer should return it. |
5565 test_point = gfx::Point(75, 75); | 5565 test_point = gfx::Point(75, 75); |
5566 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( | 5566 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
5567 test_point, render_surface_layer_list); | 5567 test_point, render_surface_layer_list); |
5568 ASSERT_TRUE(result_layer); | 5568 ASSERT_TRUE(result_layer); |
5569 EXPECT_EQ(4, result_layer->id()); | 5569 EXPECT_EQ(4, result_layer->id()); |
5570 } | 5570 } |
5571 | 5571 |
| 5572 TEST_F(LayerTreeHostCommonTest, HitTestForZeroOpacityLayers) { |
| 5573 FakeImplProxy proxy; |
| 5574 FakeLayerTreeHostImpl host_impl(&proxy); |
| 5575 const int kRootId = 1; |
| 5576 const int kTouchHandlerId = 2; |
| 5577 const int kWheelHandlerId = 3; |
| 5578 const int kNoHandlerId = 4; |
| 5579 const int kGrandChildWithEventId = 5; |
| 5580 |
| 5581 scoped_ptr<LayerImpl> root = |
| 5582 LayerImpl::Create(host_impl.active_tree(), 1); |
| 5583 gfx::Transform identity_matrix; |
| 5584 gfx::PointF anchor; |
| 5585 gfx::PointF position; |
| 5586 gfx::Size bounds(100, 100); |
| 5587 SetLayerPropertiesForTesting(root.get(), |
| 5588 identity_matrix, |
| 5589 identity_matrix, |
| 5590 anchor, |
| 5591 position, |
| 5592 bounds, |
| 5593 false); |
| 5594 root->SetDrawsContent(true); |
| 5595 |
| 5596 { |
| 5597 // Child 1 - Zero opacity, without any event handler. |
| 5598 gfx::PointF position(10.f, 10.f); |
| 5599 gfx::Size bounds(30, 30); |
| 5600 scoped_ptr<LayerImpl> child = |
| 5601 LayerImpl::Create(host_impl.active_tree(), kNoHandlerId); |
| 5602 SetLayerPropertiesForTesting(child.get(), |
| 5603 identity_matrix, |
| 5604 identity_matrix, |
| 5605 anchor, |
| 5606 position, |
| 5607 bounds, |
| 5608 false); |
| 5609 child->SetOpacity(0.f); |
| 5610 |
| 5611 // Grandchild - with a wheel handler. |
| 5612 scoped_ptr<LayerImpl> grand_child = |
| 5613 LayerImpl::Create(host_impl.active_tree(), kGrandChildWithEventId); |
| 5614 SetLayerPropertiesForTesting(grand_child.get(), |
| 5615 identity_matrix, |
| 5616 identity_matrix, |
| 5617 gfx::PointF(), |
| 5618 gfx::PointF(10, 10), |
| 5619 gfx::Size(10, 10), |
| 5620 false); |
| 5621 grand_child->SetHaveWheelEventHandlers(true); |
| 5622 child->AddChild(grand_child.Pass()); |
| 5623 root->AddChild(child.Pass()); |
| 5624 } |
| 5625 |
| 5626 { |
| 5627 // Child 2 - Zero opacity, with touch event handler. |
| 5628 gfx::PointF position(70.f, 10.f); |
| 5629 gfx::Size bounds(30, 30); |
| 5630 scoped_ptr<LayerImpl> child = |
| 5631 LayerImpl::Create(host_impl.active_tree(), kTouchHandlerId); |
| 5632 SetLayerPropertiesForTesting(child.get(), |
| 5633 identity_matrix, |
| 5634 identity_matrix, |
| 5635 anchor, |
| 5636 position, |
| 5637 bounds, |
| 5638 false); |
| 5639 child->SetOpacity(0.f); |
| 5640 child->SetTouchEventHandlerRegion(gfx::Rect(10, 10, 10, 10)); |
| 5641 root->AddChild(child.Pass()); |
| 5642 } |
| 5643 |
| 5644 { |
| 5645 // Child 3 - Zero opacity, with wheel event handler. |
| 5646 gfx::PointF position(10.f, 50.f); |
| 5647 gfx::Size bounds(30, 30); |
| 5648 scoped_ptr<LayerImpl> child = |
| 5649 LayerImpl::Create(host_impl.active_tree(), kWheelHandlerId); |
| 5650 SetLayerPropertiesForTesting(child.get(), |
| 5651 identity_matrix, |
| 5652 identity_matrix, |
| 5653 anchor, |
| 5654 position, |
| 5655 bounds, |
| 5656 false); |
| 5657 child->SetOpacity(0.f); |
| 5658 child->SetHaveWheelEventHandlers(true); |
| 5659 root->AddChild(child.Pass()); |
| 5660 } |
| 5661 |
| 5662 LayerImplList render_surface_layer_list; |
| 5663 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5664 root.get(), root->bounds(), &render_surface_layer_list); |
| 5665 inputs.can_adjust_raster_scales = true; |
| 5666 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 5667 |
| 5668 // Verify that the root layer and zero-opacity layers with touch/wheel |
| 5669 // handlers (but not the zero-opacity layer without a touch handler) are in |
| 5670 // the RSSL. |
| 5671 ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5672 EXPECT_EQ(kRootId, render_surface_layer_list[0]->id()); |
| 5673 ASSERT_EQ(4u, root->render_surface()->layer_list().size()); |
| 5674 EXPECT_EQ(kRootId, root->render_surface()->layer_list().at(0)->id()); |
| 5675 EXPECT_EQ(kGrandChildWithEventId, |
| 5676 root->render_surface()->layer_list().at(1)->id()); |
| 5677 EXPECT_EQ(kTouchHandlerId, root->render_surface()->layer_list().at(2)->id()); |
| 5678 EXPECT_EQ(kWheelHandlerId, root->render_surface()->layer_list().at(3)->id()); |
| 5679 |
| 5680 // Hit testing for a point inside the zero-opacity no-handler layer should |
| 5681 // return the root layer. |
| 5682 gfx::Point test_point = gfx::Point(15, 15); |
| 5683 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5684 test_point, render_surface_layer_list); |
| 5685 ASSERT_TRUE(result_layer); |
| 5686 EXPECT_EQ(kRootId, result_layer->id()); |
| 5687 |
| 5688 // Hit testing for a point inside the child of the zero-opacity no-handler |
| 5689 // layer should return the child layer, since that layer has mousewheel |
| 5690 // handler. |
| 5691 test_point = gfx::Point(25, 25); |
| 5692 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5693 test_point, render_surface_layer_list); |
| 5694 ASSERT_TRUE(result_layer); |
| 5695 EXPECT_EQ(kGrandChildWithEventId, result_layer->id()); |
| 5696 |
| 5697 // Hit testing for a point inside the touch handler layer should return it. |
| 5698 test_point = gfx::Point(85, 25); |
| 5699 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5700 test_point, render_surface_layer_list); |
| 5701 ASSERT_TRUE(result_layer); |
| 5702 EXPECT_EQ(kTouchHandlerId, result_layer->id()); |
| 5703 |
| 5704 // Hit testing for a point inside the mousewheel layer should return it. |
| 5705 test_point = gfx::Point(15, 55); |
| 5706 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5707 test_point, render_surface_layer_list); |
| 5708 ASSERT_TRUE(result_layer); |
| 5709 EXPECT_EQ(kWheelHandlerId, result_layer->id()); |
| 5710 } |
| 5711 |
5572 TEST_F(LayerTreeHostCommonTest, | 5712 TEST_F(LayerTreeHostCommonTest, |
5573 HitCheckingTouchHandlerRegionsForEmptyLayerList) { | 5713 HitCheckingTouchHandlerRegionsForEmptyLayerList) { |
5574 // Hit checking on an empty render_surface_layer_list should return a null | 5714 // Hit checking on an empty render_surface_layer_list should return a null |
5575 // pointer. | 5715 // pointer. |
5576 LayerImplList render_surface_layer_list; | 5716 LayerImplList render_surface_layer_list; |
5577 | 5717 |
5578 gfx::Point test_point(0, 0); | 5718 gfx::Point test_point(0, 0); |
5579 LayerImpl* result_layer = | 5719 LayerImpl* result_layer = |
5580 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( | 5720 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
5581 test_point, render_surface_layer_list); | 5721 test_point, render_surface_layer_list); |
(...skipping 3551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9133 ExecuteCalculateDrawProperties(root.get()); | 9273 ExecuteCalculateDrawProperties(root.get()); |
9134 | 9274 |
9135 EXPECT_EQ(1u, render_surface_layer_list()->size()); | 9275 EXPECT_EQ(1u, render_surface_layer_list()->size()); |
9136 EXPECT_EQ(0u, | 9276 EXPECT_EQ(0u, |
9137 render_surface_layer_list()->at(0) | 9277 render_surface_layer_list()->at(0) |
9138 ->render_surface()->layer_list().size()); | 9278 ->render_surface()->layer_list().size()); |
9139 } | 9279 } |
9140 | 9280 |
9141 } // namespace | 9281 } // namespace |
9142 } // namespace cc | 9282 } // namespace cc |
OLD | NEW |