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

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

Issue 2251303003: Implement position: sticky updates on compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with master and add comments to WebLayerStickyPositionConstraint members. Created 4 years, 3 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
« no previous file with comments | « cc/proto/property_tree.proto ('k') | cc/trees/property_tree.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6888 matching lines...) Expand 10 before | Expand all | Expand 10 after
6899 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, 6899 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation,
6900 scroller_impl->ScreenSpaceTransform().To2dTranslation()); 6900 scroller_impl->ScreenSpaceTransform().To2dTranslation());
6901 6901
6902 gfx::Transform expected_scroll_child_screen_space_transform; 6902 gfx::Transform expected_scroll_child_screen_space_transform;
6903 expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f); 6903 expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f);
6904 expected_scroll_child_screen_space_transform.RotateAboutYAxis(30); 6904 expected_scroll_child_screen_space_transform.RotateAboutYAxis(30);
6905 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform, 6905 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform,
6906 scroll_child_impl->ScreenSpaceTransform()); 6906 scroll_child_impl->ScreenSpaceTransform());
6907 } 6907 }
6908 6908
6909 TEST_F(LayerTreeHostCommonTest, StickyPositionTop) {
6910 scoped_refptr<Layer> root = Layer::Create();
6911 scoped_refptr<Layer> container = Layer::Create();
6912 scoped_refptr<Layer> scroller = Layer::Create();
6913 scoped_refptr<Layer> sticky_pos = Layer::Create();
6914 root->AddChild(container);
6915 container->AddChild(scroller);
6916 scroller->AddChild(sticky_pos);
6917 host()->SetRootLayer(root);
6918 scroller->SetScrollClipLayerId(container->id());
6919
6920 LayerStickyPositionConstraint sticky_position;
6921 sticky_position.is_sticky = true;
6922 sticky_position.is_anchored_top = true;
6923 sticky_position.top_offset = 10.0f;
6924 sticky_position.scroll_container_relative_sticky_box_rect =
6925 gfx::Rect(10, 20, 10, 10);
6926 sticky_position.scroll_container_relative_containing_block_rect =
6927 gfx::Rect(0, 0, 50, 50);
6928 sticky_pos->SetStickyPositionConstraint(sticky_position);
6929
6930 root->SetBounds(gfx::Size(100, 100));
6931 container->SetBounds(gfx::Size(100, 100));
6932 scroller->SetBounds(gfx::Size(1000, 1000));
6933 sticky_pos->SetBounds(gfx::Size(10, 10));
6934 sticky_pos->SetPosition(gfx::PointF(10, 20));
6935
6936 ExecuteCalculateDrawProperties(root.get());
6937 host()->host_impl()->CreatePendingTree();
6938 host()->CommitAndCreatePendingTree();
6939 host()->host_impl()->ActivateSyncTree();
6940 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6941
6942 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6943 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6944 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6945
6946 ExecuteCalculateDrawProperties(root_impl);
6947 EXPECT_VECTOR2DF_EQ(
6948 gfx::Vector2dF(10.f, 20.f),
6949 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6950
6951 // Scroll less than sticking point, sticky element should move with scroll as
6952 // we haven't gotten to the initial sticky item location yet.
6953 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f));
6954 ExecuteCalculateDrawProperties(root_impl);
6955 EXPECT_VECTOR2DF_EQ(
6956 gfx::Vector2dF(5.f, 15.f),
6957 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6958
6959 // Scroll past the sticking point, the Y coordinate should now be clamped.
6960 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f));
6961 ExecuteCalculateDrawProperties(root_impl);
6962 EXPECT_VECTOR2DF_EQ(
6963 gfx::Vector2dF(-5.f, 10.f),
6964 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6965 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f));
6966 ExecuteCalculateDrawProperties(root_impl);
6967 EXPECT_VECTOR2DF_EQ(
6968 gfx::Vector2dF(-5.f, 10.f),
6969 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6970
6971 // Scroll past the end of the sticky container (note: this element does not
6972 // have its own layer as it does not need to be composited).
6973 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f));
6974 ExecuteCalculateDrawProperties(root_impl);
6975 EXPECT_VECTOR2DF_EQ(
6976 gfx::Vector2dF(-5.f, -10.f),
6977 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6978 }
6979
6980 TEST_F(LayerTreeHostCommonTest, StickyPositionBottom) {
6981 scoped_refptr<Layer> root = Layer::Create();
6982 scoped_refptr<Layer> container = Layer::Create();
6983 scoped_refptr<Layer> scroller = Layer::Create();
6984 scoped_refptr<Layer> sticky_pos = Layer::Create();
6985 root->AddChild(container);
6986 container->AddChild(scroller);
6987 scroller->AddChild(sticky_pos);
6988 host()->SetRootLayer(root);
6989 scroller->SetScrollClipLayerId(container->id());
6990
6991 LayerStickyPositionConstraint sticky_position;
6992 sticky_position.is_sticky = true;
6993 sticky_position.is_anchored_bottom = true;
6994 sticky_position.bottom_offset = 10.0f;
6995 sticky_position.scroll_container_relative_sticky_box_rect =
6996 gfx::Rect(0, 150, 10, 10);
6997 sticky_position.scroll_container_relative_containing_block_rect =
6998 gfx::Rect(0, 100, 50, 50);
6999 sticky_pos->SetStickyPositionConstraint(sticky_position);
7000
7001 root->SetBounds(gfx::Size(100, 100));
7002 container->SetBounds(gfx::Size(100, 100));
7003 scroller->SetBounds(gfx::Size(1000, 1000));
7004 sticky_pos->SetBounds(gfx::Size(10, 10));
7005 sticky_pos->SetPosition(gfx::PointF(0, 150));
7006
7007 ExecuteCalculateDrawProperties(root.get());
7008 host()->host_impl()->CreatePendingTree();
7009 host()->CommitAndCreatePendingTree();
7010 host()->host_impl()->ActivateSyncTree();
7011 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7012
7013 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7014 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7015 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7016
7017 // Initially the sticky element is moved up to the top of the container.
7018 ExecuteCalculateDrawProperties(root_impl);
7019 EXPECT_VECTOR2DF_EQ(
7020 gfx::Vector2dF(0.f, 100.f),
7021 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7022 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
7023 ExecuteCalculateDrawProperties(root_impl);
7024 EXPECT_VECTOR2DF_EQ(
7025 gfx::Vector2dF(0.f, 95.f),
7026 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7027
7028 // Once we get past the top of the container it moves to be aligned 10px
7029 // up from the the bottom of the scroller.
7030 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7031 ExecuteCalculateDrawProperties(root_impl);
7032 EXPECT_VECTOR2DF_EQ(
7033 gfx::Vector2dF(0.f, 80.f),
7034 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7035 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7036 ExecuteCalculateDrawProperties(root_impl);
7037 EXPECT_VECTOR2DF_EQ(
7038 gfx::Vector2dF(0.f, 80.f),
7039 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7040
7041 // Once we scroll past its initial location, it sticks there.
7042 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 150.f));
7043 ExecuteCalculateDrawProperties(root_impl);
7044 EXPECT_VECTOR2DF_EQ(
7045 gfx::Vector2dF(0.f, 0.f),
7046 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7047 }
7048
7049 TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) {
7050 scoped_refptr<Layer> root = Layer::Create();
7051 scoped_refptr<Layer> container = Layer::Create();
7052 scoped_refptr<Layer> scroller = Layer::Create();
7053 scoped_refptr<Layer> sticky_pos = Layer::Create();
7054 root->AddChild(container);
7055 container->AddChild(scroller);
7056 scroller->AddChild(sticky_pos);
7057 host()->SetRootLayer(root);
7058 scroller->SetScrollClipLayerId(container->id());
7059
7060 LayerStickyPositionConstraint sticky_position;
7061 sticky_position.is_sticky = true;
7062 sticky_position.is_anchored_left = true;
7063 sticky_position.is_anchored_right = true;
7064 sticky_position.left_offset = 10.f;
7065 sticky_position.right_offset = 10.f;
7066 sticky_position.scroll_container_relative_sticky_box_rect =
7067 gfx::Rect(145, 0, 10, 10);
7068 sticky_position.scroll_container_relative_containing_block_rect =
7069 gfx::Rect(100, 0, 100, 100);
7070 sticky_pos->SetStickyPositionConstraint(sticky_position);
7071
7072 root->SetBounds(gfx::Size(100, 100));
7073 container->SetBounds(gfx::Size(100, 100));
7074 scroller->SetBounds(gfx::Size(1000, 1000));
7075 sticky_pos->SetBounds(gfx::Size(10, 10));
7076 sticky_pos->SetPosition(gfx::PointF(145, 0));
7077
7078 ExecuteCalculateDrawProperties(root.get());
7079 host()->host_impl()->CreatePendingTree();
7080 host()->CommitAndCreatePendingTree();
7081 host()->host_impl()->ActivateSyncTree();
7082 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7083
7084 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7085 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7086 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7087
7088 // Initially the sticky element is moved the leftmost side of the container.
7089 ExecuteCalculateDrawProperties(root_impl);
7090 EXPECT_VECTOR2DF_EQ(
7091 gfx::Vector2dF(100.f, 0.f),
7092 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7093 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 0.f));
7094 ExecuteCalculateDrawProperties(root_impl);
7095 EXPECT_VECTOR2DF_EQ(
7096 gfx::Vector2dF(95.f, 0.f),
7097 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7098
7099 // Once we get past the left side of the container it moves to be aligned 10px
7100 // up from the the right of the scroller.
7101 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(25.f, 0.f));
7102 ExecuteCalculateDrawProperties(root_impl);
7103 EXPECT_VECTOR2DF_EQ(
7104 gfx::Vector2dF(80.f, 0.f),
7105 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7106 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(30.f, 0.f));
7107 ExecuteCalculateDrawProperties(root_impl);
7108 EXPECT_VECTOR2DF_EQ(
7109 gfx::Vector2dF(80.f, 0.f),
7110 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7111
7112 // When we get to the sticky element's original position we stop sticking
7113 // to the right.
7114 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(95.f, 0.f));
7115 ExecuteCalculateDrawProperties(root_impl);
7116 EXPECT_VECTOR2DF_EQ(
7117 gfx::Vector2dF(50.f, 0.f),
7118 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7119 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(105.f, 0.f));
7120 ExecuteCalculateDrawProperties(root_impl);
7121 EXPECT_VECTOR2DF_EQ(
7122 gfx::Vector2dF(40.f, 0.f),
7123 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7124
7125 // The element starts sticking to the left once we scroll far enough.
7126 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(150.f, 0.f));
7127 ExecuteCalculateDrawProperties(root_impl);
7128 EXPECT_VECTOR2DF_EQ(
7129 gfx::Vector2dF(10.f, 0.f),
7130 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7131 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(155.f, 0.f));
7132 ExecuteCalculateDrawProperties(root_impl);
7133 EXPECT_VECTOR2DF_EQ(
7134 gfx::Vector2dF(10.f, 0.f),
7135 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7136
7137 // Finally it stops sticking when it hits the right side of the container.
7138 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(190.f, 0.f));
7139 ExecuteCalculateDrawProperties(root_impl);
7140 EXPECT_VECTOR2DF_EQ(
7141 gfx::Vector2dF(0.f, 0.f),
7142 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7143 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(195.f, 0.f));
7144 ExecuteCalculateDrawProperties(root_impl);
7145 EXPECT_VECTOR2DF_EQ(
7146 gfx::Vector2dF(-5.f, 0.f),
7147 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7148 }
7149
7150 // This test ensures that the compositor sticky position code correctly accounts
7151 // for the element having been given a position from the main thread sticky
7152 // position code.
7153 TEST_F(LayerTreeHostCommonTest, StickyPositionMainThreadUpdates) {
7154 scoped_refptr<Layer> root = Layer::Create();
7155 scoped_refptr<Layer> container = Layer::Create();
7156 scoped_refptr<Layer> scroller = Layer::Create();
7157 scoped_refptr<Layer> sticky_pos = Layer::Create();
7158 root->AddChild(container);
7159 container->AddChild(scroller);
7160 scroller->AddChild(sticky_pos);
7161 host()->SetRootLayer(root);
7162 scroller->SetScrollClipLayerId(container->id());
7163
7164 LayerStickyPositionConstraint sticky_position;
7165 sticky_position.is_sticky = true;
7166 sticky_position.is_anchored_top = true;
7167 sticky_position.top_offset = 10.0f;
7168 sticky_position.scroll_container_relative_sticky_box_rect =
7169 gfx::Rect(10, 20, 10, 10);
7170 sticky_position.scroll_container_relative_containing_block_rect =
7171 gfx::Rect(0, 0, 50, 50);
7172 sticky_pos->SetStickyPositionConstraint(sticky_position);
7173
7174 root->SetBounds(gfx::Size(100, 100));
7175 container->SetBounds(gfx::Size(100, 100));
7176 scroller->SetBounds(gfx::Size(1000, 1000));
7177 sticky_pos->SetBounds(gfx::Size(10, 10));
7178 sticky_pos->SetPosition(gfx::PointF(10, 20));
7179
7180 ExecuteCalculateDrawProperties(root.get());
7181 host()->host_impl()->CreatePendingTree();
7182 host()->CommitAndCreatePendingTree();
7183 host()->host_impl()->ActivateSyncTree();
7184 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7185
7186 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7187 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7188 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7189
7190 ExecuteCalculateDrawProperties(root_impl);
7191 EXPECT_VECTOR2DF_EQ(
7192 gfx::Vector2dF(10.f, 20.f),
7193 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7194
7195 // Scroll less than sticking point, sticky element should move with scroll as
7196 // we haven't gotten to the initial sticky item location yet.
7197 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f));
7198 ExecuteCalculateDrawProperties(root_impl);
7199 EXPECT_VECTOR2DF_EQ(
7200 gfx::Vector2dF(5.f, 15.f),
7201 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7202
7203 // Scroll past the sticking point, the Y coordinate should now be clamped.
7204 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f));
7205 ExecuteCalculateDrawProperties(root_impl);
7206 EXPECT_VECTOR2DF_EQ(
7207 gfx::Vector2dF(-5.f, 10.f),
7208 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7209
7210 // Now the main thread commits the new position of the sticky element.
7211 scroller->SetScrollOffset(gfx::ScrollOffset(15, 15));
7212 sticky_pos->SetPosition(gfx::PointF(10, 25));
7213 ExecuteCalculateDrawProperties(root.get());
7214 host()->host_impl()->CreatePendingTree();
7215 host()->CommitAndCreatePendingTree();
7216 host()->host_impl()->ActivateSyncTree();
7217 layer_tree_impl = host()->host_impl()->active_tree();
7218 root_impl = layer_tree_impl->LayerById(root->id());
7219 scroller_impl = layer_tree_impl->LayerById(scroller->id());
7220 sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7221
7222 // The element should still be where it was before. We reset the delta to
7223 // (0, 0) because we have synced a scroll offset of (15, 15) from the main
7224 // thread.
7225 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f));
7226 ExecuteCalculateDrawProperties(root_impl);
7227 EXPECT_VECTOR2DF_EQ(
7228 gfx::Vector2dF(-5.f, 10.f),
7229 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7230
7231 // And if we scroll a little further it remains there.
7232 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f));
7233 ExecuteCalculateDrawProperties(root_impl);
7234 EXPECT_VECTOR2DF_EQ(
7235 gfx::Vector2dF(-5.f, 10.f),
7236 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7237 }
7238
7239 // A transform on a sticky element should not affect its sticky position.
7240 TEST_F(LayerTreeHostCommonTest, StickyPositionScaledStickyBox) {
7241 scoped_refptr<Layer> root = Layer::Create();
7242 scoped_refptr<Layer> container = Layer::Create();
7243 scoped_refptr<Layer> scroller = Layer::Create();
7244 scoped_refptr<Layer> sticky_pos = Layer::Create();
7245 root->AddChild(container);
7246 container->AddChild(scroller);
7247 scroller->AddChild(sticky_pos);
7248 host()->SetRootLayer(root);
7249 scroller->SetScrollClipLayerId(container->id());
7250 gfx::Transform t;
7251 t.Scale(2, 2);
7252 sticky_pos->SetTransform(t);
7253
7254 LayerStickyPositionConstraint sticky_position;
7255 sticky_position.is_sticky = true;
7256 sticky_position.is_anchored_top = true;
7257 sticky_position.top_offset = 0.0f;
7258 sticky_position.scroll_container_relative_sticky_box_rect =
7259 gfx::Rect(0, 20, 10, 10);
7260 sticky_position.scroll_container_relative_containing_block_rect =
7261 gfx::Rect(0, 0, 50, 50);
7262 sticky_pos->SetStickyPositionConstraint(sticky_position);
7263
7264 root->SetBounds(gfx::Size(100, 100));
7265 container->SetBounds(gfx::Size(100, 100));
7266 scroller->SetBounds(gfx::Size(1000, 1000));
7267 sticky_pos->SetBounds(gfx::Size(10, 10));
7268 sticky_pos->SetPosition(gfx::PointF(0, 20));
7269
7270 ExecuteCalculateDrawProperties(root.get());
7271 host()->host_impl()->CreatePendingTree();
7272 host()->CommitAndCreatePendingTree();
7273 host()->host_impl()->ActivateSyncTree();
7274 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7275
7276 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7277 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7278 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7279
7280 ExecuteCalculateDrawProperties(root_impl);
7281 EXPECT_VECTOR2DF_EQ(
7282 gfx::Vector2dF(0.f, 20.f),
7283 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7284
7285 // Scroll less than sticking point, sticky element should move with scroll as
7286 // we haven't gotten to the initial sticky item location yet.
7287 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f));
7288 ExecuteCalculateDrawProperties(root_impl);
7289 EXPECT_VECTOR2DF_EQ(
7290 gfx::Vector2dF(0.f, 5.f),
7291 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7292
7293 // Scroll past the sticking point, the box is positioned at the scroller
7294 // edge.
7295 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7296 ExecuteCalculateDrawProperties(root_impl);
7297 EXPECT_VECTOR2DF_EQ(
7298 gfx::Vector2dF(0.f, 0.f),
7299 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7300 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7301 ExecuteCalculateDrawProperties(root_impl);
7302 EXPECT_VECTOR2DF_EQ(
7303 gfx::Vector2dF(0.f, 0.f),
7304 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7305
7306 // Scroll past the end of the sticky container.
7307 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f));
7308 ExecuteCalculateDrawProperties(root_impl);
7309 EXPECT_VECTOR2DF_EQ(
7310 gfx::Vector2dF(0.f, -10.f),
7311 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7312 }
7313
7314 // Tests that a transform does not affect the sticking points. The sticky
7315 // element will however move relative to the viewport due to its transform.
7316 TEST_F(LayerTreeHostCommonTest, StickyPositionScaledContainer) {
7317 scoped_refptr<Layer> root = Layer::Create();
7318 scoped_refptr<Layer> container = Layer::Create();
7319 scoped_refptr<Layer> scroller = Layer::Create();
7320 scoped_refptr<Layer> sticky_container = Layer::Create();
7321 scoped_refptr<Layer> sticky_pos = Layer::Create();
7322 root->AddChild(container);
7323 container->AddChild(scroller);
7324 scroller->AddChild(sticky_container);
7325 sticky_container->AddChild(sticky_pos);
7326 host()->SetRootLayer(root);
7327 scroller->SetScrollClipLayerId(container->id());
7328 gfx::Transform t;
7329 t.Scale(2, 2);
7330 sticky_container->SetTransform(t);
7331
7332 LayerStickyPositionConstraint sticky_position;
7333 sticky_position.is_sticky = true;
7334 sticky_position.is_anchored_top = true;
7335 sticky_position.top_offset = 0.0f;
7336 sticky_position.scroll_container_relative_sticky_box_rect =
7337 gfx::Rect(0, 20, 10, 10);
7338 sticky_position.scroll_container_relative_containing_block_rect =
7339 gfx::Rect(0, 0, 50, 50);
7340 sticky_pos->SetStickyPositionConstraint(sticky_position);
7341
7342 root->SetBounds(gfx::Size(100, 100));
7343 container->SetBounds(gfx::Size(100, 100));
7344 scroller->SetBounds(gfx::Size(1000, 1000));
7345 sticky_container->SetBounds(gfx::Size(50, 50));
7346 sticky_pos->SetBounds(gfx::Size(10, 10));
7347 sticky_pos->SetPosition(gfx::PointF(0, 20));
7348
7349 ExecuteCalculateDrawProperties(root.get());
7350 host()->host_impl()->CreatePendingTree();
7351 host()->CommitAndCreatePendingTree();
7352 host()->host_impl()->ActivateSyncTree();
7353 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7354
7355 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7356 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7357 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7358
7359 ExecuteCalculateDrawProperties(root_impl);
7360 EXPECT_VECTOR2DF_EQ(
7361 gfx::Vector2dF(0.f, 40.f),
7362 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7363
7364 // Scroll less than sticking point, sticky element should move with scroll as
7365 // we haven't gotten to the initial sticky item location yet.
7366 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f));
7367 ExecuteCalculateDrawProperties(root_impl);
7368 EXPECT_VECTOR2DF_EQ(
7369 gfx::Vector2dF(0.f, 25.f),
7370 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7371
7372 // Scroll past the sticking point, the box is positioned at the scroller
7373 // edge but is also scaled by its container so it begins to move down.
7374 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7375 ExecuteCalculateDrawProperties(root_impl);
7376 EXPECT_VECTOR2DF_EQ(
7377 gfx::Vector2dF(0.f, 25.f),
7378 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7379 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7380 ExecuteCalculateDrawProperties(root_impl);
7381 EXPECT_VECTOR2DF_EQ(
7382 gfx::Vector2dF(0.f, 30.f),
7383 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7384
7385 // Scroll past the end of the sticky container.
7386 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f));
7387 ExecuteCalculateDrawProperties(root_impl);
7388 EXPECT_VECTOR2DF_EQ(
7389 gfx::Vector2dF(0.f, 30.f),
7390 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7391 }
7392
6909 TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) { 7393 TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) {
6910 scoped_refptr<Layer> root = Layer::Create(); 7394 scoped_refptr<Layer> root = Layer::Create();
6911 scoped_refptr<Layer> container = Layer::Create(); 7395 scoped_refptr<Layer> container = Layer::Create();
6912 scoped_refptr<Layer> scroller = Layer::Create(); 7396 scoped_refptr<Layer> scroller = Layer::Create();
6913 scoped_refptr<Layer> fixed_pos = Layer::Create(); 7397 scoped_refptr<Layer> fixed_pos = Layer::Create();
6914 7398
6915 scroller->SetIsContainerForFixedPositionLayers(true); 7399 scroller->SetIsContainerForFixedPositionLayers(true);
6916 root->AddChild(container); 7400 root->AddChild(container);
6917 container->AddChild(scroller); 7401 container->AddChild(scroller);
6918 scroller->AddChild(fixed_pos); 7402 scroller->AddChild(fixed_pos);
(...skipping 2920 matching lines...) Expand 10 before | Expand all | Expand 10 after
9839 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); 10323 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index());
9840 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); 10324 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index());
9841 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); 10325 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index());
9842 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); 10326 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index());
9843 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); 10327 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index());
9844 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); 10328 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index());
9845 } 10329 }
9846 10330
9847 } // namespace 10331 } // namespace
9848 } // namespace cc 10332 } // namespace cc
OLDNEW
« no previous file with comments | « cc/proto/property_tree.proto ('k') | cc/trees/property_tree.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698