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 "cc/trees/layer_tree_host_common.h" | 5 #include "cc/trees/layer_tree_host_common.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 6897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6908 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, | 6908 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, |
| 6909 scroller_impl->ScreenSpaceTransform().To2dTranslation()); | 6909 scroller_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6910 | 6910 |
| 6911 gfx::Transform expected_scroll_child_screen_space_transform; | 6911 gfx::Transform expected_scroll_child_screen_space_transform; |
| 6912 expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f); | 6912 expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f); |
| 6913 expected_scroll_child_screen_space_transform.RotateAboutYAxis(30); | 6913 expected_scroll_child_screen_space_transform.RotateAboutYAxis(30); |
| 6914 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform, | 6914 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform, |
| 6915 scroll_child_impl->ScreenSpaceTransform()); | 6915 scroll_child_impl->ScreenSpaceTransform()); |
| 6916 } | 6916 } |
| 6917 | 6917 |
| 6918 TEST_F(LayerTreeHostCommonTest, StickyPosition) { | |
| 6919 scoped_refptr<Layer> root = Layer::Create(); | |
| 6920 scoped_refptr<Layer> container = Layer::Create(); | |
| 6921 scoped_refptr<Layer> scroller = Layer::Create(); | |
| 6922 scoped_refptr<Layer> sticky_pos = Layer::Create(); | |
| 6923 root->AddChild(container); | |
| 6924 container->AddChild(scroller); | |
| 6925 scroller->AddChild(sticky_pos); | |
| 6926 host()->SetRootLayer(root); | |
| 6927 scroller->SetScrollClipLayerId(container->id()); | |
| 6928 | |
| 6929 LayerStickyPositionConstraint sticky_position; | |
| 6930 sticky_position.is_sticky = true; | |
| 6931 sticky_position.is_anchored_top = true; | |
| 6932 sticky_position.top_offset = 10.0f; | |
| 6933 sticky_position.absolute_sticky_box_rect = gfx::Rect(10, 20, 10, 10); | |
| 6934 sticky_position.absolute_containing_block_rect = gfx::Rect(0, 0, 50, 50); | |
|
ajuma
2016/09/08 22:08:53
Please also include tests that use the other stick
flackr
2016/09/20 17:08:47
Done.
| |
| 6935 sticky_pos->SetStickyPositionConstraint(sticky_position); | |
| 6936 | |
| 6937 root->SetBounds(gfx::Size(100, 100)); | |
| 6938 container->SetBounds(gfx::Size(100, 100)); | |
| 6939 scroller->SetBounds(gfx::Size(1000, 1000)); | |
| 6940 sticky_pos->SetBounds(gfx::Size(10, 10)); | |
| 6941 sticky_pos->SetPosition(gfx::PointF(10, 20)); | |
| 6942 | |
| 6943 ExecuteCalculateDrawProperties(root.get()); | |
| 6944 host()->host_impl()->CreatePendingTree(); | |
| 6945 host()->CommitAndCreatePendingTree(); | |
| 6946 host()->host_impl()->ActivateSyncTree(); | |
| 6947 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); | |
| 6948 | |
| 6949 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); | |
| 6950 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); | |
| 6951 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); | |
| 6952 | |
| 6953 ExecuteCalculateDrawProperties(root_impl); | |
| 6954 EXPECT_VECTOR2DF_EQ( | |
| 6955 gfx::Vector2dF(10.f, 20.f), | |
| 6956 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | |
| 6957 | |
| 6958 // Scroll less than sticking point, sticky element should move with scroll as | |
| 6959 // we haven't gotten to the initial sticky item location yet. | |
| 6960 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f)); | |
| 6961 ExecuteCalculateDrawProperties(root_impl); | |
| 6962 EXPECT_VECTOR2DF_EQ( | |
| 6963 gfx::Vector2dF(5.f, 15.f), | |
| 6964 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | |
| 6965 | |
| 6966 // Scroll past the sticking point, the Y coordinate should now be clamped. | |
| 6967 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f)); | |
| 6968 ExecuteCalculateDrawProperties(root_impl); | |
| 6969 EXPECT_VECTOR2DF_EQ( | |
| 6970 gfx::Vector2dF(-5.f, 10.f), | |
| 6971 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | |
| 6972 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f)); | |
| 6973 ExecuteCalculateDrawProperties(root_impl); | |
| 6974 EXPECT_VECTOR2DF_EQ( | |
| 6975 gfx::Vector2dF(-5.f, 10.f), | |
| 6976 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | |
| 6977 | |
| 6978 // Scroll past the end of the sticky container (note: this element does not | |
| 6979 // have its own layer as it does not need to be composited). | |
| 6980 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f)); | |
| 6981 ExecuteCalculateDrawProperties(root_impl); | |
| 6982 EXPECT_VECTOR2DF_EQ( | |
| 6983 gfx::Vector2dF(-5.f, -10.f), | |
| 6984 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | |
| 6985 } | |
| 6986 | |
| 6918 TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) { | 6987 TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) { |
| 6919 scoped_refptr<Layer> root = Layer::Create(); | 6988 scoped_refptr<Layer> root = Layer::Create(); |
| 6920 scoped_refptr<Layer> container = Layer::Create(); | 6989 scoped_refptr<Layer> container = Layer::Create(); |
| 6921 scoped_refptr<Layer> scroller = Layer::Create(); | 6990 scoped_refptr<Layer> scroller = Layer::Create(); |
| 6922 scoped_refptr<Layer> fixed_pos = Layer::Create(); | 6991 scoped_refptr<Layer> fixed_pos = Layer::Create(); |
| 6923 | 6992 |
| 6924 scroller->SetIsContainerForFixedPositionLayers(true); | 6993 scroller->SetIsContainerForFixedPositionLayers(true); |
| 6925 root->AddChild(container); | 6994 root->AddChild(container); |
| 6926 container->AddChild(scroller); | 6995 container->AddChild(scroller); |
| 6927 scroller->AddChild(fixed_pos); | 6996 scroller->AddChild(fixed_pos); |
| (...skipping 2891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9819 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); | 9888 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 9820 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); | 9889 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 9821 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); | 9890 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 9822 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); | 9891 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 9823 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); | 9892 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 9824 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); | 9893 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 9825 } | 9894 } |
| 9826 | 9895 |
| 9827 } // namespace | 9896 } // namespace |
| 9828 } // namespace cc | 9897 } // namespace cc |
| OLD | NEW |