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

Side by Side Diff: cc/trees/layer_tree_impl_unittest.cc

Issue 1917043002: cc: Fix sublayer scale bug in hit testing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months 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
« cc/trees/layer_tree_impl.cc ('K') | « cc/trees/layer_tree_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1877 matching lines...) Expand 10 before | Expand all | Expand 10 after
1888 EXPECT_EQ(456, result_layer->id()); 1888 EXPECT_EQ(456, result_layer->id());
1889 1889
1890 test_point = gfx::PointF(34.f, 34.f); 1890 test_point = gfx::PointF(34.f, 34.f);
1891 result_layer = 1891 result_layer =
1892 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1892 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1893 test_point); 1893 test_point);
1894 ASSERT_TRUE(result_layer); 1894 ASSERT_TRUE(result_layer);
1895 EXPECT_EQ(456, result_layer->id()); 1895 EXPECT_EQ(456, result_layer->id());
1896 } 1896 }
1897 1897
1898 TEST_F(LayerTreeImplTest,
1899 HitCheckingTouchHandlerRegionsForClippedLayerWithDeviceScale) {
1900 // The layer's device_scale_factor and page_scale_factor should scale the
1901 // content rect and we should be able to hit the touch handler region by
1902 // scaling the points accordingly.
1903 std::unique_ptr<LayerImpl> root =
1904 LayerImpl::Create(host_impl().active_tree(), 1);
1905
1906 gfx::Transform identity_matrix;
1907 gfx::Point3F transform_origin;
1908 // Set the bounds of the root layer big enough to fit the child when scaled.
1909 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin,
1910 gfx::PointF(), gfx::Size(100, 100), true, false,
1911 true);
1912 std::unique_ptr<LayerImpl> surface =
1913 LayerImpl::Create(host_impl().active_tree(), 2);
1914 SetLayerPropertiesForTesting(surface.get(), identity_matrix, transform_origin,
1915 gfx::PointF(), gfx::Size(100, 100), true, false,
1916 true);
1917 {
1918 std::unique_ptr<LayerImpl> clipping_layer =
1919 LayerImpl::Create(host_impl().active_tree(), 123);
1920 // This layer is positioned, and hit testing should correctly know where the
1921 // layer is located.
1922 gfx::PointF position(25.f, 20.f);
1923 gfx::Size bounds(50, 50);
1924 SetLayerPropertiesForTesting(clipping_layer.get(), identity_matrix,
1925 transform_origin, position, bounds, true,
1926 false, false);
1927 clipping_layer->SetMasksToBounds(true);
1928
1929 std::unique_ptr<LayerImpl> child =
1930 LayerImpl::Create(host_impl().active_tree(), 456);
1931 Region touch_handler_region(gfx::Rect(0, 0, 300, 300));
1932 position = gfx::PointF(-50.f, -50.f);
1933 bounds = gfx::Size(300, 300);
1934 SetLayerPropertiesForTesting(child.get(), identity_matrix, transform_origin,
1935 position, bounds, true, false, false);
1936 child->SetDrawsContent(true);
1937 child->SetTouchEventHandlerRegion(touch_handler_region);
1938 clipping_layer->AddChild(std::move(child));
1939 surface->AddChild(std::move(clipping_layer));
1940 root->AddChild(std::move(surface));
1941 }
1942
1943 float device_scale_factor = 3.f;
1944 float page_scale_factor = 1.f;
1945 float max_page_scale_factor = 1.f;
1946 gfx::Size scaled_bounds_for_root = gfx::ScaleToCeiledSize(
1947 root->bounds(), device_scale_factor * page_scale_factor);
1948 host_impl().SetViewportSize(scaled_bounds_for_root);
1949
1950 host_impl().active_tree()->SetDeviceScaleFactor(device_scale_factor);
1951 host_impl().active_tree()->SetRootLayer(std::move(root));
1952 host_impl().active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 1,
1953 Layer::INVALID_ID);
1954 host_impl().active_tree()->BuildPropertyTreesForTesting();
1955 host_impl().active_tree()->PushPageScaleFromMainThread(
1956 page_scale_factor, page_scale_factor, max_page_scale_factor);
1957 host_impl().active_tree()->SetPageScaleOnActiveTree(page_scale_factor);
1958 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1959
1960 // Sanity check the scenario we just created.
1961 ASSERT_EQ(2u, RenderSurfaceLayerList().size());
1962
1963 // Hit checking for a point outside the layer should return a null pointer.
1964 // Despite the child layer being very large, it should be clipped to the root
1965 // layer's bounds.
1966 gfx::PointF test_point(24.f, 24.f);
1967 test_point =
1968 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
1969 LayerImpl* result_layer =
1970 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1971 test_point);
1972 EXPECT_FALSE(result_layer);
1973
1974 // Hit checking for a point inside the touch event handler region should
1975 // return the child layer.
1976 test_point = gfx::PointF(25.f, 25.f);
1977 test_point =
1978 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
1979 result_layer =
1980 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1981 test_point);
1982 ASSERT_TRUE(result_layer);
1983 EXPECT_EQ(456, result_layer->id());
1984 }
1985
1898 TEST_F(LayerTreeImplTest, HitCheckingTouchHandlerOverlappingRegions) { 1986 TEST_F(LayerTreeImplTest, HitCheckingTouchHandlerOverlappingRegions) {
1899 gfx::Transform identity_matrix; 1987 gfx::Transform identity_matrix;
1900 gfx::Point3F transform_origin; 1988 gfx::Point3F transform_origin;
1901 1989
1902 std::unique_ptr<LayerImpl> root = 1990 std::unique_ptr<LayerImpl> root =
1903 LayerImpl::Create(host_impl().active_tree(), 1); 1991 LayerImpl::Create(host_impl().active_tree(), 1);
1904 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, 1992 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin,
1905 gfx::PointF(), gfx::Size(100, 100), true, false, 1993 gfx::PointF(), gfx::Size(100, 100), true, false,
1906 true); 1994 true);
1907 { 1995 {
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
2453 gfx::PointF test_point = gfx::PointF(1.f, 1.f); 2541 gfx::PointF test_point = gfx::PointF(1.f, 1.f);
2454 LayerImpl* result_layer = 2542 LayerImpl* result_layer =
2455 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 2543 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
2456 2544
2457 CHECK(result_layer); 2545 CHECK(result_layer);
2458 EXPECT_EQ(2, result_layer->id()); 2546 EXPECT_EQ(2, result_layer->id());
2459 } 2547 }
2460 2548
2461 } // namespace 2549 } // namespace
2462 } // namespace cc 2550 } // namespace cc
OLDNEW
« cc/trees/layer_tree_impl.cc ('K') | « cc/trees/layer_tree_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698