| 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 6884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6895 | 6895 |
| 6896 // Scroll past the end of the sticky container (note: this element does not | 6896 // Scroll past the end of the sticky container (note: this element does not |
| 6897 // have its own layer as it does not need to be composited). | 6897 // have its own layer as it does not need to be composited). |
| 6898 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f)); | 6898 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f)); |
| 6899 ExecuteCalculateDrawProperties(root_impl); | 6899 ExecuteCalculateDrawProperties(root_impl); |
| 6900 EXPECT_VECTOR2DF_EQ( | 6900 EXPECT_VECTOR2DF_EQ( |
| 6901 gfx::Vector2dF(-5.f, -10.f), | 6901 gfx::Vector2dF(-5.f, -10.f), |
| 6902 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 6902 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6903 } | 6903 } |
| 6904 | 6904 |
| 6905 TEST_F(LayerTreeHostCommonTest, StickyPositionTopScrollParent) { |
| 6906 scoped_refptr<Layer> root = Layer::Create(); |
| 6907 scoped_refptr<Layer> container = Layer::Create(); |
| 6908 scoped_refptr<Layer> scroller = Layer::Create(); |
| 6909 scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6910 root->AddChild(container); |
| 6911 container->AddChild(scroller); |
| 6912 root->AddChild(sticky_pos); |
| 6913 sticky_pos->SetScrollParent(scroller.get()); |
| 6914 host()->SetRootLayer(root); |
| 6915 scroller->SetScrollClipLayerId(container->id()); |
| 6916 |
| 6917 LayerStickyPositionConstraint sticky_position; |
| 6918 sticky_position.is_sticky = true; |
| 6919 sticky_position.is_anchored_top = true; |
| 6920 sticky_position.top_offset = 10.0f; |
| 6921 sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20); |
| 6922 sticky_position.scroll_container_relative_sticky_box_rect = |
| 6923 gfx::Rect(10, 20, 10, 10); |
| 6924 sticky_position.scroll_container_relative_containing_block_rect = |
| 6925 gfx::Rect(0, 0, 50, 50); |
| 6926 sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6927 |
| 6928 root->SetBounds(gfx::Size(200, 200)); |
| 6929 container->SetBounds(gfx::Size(100, 100)); |
| 6930 container->SetPosition(gfx::PointF(50, 50)); |
| 6931 scroller->SetBounds(gfx::Size(1000, 1000)); |
| 6932 sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6933 sticky_pos->SetPosition(gfx::PointF(60, 70)); |
| 6934 |
| 6935 ExecuteCalculateDrawProperties(root.get()); |
| 6936 host()->host_impl()->CreatePendingTree(); |
| 6937 host()->CommitAndCreatePendingTree(); |
| 6938 host()->host_impl()->ActivateSyncTree(); |
| 6939 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6940 |
| 6941 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6942 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6943 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6944 |
| 6945 ExecuteCalculateDrawProperties(root_impl); |
| 6946 EXPECT_VECTOR2DF_EQ( |
| 6947 gfx::Vector2dF(60.f, 70.f), |
| 6948 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6949 |
| 6950 // Scroll less than sticking point, sticky element should move with scroll as |
| 6951 // we haven't gotten to the initial sticky item location yet. |
| 6952 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f)); |
| 6953 ExecuteCalculateDrawProperties(root_impl); |
| 6954 EXPECT_VECTOR2DF_EQ( |
| 6955 gfx::Vector2dF(55.f, 65.f), |
| 6956 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6957 |
| 6958 // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 6959 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f)); |
| 6960 ExecuteCalculateDrawProperties(root_impl); |
| 6961 EXPECT_VECTOR2DF_EQ( |
| 6962 gfx::Vector2dF(45.f, 60.f), |
| 6963 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6964 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f)); |
| 6965 ExecuteCalculateDrawProperties(root_impl); |
| 6966 EXPECT_VECTOR2DF_EQ( |
| 6967 gfx::Vector2dF(45.f, 60.f), |
| 6968 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6969 |
| 6970 // Scroll past the end of the sticky container (note: this element does not |
| 6971 // have its own layer as it does not need to be composited). |
| 6972 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f)); |
| 6973 ExecuteCalculateDrawProperties(root_impl); |
| 6974 EXPECT_VECTOR2DF_EQ( |
| 6975 gfx::Vector2dF(45.f, 40.f), |
| 6976 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6977 } |
| 6978 |
| 6905 TEST_F(LayerTreeHostCommonTest, StickyPositionSubpixelScroll) { | 6979 TEST_F(LayerTreeHostCommonTest, StickyPositionSubpixelScroll) { |
| 6906 scoped_refptr<Layer> root = Layer::Create(); | 6980 scoped_refptr<Layer> root = Layer::Create(); |
| 6907 scoped_refptr<Layer> container = Layer::Create(); | 6981 scoped_refptr<Layer> container = Layer::Create(); |
| 6908 scoped_refptr<Layer> scroller = Layer::Create(); | 6982 scoped_refptr<Layer> scroller = Layer::Create(); |
| 6909 scoped_refptr<Layer> sticky_pos = Layer::Create(); | 6983 scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6910 root->AddChild(container); | 6984 root->AddChild(container); |
| 6911 container->AddChild(scroller); | 6985 container->AddChild(scroller); |
| 6912 scroller->AddChild(sticky_pos); | 6986 scroller->AddChild(sticky_pos); |
| 6913 host()->SetRootLayer(root); | 6987 host()->SetRootLayer(root); |
| 6914 scroller->SetScrollClipLayerId(container->id()); | 6988 scroller->SetScrollClipLayerId(container->id()); |
| (...skipping 3584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10499 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); | 10573 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 10500 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); | 10574 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 10501 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); | 10575 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 10502 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); | 10576 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 10503 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); | 10577 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 10504 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); | 10578 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 10505 } | 10579 } |
| 10506 | 10580 |
| 10507 } // namespace | 10581 } // namespace |
| 10508 } // namespace cc | 10582 } // namespace cc |
| OLD | NEW |