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

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

Issue 2733633002: Handle nested position:sticky elements correctly (compositor) (Closed)
Patch Set: Revert float changes to unittests too Created 3 years, 9 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
OLDNEW
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 7137 matching lines...) Expand 10 before | Expand all | Expand 10 after
7148 scoped_refptr<Layer> container = Layer::Create(); 7148 scoped_refptr<Layer> container = Layer::Create();
7149 scoped_refptr<Layer> scroller = Layer::Create(); 7149 scoped_refptr<Layer> scroller = Layer::Create();
7150 scoped_refptr<Layer> sticky_pos = Layer::Create(); 7150 scoped_refptr<Layer> sticky_pos = Layer::Create();
7151 root->AddChild(container); 7151 root->AddChild(container);
7152 container->AddChild(scroller); 7152 container->AddChild(scroller);
7153 root->AddChild(sticky_pos); 7153 root->AddChild(sticky_pos);
7154 sticky_pos->SetScrollParent(scroller.get()); 7154 sticky_pos->SetScrollParent(scroller.get());
7155 host()->SetRootLayer(root); 7155 host()->SetRootLayer(root);
7156 scroller->SetScrollClipLayerId(container->id()); 7156 scroller->SetScrollClipLayerId(container->id());
7157 7157
7158 // The sticky layer has already been scrolled on the main thread side, and has
7159 // stuck. This test then checks that further changes from cc-only scrolling
7160 // are handled correctly.
7158 LayerStickyPositionConstraint sticky_position; 7161 LayerStickyPositionConstraint sticky_position;
7159 sticky_position.is_sticky = true; 7162 sticky_position.is_sticky = true;
7160 sticky_position.is_anchored_top = true; 7163 sticky_position.is_anchored_top = true;
7161 sticky_position.top_offset = 10.0f; 7164 sticky_position.top_offset = 10.0f;
7162 sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20); 7165 sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20);
7163 sticky_position.scroll_container_relative_sticky_box_rect = 7166 sticky_position.scroll_container_relative_sticky_box_rect =
7164 gfx::Rect(10, 20, 10, 10); 7167 gfx::Rect(10, 20, 10, 10);
7165 sticky_position.scroll_container_relative_containing_block_rect = 7168 sticky_position.scroll_container_relative_containing_block_rect =
7166 gfx::Rect(0, 0, 50, 50); 7169 gfx::Rect(0, 0, 50, 50);
7167 sticky_pos->SetStickyPositionConstraint(sticky_position); 7170 sticky_pos->SetStickyPositionConstraint(sticky_position);
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
7925 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); 7928 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7926 7929
7927 // Scroll past the end of the sticky container. 7930 // Scroll past the end of the sticky container.
7928 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f)); 7931 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f));
7929 ExecuteCalculateDrawProperties(root_impl); 7932 ExecuteCalculateDrawProperties(root_impl);
7930 EXPECT_VECTOR2DF_EQ( 7933 EXPECT_VECTOR2DF_EQ(
7931 gfx::Vector2dF(0.f, 30.f), 7934 gfx::Vector2dF(0.f, 30.f),
7932 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); 7935 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7933 } 7936 }
7934 7937
7938 TEST_F(LayerTreeHostCommonTest, StickyPositionNested) {
7939 scoped_refptr<Layer> root = Layer::Create();
7940 scoped_refptr<Layer> container = Layer::Create();
7941 scoped_refptr<Layer> scroller = Layer::Create();
7942 scoped_refptr<Layer> outer_sticky = Layer::Create();
7943 scoped_refptr<Layer> inner_sticky = Layer::Create();
7944
7945 root->AddChild(container);
7946 container->AddChild(scroller);
7947 scroller->AddChild(outer_sticky);
7948 outer_sticky->AddChild(inner_sticky);
7949 host()->SetRootLayer(root);
7950 scroller->SetScrollClipLayerId(container->id());
7951
7952 root->SetBounds(gfx::Size(100, 100));
7953 container->SetBounds(gfx::Size(100, 100));
7954 scroller->SetBounds(gfx::Size(100, 1000));
7955 outer_sticky->SetBounds(gfx::Size(10, 50));
7956 outer_sticky->SetPosition(gfx::PointF(0, 50));
7957 inner_sticky->SetBounds(gfx::Size(10, 10));
7958 inner_sticky->SetPosition(gfx::PointF(0, 0));
7959
7960 LayerStickyPositionConstraint outer_sticky_pos;
7961 outer_sticky_pos.is_sticky = true;
7962 outer_sticky_pos.is_anchored_top = true;
7963 outer_sticky_pos.top_offset = 10.0f;
7964 outer_sticky_pos.parent_relative_sticky_box_offset = gfx::Point(0, 50);
7965 outer_sticky_pos.scroll_container_relative_sticky_box_rect =
7966 gfx::Rect(0, 50, 10, 50);
7967 outer_sticky_pos.scroll_container_relative_containing_block_rect =
7968 gfx::Rect(0, 0, 50, 400);
7969 outer_sticky->SetStickyPositionConstraint(outer_sticky_pos);
7970
7971 LayerStickyPositionConstraint inner_sticky_pos;
7972 inner_sticky_pos.is_sticky = true;
7973 inner_sticky_pos.is_anchored_top = true;
7974 inner_sticky_pos.top_offset = 25.0f;
7975 inner_sticky_pos.parent_relative_sticky_box_offset = gfx::Point(0, 0);
7976 inner_sticky_pos.scroll_container_relative_sticky_box_rect =
7977 gfx::Rect(0, 50, 10, 10);
7978 inner_sticky_pos.scroll_container_relative_containing_block_rect =
7979 gfx::Rect(0, 50, 10, 50);
7980 inner_sticky_pos.nearest_layer_shifting_containing_block = outer_sticky->id();
7981 inner_sticky->SetStickyPositionConstraint(inner_sticky_pos);
7982
7983 ExecuteCalculateDrawProperties(root.get());
7984 host()->host_impl()->CreatePendingTree();
7985 host()->CommitAndCreatePendingTree();
7986 host()->host_impl()->ActivateSyncTree();
7987 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7988
7989 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7990 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7991 LayerImpl* outer_sticky_impl = layer_tree_impl->LayerById(outer_sticky->id());
7992 LayerImpl* inner_sticky_impl = layer_tree_impl->LayerById(inner_sticky->id());
7993
7994 ExecuteCalculateDrawProperties(root_impl);
7995
7996 // Before any scrolling is done, the sticky elements should still be at their
7997 // original positions.
7998 EXPECT_VECTOR2DF_EQ(
7999 gfx::Vector2dF(0.f, 50.f),
8000 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation());
8001 EXPECT_VECTOR2DF_EQ(
8002 gfx::Vector2dF(0.f, 50.f),
8003 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation());
8004
8005 // Scroll less than the sticking point. Both sticky elements should move with
8006 // scroll as we haven't gotten to the sticky item locations yet.
8007 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
8008 ExecuteCalculateDrawProperties(root_impl);
8009 EXPECT_VECTOR2DF_EQ(
8010 gfx::Vector2dF(0.f, 45.f),
8011 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation());
8012 EXPECT_VECTOR2DF_EQ(
8013 gfx::Vector2dF(0.f, 45.f),
8014 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation());
8015
8016 // Scroll such that the inner sticky should stick, but the outer one should
8017 // keep going as it hasn't reached its position yet.
8018 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
8019 ExecuteCalculateDrawProperties(root_impl);
8020 EXPECT_VECTOR2DF_EQ(
8021 gfx::Vector2dF(0.f, 20.f),
8022 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation());
8023 EXPECT_VECTOR2DF_EQ(
8024 gfx::Vector2dF(0.f, 25.f),
8025 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation());
8026
8027 // Keep going, both should stick.
8028 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 100.f));
8029 ExecuteCalculateDrawProperties(root_impl);
8030 EXPECT_VECTOR2DF_EQ(
8031 gfx::Vector2dF(0.f, 10.f),
8032 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation());
8033 EXPECT_VECTOR2DF_EQ(
8034 gfx::Vector2dF(0.f, 25.f),
8035 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation());
8036 }
8037
7935 TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) { 8038 TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) {
7936 scoped_refptr<Layer> root = Layer::Create(); 8039 scoped_refptr<Layer> root = Layer::Create();
7937 scoped_refptr<Layer> container = Layer::Create(); 8040 scoped_refptr<Layer> container = Layer::Create();
7938 scoped_refptr<Layer> scroller = Layer::Create(); 8041 scoped_refptr<Layer> scroller = Layer::Create();
7939 scoped_refptr<Layer> fixed_pos = Layer::Create(); 8042 scoped_refptr<Layer> fixed_pos = Layer::Create();
7940 8043
7941 scroller->SetIsContainerForFixedPositionLayers(true); 8044 scroller->SetIsContainerForFixedPositionLayers(true);
7942 root->AddChild(container); 8045 root->AddChild(container);
7943 container->AddChild(scroller); 8046 container->AddChild(scroller);
7944 scroller->AddChild(fixed_pos); 8047 scroller->AddChild(fixed_pos);
(...skipping 2845 matching lines...) Expand 10 before | Expand all | Expand 10 after
10790 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); 10893 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index());
10791 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); 10894 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index());
10792 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); 10895 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index());
10793 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); 10896 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index());
10794 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); 10897 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index());
10795 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); 10898 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index());
10796 } 10899 }
10797 10900
10798 } // namespace 10901 } // namespace
10799 } // namespace cc 10902 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698