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

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

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

Powered by Google App Engine
This is Rietveld 408576698