| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_impl.h" | 5 #include "cc/trees/layer_tree_impl.h" |
| 6 | 6 |
| 7 #include "cc/layers/heads_up_display_layer_impl.h" | 7 #include "cc/layers/heads_up_display_layer_impl.h" |
| 8 #include "cc/layers/layer.h" | 8 #include "cc/layers/layer.h" |
| 9 #include "cc/layers/solid_color_scrollbar_layer_impl.h" | 9 #include "cc/layers/solid_color_scrollbar_layer_impl.h" |
| 10 #include "cc/test/fake_impl_task_runner_provider.h" | 10 #include "cc/test/fake_impl_task_runner_provider.h" |
| (...skipping 1860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1871 EXPECT_EQ(456, result_layer->id()); | 1871 EXPECT_EQ(456, result_layer->id()); |
| 1872 | 1872 |
| 1873 test_point = gfx::PointF(34.f, 34.f); | 1873 test_point = gfx::PointF(34.f, 34.f); |
| 1874 result_layer = | 1874 result_layer = |
| 1875 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( | 1875 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 1876 test_point); | 1876 test_point); |
| 1877 ASSERT_TRUE(result_layer); | 1877 ASSERT_TRUE(result_layer); |
| 1878 EXPECT_EQ(456, result_layer->id()); | 1878 EXPECT_EQ(456, result_layer->id()); |
| 1879 } | 1879 } |
| 1880 | 1880 |
| 1881 TEST_F(LayerTreeImplTest, |
| 1882 HitCheckingTouchHandlerRegionsForClippedLayerWithDeviceScale) { |
| 1883 // The layer's device_scale_factor and page_scale_factor should scale the |
| 1884 // content rect and we should be able to hit the touch handler region by |
| 1885 // scaling the points accordingly. |
| 1886 std::unique_ptr<LayerImpl> root = |
| 1887 LayerImpl::Create(host_impl().active_tree(), 1); |
| 1888 |
| 1889 gfx::Transform identity_matrix; |
| 1890 gfx::Point3F transform_origin; |
| 1891 // Set the bounds of the root layer big enough to fit the child when scaled. |
| 1892 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, |
| 1893 gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1894 true); |
| 1895 std::unique_ptr<LayerImpl> surface = |
| 1896 LayerImpl::Create(host_impl().active_tree(), 2); |
| 1897 SetLayerPropertiesForTesting(surface.get(), identity_matrix, transform_origin, |
| 1898 gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1899 true); |
| 1900 { |
| 1901 std::unique_ptr<LayerImpl> clipping_layer = |
| 1902 LayerImpl::Create(host_impl().active_tree(), 123); |
| 1903 // This layer is positioned, and hit testing should correctly know where the |
| 1904 // layer is located. |
| 1905 gfx::PointF position(25.f, 20.f); |
| 1906 gfx::Size bounds(50, 50); |
| 1907 SetLayerPropertiesForTesting(clipping_layer.get(), identity_matrix, |
| 1908 transform_origin, position, bounds, true, |
| 1909 false, false); |
| 1910 clipping_layer->SetMasksToBounds(true); |
| 1911 |
| 1912 std::unique_ptr<LayerImpl> child = |
| 1913 LayerImpl::Create(host_impl().active_tree(), 456); |
| 1914 Region touch_handler_region(gfx::Rect(0, 0, 300, 300)); |
| 1915 position = gfx::PointF(-50.f, -50.f); |
| 1916 bounds = gfx::Size(300, 300); |
| 1917 SetLayerPropertiesForTesting(child.get(), identity_matrix, transform_origin, |
| 1918 position, bounds, true, false, false); |
| 1919 child->SetDrawsContent(true); |
| 1920 child->SetTouchEventHandlerRegion(touch_handler_region); |
| 1921 clipping_layer->AddChild(std::move(child)); |
| 1922 surface->AddChild(std::move(clipping_layer)); |
| 1923 root->AddChild(std::move(surface)); |
| 1924 } |
| 1925 |
| 1926 float device_scale_factor = 3.f; |
| 1927 float page_scale_factor = 1.f; |
| 1928 float max_page_scale_factor = 1.f; |
| 1929 gfx::Size scaled_bounds_for_root = gfx::ScaleToCeiledSize( |
| 1930 root->bounds(), device_scale_factor * page_scale_factor); |
| 1931 host_impl().SetViewportSize(scaled_bounds_for_root); |
| 1932 |
| 1933 host_impl().active_tree()->SetDeviceScaleFactor(device_scale_factor); |
| 1934 host_impl().active_tree()->SetRootLayer(std::move(root)); |
| 1935 host_impl().active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 1, |
| 1936 Layer::INVALID_ID); |
| 1937 host_impl().active_tree()->BuildPropertyTreesForTesting(); |
| 1938 host_impl().active_tree()->PushPageScaleFromMainThread( |
| 1939 page_scale_factor, page_scale_factor, max_page_scale_factor); |
| 1940 host_impl().active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
| 1941 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| 1942 |
| 1943 // Sanity check the scenario we just created. |
| 1944 ASSERT_EQ(2u, RenderSurfaceLayerList().size()); |
| 1945 |
| 1946 // Hit checking for a point outside the layer should return a null pointer. |
| 1947 // Despite the child layer being very large, it should be clipped to the root |
| 1948 // layer's bounds. |
| 1949 gfx::PointF test_point(24.f, 24.f); |
| 1950 test_point = |
| 1951 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 1952 LayerImpl* result_layer = |
| 1953 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 1954 test_point); |
| 1955 EXPECT_FALSE(result_layer); |
| 1956 |
| 1957 // Hit checking for a point inside the touch event handler region should |
| 1958 // return the child layer. |
| 1959 test_point = gfx::PointF(25.f, 25.f); |
| 1960 test_point = |
| 1961 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 1962 result_layer = |
| 1963 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 1964 test_point); |
| 1965 ASSERT_TRUE(result_layer); |
| 1966 EXPECT_EQ(456, result_layer->id()); |
| 1967 } |
| 1968 |
| 1881 TEST_F(LayerTreeImplTest, HitCheckingTouchHandlerOverlappingRegions) { | 1969 TEST_F(LayerTreeImplTest, HitCheckingTouchHandlerOverlappingRegions) { |
| 1882 gfx::Transform identity_matrix; | 1970 gfx::Transform identity_matrix; |
| 1883 gfx::Point3F transform_origin; | 1971 gfx::Point3F transform_origin; |
| 1884 | 1972 |
| 1885 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 1); | 1973 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 1); |
| 1886 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, | 1974 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, |
| 1887 gfx::PointF(), gfx::Size(100, 100), true, false, | 1975 gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1888 true); | 1976 true); |
| 1889 { | 1977 { |
| 1890 scoped_ptr<LayerImpl> touch_layer = | 1978 scoped_ptr<LayerImpl> touch_layer = |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2431 gfx::PointF test_point = gfx::PointF(1.f, 1.f); | 2519 gfx::PointF test_point = gfx::PointF(1.f, 1.f); |
| 2432 LayerImpl* result_layer = | 2520 LayerImpl* result_layer = |
| 2433 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); | 2521 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); |
| 2434 | 2522 |
| 2435 CHECK(result_layer); | 2523 CHECK(result_layer); |
| 2436 EXPECT_EQ(2, result_layer->id()); | 2524 EXPECT_EQ(2, result_layer->id()); |
| 2437 } | 2525 } |
| 2438 | 2526 |
| 2439 } // namespace | 2527 } // namespace |
| 2440 } // namespace cc | 2528 } // namespace cc |
| OLD | NEW |