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

Side by Side Diff: cc/layers/layer_position_constraint_unittest.cc

Issue 23983047: Pinch/Zoom Infrastructure & Plumbing CL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Draft for review. Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/layers/layer_position_constraint.h" 5 #include "cc/layers/layer_position_constraint.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "cc/layers/layer_impl.h" 9 #include "cc/layers/layer_impl.h"
10 #include "cc/test/fake_impl_proxy.h" 10 #include "cc/test/fake_impl_proxy.h"
(...skipping 21 matching lines...) Expand all
32 layer->SetContentBounds(bounds); 32 layer->SetContentBounds(bounds);
33 } 33 }
34 34
35 void ExecuteCalculateDrawProperties(LayerImpl* root_layer, 35 void ExecuteCalculateDrawProperties(LayerImpl* root_layer,
36 float device_scale_factor, 36 float device_scale_factor,
37 float page_scale_factor, 37 float page_scale_factor,
38 LayerImpl* page_scale_application_layer, 38 LayerImpl* page_scale_application_layer,
39 bool can_use_lcd_text) { 39 bool can_use_lcd_text) {
40 gfx::Transform identity_matrix; 40 gfx::Transform identity_matrix;
41 std::vector<LayerImpl*> dummy_render_surface_layer_list; 41 std::vector<LayerImpl*> dummy_render_surface_layer_list;
42 LayerImpl* scroll_layer = root_layer->children()[0];
42 gfx::Size device_viewport_size = 43 gfx::Size device_viewport_size =
43 gfx::Size(root_layer->bounds().width() * device_scale_factor, 44 gfx::Size(root_layer->bounds().width() * device_scale_factor,
44 root_layer->bounds().height() * device_scale_factor); 45 root_layer->bounds().height() * device_scale_factor);
45 46
46 // We are probably not testing what is intended if the root_layer bounds are 47 // We are probably not testing what is intended if the scroll_layer bounds are
47 // empty. 48 // empty.
48 DCHECK(!root_layer->bounds().IsEmpty()); 49 DCHECK(!scroll_layer->bounds().IsEmpty());
49 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 50 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
50 root_layer, device_viewport_size, &dummy_render_surface_layer_list); 51 root_layer, device_viewport_size, &dummy_render_surface_layer_list);
51 inputs.device_scale_factor = device_scale_factor; 52 inputs.device_scale_factor = device_scale_factor;
52 inputs.page_scale_factor = page_scale_factor; 53 inputs.page_scale_factor = page_scale_factor;
53 inputs.page_scale_application_layer = page_scale_application_layer; 54 inputs.page_scale_application_layer = page_scale_application_layer;
54 inputs.can_use_lcd_text = can_use_lcd_text; 55 inputs.can_use_lcd_text = can_use_lcd_text;
55 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 56 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
56 } 57 }
57 58
58 void ExecuteCalculateDrawProperties(LayerImpl* root_layer) { 59 void ExecuteCalculateDrawProperties(LayerImpl* root_layer) {
59 LayerImpl* page_scale_application_layer = NULL; 60 LayerImpl* page_scale_application_layer = NULL;
60 ExecuteCalculateDrawProperties( 61 ExecuteCalculateDrawProperties(
61 root_layer, 1.f, 1.f, page_scale_application_layer, false); 62 root_layer, 1.f, 1.f, page_scale_application_layer, false);
62 } 63 }
63 64
64 class LayerPositionConstraintTest : public testing::Test { 65 class LayerPositionConstraintTest : public testing::Test {
65 public: 66 public:
66 LayerPositionConstraintTest() 67 LayerPositionConstraintTest()
67 : host_impl_(&proxy_) { 68 : host_impl_(&proxy_) {
68 root_ = CreateTreeForTest(); 69 root_ = CreateTreeForTest();
70 scroll_ = root_->children()[0];
69 fixed_to_top_left_.set_is_fixed_position(true); 71 fixed_to_top_left_.set_is_fixed_position(true);
70 fixed_to_bottom_right_.set_is_fixed_position(true); 72 fixed_to_bottom_right_.set_is_fixed_position(true);
71 fixed_to_bottom_right_.set_is_fixed_to_right_edge(true); 73 fixed_to_bottom_right_.set_is_fixed_to_right_edge(true);
72 fixed_to_bottom_right_.set_is_fixed_to_bottom_edge(true); 74 fixed_to_bottom_right_.set_is_fixed_to_bottom_edge(true);
73 } 75 }
74 76
75 scoped_ptr<LayerImpl> CreateTreeForTest() { 77 scoped_ptr<LayerImpl> CreateTreeForTest() {
76 scoped_ptr<LayerImpl> root = 78 scoped_ptr<LayerImpl> root =
79 LayerImpl::Create(host_impl_.active_tree(), 42);
80 scoped_ptr<LayerImpl> scroll_layer =
77 LayerImpl::Create(host_impl_.active_tree(), 1); 81 LayerImpl::Create(host_impl_.active_tree(), 1);
78 scoped_ptr<LayerImpl> child = 82 scoped_ptr<LayerImpl> child =
79 LayerImpl::Create(host_impl_.active_tree(), 2); 83 LayerImpl::Create(host_impl_.active_tree(), 2);
80 scoped_ptr<LayerImpl> grand_child = 84 scoped_ptr<LayerImpl> grand_child =
81 LayerImpl::Create(host_impl_.active_tree(), 3); 85 LayerImpl::Create(host_impl_.active_tree(), 3);
82 scoped_ptr<LayerImpl> great_grand_child = 86 scoped_ptr<LayerImpl> great_grand_child =
83 LayerImpl::Create(host_impl_.active_tree(), 4); 87 LayerImpl::Create(host_impl_.active_tree(), 4);
84 88
85 gfx::Transform IdentityMatrix; 89 gfx::Transform IdentityMatrix;
86 gfx::PointF anchor; 90 gfx::PointF anchor;
87 gfx::PointF position; 91 gfx::PointF position;
88 gfx::Size bounds(100, 100); 92 gfx::Size bounds(200, 200);
89 SetLayerPropertiesForTesting(root.get(), 93 gfx::Size clip_bounds(100, 100);
94 SetLayerPropertiesForTesting(scroll_layer.get(),
90 IdentityMatrix, 95 IdentityMatrix,
91 IdentityMatrix, 96 IdentityMatrix,
92 anchor, 97 anchor,
93 position, 98 position,
94 bounds, 99 bounds,
95 false); 100 false);
96 SetLayerPropertiesForTesting(child.get(), 101 SetLayerPropertiesForTesting(child.get(),
97 IdentityMatrix, 102 IdentityMatrix,
98 IdentityMatrix, 103 IdentityMatrix,
99 anchor, 104 anchor,
100 position, 105 position,
101 bounds, 106 bounds,
102 false); 107 false);
103 SetLayerPropertiesForTesting(grand_child.get(), 108 SetLayerPropertiesForTesting(grand_child.get(),
104 IdentityMatrix, 109 IdentityMatrix,
105 IdentityMatrix, 110 IdentityMatrix,
106 anchor, 111 anchor,
107 position, 112 position,
108 bounds, 113 bounds,
109 false); 114 false);
110 SetLayerPropertiesForTesting(great_grand_child.get(), 115 SetLayerPropertiesForTesting(great_grand_child.get(),
111 IdentityMatrix, 116 IdentityMatrix,
112 IdentityMatrix, 117 IdentityMatrix,
113 anchor, 118 anchor,
114 position, 119 position,
115 bounds, 120 bounds,
116 false); 121 false);
117 122
118 root->SetMaxScrollOffset(gfx::Vector2d(100, 100)); 123 root->SetBounds(clip_bounds);
119 root->SetScrollable(true); 124 scroll_layer->SetScrollable(root->id());
120 child->SetMaxScrollOffset(gfx::Vector2d(100, 100)); 125 child->SetScrollable(root->id());
121 child->SetScrollable(true); 126 grand_child->SetScrollable(root->id());
122 grand_child->SetMaxScrollOffset(gfx::Vector2d(100, 100));
123 grand_child->SetScrollable(true);
124 127
125 grand_child->AddChild(great_grand_child.Pass()); 128 grand_child->AddChild(great_grand_child.Pass());
126 child->AddChild(grand_child.Pass()); 129 child->AddChild(grand_child.Pass());
127 root->AddChild(child.Pass()); 130 scroll_layer->AddChild(child.Pass());
131 root->AddChild(scroll_layer.Pass());
128 132
129 return root.Pass(); 133 return root.Pass();
130 } 134 }
131 135
132 protected: 136 protected:
133 FakeImplProxy proxy_; 137 FakeImplProxy proxy_;
134 FakeLayerTreeHostImpl host_impl_; 138 FakeLayerTreeHostImpl host_impl_;
135 scoped_ptr<LayerImpl> root_; 139 scoped_ptr<LayerImpl> root_;
140 LayerImpl* scroll_;
136 141
137 LayerPositionConstraint fixed_to_top_left_; 142 LayerPositionConstraint fixed_to_top_left_;
138 LayerPositionConstraint fixed_to_bottom_right_; 143 LayerPositionConstraint fixed_to_bottom_right_;
139 }; 144 };
140 145
141 TEST_F(LayerPositionConstraintTest, 146 TEST_F(LayerPositionConstraintTest,
142 ScrollCompensationForFixedPositionLayerWithDirectContainer) { 147 ScrollCompensationForFixedPositionLayerWithDirectContainer) {
143 // This test checks for correct scroll compensation when the fixed-position 148 // This test checks for correct scroll compensation when the fixed-position
144 // container is the direct parent of the fixed-position layer. 149 // container is the direct parent of the fixed-position layer.
145 LayerImpl* child = root_->children()[0]; 150 LayerImpl* child = scroll_->children()[0];
146 LayerImpl* grand_child = child->children()[0]; 151 LayerImpl* grand_child = child->children()[0];
147 152
148 child->SetIsContainerForFixedPositionLayers(true); 153 child->SetIsContainerForFixedPositionLayers(true);
149 grand_child->SetPositionConstraint(fixed_to_top_left_); 154 grand_child->SetPositionConstraint(fixed_to_top_left_);
150 155
151 // Case 1: scroll delta of 0, 0 156 // Case 1: scroll delta of 0, 0
152 child->SetScrollDelta(gfx::Vector2d(0, 0)); 157 child->SetScrollDelta(gfx::Vector2d(0, 0));
153 ExecuteCalculateDrawProperties(root_.get()); 158 ExecuteCalculateDrawProperties(root_.get());
154 159
155 gfx::Transform expected_child_transform; 160 gfx::Transform expected_child_transform;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 ScrollCompensationForFixedPositionLayerWithTransformedDirectContainer) { 208 ScrollCompensationForFixedPositionLayerWithTransformedDirectContainer) {
204 // This test checks for correct scroll compensation when the fixed-position 209 // This test checks for correct scroll compensation when the fixed-position
205 // container is the direct parent of the fixed-position layer, but that 210 // container is the direct parent of the fixed-position layer, but that
206 // container is transformed. In this case, the fixed position element 211 // container is transformed. In this case, the fixed position element
207 // inherits the container's transform, but the scroll delta that has to be 212 // inherits the container's transform, but the scroll delta that has to be
208 // undone should not be affected by that transform. 213 // undone should not be affected by that transform.
209 // 214 //
210 // Transforms are in general non-commutative; using something like a 215 // Transforms are in general non-commutative; using something like a
211 // non-uniform scale helps to verify that translations and non-uniform scales 216 // non-uniform scale helps to verify that translations and non-uniform scales
212 // are applied in the correct order. 217 // are applied in the correct order.
213 LayerImpl* child = root_->children()[0]; 218 LayerImpl* child = scroll_->children()[0];
214 LayerImpl* grand_child = child->children()[0]; 219 LayerImpl* grand_child = child->children()[0];
215 220
216 // This scale will cause child and grand_child to be effectively 200 x 800 221 // This scale will cause child and grand_child to be effectively 200 x 800
217 // with respect to the render target. 222 // with respect to the render target.
218 gfx::Transform non_uniform_scale; 223 gfx::Transform non_uniform_scale;
219 non_uniform_scale.Scale(2.0, 8.0); 224 non_uniform_scale.Scale(2.0, 8.0);
220 child->SetTransform(non_uniform_scale); 225 child->SetTransform(non_uniform_scale);
221 226
222 child->SetIsContainerForFixedPositionLayers(true); 227 child->SetIsContainerForFixedPositionLayers(true);
223 grand_child->SetPositionConstraint(fixed_to_top_left_); 228 grand_child->SetPositionConstraint(fixed_to_top_left_);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, 280 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
276 child->draw_transform()); 281 child->draw_transform());
277 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, 282 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
278 grand_child->draw_transform()); 283 grand_child->draw_transform());
279 } 284 }
280 285
281 TEST_F(LayerPositionConstraintTest, 286 TEST_F(LayerPositionConstraintTest,
282 ScrollCompensationForFixedPositionLayerWithDistantContainer) { 287 ScrollCompensationForFixedPositionLayerWithDistantContainer) {
283 // This test checks for correct scroll compensation when the fixed-position 288 // This test checks for correct scroll compensation when the fixed-position
284 // container is NOT the direct parent of the fixed-position layer. 289 // container is NOT the direct parent of the fixed-position layer.
285 LayerImpl* child = root_->children()[0]; 290 LayerImpl* child = scroll_->children()[0];
286 LayerImpl* grand_child = child->children()[0]; 291 LayerImpl* grand_child = child->children()[0];
287 LayerImpl* great_grand_child = grand_child->children()[0]; 292 LayerImpl* great_grand_child = grand_child->children()[0];
288 293
289 child->SetIsContainerForFixedPositionLayers(true); 294 child->SetIsContainerForFixedPositionLayers(true);
290 grand_child->SetPosition(gfx::PointF(8.f, 6.f)); 295 grand_child->SetPosition(gfx::PointF(8.f, 6.f));
291 great_grand_child->SetPositionConstraint(fixed_to_top_left_); 296 great_grand_child->SetPositionConstraint(fixed_to_top_left_);
292 297
293 // Case 1: scroll delta of 0, 0 298 // Case 1: scroll delta of 0, 0
294 child->SetScrollDelta(gfx::Vector2d(0, 0)); 299 child->SetScrollDelta(gfx::Vector2d(0, 0));
295 ExecuteCalculateDrawProperties(root_.get()); 300 ExecuteCalculateDrawProperties(root_.get());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, 360 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
356 great_grand_child->draw_transform()); 361 great_grand_child->draw_transform());
357 } 362 }
358 363
359 TEST_F(LayerPositionConstraintTest, 364 TEST_F(LayerPositionConstraintTest,
360 ScrollCompensationForFixedPositionLayerWithDistantContainerAndTransforms) { 365 ScrollCompensationForFixedPositionLayerWithDistantContainerAndTransforms) {
361 // This test checks for correct scroll compensation when the fixed-position 366 // This test checks for correct scroll compensation when the fixed-position
362 // container is NOT the direct parent of the fixed-position layer, and the 367 // container is NOT the direct parent of the fixed-position layer, and the
363 // hierarchy has various transforms that have to be processed in the correct 368 // hierarchy has various transforms that have to be processed in the correct
364 // order. 369 // order.
365 LayerImpl* child = root_->children()[0]; 370 LayerImpl* child = scroll_->children()[0];
366 LayerImpl* grand_child = child->children()[0]; 371 LayerImpl* grand_child = child->children()[0];
367 LayerImpl* great_grand_child = grand_child->children()[0]; 372 LayerImpl* great_grand_child = grand_child->children()[0];
368 373
369 gfx::Transform rotation_about_z; 374 gfx::Transform rotation_about_z;
370 rotation_about_z.RotateAboutZAxis(90.0); 375 rotation_about_z.RotateAboutZAxis(90.0);
371 376
372 child->SetIsContainerForFixedPositionLayers(true); 377 child->SetIsContainerForFixedPositionLayers(true);
373 child->SetTransform(rotation_about_z); 378 child->SetTransform(rotation_about_z);
374 grand_child->SetPosition(gfx::PointF(8.f, 6.f)); 379 grand_child->SetPosition(gfx::PointF(8.f, 6.f));
375 grand_child->SetTransform(rotation_about_z); 380 grand_child->SetTransform(rotation_about_z);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 TEST_F(LayerPositionConstraintTest, 472 TEST_F(LayerPositionConstraintTest,
468 ScrollCompensationForFixedPositionLayerWithMultipleScrollDeltas) { 473 ScrollCompensationForFixedPositionLayerWithMultipleScrollDeltas) {
469 // This test checks for correct scroll compensation when the fixed-position 474 // This test checks for correct scroll compensation when the fixed-position
470 // container has multiple ancestors that have nonzero scroll delta before 475 // container has multiple ancestors that have nonzero scroll delta before
471 // reaching the space where the layer is fixed. In this test, each scroll 476 // reaching the space where the layer is fixed. In this test, each scroll
472 // delta occurs in a different space because of each layer's local transform. 477 // delta occurs in a different space because of each layer's local transform.
473 // This test checks for correct scroll compensation when the fixed-position 478 // This test checks for correct scroll compensation when the fixed-position
474 // container is NOT the direct parent of the fixed-position layer, and the 479 // container is NOT the direct parent of the fixed-position layer, and the
475 // hierarchy has various transforms that have to be processed in the correct 480 // hierarchy has various transforms that have to be processed in the correct
476 // order. 481 // order.
477 LayerImpl* child = root_->children()[0]; 482 LayerImpl* child = scroll_->children()[0];
478 LayerImpl* grand_child = child->children()[0]; 483 LayerImpl* grand_child = child->children()[0];
479 LayerImpl* great_grand_child = grand_child->children()[0]; 484 LayerImpl* great_grand_child = grand_child->children()[0];
480 485
481 gfx::Transform rotation_about_z; 486 gfx::Transform rotation_about_z;
482 rotation_about_z.RotateAboutZAxis(90.0); 487 rotation_about_z.RotateAboutZAxis(90.0);
483 488
484 child->SetIsContainerForFixedPositionLayers(true); 489 child->SetIsContainerForFixedPositionLayers(true);
485 child->SetTransform(rotation_about_z); 490 child->SetTransform(rotation_about_z);
486 grand_child->SetPosition(gfx::PointF(8.f, 6.f)); 491 grand_child->SetPosition(gfx::PointF(8.f, 6.f));
487 grand_child->SetTransform(rotation_about_z); 492 grand_child->SetTransform(rotation_about_z);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, 583 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
579 great_grand_child->draw_transform()); 584 great_grand_child->draw_transform());
580 } 585 }
581 586
582 TEST_F(LayerPositionConstraintTest, 587 TEST_F(LayerPositionConstraintTest,
583 ScrollCompensationForFixedPositionWithIntermediateSurfaceAndTransforms) { 588 ScrollCompensationForFixedPositionWithIntermediateSurfaceAndTransforms) {
584 // This test checks for correct scroll compensation when the fixed-position 589 // This test checks for correct scroll compensation when the fixed-position
585 // container contributes to a different render surface than the fixed-position 590 // container contributes to a different render surface than the fixed-position
586 // layer. In this case, the surface draw transforms also have to be accounted 591 // layer. In this case, the surface draw transforms also have to be accounted
587 // for when checking the scroll delta. 592 // for when checking the scroll delta.
588 LayerImpl* child = root_->children()[0]; 593 LayerImpl* child = scroll_->children()[0];
589 LayerImpl* grand_child = child->children()[0]; 594 LayerImpl* grand_child = child->children()[0];
590 LayerImpl* great_grand_child = grand_child->children()[0]; 595 LayerImpl* great_grand_child = grand_child->children()[0];
591 596
592 child->SetIsContainerForFixedPositionLayers(true); 597 child->SetIsContainerForFixedPositionLayers(true);
593 grand_child->SetPosition(gfx::PointF(8.f, 6.f)); 598 grand_child->SetPosition(gfx::PointF(8.f, 6.f));
594 grand_child->SetForceRenderSurface(true); 599 grand_child->SetForceRenderSurface(true);
595 great_grand_child->SetPositionConstraint(fixed_to_top_left_); 600 great_grand_child->SetPositionConstraint(fixed_to_top_left_);
596 great_grand_child->SetDrawsContent(true); 601 great_grand_child->SetDrawsContent(true);
597 602
598 gfx::Transform rotation_about_z; 603 gfx::Transform rotation_about_z;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 great_grand_child->draw_transform()); 707 great_grand_child->draw_transform());
703 } 708 }
704 709
705 TEST_F(LayerPositionConstraintTest, 710 TEST_F(LayerPositionConstraintTest,
706 ScrollCompensationForFixedPositionLayerWithMultipleIntermediateSurfaces) { 711 ScrollCompensationForFixedPositionLayerWithMultipleIntermediateSurfaces) {
707 // This test checks for correct scroll compensation when the fixed-position 712 // This test checks for correct scroll compensation when the fixed-position
708 // container contributes to a different render surface than the fixed-position 713 // container contributes to a different render surface than the fixed-position
709 // layer, with additional render surfaces in-between. This checks that the 714 // layer, with additional render surfaces in-between. This checks that the
710 // conversion to ancestor surfaces is accumulated properly in the final matrix 715 // conversion to ancestor surfaces is accumulated properly in the final matrix
711 // transform. 716 // transform.
712 LayerImpl* child = root_->children()[0]; 717 LayerImpl* child = scroll_->children()[0];
713 LayerImpl* grand_child = child->children()[0]; 718 LayerImpl* grand_child = child->children()[0];
714 LayerImpl* great_grand_child = grand_child->children()[0]; 719 LayerImpl* great_grand_child = grand_child->children()[0];
715 720
716 // Add one more layer to the test tree for this scenario. 721 // Add one more layer to the test tree for this scenario.
717 { 722 {
718 gfx::Transform identity; 723 gfx::Transform identity;
719 scoped_ptr<LayerImpl> fixed_position_child = 724 scoped_ptr<LayerImpl> fixed_position_child =
720 LayerImpl::Create(host_impl_.active_tree(), 5); 725 LayerImpl::Create(host_impl_.active_tree(), 5);
721 SetLayerPropertiesForTesting(fixed_position_child.get(), 726 SetLayerPropertiesForTesting(fixed_position_child.get(),
722 identity, 727 identity,
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 fixed_position_child->draw_transform()); 894 fixed_position_child->draw_transform());
890 } 895 }
891 896
892 TEST_F(LayerPositionConstraintTest, 897 TEST_F(LayerPositionConstraintTest,
893 ScrollCompensationForFixedPositionLayerWithContainerLayerThatHasSurface) { 898 ScrollCompensationForFixedPositionLayerWithContainerLayerThatHasSurface) {
894 // This test checks for correct scroll compensation when the fixed-position 899 // This test checks for correct scroll compensation when the fixed-position
895 // container itself has a render surface. In this case, the container layer 900 // container itself has a render surface. In this case, the container layer
896 // should be treated like a layer that contributes to a render target, and 901 // should be treated like a layer that contributes to a render target, and
897 // that render target is completely irrelevant; it should not affect the 902 // that render target is completely irrelevant; it should not affect the
898 // scroll compensation. 903 // scroll compensation.
899 LayerImpl* child = root_->children()[0]; 904 LayerImpl* child = scroll_->children()[0];
900 LayerImpl* grand_child = child->children()[0]; 905 LayerImpl* grand_child = child->children()[0];
901 906
902 child->SetIsContainerForFixedPositionLayers(true); 907 child->SetIsContainerForFixedPositionLayers(true);
903 child->SetForceRenderSurface(true); 908 child->SetForceRenderSurface(true);
904 grand_child->SetPositionConstraint(fixed_to_top_left_); 909 grand_child->SetPositionConstraint(fixed_to_top_left_);
905 grand_child->SetDrawsContent(true); 910 grand_child->SetDrawsContent(true);
906 911
907 // Case 1: scroll delta of 0, 0 912 // Case 1: scroll delta of 0, 0
908 child->SetScrollDelta(gfx::Vector2d(0, 0)); 913 child->SetScrollDelta(gfx::Vector2d(0, 0));
909 ExecuteCalculateDrawProperties(root_.get()); 914 ExecuteCalculateDrawProperties(root_.get());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 child->draw_transform()); 972 child->draw_transform());
968 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, 973 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
969 grand_child->draw_transform()); 974 grand_child->draw_transform());
970 } 975 }
971 976
972 TEST_F(LayerPositionConstraintTest, 977 TEST_F(LayerPositionConstraintTest,
973 ScrollCompensationForFixedPositionLayerThatIsAlsoFixedPositionContainer) { 978 ScrollCompensationForFixedPositionLayerThatIsAlsoFixedPositionContainer) {
974 // This test checks the scenario where a fixed-position layer also happens to 979 // This test checks the scenario where a fixed-position layer also happens to
975 // be a container itself for a descendant fixed position layer. In particular, 980 // be a container itself for a descendant fixed position layer. In particular,
976 // the layer should not accidentally be fixed to itself. 981 // the layer should not accidentally be fixed to itself.
977 LayerImpl* child = root_->children()[0]; 982 LayerImpl* child = scroll_->children()[0];
978 LayerImpl* grand_child = child->children()[0]; 983 LayerImpl* grand_child = child->children()[0];
979 984
980 child->SetIsContainerForFixedPositionLayers(true); 985 child->SetIsContainerForFixedPositionLayers(true);
981 grand_child->SetPositionConstraint(fixed_to_top_left_); 986 grand_child->SetPositionConstraint(fixed_to_top_left_);
982 987
983 // This should not confuse the grand_child. If correct, the grand_child would 988 // This should not confuse the grand_child. If correct, the grand_child would
984 // still be considered fixed to its container (i.e. "child"). 989 // still be considered fixed to its container (i.e. "child").
985 grand_child->SetIsContainerForFixedPositionLayers(true); 990 grand_child->SetIsContainerForFixedPositionLayers(true);
986 991
987 // Case 1: scroll delta of 0, 0 992 // Case 1: scroll delta of 0, 0
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 child->draw_transform()); 1036 child->draw_transform());
1032 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, 1037 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
1033 grand_child->draw_transform()); 1038 grand_child->draw_transform());
1034 } 1039 }
1035 1040
1036 TEST_F(LayerPositionConstraintTest, 1041 TEST_F(LayerPositionConstraintTest,
1037 ScrollCompensationForFixedPositionLayerThatHasNoContainer) { 1042 ScrollCompensationForFixedPositionLayerThatHasNoContainer) {
1038 // This test checks scroll compensation when a fixed-position layer does not 1043 // This test checks scroll compensation when a fixed-position layer does not
1039 // find any ancestor that is a "containerForFixedPositionLayers". In this 1044 // find any ancestor that is a "containerForFixedPositionLayers". In this
1040 // situation, the layer should be fixed to the root layer. 1045 // situation, the layer should be fixed to the root layer.
1041 LayerImpl* child = root_->children()[0]; 1046 LayerImpl* child = scroll_->children()[0];
1042 LayerImpl* grand_child = child->children()[0]; 1047 LayerImpl* grand_child = child->children()[0];
1043 1048
1044 gfx::Transform rotation_by_z; 1049 gfx::Transform rotation_by_z;
1045 rotation_by_z.RotateAboutZAxis(90.0); 1050 rotation_by_z.RotateAboutZAxis(90.0);
1046 1051
1047 root_->SetTransform(rotation_by_z); 1052 scroll_->SetTransform(rotation_by_z);
1048 grand_child->SetPositionConstraint(fixed_to_top_left_); 1053 grand_child->SetPositionConstraint(fixed_to_top_left_);
1049 1054
1050 // Case 1: root scroll delta of 0, 0 1055 // Case 1: root scroll delta of 0, 0
1051 root_->SetScrollDelta(gfx::Vector2d(0, 0)); 1056 scroll_->SetScrollDelta(gfx::Vector2d(0, 0));
1052 ExecuteCalculateDrawProperties(root_.get()); 1057 ExecuteCalculateDrawProperties(root_.get());
1053 1058
1054 gfx::Transform identity_matrix; 1059 gfx::Transform identity_matrix;
1055 1060
1056 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_by_z, child->draw_transform()); 1061 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_by_z, child->draw_transform());
1057 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_by_z, 1062 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_by_z,
1058 grand_child->draw_transform()); 1063 grand_child->draw_transform());
1059 1064
1060 // Case 2: root scroll delta of 10, 10 1065 // Case 2: root scroll delta of 10, 10
1061 root_->SetScrollDelta(gfx::Vector2d(10, 20)); 1066 scroll_->SetScrollDelta(gfx::Vector2d(10, 20));
1062 ExecuteCalculateDrawProperties(root_.get()); 1067 ExecuteCalculateDrawProperties(root_.get());
1063 1068
1064 gfx::Transform expected_child_transform; 1069 gfx::Transform expected_child_transform;
1065 expected_child_transform.Translate(-10.0, -20.0); 1070 expected_child_transform.Translate(-10.0, -20.0);
1066 expected_child_transform.PreconcatTransform(rotation_by_z); 1071 expected_child_transform.PreconcatTransform(rotation_by_z);
1067 1072
1068 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, 1073 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
1069 child->draw_transform()); 1074 child->draw_transform());
1070 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_by_z, 1075 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_by_z,
1071 grand_child->draw_transform()); 1076 grand_child->draw_transform());
1072 1077
1073 // Case 3: fixed-container size delta of 20, 20 1078 // Case 3: fixed-container size delta of 20, 20
1074 root_->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20)); 1079 root_->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20));
1075 ExecuteCalculateDrawProperties(root_.get()); 1080 ExecuteCalculateDrawProperties(root_.get());
1076 1081
1077 // Top-left fixed-position layer should not be affected by container size. 1082 // Top-left fixed-position layer should not be affected by container size.
1078 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, 1083 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
1079 child->draw_transform()); 1084 child->draw_transform());
1080 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_by_z, 1085 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_by_z,
1081 grand_child->draw_transform()); 1086 grand_child->draw_transform());
1082 1087
1083 // Case 4: Bottom-right fixed-position layer. 1088 // Case 4: Bottom-right fixed-position layer.
1084 grand_child->SetPositionConstraint(fixed_to_bottom_right_); 1089 grand_child->SetPositionConstraint(fixed_to_bottom_right_);
1085 ExecuteCalculateDrawProperties(root_.get()); 1090 ExecuteCalculateDrawProperties(root_.get());
1086 1091
1087 gfx::Transform expected_grand_child_transform; 1092 gfx::Transform expected_grand_child_transform;
1088 expected_grand_child_transform.Translate(-20.0, 20.0); 1093 // TODO(wjmaclean) Not sure why this used to be (-20, 20), is this right?
enne (OOO) 2013/11/19 19:30:22 I would talk to shawnsingh about this, but I think
wjmaclean 2013/12/24 21:03:49 I have contacted Shawn about this, and will resolv
1094 expected_grand_child_transform.Translate(20.0, 20.0);
1089 expected_grand_child_transform.PreconcatTransform(rotation_by_z); 1095 expected_grand_child_transform.PreconcatTransform(rotation_by_z);
1090 1096
1091 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, 1097 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
1092 child->draw_transform()); 1098 child->draw_transform());
1093 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, 1099 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
1094 grand_child->draw_transform()); 1100 grand_child->draw_transform());
1095 } 1101 }
1096 1102
1097 TEST_F(LayerPositionConstraintTest, 1103 TEST_F(LayerPositionConstraintTest,
1098 ScrollCompensationForFixedWithinFixedWithSameContainer) { 1104 ScrollCompensationForFixedWithinFixedWithSameContainer) {
1099 // This test checks scroll compensation for a fixed-position layer that is 1105 // This test checks scroll compensation for a fixed-position layer that is
1100 // inside of another fixed-position layer and both share the same container. 1106 // inside of another fixed-position layer and both share the same container.
1101 // In this situation, the parent fixed-position layer will receive 1107 // In this situation, the parent fixed-position layer will receive
1102 // the scroll compensation, and the child fixed-position layer does not 1108 // the scroll compensation, and the child fixed-position layer does not
1103 // need to compensate further. 1109 // need to compensate further.
1104 1110
1105 LayerImpl* child = root_->children()[0]; 1111 LayerImpl* child = scroll_->children()[0];
1106 LayerImpl* grand_child = child->children()[0]; 1112 LayerImpl* grand_child = child->children()[0];
1107 LayerImpl* great_grand_child = grand_child->children()[0]; 1113 LayerImpl* great_grand_child = grand_child->children()[0];
1108 1114
1109 child->SetIsContainerForFixedPositionLayers(true); 1115 child->SetIsContainerForFixedPositionLayers(true);
1110 grand_child->SetPositionConstraint(fixed_to_top_left_); 1116 grand_child->SetPositionConstraint(fixed_to_top_left_);
1111 1117
1112 // Note carefully - great_grand_child is fixed to bottom right, to test 1118 // Note carefully - great_grand_child is fixed to bottom right, to test
1113 // sizeDelta being applied correctly; the compensation skips the grand_child 1119 // sizeDelta being applied correctly; the compensation skips the grand_child
1114 // because it is fixed to top left. 1120 // because it is fixed to top left.
1115 great_grand_child->SetPositionConstraint(fixed_to_bottom_right_); 1121 great_grand_child->SetPositionConstraint(fixed_to_bottom_right_);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 great_grand_child->draw_transform()); 1160 great_grand_child->draw_transform());
1155 } 1161 }
1156 1162
1157 TEST_F(LayerPositionConstraintTest, 1163 TEST_F(LayerPositionConstraintTest,
1158 ScrollCompensationForFixedWithinFixedWithInterveningContainer) { 1164 ScrollCompensationForFixedWithinFixedWithInterveningContainer) {
1159 // This test checks scroll compensation for a fixed-position layer that is 1165 // This test checks scroll compensation for a fixed-position layer that is
1160 // inside of another fixed-position layer, but they have different fixed 1166 // inside of another fixed-position layer, but they have different fixed
1161 // position containers. In this situation, the child fixed-position element 1167 // position containers. In this situation, the child fixed-position element
1162 // would still have to compensate with respect to its container. 1168 // would still have to compensate with respect to its container.
1163 1169
1164 LayerImpl* container1 = root_->children()[0]; 1170 LayerImpl* container1 = scroll_->children()[0];
1165 LayerImpl* fixed_to_container1 = container1->children()[0]; 1171 LayerImpl* fixed_to_container1 = container1->children()[0];
1166 LayerImpl* container2 = fixed_to_container1->children()[0]; 1172 LayerImpl* container2 = fixed_to_container1->children()[0];
1167 1173
1168 { 1174 {
1169 // Add one more layer to the hierarchy for this test. 1175 // Add one more layer to the hierarchy for this test.
1170 scoped_ptr<LayerImpl> fixed_to_container2_ptr = 1176 scoped_ptr<LayerImpl> fixed_to_container2_ptr =
1171 LayerImpl::Create(host_impl_.active_tree(), 5); 1177 LayerImpl::Create(host_impl_.active_tree(), 5);
1172 container2->AddChild(fixed_to_container2_ptr.Pass()); 1178 container2->AddChild(fixed_to_container2_ptr.Pass());
1173 } 1179 }
1174 1180
(...skipping 29 matching lines...) Expand all
1204 1210
1205 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_container2_transform, 1211 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_container2_transform,
1206 container2->draw_transform()); 1212 container2->draw_transform());
1207 1213
1208 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_to_container2_transform, 1214 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_to_container2_transform,
1209 fixed_to_container2->draw_transform()); 1215 fixed_to_container2->draw_transform());
1210 } 1216 }
1211 1217
1212 } // namespace 1218 } // namespace
1213 } // namespace cc 1219 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698