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 7897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7908 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7908 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
7909 | 7909 |
7910 // Scroll past the end of the sticky container. | 7910 // Scroll past the end of the sticky container. |
7911 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f)); | 7911 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f)); |
7912 ExecuteCalculateDrawProperties(root_impl); | 7912 ExecuteCalculateDrawProperties(root_impl); |
7913 EXPECT_VECTOR2DF_EQ( | 7913 EXPECT_VECTOR2DF_EQ( |
7914 gfx::Vector2dF(0.f, 30.f), | 7914 gfx::Vector2dF(0.f, 30.f), |
7915 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7915 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
7916 } | 7916 } |
7917 | 7917 |
| 7918 TEST_F(LayerTreeHostCommonTest, StickyPositionNested) { |
| 7919 scoped_refptr<Layer> root = Layer::Create(); |
| 7920 scoped_refptr<Layer> container = Layer::Create(); |
| 7921 scoped_refptr<Layer> scroller = Layer::Create(); |
| 7922 scoped_refptr<Layer> outer_sticky = Layer::Create(); |
| 7923 scoped_refptr<Layer> inner_sticky = Layer::Create(); |
| 7924 |
| 7925 root->AddChild(container); |
| 7926 container->AddChild(scroller); |
| 7927 scroller->AddChild(outer_sticky); |
| 7928 outer_sticky->AddChild(inner_sticky); |
| 7929 host()->SetRootLayer(root); |
| 7930 scroller->SetScrollClipLayerId(container->id()); |
| 7931 |
| 7932 root->SetBounds(gfx::Size(100, 100)); |
| 7933 container->SetBounds(gfx::Size(100, 100)); |
| 7934 scroller->SetBounds(gfx::Size(100, 1000)); |
| 7935 outer_sticky->SetBounds(gfx::Size(10, 50)); |
| 7936 outer_sticky->SetPosition(gfx::PointF(0, 50)); |
| 7937 inner_sticky->SetBounds(gfx::Size(10, 10)); |
| 7938 inner_sticky->SetPosition(gfx::PointF(0, 0)); |
| 7939 |
| 7940 LayerStickyPositionConstraint outer_sticky_pos; |
| 7941 outer_sticky_pos.is_sticky = true; |
| 7942 outer_sticky_pos.is_anchored_top = true; |
| 7943 outer_sticky_pos.top_offset = 10.0f; |
| 7944 outer_sticky_pos.parent_relative_sticky_box_offset = gfx::Point(0, 50); |
| 7945 outer_sticky_pos.scroll_container_relative_sticky_box_rect = |
| 7946 gfx::Rect(0, 50, 10, 50); |
| 7947 outer_sticky_pos.scroll_container_relative_containing_block_rect = |
| 7948 gfx::Rect(0, 0, 50, 400); |
| 7949 outer_sticky->SetStickyPositionConstraint(outer_sticky_pos); |
| 7950 |
| 7951 LayerStickyPositionConstraint inner_sticky_pos; |
| 7952 inner_sticky_pos.is_sticky = true; |
| 7953 inner_sticky_pos.is_anchored_top = true; |
| 7954 inner_sticky_pos.top_offset = 25.0f; |
| 7955 inner_sticky_pos.parent_relative_sticky_box_offset = gfx::Point(0, 0); |
| 7956 inner_sticky_pos.scroll_container_relative_sticky_box_rect = |
| 7957 gfx::Rect(0, 50, 10, 10); |
| 7958 inner_sticky_pos.scroll_container_relative_containing_block_rect = |
| 7959 gfx::Rect(0, 50, 10, 50); |
| 7960 inner_sticky_pos.nearest_layer_shifting_containing_block = outer_sticky.get(); |
| 7961 inner_sticky->SetStickyPositionConstraint(inner_sticky_pos); |
| 7962 |
| 7963 ExecuteCalculateDrawProperties(root.get()); |
| 7964 host()->host_impl()->CreatePendingTree(); |
| 7965 host()->CommitAndCreatePendingTree(); |
| 7966 host()->host_impl()->ActivateSyncTree(); |
| 7967 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7968 |
| 7969 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7970 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7971 LayerImpl* outer_sticky_impl = layer_tree_impl->LayerById(outer_sticky->id()); |
| 7972 LayerImpl* inner_sticky_impl = layer_tree_impl->LayerById(inner_sticky->id()); |
| 7973 |
| 7974 ExecuteCalculateDrawProperties(root_impl); |
| 7975 |
| 7976 // Before any scrolling is done, the sticky elements should still be at their |
| 7977 // original positions. |
| 7978 EXPECT_VECTOR2DF_EQ( |
| 7979 gfx::Vector2dF(0.f, 50.f), |
| 7980 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7981 EXPECT_VECTOR2DF_EQ( |
| 7982 gfx::Vector2dF(0.f, 50.f), |
| 7983 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7984 |
| 7985 // Scroll less than the sticking point. Both sticky elements should move with |
| 7986 // scroll as we haven't gotten to the sticky item locations yet. |
| 7987 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); |
| 7988 ExecuteCalculateDrawProperties(root_impl); |
| 7989 EXPECT_VECTOR2DF_EQ( |
| 7990 gfx::Vector2dF(0.f, 45.f), |
| 7991 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7992 EXPECT_VECTOR2DF_EQ( |
| 7993 gfx::Vector2dF(0.f, 45.f), |
| 7994 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7995 |
| 7996 // Scroll such that the inner sticky should stick, but the outer one should |
| 7997 // keep going as it hasnt reached its position yet. |
| 7998 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); |
| 7999 ExecuteCalculateDrawProperties(root_impl); |
| 8000 EXPECT_VECTOR2DF_EQ( |
| 8001 gfx::Vector2dF(0.f, 20.f), |
| 8002 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| 8003 EXPECT_VECTOR2DF_EQ( |
| 8004 gfx::Vector2dF(0.f, 25.f), |
| 8005 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| 8006 |
| 8007 // Keep going, both should stick. |
| 8008 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 100.f)); |
| 8009 ExecuteCalculateDrawProperties(root_impl); |
| 8010 EXPECT_VECTOR2DF_EQ( |
| 8011 gfx::Vector2dF(0.f, 10.f), |
| 8012 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| 8013 EXPECT_VECTOR2DF_EQ( |
| 8014 gfx::Vector2dF(0.f, 25.f), |
| 8015 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| 8016 } |
| 8017 |
7918 TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) { | 8018 TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) { |
7919 scoped_refptr<Layer> root = Layer::Create(); | 8019 scoped_refptr<Layer> root = Layer::Create(); |
7920 scoped_refptr<Layer> container = Layer::Create(); | 8020 scoped_refptr<Layer> container = Layer::Create(); |
7921 scoped_refptr<Layer> scroller = Layer::Create(); | 8021 scoped_refptr<Layer> scroller = Layer::Create(); |
7922 scoped_refptr<Layer> fixed_pos = Layer::Create(); | 8022 scoped_refptr<Layer> fixed_pos = Layer::Create(); |
7923 | 8023 |
7924 scroller->SetIsContainerForFixedPositionLayers(true); | 8024 scroller->SetIsContainerForFixedPositionLayers(true); |
7925 root->AddChild(container); | 8025 root->AddChild(container); |
7926 container->AddChild(scroller); | 8026 container->AddChild(scroller); |
7927 scroller->AddChild(fixed_pos); | 8027 scroller->AddChild(fixed_pos); |
(...skipping 2833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10761 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); | 10861 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
10762 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); | 10862 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
10763 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); | 10863 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
10764 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); | 10864 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
10765 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); | 10865 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
10766 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); | 10866 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
10767 } | 10867 } |
10768 | 10868 |
10769 } // namespace | 10869 } // namespace |
10770 } // namespace cc | 10870 } // namespace cc |
OLD | NEW |