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

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

Issue 2733633002: Handle nested position:sticky elements correctly (compositor) (Closed)
Patch Set: More layer id fixes 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 7056 matching lines...) Expand 10 before | Expand all | Expand 10 after
7067 root->AddChild(container); 7067 root->AddChild(container);
7068 container->AddChild(scroller); 7068 container->AddChild(scroller);
7069 scroller->AddChild(sticky_pos); 7069 scroller->AddChild(sticky_pos);
7070 host()->SetRootLayer(root); 7070 host()->SetRootLayer(root);
7071 scroller->SetScrollClipLayerId(container->id()); 7071 scroller->SetScrollClipLayerId(container->id());
7072 7072
7073 LayerStickyPositionConstraint sticky_position; 7073 LayerStickyPositionConstraint sticky_position;
7074 sticky_position.is_sticky = true; 7074 sticky_position.is_sticky = true;
7075 sticky_position.is_anchored_top = true; 7075 sticky_position.is_anchored_top = true;
7076 sticky_position.top_offset = 10.0f; 7076 sticky_position.top_offset = 10.0f;
7077 sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20); 7077 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(10, 20);
7078 sticky_position.scroll_container_relative_sticky_box_rect = 7078 sticky_position.scroll_container_relative_sticky_box_rect =
7079 gfx::Rect(10, 20, 10, 10); 7079 gfx::RectF(10, 20, 10, 10);
7080 sticky_position.scroll_container_relative_containing_block_rect = 7080 sticky_position.scroll_container_relative_containing_block_rect =
7081 gfx::Rect(0, 0, 50, 50); 7081 gfx::RectF(0, 0, 50, 50);
7082 sticky_pos->SetStickyPositionConstraint(sticky_position); 7082 sticky_pos->SetStickyPositionConstraint(sticky_position);
7083 7083
7084 root->SetBounds(gfx::Size(100, 100)); 7084 root->SetBounds(gfx::Size(100, 100));
7085 container->SetBounds(gfx::Size(100, 100)); 7085 container->SetBounds(gfx::Size(100, 100));
7086 scroller->SetBounds(gfx::Size(1000, 1000)); 7086 scroller->SetBounds(gfx::Size(1000, 1000));
7087 sticky_pos->SetBounds(gfx::Size(10, 10)); 7087 sticky_pos->SetBounds(gfx::Size(10, 10));
7088 sticky_pos->SetPosition(gfx::PointF(10, 20)); 7088 sticky_pos->SetPosition(gfx::PointF(10, 20));
7089 7089
7090 ExecuteCalculateDrawProperties(root.get()); 7090 ExecuteCalculateDrawProperties(root.get());
7091 host()->host_impl()->CreatePendingTree(); 7091 host()->host_impl()->CreatePendingTree();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
7136 scoped_refptr<Layer> container = Layer::Create(); 7136 scoped_refptr<Layer> container = Layer::Create();
7137 scoped_refptr<Layer> scroller = Layer::Create(); 7137 scoped_refptr<Layer> scroller = Layer::Create();
7138 scoped_refptr<Layer> sticky_pos = Layer::Create(); 7138 scoped_refptr<Layer> sticky_pos = Layer::Create();
7139 root->AddChild(container); 7139 root->AddChild(container);
7140 container->AddChild(scroller); 7140 container->AddChild(scroller);
7141 root->AddChild(sticky_pos); 7141 root->AddChild(sticky_pos);
7142 sticky_pos->SetScrollParent(scroller.get()); 7142 sticky_pos->SetScrollParent(scroller.get());
7143 host()->SetRootLayer(root); 7143 host()->SetRootLayer(root);
7144 scroller->SetScrollClipLayerId(container->id()); 7144 scroller->SetScrollClipLayerId(container->id());
7145 7145
7146 // The sticky layer has already been scrolled on the main thread side, and has
7147 // stuck. This test then checks that further changes from cc-only scrolling
7148 // are handled correctly.
7146 LayerStickyPositionConstraint sticky_position; 7149 LayerStickyPositionConstraint sticky_position;
7147 sticky_position.is_sticky = true; 7150 sticky_position.is_sticky = true;
7148 sticky_position.is_anchored_top = true; 7151 sticky_position.is_anchored_top = true;
7149 sticky_position.top_offset = 10.0f; 7152 sticky_position.top_offset = 10.0f;
7150 sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20); 7153 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(10, 20);
7151 sticky_position.scroll_container_relative_sticky_box_rect = 7154 sticky_position.scroll_container_relative_sticky_box_rect =
7152 gfx::Rect(10, 20, 10, 10); 7155 gfx::RectF(10, 20, 10, 10);
7153 sticky_position.scroll_container_relative_containing_block_rect = 7156 sticky_position.scroll_container_relative_containing_block_rect =
7154 gfx::Rect(0, 0, 50, 50); 7157 gfx::RectF(0, 0, 50, 50);
7155 sticky_pos->SetStickyPositionConstraint(sticky_position); 7158 sticky_pos->SetStickyPositionConstraint(sticky_position);
7156 7159
7157 root->SetBounds(gfx::Size(200, 200)); 7160 root->SetBounds(gfx::Size(200, 200));
7158 container->SetBounds(gfx::Size(100, 100)); 7161 container->SetBounds(gfx::Size(100, 100));
7159 container->SetPosition(gfx::PointF(50, 50)); 7162 container->SetPosition(gfx::PointF(50, 50));
7160 scroller->SetBounds(gfx::Size(1000, 1000)); 7163 scroller->SetBounds(gfx::Size(1000, 1000));
7161 sticky_pos->SetBounds(gfx::Size(10, 10)); 7164 sticky_pos->SetBounds(gfx::Size(10, 10));
7162 sticky_pos->SetPosition(gfx::PointF(60, 70)); 7165 sticky_pos->SetPosition(gfx::PointF(60, 70));
7163 7166
7164 ExecuteCalculateDrawProperties(root.get()); 7167 ExecuteCalculateDrawProperties(root.get());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
7213 root->AddChild(container); 7216 root->AddChild(container);
7214 container->AddChild(scroller); 7217 container->AddChild(scroller);
7215 scroller->AddChild(sticky_pos); 7218 scroller->AddChild(sticky_pos);
7216 host()->SetRootLayer(root); 7219 host()->SetRootLayer(root);
7217 scroller->SetScrollClipLayerId(container->id()); 7220 scroller->SetScrollClipLayerId(container->id());
7218 7221
7219 LayerStickyPositionConstraint sticky_position; 7222 LayerStickyPositionConstraint sticky_position;
7220 sticky_position.is_sticky = true; 7223 sticky_position.is_sticky = true;
7221 sticky_position.is_anchored_bottom = true; 7224 sticky_position.is_anchored_bottom = true;
7222 sticky_position.bottom_offset = 10.0f; 7225 sticky_position.bottom_offset = 10.0f;
7223 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 200); 7226 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(0, 200);
7224 sticky_position.scroll_container_relative_sticky_box_rect = 7227 sticky_position.scroll_container_relative_sticky_box_rect =
7225 gfx::Rect(0, 200, 10, 10); 7228 gfx::RectF(0, 200, 10, 10);
7226 sticky_position.scroll_container_relative_containing_block_rect = 7229 sticky_position.scroll_container_relative_containing_block_rect =
7227 gfx::Rect(0, 0, 100, 500); 7230 gfx::RectF(0, 0, 100, 500);
7228 sticky_pos->SetStickyPositionConstraint(sticky_position); 7231 sticky_pos->SetStickyPositionConstraint(sticky_position);
7229 7232
7230 root->SetBounds(gfx::Size(100, 100)); 7233 root->SetBounds(gfx::Size(100, 100));
7231 container->SetBounds(gfx::Size(100, 100)); 7234 container->SetBounds(gfx::Size(100, 100));
7232 scroller->SetBounds(gfx::Size(100, 1000)); 7235 scroller->SetBounds(gfx::Size(100, 1000));
7233 sticky_pos->SetBounds(gfx::Size(10, 10)); 7236 sticky_pos->SetBounds(gfx::Size(10, 10));
7234 sticky_pos->SetPosition(gfx::PointF(0, 200)); 7237 sticky_pos->SetPosition(gfx::PointF(0, 200));
7235 7238
7236 ExecuteCalculateDrawProperties(root.get()); 7239 ExecuteCalculateDrawProperties(root.get());
7237 host()->host_impl()->CreatePendingTree(); 7240 host()->host_impl()->CreatePendingTree();
(...skipping 21 matching lines...) Expand all
7259 root->AddChild(container); 7262 root->AddChild(container);
7260 container->AddChild(scroller); 7263 container->AddChild(scroller);
7261 scroller->AddChild(sticky_pos); 7264 scroller->AddChild(sticky_pos);
7262 host()->SetRootLayer(root); 7265 host()->SetRootLayer(root);
7263 scroller->SetScrollClipLayerId(container->id()); 7266 scroller->SetScrollClipLayerId(container->id());
7264 7267
7265 LayerStickyPositionConstraint sticky_position; 7268 LayerStickyPositionConstraint sticky_position;
7266 sticky_position.is_sticky = true; 7269 sticky_position.is_sticky = true;
7267 sticky_position.is_anchored_bottom = true; 7270 sticky_position.is_anchored_bottom = true;
7268 sticky_position.bottom_offset = 10.0f; 7271 sticky_position.bottom_offset = 10.0f;
7269 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 150); 7272 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(0, 150);
7270 sticky_position.scroll_container_relative_sticky_box_rect = 7273 sticky_position.scroll_container_relative_sticky_box_rect =
7271 gfx::Rect(0, 150, 10, 10); 7274 gfx::RectF(0, 150, 10, 10);
7272 sticky_position.scroll_container_relative_containing_block_rect = 7275 sticky_position.scroll_container_relative_containing_block_rect =
7273 gfx::Rect(0, 100, 50, 50); 7276 gfx::RectF(0, 100, 50, 50);
7274 sticky_pos->SetStickyPositionConstraint(sticky_position); 7277 sticky_pos->SetStickyPositionConstraint(sticky_position);
7275 7278
7276 root->SetBounds(gfx::Size(100, 100)); 7279 root->SetBounds(gfx::Size(100, 100));
7277 container->SetBounds(gfx::Size(100, 100)); 7280 container->SetBounds(gfx::Size(100, 100));
7278 scroller->SetBounds(gfx::Size(1000, 1000)); 7281 scroller->SetBounds(gfx::Size(1000, 1000));
7279 sticky_pos->SetBounds(gfx::Size(10, 10)); 7282 sticky_pos->SetBounds(gfx::Size(10, 10));
7280 sticky_pos->SetPosition(gfx::PointF(0, 150)); 7283 sticky_pos->SetPosition(gfx::PointF(0, 150));
7281 7284
7282 ExecuteCalculateDrawProperties(root.get()); 7285 ExecuteCalculateDrawProperties(root.get());
7283 host()->host_impl()->CreatePendingTree(); 7286 host()->host_impl()->CreatePendingTree();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
7328 root->AddChild(scroller); 7331 root->AddChild(scroller);
7329 scroller->AddChild(sticky_pos); 7332 scroller->AddChild(sticky_pos);
7330 host()->SetRootLayer(root); 7333 host()->SetRootLayer(root);
7331 scroller->SetScrollClipLayerId(root->id()); 7334 scroller->SetScrollClipLayerId(root->id());
7332 host()->RegisterViewportLayers(nullptr, root, scroller, nullptr); 7335 host()->RegisterViewportLayers(nullptr, root, scroller, nullptr);
7333 7336
7334 LayerStickyPositionConstraint sticky_position; 7337 LayerStickyPositionConstraint sticky_position;
7335 sticky_position.is_sticky = true; 7338 sticky_position.is_sticky = true;
7336 sticky_position.is_anchored_bottom = true; 7339 sticky_position.is_anchored_bottom = true;
7337 sticky_position.bottom_offset = 10.0f; 7340 sticky_position.bottom_offset = 10.0f;
7338 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70); 7341 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(0, 70);
7339 sticky_position.scroll_container_relative_sticky_box_rect = 7342 sticky_position.scroll_container_relative_sticky_box_rect =
7340 gfx::Rect(0, 70, 10, 10); 7343 gfx::RectF(0, 70, 10, 10);
7341 sticky_position.scroll_container_relative_containing_block_rect = 7344 sticky_position.scroll_container_relative_containing_block_rect =
7342 gfx::Rect(0, 60, 100, 100); 7345 gfx::RectF(0, 60, 100, 100);
7343 sticky_pos->SetStickyPositionConstraint(sticky_position); 7346 sticky_pos->SetStickyPositionConstraint(sticky_position);
7344 7347
7345 root->SetBounds(gfx::Size(100, 100)); 7348 root->SetBounds(gfx::Size(100, 100));
7346 scroller->SetBounds(gfx::Size(100, 1000)); 7349 scroller->SetBounds(gfx::Size(100, 1000));
7347 sticky_pos->SetBounds(gfx::Size(10, 10)); 7350 sticky_pos->SetBounds(gfx::Size(10, 10));
7348 sticky_pos->SetPosition(gfx::PointF(0, 70)); 7351 sticky_pos->SetPosition(gfx::PointF(0, 70));
7349 7352
7350 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), 7353 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(),
7351 scroller.get(), nullptr); 7354 scroller.get(), nullptr);
7352 host()->CommitAndCreateLayerImplTree(); 7355 host()->CommitAndCreateLayerImplTree();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
7401 outer_viewport->AddChild(sticky_pos); 7404 outer_viewport->AddChild(sticky_pos);
7402 host()->SetRootLayer(root); 7405 host()->SetRootLayer(root);
7403 scroller->SetScrollClipLayerId(root->id()); 7406 scroller->SetScrollClipLayerId(root->id());
7404 outer_viewport->SetScrollClipLayerId(outer_clip->id()); 7407 outer_viewport->SetScrollClipLayerId(outer_clip->id());
7405 host()->RegisterViewportLayers(nullptr, root, scroller, outer_viewport); 7408 host()->RegisterViewportLayers(nullptr, root, scroller, outer_viewport);
7406 7409
7407 LayerStickyPositionConstraint sticky_position; 7410 LayerStickyPositionConstraint sticky_position;
7408 sticky_position.is_sticky = true; 7411 sticky_position.is_sticky = true;
7409 sticky_position.is_anchored_bottom = true; 7412 sticky_position.is_anchored_bottom = true;
7410 sticky_position.bottom_offset = 10.0f; 7413 sticky_position.bottom_offset = 10.0f;
7411 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70); 7414 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(0, 70);
7412 sticky_position.scroll_container_relative_sticky_box_rect = 7415 sticky_position.scroll_container_relative_sticky_box_rect =
7413 gfx::Rect(0, 70, 10, 10); 7416 gfx::RectF(0, 70, 10, 10);
7414 sticky_position.scroll_container_relative_containing_block_rect = 7417 sticky_position.scroll_container_relative_containing_block_rect =
7415 gfx::Rect(0, 60, 100, 100); 7418 gfx::RectF(0, 60, 100, 100);
7416 sticky_pos->SetStickyPositionConstraint(sticky_position); 7419 sticky_pos->SetStickyPositionConstraint(sticky_position);
7417 7420
7418 root->SetBounds(gfx::Size(100, 100)); 7421 root->SetBounds(gfx::Size(100, 100));
7419 scroller->SetBounds(gfx::Size(100, 1000)); 7422 scroller->SetBounds(gfx::Size(100, 1000));
7420 outer_clip->SetBounds(gfx::Size(100, 100)); 7423 outer_clip->SetBounds(gfx::Size(100, 100));
7421 sticky_pos->SetBounds(gfx::Size(10, 10)); 7424 sticky_pos->SetBounds(gfx::Size(10, 10));
7422 sticky_pos->SetPosition(gfx::PointF(0, 70)); 7425 sticky_pos->SetPosition(gfx::PointF(0, 70));
7423 7426
7424 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), 7427 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(),
7425 scroller.get(), outer_viewport.get()); 7428 scroller.get(), outer_viewport.get());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
7478 scroller->AddChild(sticky_pos); 7481 scroller->AddChild(sticky_pos);
7479 host()->SetRootLayer(root); 7482 host()->SetRootLayer(root);
7480 scroller->SetScrollClipLayerId(container->id()); 7483 scroller->SetScrollClipLayerId(container->id());
7481 7484
7482 LayerStickyPositionConstraint sticky_position; 7485 LayerStickyPositionConstraint sticky_position;
7483 sticky_position.is_sticky = true; 7486 sticky_position.is_sticky = true;
7484 sticky_position.is_anchored_left = true; 7487 sticky_position.is_anchored_left = true;
7485 sticky_position.is_anchored_right = true; 7488 sticky_position.is_anchored_right = true;
7486 sticky_position.left_offset = 10.f; 7489 sticky_position.left_offset = 10.f;
7487 sticky_position.right_offset = 10.f; 7490 sticky_position.right_offset = 10.f;
7488 sticky_position.parent_relative_sticky_box_offset = gfx::Point(145, 0); 7491 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(145, 0);
7489 sticky_position.scroll_container_relative_sticky_box_rect = 7492 sticky_position.scroll_container_relative_sticky_box_rect =
7490 gfx::Rect(145, 0, 10, 10); 7493 gfx::RectF(145, 0, 10, 10);
7491 sticky_position.scroll_container_relative_containing_block_rect = 7494 sticky_position.scroll_container_relative_containing_block_rect =
7492 gfx::Rect(100, 0, 100, 100); 7495 gfx::RectF(100, 0, 100, 100);
7493 sticky_pos->SetStickyPositionConstraint(sticky_position); 7496 sticky_pos->SetStickyPositionConstraint(sticky_position);
7494 7497
7495 root->SetBounds(gfx::Size(100, 100)); 7498 root->SetBounds(gfx::Size(100, 100));
7496 container->SetBounds(gfx::Size(100, 100)); 7499 container->SetBounds(gfx::Size(100, 100));
7497 scroller->SetBounds(gfx::Size(1000, 1000)); 7500 scroller->SetBounds(gfx::Size(1000, 1000));
7498 sticky_pos->SetBounds(gfx::Size(10, 10)); 7501 sticky_pos->SetBounds(gfx::Size(10, 10));
7499 sticky_pos->SetPosition(gfx::PointF(145, 0)); 7502 sticky_pos->SetPosition(gfx::PointF(145, 0));
7500 7503
7501 ExecuteCalculateDrawProperties(root.get()); 7504 ExecuteCalculateDrawProperties(root.get());
7502 host()->host_impl()->CreatePendingTree(); 7505 host()->host_impl()->CreatePendingTree();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
7581 root->AddChild(container); 7584 root->AddChild(container);
7582 container->AddChild(scroller); 7585 container->AddChild(scroller);
7583 scroller->AddChild(sticky_pos); 7586 scroller->AddChild(sticky_pos);
7584 host()->SetRootLayer(root); 7587 host()->SetRootLayer(root);
7585 scroller->SetScrollClipLayerId(container->id()); 7588 scroller->SetScrollClipLayerId(container->id());
7586 7589
7587 LayerStickyPositionConstraint sticky_position; 7590 LayerStickyPositionConstraint sticky_position;
7588 sticky_position.is_sticky = true; 7591 sticky_position.is_sticky = true;
7589 sticky_position.is_anchored_top = true; 7592 sticky_position.is_anchored_top = true;
7590 sticky_position.top_offset = 10.0f; 7593 sticky_position.top_offset = 10.0f;
7591 sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20); 7594 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(10, 20);
7592 sticky_position.scroll_container_relative_sticky_box_rect = 7595 sticky_position.scroll_container_relative_sticky_box_rect =
7593 gfx::Rect(10, 20, 10, 10); 7596 gfx::RectF(10, 20, 10, 10);
7594 sticky_position.scroll_container_relative_containing_block_rect = 7597 sticky_position.scroll_container_relative_containing_block_rect =
7595 gfx::Rect(0, 0, 50, 50); 7598 gfx::RectF(0, 0, 50, 50);
7596 sticky_pos->SetStickyPositionConstraint(sticky_position); 7599 sticky_pos->SetStickyPositionConstraint(sticky_position);
7597 7600
7598 root->SetBounds(gfx::Size(100, 100)); 7601 root->SetBounds(gfx::Size(100, 100));
7599 container->SetBounds(gfx::Size(100, 100)); 7602 container->SetBounds(gfx::Size(100, 100));
7600 scroller->SetBounds(gfx::Size(1000, 1000)); 7603 scroller->SetBounds(gfx::Size(1000, 1000));
7601 sticky_pos->SetBounds(gfx::Size(10, 10)); 7604 sticky_pos->SetBounds(gfx::Size(10, 10));
7602 sticky_pos->SetPosition(gfx::PointF(10, 20)); 7605 sticky_pos->SetPosition(gfx::PointF(10, 20));
7603 7606
7604 ExecuteCalculateDrawProperties(root.get()); 7607 ExecuteCalculateDrawProperties(root.get());
7605 host()->host_impl()->CreatePendingTree(); 7608 host()->host_impl()->CreatePendingTree();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
7676 host()->SetRootLayer(root); 7679 host()->SetRootLayer(root);
7677 scroller->SetScrollClipLayerId(container->id()); 7680 scroller->SetScrollClipLayerId(container->id());
7678 7681
7679 LayerStickyPositionConstraint sticky_position; 7682 LayerStickyPositionConstraint sticky_position;
7680 sticky_position.is_sticky = true; 7683 sticky_position.is_sticky = true;
7681 sticky_position.is_anchored_top = true; 7684 sticky_position.is_anchored_top = true;
7682 sticky_position.top_offset = 10.0f; 7685 sticky_position.top_offset = 10.0f;
7683 // The sticky position layer is only offset by (0, 10) from its parent 7686 // The sticky position layer is only offset by (0, 10) from its parent
7684 // layer, this position is used to determine the offset applied by the main 7687 // layer, this position is used to determine the offset applied by the main
7685 // thread. 7688 // thread.
7686 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 10); 7689 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(0, 10);
7687 sticky_position.scroll_container_relative_sticky_box_rect = 7690 sticky_position.scroll_container_relative_sticky_box_rect =
7688 gfx::Rect(20, 30, 10, 10); 7691 gfx::RectF(20, 30, 10, 10);
7689 sticky_position.scroll_container_relative_containing_block_rect = 7692 sticky_position.scroll_container_relative_containing_block_rect =
7690 gfx::Rect(20, 20, 30, 30); 7693 gfx::RectF(20, 20, 30, 30);
7691 sticky_pos->SetStickyPositionConstraint(sticky_position); 7694 sticky_pos->SetStickyPositionConstraint(sticky_position);
7692 7695
7693 root->SetBounds(gfx::Size(100, 100)); 7696 root->SetBounds(gfx::Size(100, 100));
7694 container->SetBounds(gfx::Size(100, 100)); 7697 container->SetBounds(gfx::Size(100, 100));
7695 scroller->SetBounds(gfx::Size(1000, 1000)); 7698 scroller->SetBounds(gfx::Size(1000, 1000));
7696 sticky_container->SetPosition(gfx::PointF(20, 20)); 7699 sticky_container->SetPosition(gfx::PointF(20, 20));
7697 sticky_container->SetBounds(gfx::Size(30, 30)); 7700 sticky_container->SetBounds(gfx::Size(30, 30));
7698 sticky_pos->SetBounds(gfx::Size(10, 10)); 7701 sticky_pos->SetBounds(gfx::Size(10, 10));
7699 sticky_pos->SetPosition(gfx::PointF(0, 10)); 7702 sticky_pos->SetPosition(gfx::PointF(0, 10));
7700 7703
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
7776 host()->SetRootLayer(root); 7779 host()->SetRootLayer(root);
7777 scroller->SetScrollClipLayerId(container->id()); 7780 scroller->SetScrollClipLayerId(container->id());
7778 gfx::Transform t; 7781 gfx::Transform t;
7779 t.Scale(2, 2); 7782 t.Scale(2, 2);
7780 sticky_pos->SetTransform(t); 7783 sticky_pos->SetTransform(t);
7781 7784
7782 LayerStickyPositionConstraint sticky_position; 7785 LayerStickyPositionConstraint sticky_position;
7783 sticky_position.is_sticky = true; 7786 sticky_position.is_sticky = true;
7784 sticky_position.is_anchored_top = true; 7787 sticky_position.is_anchored_top = true;
7785 sticky_position.top_offset = 0.0f; 7788 sticky_position.top_offset = 0.0f;
7786 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 20); 7789 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(0, 20);
7787 sticky_position.scroll_container_relative_sticky_box_rect = 7790 sticky_position.scroll_container_relative_sticky_box_rect =
7788 gfx::Rect(0, 20, 10, 10); 7791 gfx::RectF(0, 20, 10, 10);
7789 sticky_position.scroll_container_relative_containing_block_rect = 7792 sticky_position.scroll_container_relative_containing_block_rect =
7790 gfx::Rect(0, 0, 50, 50); 7793 gfx::RectF(0, 0, 50, 50);
7791 sticky_pos->SetStickyPositionConstraint(sticky_position); 7794 sticky_pos->SetStickyPositionConstraint(sticky_position);
7792 7795
7793 root->SetBounds(gfx::Size(100, 100)); 7796 root->SetBounds(gfx::Size(100, 100));
7794 container->SetBounds(gfx::Size(100, 100)); 7797 container->SetBounds(gfx::Size(100, 100));
7795 scroller->SetBounds(gfx::Size(1000, 1000)); 7798 scroller->SetBounds(gfx::Size(1000, 1000));
7796 sticky_pos->SetBounds(gfx::Size(10, 10)); 7799 sticky_pos->SetBounds(gfx::Size(10, 10));
7797 sticky_pos->SetPosition(gfx::PointF(0, 20)); 7800 sticky_pos->SetPosition(gfx::PointF(0, 20));
7798 7801
7799 ExecuteCalculateDrawProperties(root.get()); 7802 ExecuteCalculateDrawProperties(root.get());
7800 host()->host_impl()->CreatePendingTree(); 7803 host()->host_impl()->CreatePendingTree();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
7855 host()->SetRootLayer(root); 7858 host()->SetRootLayer(root);
7856 scroller->SetScrollClipLayerId(container->id()); 7859 scroller->SetScrollClipLayerId(container->id());
7857 gfx::Transform t; 7860 gfx::Transform t;
7858 t.Scale(2, 2); 7861 t.Scale(2, 2);
7859 sticky_container->SetTransform(t); 7862 sticky_container->SetTransform(t);
7860 7863
7861 LayerStickyPositionConstraint sticky_position; 7864 LayerStickyPositionConstraint sticky_position;
7862 sticky_position.is_sticky = true; 7865 sticky_position.is_sticky = true;
7863 sticky_position.is_anchored_top = true; 7866 sticky_position.is_anchored_top = true;
7864 sticky_position.top_offset = 0.0f; 7867 sticky_position.top_offset = 0.0f;
7865 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 20); 7868 sticky_position.parent_relative_sticky_box_offset = gfx::PointF(0, 20);
7866 sticky_position.scroll_container_relative_sticky_box_rect = 7869 sticky_position.scroll_container_relative_sticky_box_rect =
7867 gfx::Rect(0, 20, 10, 10); 7870 gfx::RectF(0, 20, 10, 10);
7868 sticky_position.scroll_container_relative_containing_block_rect = 7871 sticky_position.scroll_container_relative_containing_block_rect =
7869 gfx::Rect(0, 0, 50, 50); 7872 gfx::RectF(0, 0, 50, 50);
7870 sticky_pos->SetStickyPositionConstraint(sticky_position); 7873 sticky_pos->SetStickyPositionConstraint(sticky_position);
7871 7874
7872 root->SetBounds(gfx::Size(100, 100)); 7875 root->SetBounds(gfx::Size(100, 100));
7873 container->SetBounds(gfx::Size(100, 100)); 7876 container->SetBounds(gfx::Size(100, 100));
7874 scroller->SetBounds(gfx::Size(1000, 1000)); 7877 scroller->SetBounds(gfx::Size(1000, 1000));
7875 sticky_container->SetBounds(gfx::Size(50, 50)); 7878 sticky_container->SetBounds(gfx::Size(50, 50));
7876 sticky_pos->SetBounds(gfx::Size(10, 10)); 7879 sticky_pos->SetBounds(gfx::Size(10, 10));
7877 sticky_pos->SetPosition(gfx::PointF(0, 20)); 7880 sticky_pos->SetPosition(gfx::PointF(0, 20));
7878 7881
7879 ExecuteCalculateDrawProperties(root.get()); 7882 ExecuteCalculateDrawProperties(root.get());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
7913 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); 7916 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7914 7917
7915 // Scroll past the end of the sticky container. 7918 // Scroll past the end of the sticky container.
7916 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f)); 7919 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f));
7917 ExecuteCalculateDrawProperties(root_impl); 7920 ExecuteCalculateDrawProperties(root_impl);
7918 EXPECT_VECTOR2DF_EQ( 7921 EXPECT_VECTOR2DF_EQ(
7919 gfx::Vector2dF(0.f, 30.f), 7922 gfx::Vector2dF(0.f, 30.f),
7920 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); 7923 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7921 } 7924 }
7922 7925
7926 TEST_F(LayerTreeHostCommonTest, StickyPositionNested) {
7927 scoped_refptr<Layer> root = Layer::Create();
7928 scoped_refptr<Layer> container = Layer::Create();
7929 scoped_refptr<Layer> scroller = Layer::Create();
7930 scoped_refptr<Layer> outer_sticky = Layer::Create();
7931 scoped_refptr<Layer> inner_sticky = Layer::Create();
7932
7933 root->AddChild(container);
7934 container->AddChild(scroller);
7935 scroller->AddChild(outer_sticky);
7936 outer_sticky->AddChild(inner_sticky);
7937 host()->SetRootLayer(root);
7938 scroller->SetScrollClipLayerId(container->id());
7939
7940 root->SetBounds(gfx::Size(100, 100));
7941 container->SetBounds(gfx::Size(100, 100));
7942 scroller->SetBounds(gfx::Size(100, 1000));
7943 outer_sticky->SetBounds(gfx::Size(10, 50));
7944 outer_sticky->SetPosition(gfx::PointF(0, 50));
7945 inner_sticky->SetBounds(gfx::Size(10, 10));
7946 inner_sticky->SetPosition(gfx::PointF(0, 0));
7947
7948 LayerStickyPositionConstraint outer_sticky_pos;
7949 outer_sticky_pos.is_sticky = true;
7950 outer_sticky_pos.is_anchored_top = true;
7951 outer_sticky_pos.top_offset = 10.0f;
7952 outer_sticky_pos.parent_relative_sticky_box_offset = gfx::PointF(0, 50);
7953 outer_sticky_pos.scroll_container_relative_sticky_box_rect =
7954 gfx::RectF(0, 50, 10, 50);
7955 outer_sticky_pos.scroll_container_relative_containing_block_rect =
7956 gfx::RectF(0, 0, 50, 400);
7957 outer_sticky->SetStickyPositionConstraint(outer_sticky_pos);
7958
7959 LayerStickyPositionConstraint inner_sticky_pos;
7960 inner_sticky_pos.is_sticky = true;
7961 inner_sticky_pos.is_anchored_top = true;
7962 inner_sticky_pos.top_offset = 25.0f;
7963 inner_sticky_pos.parent_relative_sticky_box_offset = gfx::PointF(0, 0);
7964 inner_sticky_pos.scroll_container_relative_sticky_box_rect =
7965 gfx::RectF(0, 50, 10, 10);
7966 inner_sticky_pos.scroll_container_relative_containing_block_rect =
7967 gfx::RectF(0, 50, 10, 50);
7968 inner_sticky_pos.nearest_layer_shifting_containing_block = outer_sticky->id();
7969 inner_sticky->SetStickyPositionConstraint(inner_sticky_pos);
7970
7971 ExecuteCalculateDrawProperties(root.get());
7972 host()->host_impl()->CreatePendingTree();
7973 host()->CommitAndCreatePendingTree();
7974 host()->host_impl()->ActivateSyncTree();
7975 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7976
7977 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7978 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7979 LayerImpl* outer_sticky_impl = layer_tree_impl->LayerById(outer_sticky->id());
7980 LayerImpl* inner_sticky_impl = layer_tree_impl->LayerById(inner_sticky->id());
7981
7982 ExecuteCalculateDrawProperties(root_impl);
7983
7984 // Before any scrolling is done, the sticky elements should still be at their
7985 // original positions.
7986 EXPECT_VECTOR2DF_EQ(
7987 gfx::Vector2dF(0.f, 50.f),
7988 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation());
7989 EXPECT_VECTOR2DF_EQ(
7990 gfx::Vector2dF(0.f, 50.f),
7991 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation());
7992
7993 // Scroll less than the sticking point. Both sticky elements should move with
7994 // scroll as we haven't gotten to the sticky item locations yet.
7995 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
7996 ExecuteCalculateDrawProperties(root_impl);
7997 EXPECT_VECTOR2DF_EQ(
7998 gfx::Vector2dF(0.f, 45.f),
7999 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation());
8000 EXPECT_VECTOR2DF_EQ(
8001 gfx::Vector2dF(0.f, 45.f),
8002 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation());
8003
8004 // Scroll such that the inner sticky should stick, but the outer one should
8005 // keep going as it hasnt reached its position yet.
ajuma 2017/03/17 23:59:52 hasn't
smcgruer 2017/03/20 13:36:29 Done.
8006 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
8007 ExecuteCalculateDrawProperties(root_impl);
8008 EXPECT_VECTOR2DF_EQ(
8009 gfx::Vector2dF(0.f, 20.f),
8010 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation());
8011 EXPECT_VECTOR2DF_EQ(
8012 gfx::Vector2dF(0.f, 25.f),
8013 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation());
8014
8015 // Keep going, both should stick.
8016 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 100.f));
8017 ExecuteCalculateDrawProperties(root_impl);
8018 EXPECT_VECTOR2DF_EQ(
8019 gfx::Vector2dF(0.f, 10.f),
8020 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation());
8021 EXPECT_VECTOR2DF_EQ(
8022 gfx::Vector2dF(0.f, 25.f),
8023 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation());
8024 }
8025
7923 TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) { 8026 TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) {
7924 scoped_refptr<Layer> root = Layer::Create(); 8027 scoped_refptr<Layer> root = Layer::Create();
7925 scoped_refptr<Layer> container = Layer::Create(); 8028 scoped_refptr<Layer> container = Layer::Create();
7926 scoped_refptr<Layer> scroller = Layer::Create(); 8029 scoped_refptr<Layer> scroller = Layer::Create();
7927 scoped_refptr<Layer> fixed_pos = Layer::Create(); 8030 scoped_refptr<Layer> fixed_pos = Layer::Create();
7928 8031
7929 scroller->SetIsContainerForFixedPositionLayers(true); 8032 scroller->SetIsContainerForFixedPositionLayers(true);
7930 root->AddChild(container); 8033 root->AddChild(container);
7931 container->AddChild(scroller); 8034 container->AddChild(scroller);
7932 scroller->AddChild(fixed_pos); 8035 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()); 10869 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index());
10767 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); 10870 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index());
10768 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); 10871 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index());
10769 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); 10872 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index());
10770 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); 10873 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index());
10771 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); 10874 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index());
10772 } 10875 }
10773 10876
10774 } // namespace 10877 } // namespace
10775 } // namespace cc 10878 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698