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