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

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

Issue 2733633002: Handle nested position:sticky elements correctly (compositor) (Closed)
Patch Set: Use FindNodeIndexFromOwningLayerId 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 7068 matching lines...) Expand 10 before | Expand all | Expand 10 after
7079 root->AddChild(container); 7079 root->AddChild(container);
7080 container->AddChild(scroller); 7080 container->AddChild(scroller);
7081 scroller->AddChild(sticky_pos); 7081 scroller->AddChild(sticky_pos);
7082 host()->SetRootLayer(root); 7082 host()->SetRootLayer(root);
7083 scroller->SetScrollClipLayerId(container->id()); 7083 scroller->SetScrollClipLayerId(container->id());
7084 7084
7085 LayerStickyPositionConstraint sticky_position; 7085 LayerStickyPositionConstraint sticky_position;
7086 sticky_position.is_sticky = true; 7086 sticky_position.is_sticky = true;
7087 sticky_position.is_anchored_top = true; 7087 sticky_position.is_anchored_top = true;
7088 sticky_position.top_offset = 10.0f; 7088 sticky_position.top_offset = 10.0f;
7089 sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20); 7089 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(10, 20);
7090 sticky_position.scroll_container_relative_sticky_box_rect = 7090 sticky_position.scroll_container_relative_sticky_box_rect =
7091 gfx::Rect(10, 20, 10, 10); 7091 gfx::RectF(10, 20, 10, 10);
7092 sticky_position.scroll_container_relative_containing_block_rect = 7092 sticky_position.scroll_container_relative_containing_block_rect =
7093 gfx::Rect(0, 0, 50, 50); 7093 gfx::RectF(0, 0, 50, 50);
7094 sticky_pos->SetStickyPositionConstraint(sticky_position); 7094 sticky_pos->SetStickyPositionConstraint(sticky_position);
7095 7095
7096 root->SetBounds(gfx::Size(100, 100)); 7096 root->SetBounds(gfx::Size(100, 100));
7097 container->SetBounds(gfx::Size(100, 100)); 7097 container->SetBounds(gfx::Size(100, 100));
7098 scroller->SetBounds(gfx::Size(1000, 1000)); 7098 scroller->SetBounds(gfx::Size(1000, 1000));
7099 sticky_pos->SetBounds(gfx::Size(10, 10)); 7099 sticky_pos->SetBounds(gfx::Size(10, 10));
7100 sticky_pos->SetPosition(gfx::PointF(10, 20)); 7100 sticky_pos->SetPosition(gfx::PointF(10, 20));
7101 7101
7102 ExecuteCalculateDrawProperties(root.get()); 7102 ExecuteCalculateDrawProperties(root.get());
7103 host()->host_impl()->CreatePendingTree(); 7103 host()->host_impl()->CreatePendingTree();
(...skipping 44 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::PointF(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::RectF(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::RectF(0, 0, 50, 50);
7167 sticky_pos->SetStickyPositionConstraint(sticky_position); 7170 sticky_pos->SetStickyPositionConstraint(sticky_position);
7168 7171
7169 root->SetBounds(gfx::Size(200, 200)); 7172 root->SetBounds(gfx::Size(200, 200));
7170 container->SetBounds(gfx::Size(100, 100)); 7173 container->SetBounds(gfx::Size(100, 100));
7171 container->SetPosition(gfx::PointF(50, 50)); 7174 container->SetPosition(gfx::PointF(50, 50));
7172 scroller->SetBounds(gfx::Size(1000, 1000)); 7175 scroller->SetBounds(gfx::Size(1000, 1000));
7173 sticky_pos->SetBounds(gfx::Size(10, 10)); 7176 sticky_pos->SetBounds(gfx::Size(10, 10));
7174 sticky_pos->SetPosition(gfx::PointF(60, 70)); 7177 sticky_pos->SetPosition(gfx::PointF(60, 70));
7175 7178
7176 ExecuteCalculateDrawProperties(root.get()); 7179 ExecuteCalculateDrawProperties(root.get());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
7225 root->AddChild(container); 7228 root->AddChild(container);
7226 container->AddChild(scroller); 7229 container->AddChild(scroller);
7227 scroller->AddChild(sticky_pos); 7230 scroller->AddChild(sticky_pos);
7228 host()->SetRootLayer(root); 7231 host()->SetRootLayer(root);
7229 scroller->SetScrollClipLayerId(container->id()); 7232 scroller->SetScrollClipLayerId(container->id());
7230 7233
7231 LayerStickyPositionConstraint sticky_position; 7234 LayerStickyPositionConstraint sticky_position;
7232 sticky_position.is_sticky = true; 7235 sticky_position.is_sticky = true;
7233 sticky_position.is_anchored_bottom = true; 7236 sticky_position.is_anchored_bottom = true;
7234 sticky_position.bottom_offset = 10.0f; 7237 sticky_position.bottom_offset = 10.0f;
7235 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 200); 7238 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(0, 200);
7236 sticky_position.scroll_container_relative_sticky_box_rect = 7239 sticky_position.scroll_container_relative_sticky_box_rect =
7237 gfx::Rect(0, 200, 10, 10); 7240 gfx::RectF(0, 200, 10, 10);
7238 sticky_position.scroll_container_relative_containing_block_rect = 7241 sticky_position.scroll_container_relative_containing_block_rect =
7239 gfx::Rect(0, 0, 100, 500); 7242 gfx::RectF(0, 0, 100, 500);
7240 sticky_pos->SetStickyPositionConstraint(sticky_position); 7243 sticky_pos->SetStickyPositionConstraint(sticky_position);
7241 7244
7242 root->SetBounds(gfx::Size(100, 100)); 7245 root->SetBounds(gfx::Size(100, 100));
7243 container->SetBounds(gfx::Size(100, 100)); 7246 container->SetBounds(gfx::Size(100, 100));
7244 scroller->SetBounds(gfx::Size(100, 1000)); 7247 scroller->SetBounds(gfx::Size(100, 1000));
7245 sticky_pos->SetBounds(gfx::Size(10, 10)); 7248 sticky_pos->SetBounds(gfx::Size(10, 10));
7246 sticky_pos->SetPosition(gfx::PointF(0, 200)); 7249 sticky_pos->SetPosition(gfx::PointF(0, 200));
7247 7250
7248 ExecuteCalculateDrawProperties(root.get()); 7251 ExecuteCalculateDrawProperties(root.get());
7249 host()->host_impl()->CreatePendingTree(); 7252 host()->host_impl()->CreatePendingTree();
(...skipping 21 matching lines...) Expand all
7271 root->AddChild(container); 7274 root->AddChild(container);
7272 container->AddChild(scroller); 7275 container->AddChild(scroller);
7273 scroller->AddChild(sticky_pos); 7276 scroller->AddChild(sticky_pos);
7274 host()->SetRootLayer(root); 7277 host()->SetRootLayer(root);
7275 scroller->SetScrollClipLayerId(container->id()); 7278 scroller->SetScrollClipLayerId(container->id());
7276 7279
7277 LayerStickyPositionConstraint sticky_position; 7280 LayerStickyPositionConstraint sticky_position;
7278 sticky_position.is_sticky = true; 7281 sticky_position.is_sticky = true;
7279 sticky_position.is_anchored_bottom = true; 7282 sticky_position.is_anchored_bottom = true;
7280 sticky_position.bottom_offset = 10.0f; 7283 sticky_position.bottom_offset = 10.0f;
7281 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 150); 7284 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(0, 150);
7282 sticky_position.scroll_container_relative_sticky_box_rect = 7285 sticky_position.scroll_container_relative_sticky_box_rect =
7283 gfx::Rect(0, 150, 10, 10); 7286 gfx::RectF(0, 150, 10, 10);
7284 sticky_position.scroll_container_relative_containing_block_rect = 7287 sticky_position.scroll_container_relative_containing_block_rect =
7285 gfx::Rect(0, 100, 50, 50); 7288 gfx::RectF(0, 100, 50, 50);
7286 sticky_pos->SetStickyPositionConstraint(sticky_position); 7289 sticky_pos->SetStickyPositionConstraint(sticky_position);
7287 7290
7288 root->SetBounds(gfx::Size(100, 100)); 7291 root->SetBounds(gfx::Size(100, 100));
7289 container->SetBounds(gfx::Size(100, 100)); 7292 container->SetBounds(gfx::Size(100, 100));
7290 scroller->SetBounds(gfx::Size(1000, 1000)); 7293 scroller->SetBounds(gfx::Size(1000, 1000));
7291 sticky_pos->SetBounds(gfx::Size(10, 10)); 7294 sticky_pos->SetBounds(gfx::Size(10, 10));
7292 sticky_pos->SetPosition(gfx::PointF(0, 150)); 7295 sticky_pos->SetPosition(gfx::PointF(0, 150));
7293 7296
7294 ExecuteCalculateDrawProperties(root.get()); 7297 ExecuteCalculateDrawProperties(root.get());
7295 host()->host_impl()->CreatePendingTree(); 7298 host()->host_impl()->CreatePendingTree();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
7340 root->AddChild(scroller); 7343 root->AddChild(scroller);
7341 scroller->AddChild(sticky_pos); 7344 scroller->AddChild(sticky_pos);
7342 host()->SetRootLayer(root); 7345 host()->SetRootLayer(root);
7343 scroller->SetScrollClipLayerId(root->id()); 7346 scroller->SetScrollClipLayerId(root->id());
7344 host()->RegisterViewportLayers(nullptr, root, scroller, nullptr); 7347 host()->RegisterViewportLayers(nullptr, root, scroller, nullptr);
7345 7348
7346 LayerStickyPositionConstraint sticky_position; 7349 LayerStickyPositionConstraint sticky_position;
7347 sticky_position.is_sticky = true; 7350 sticky_position.is_sticky = true;
7348 sticky_position.is_anchored_bottom = true; 7351 sticky_position.is_anchored_bottom = true;
7349 sticky_position.bottom_offset = 10.0f; 7352 sticky_position.bottom_offset = 10.0f;
7350 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70); 7353 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(0, 70);
7351 sticky_position.scroll_container_relative_sticky_box_rect = 7354 sticky_position.scroll_container_relative_sticky_box_rect =
7352 gfx::Rect(0, 70, 10, 10); 7355 gfx::RectF(0, 70, 10, 10);
7353 sticky_position.scroll_container_relative_containing_block_rect = 7356 sticky_position.scroll_container_relative_containing_block_rect =
7354 gfx::Rect(0, 60, 100, 100); 7357 gfx::RectF(0, 60, 100, 100);
7355 sticky_pos->SetStickyPositionConstraint(sticky_position); 7358 sticky_pos->SetStickyPositionConstraint(sticky_position);
7356 7359
7357 root->SetBounds(gfx::Size(100, 100)); 7360 root->SetBounds(gfx::Size(100, 100));
7358 scroller->SetBounds(gfx::Size(100, 1000)); 7361 scroller->SetBounds(gfx::Size(100, 1000));
7359 sticky_pos->SetBounds(gfx::Size(10, 10)); 7362 sticky_pos->SetBounds(gfx::Size(10, 10));
7360 sticky_pos->SetPosition(gfx::PointF(0, 70)); 7363 sticky_pos->SetPosition(gfx::PointF(0, 70));
7361 7364
7362 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), 7365 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(),
7363 scroller.get(), nullptr); 7366 scroller.get(), nullptr);
7364 host()->CommitAndCreateLayerImplTree(); 7367 host()->CommitAndCreateLayerImplTree();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
7413 outer_viewport->AddChild(sticky_pos); 7416 outer_viewport->AddChild(sticky_pos);
7414 host()->SetRootLayer(root); 7417 host()->SetRootLayer(root);
7415 scroller->SetScrollClipLayerId(root->id()); 7418 scroller->SetScrollClipLayerId(root->id());
7416 outer_viewport->SetScrollClipLayerId(outer_clip->id()); 7419 outer_viewport->SetScrollClipLayerId(outer_clip->id());
7417 host()->RegisterViewportLayers(nullptr, root, scroller, outer_viewport); 7420 host()->RegisterViewportLayers(nullptr, root, scroller, outer_viewport);
7418 7421
7419 LayerStickyPositionConstraint sticky_position; 7422 LayerStickyPositionConstraint sticky_position;
7420 sticky_position.is_sticky = true; 7423 sticky_position.is_sticky = true;
7421 sticky_position.is_anchored_bottom = true; 7424 sticky_position.is_anchored_bottom = true;
7422 sticky_position.bottom_offset = 10.0f; 7425 sticky_position.bottom_offset = 10.0f;
7423 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70); 7426 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(0, 70);
7424 sticky_position.scroll_container_relative_sticky_box_rect = 7427 sticky_position.scroll_container_relative_sticky_box_rect =
7425 gfx::Rect(0, 70, 10, 10); 7428 gfx::RectF(0, 70, 10, 10);
7426 sticky_position.scroll_container_relative_containing_block_rect = 7429 sticky_position.scroll_container_relative_containing_block_rect =
7427 gfx::Rect(0, 60, 100, 100); 7430 gfx::RectF(0, 60, 100, 100);
7428 sticky_pos->SetStickyPositionConstraint(sticky_position); 7431 sticky_pos->SetStickyPositionConstraint(sticky_position);
7429 7432
7430 root->SetBounds(gfx::Size(100, 100)); 7433 root->SetBounds(gfx::Size(100, 100));
7431 scroller->SetBounds(gfx::Size(100, 1000)); 7434 scroller->SetBounds(gfx::Size(100, 1000));
7432 outer_clip->SetBounds(gfx::Size(100, 100)); 7435 outer_clip->SetBounds(gfx::Size(100, 100));
7433 sticky_pos->SetBounds(gfx::Size(10, 10)); 7436 sticky_pos->SetBounds(gfx::Size(10, 10));
7434 sticky_pos->SetPosition(gfx::PointF(0, 70)); 7437 sticky_pos->SetPosition(gfx::PointF(0, 70));
7435 7438
7436 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), 7439 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(),
7437 scroller.get(), outer_viewport.get()); 7440 scroller.get(), outer_viewport.get());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
7490 scroller->AddChild(sticky_pos); 7493 scroller->AddChild(sticky_pos);
7491 host()->SetRootLayer(root); 7494 host()->SetRootLayer(root);
7492 scroller->SetScrollClipLayerId(container->id()); 7495 scroller->SetScrollClipLayerId(container->id());
7493 7496
7494 LayerStickyPositionConstraint sticky_position; 7497 LayerStickyPositionConstraint sticky_position;
7495 sticky_position.is_sticky = true; 7498 sticky_position.is_sticky = true;
7496 sticky_position.is_anchored_left = true; 7499 sticky_position.is_anchored_left = true;
7497 sticky_position.is_anchored_right = true; 7500 sticky_position.is_anchored_right = true;
7498 sticky_position.left_offset = 10.f; 7501 sticky_position.left_offset = 10.f;
7499 sticky_position.right_offset = 10.f; 7502 sticky_position.right_offset = 10.f;
7500 sticky_position.parent_relative_sticky_box_offset = gfx::Point(145, 0); 7503 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(145, 0);
7501 sticky_position.scroll_container_relative_sticky_box_rect = 7504 sticky_position.scroll_container_relative_sticky_box_rect =
7502 gfx::Rect(145, 0, 10, 10); 7505 gfx::RectF(145, 0, 10, 10);
7503 sticky_position.scroll_container_relative_containing_block_rect = 7506 sticky_position.scroll_container_relative_containing_block_rect =
7504 gfx::Rect(100, 0, 100, 100); 7507 gfx::RectF(100, 0, 100, 100);
7505 sticky_pos->SetStickyPositionConstraint(sticky_position); 7508 sticky_pos->SetStickyPositionConstraint(sticky_position);
7506 7509
7507 root->SetBounds(gfx::Size(100, 100)); 7510 root->SetBounds(gfx::Size(100, 100));
7508 container->SetBounds(gfx::Size(100, 100)); 7511 container->SetBounds(gfx::Size(100, 100));
7509 scroller->SetBounds(gfx::Size(1000, 1000)); 7512 scroller->SetBounds(gfx::Size(1000, 1000));
7510 sticky_pos->SetBounds(gfx::Size(10, 10)); 7513 sticky_pos->SetBounds(gfx::Size(10, 10));
7511 sticky_pos->SetPosition(gfx::PointF(145, 0)); 7514 sticky_pos->SetPosition(gfx::PointF(145, 0));
7512 7515
7513 ExecuteCalculateDrawProperties(root.get()); 7516 ExecuteCalculateDrawProperties(root.get());
7514 host()->host_impl()->CreatePendingTree(); 7517 host()->host_impl()->CreatePendingTree();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
7593 root->AddChild(container); 7596 root->AddChild(container);
7594 container->AddChild(scroller); 7597 container->AddChild(scroller);
7595 scroller->AddChild(sticky_pos); 7598 scroller->AddChild(sticky_pos);
7596 host()->SetRootLayer(root); 7599 host()->SetRootLayer(root);
7597 scroller->SetScrollClipLayerId(container->id()); 7600 scroller->SetScrollClipLayerId(container->id());
7598 7601
7599 LayerStickyPositionConstraint sticky_position; 7602 LayerStickyPositionConstraint sticky_position;
7600 sticky_position.is_sticky = true; 7603 sticky_position.is_sticky = true;
7601 sticky_position.is_anchored_top = true; 7604 sticky_position.is_anchored_top = true;
7602 sticky_position.top_offset = 10.0f; 7605 sticky_position.top_offset = 10.0f;
7603 sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20); 7606 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(10, 20);
7604 sticky_position.scroll_container_relative_sticky_box_rect = 7607 sticky_position.scroll_container_relative_sticky_box_rect =
7605 gfx::Rect(10, 20, 10, 10); 7608 gfx::RectF(10, 20, 10, 10);
7606 sticky_position.scroll_container_relative_containing_block_rect = 7609 sticky_position.scroll_container_relative_containing_block_rect =
7607 gfx::Rect(0, 0, 50, 50); 7610 gfx::RectF(0, 0, 50, 50);
7608 sticky_pos->SetStickyPositionConstraint(sticky_position); 7611 sticky_pos->SetStickyPositionConstraint(sticky_position);
7609 7612
7610 root->SetBounds(gfx::Size(100, 100)); 7613 root->SetBounds(gfx::Size(100, 100));
7611 container->SetBounds(gfx::Size(100, 100)); 7614 container->SetBounds(gfx::Size(100, 100));
7612 scroller->SetBounds(gfx::Size(1000, 1000)); 7615 scroller->SetBounds(gfx::Size(1000, 1000));
7613 sticky_pos->SetBounds(gfx::Size(10, 10)); 7616 sticky_pos->SetBounds(gfx::Size(10, 10));
7614 sticky_pos->SetPosition(gfx::PointF(10, 20)); 7617 sticky_pos->SetPosition(gfx::PointF(10, 20));
7615 7618
7616 ExecuteCalculateDrawProperties(root.get()); 7619 ExecuteCalculateDrawProperties(root.get());
7617 host()->host_impl()->CreatePendingTree(); 7620 host()->host_impl()->CreatePendingTree();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
7688 host()->SetRootLayer(root); 7691 host()->SetRootLayer(root);
7689 scroller->SetScrollClipLayerId(container->id()); 7692 scroller->SetScrollClipLayerId(container->id());
7690 7693
7691 LayerStickyPositionConstraint sticky_position; 7694 LayerStickyPositionConstraint sticky_position;
7692 sticky_position.is_sticky = true; 7695 sticky_position.is_sticky = true;
7693 sticky_position.is_anchored_top = true; 7696 sticky_position.is_anchored_top = true;
7694 sticky_position.top_offset = 10.0f; 7697 sticky_position.top_offset = 10.0f;
7695 // The sticky position layer is only offset by (0, 10) from its parent 7698 // The sticky position layer is only offset by (0, 10) from its parent
7696 // layer, this position is used to determine the offset applied by the main 7699 // layer, this position is used to determine the offset applied by the main
7697 // thread. 7700 // thread.
7698 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 10); 7701 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(0, 10);
7699 sticky_position.scroll_container_relative_sticky_box_rect = 7702 sticky_position.scroll_container_relative_sticky_box_rect =
7700 gfx::Rect(20, 30, 10, 10); 7703 gfx::RectF(20, 30, 10, 10);
7701 sticky_position.scroll_container_relative_containing_block_rect = 7704 sticky_position.scroll_container_relative_containing_block_rect =
7702 gfx::Rect(20, 20, 30, 30); 7705 gfx::RectF(20, 20, 30, 30);
7703 sticky_pos->SetStickyPositionConstraint(sticky_position); 7706 sticky_pos->SetStickyPositionConstraint(sticky_position);
7704 7707
7705 root->SetBounds(gfx::Size(100, 100)); 7708 root->SetBounds(gfx::Size(100, 100));
7706 container->SetBounds(gfx::Size(100, 100)); 7709 container->SetBounds(gfx::Size(100, 100));
7707 scroller->SetBounds(gfx::Size(1000, 1000)); 7710 scroller->SetBounds(gfx::Size(1000, 1000));
7708 sticky_container->SetPosition(gfx::PointF(20, 20)); 7711 sticky_container->SetPosition(gfx::PointF(20, 20));
7709 sticky_container->SetBounds(gfx::Size(30, 30)); 7712 sticky_container->SetBounds(gfx::Size(30, 30));
7710 sticky_pos->SetBounds(gfx::Size(10, 10)); 7713 sticky_pos->SetBounds(gfx::Size(10, 10));
7711 sticky_pos->SetPosition(gfx::PointF(0, 10)); 7714 sticky_pos->SetPosition(gfx::PointF(0, 10));
7712 7715
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
7788 host()->SetRootLayer(root); 7791 host()->SetRootLayer(root);
7789 scroller->SetScrollClipLayerId(container->id()); 7792 scroller->SetScrollClipLayerId(container->id());
7790 gfx::Transform t; 7793 gfx::Transform t;
7791 t.Scale(2, 2); 7794 t.Scale(2, 2);
7792 sticky_pos->SetTransform(t); 7795 sticky_pos->SetTransform(t);
7793 7796
7794 LayerStickyPositionConstraint sticky_position; 7797 LayerStickyPositionConstraint sticky_position;
7795 sticky_position.is_sticky = true; 7798 sticky_position.is_sticky = true;
7796 sticky_position.is_anchored_top = true; 7799 sticky_position.is_anchored_top = true;
7797 sticky_position.top_offset = 0.0f; 7800 sticky_position.top_offset = 0.0f;
7798 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 20); 7801 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(0, 20);
7799 sticky_position.scroll_container_relative_sticky_box_rect = 7802 sticky_position.scroll_container_relative_sticky_box_rect =
7800 gfx::Rect(0, 20, 10, 10); 7803 gfx::RectF(0, 20, 10, 10);
7801 sticky_position.scroll_container_relative_containing_block_rect = 7804 sticky_position.scroll_container_relative_containing_block_rect =
7802 gfx::Rect(0, 0, 50, 50); 7805 gfx::RectF(0, 0, 50, 50);
7803 sticky_pos->SetStickyPositionConstraint(sticky_position); 7806 sticky_pos->SetStickyPositionConstraint(sticky_position);
7804 7807
7805 root->SetBounds(gfx::Size(100, 100)); 7808 root->SetBounds(gfx::Size(100, 100));
7806 container->SetBounds(gfx::Size(100, 100)); 7809 container->SetBounds(gfx::Size(100, 100));
7807 scroller->SetBounds(gfx::Size(1000, 1000)); 7810 scroller->SetBounds(gfx::Size(1000, 1000));
7808 sticky_pos->SetBounds(gfx::Size(10, 10)); 7811 sticky_pos->SetBounds(gfx::Size(10, 10));
7809 sticky_pos->SetPosition(gfx::PointF(0, 20)); 7812 sticky_pos->SetPosition(gfx::PointF(0, 20));
7810 7813
7811 ExecuteCalculateDrawProperties(root.get()); 7814 ExecuteCalculateDrawProperties(root.get());
7812 host()->host_impl()->CreatePendingTree(); 7815 host()->host_impl()->CreatePendingTree();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
7867 host()->SetRootLayer(root); 7870 host()->SetRootLayer(root);
7868 scroller->SetScrollClipLayerId(container->id()); 7871 scroller->SetScrollClipLayerId(container->id());
7869 gfx::Transform t; 7872 gfx::Transform t;
7870 t.Scale(2, 2); 7873 t.Scale(2, 2);
7871 sticky_container->SetTransform(t); 7874 sticky_container->SetTransform(t);
7872 7875
7873 LayerStickyPositionConstraint sticky_position; 7876 LayerStickyPositionConstraint sticky_position;
7874 sticky_position.is_sticky = true; 7877 sticky_position.is_sticky = true;
7875 sticky_position.is_anchored_top = true; 7878 sticky_position.is_anchored_top = true;
7876 sticky_position.top_offset = 0.0f; 7879 sticky_position.top_offset = 0.0f;
7877 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 20); 7880 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(0, 20);
7878 sticky_position.scroll_container_relative_sticky_box_rect = 7881 sticky_position.scroll_container_relative_sticky_box_rect =
7879 gfx::Rect(0, 20, 10, 10); 7882 gfx::RectF(0, 20, 10, 10);
7880 sticky_position.scroll_container_relative_containing_block_rect = 7883 sticky_position.scroll_container_relative_containing_block_rect =
7881 gfx::Rect(0, 0, 50, 50); 7884 gfx::RectF(0, 0, 50, 50);
7882 sticky_pos->SetStickyPositionConstraint(sticky_position); 7885 sticky_pos->SetStickyPositionConstraint(sticky_position);
7883 7886
7884 root->SetBounds(gfx::Size(100, 100)); 7887 root->SetBounds(gfx::Size(100, 100));
7885 container->SetBounds(gfx::Size(100, 100)); 7888 container->SetBounds(gfx::Size(100, 100));
7886 scroller->SetBounds(gfx::Size(1000, 1000)); 7889 scroller->SetBounds(gfx::Size(1000, 1000));
7887 sticky_container->SetBounds(gfx::Size(50, 50)); 7890 sticky_container->SetBounds(gfx::Size(50, 50));
7888 sticky_pos->SetBounds(gfx::Size(10, 10)); 7891 sticky_pos->SetBounds(gfx::Size(10, 10));
7889 sticky_pos->SetPosition(gfx::PointF(0, 20)); 7892 sticky_pos->SetPosition(gfx::PointF(0, 20));
7890 7893
7891 ExecuteCalculateDrawProperties(root.get()); 7894 ExecuteCalculateDrawProperties(root.get());
(...skipping 33 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::PointF(0, 50);
7965 outer_sticky_pos.scroll_container_relative_sticky_box_rect =
7966 gfx::RectF(0, 50, 10, 50);
7967 outer_sticky_pos.scroll_container_relative_containing_block_rect =
7968 gfx::RectF(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::PointF(0, 0);
7976 inner_sticky_pos.scroll_container_relative_sticky_box_rect =
7977 gfx::RectF(0, 50, 10, 10);
7978 inner_sticky_pos.scroll_container_relative_containing_block_rect =
7979 gfx::RectF(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