| 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/animation/animation_host.h" | 9 #include "cc/animation/animation_host.h" |
| 10 #include "cc/layers/layer.h" | 10 #include "cc/layers/layer.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 SetLayerPropertiesForTesting(child_.get(), IdentityMatrix, transform_origin, | 111 SetLayerPropertiesForTesting(child_.get(), IdentityMatrix, transform_origin, |
| 112 position, bounds, true); | 112 position, bounds, true); |
| 113 SetLayerPropertiesForTesting(grand_child_.get(), IdentityMatrix, | 113 SetLayerPropertiesForTesting(grand_child_.get(), IdentityMatrix, |
| 114 transform_origin, position, bounds, true); | 114 transform_origin, position, bounds, true); |
| 115 SetLayerPropertiesForTesting(great_grand_child_.get(), IdentityMatrix, | 115 SetLayerPropertiesForTesting(great_grand_child_.get(), IdentityMatrix, |
| 116 transform_origin, position, bounds, true); | 116 transform_origin, position, bounds, true); |
| 117 | 117 |
| 118 root_->SetBounds(clip_bounds); | 118 root_->SetBounds(clip_bounds); |
| 119 | 119 |
| 120 inner_viewport_container_layer_->SetMasksToBounds(true); | 120 inner_viewport_container_layer_->SetMasksToBounds(true); |
| 121 inner_viewport_container_layer_->SetIsContainerForFixedPositionLayers(true); |
| 121 scroll_layer_->SetScrollClipLayerId(inner_viewport_container_layer_->id()); | 122 scroll_layer_->SetScrollClipLayerId(inner_viewport_container_layer_->id()); |
| 122 scroll_layer_->SetIsContainerForFixedPositionLayers(true); | |
| 123 | 123 |
| 124 outer_viewport_container_layer_->SetMasksToBounds(true); | 124 outer_viewport_container_layer_->SetMasksToBounds(true); |
| 125 outer_viewport_container_layer_->SetIsContainerForFixedPositionLayers(true); |
| 125 child_->SetScrollClipLayerId(outer_viewport_container_layer_->id()); | 126 child_->SetScrollClipLayerId(outer_viewport_container_layer_->id()); |
| 126 grand_child_->SetScrollClipLayerId(outer_viewport_container_layer_->id()); | 127 grand_child_->SetScrollClipLayerId(outer_viewport_container_layer_->id()); |
| 127 | 128 |
| 128 grand_child_->AddChild(great_grand_child_); | 129 grand_child_->AddChild(great_grand_child_); |
| 129 child_->AddChild(grand_child_); | 130 child_->AddChild(grand_child_); |
| 130 child_transform_layer_->AddChild(child_); | 131 child_transform_layer_->AddChild(child_); |
| 131 outer_viewport_container_layer_->AddChild(child_transform_layer_); | 132 outer_viewport_container_layer_->AddChild(child_transform_layer_); |
| 132 scroll_layer_->AddChild(outer_viewport_container_layer_); | 133 scroll_layer_->AddChild(outer_viewport_container_layer_); |
| 133 inner_viewport_container_layer_->AddChild(scroll_layer_); | 134 inner_viewport_container_layer_->AddChild(scroll_layer_); |
| 134 root_->AddChild(inner_viewport_container_layer_); | 135 root_->AddChild(inner_viewport_container_layer_); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 ->scroll_tree.SetScrollOffsetDeltaForTesting(layer_impl->id(), | 205 ->scroll_tree.SetScrollOffsetDeltaForTesting(layer_impl->id(), |
| 205 delta)) | 206 delta)) |
| 206 layer_impl->layer_tree_impl()->DidUpdateScrollOffset(layer_impl->id()); | 207 layer_impl->layer_tree_impl()->DidUpdateScrollOffset(layer_impl->id()); |
| 207 } | 208 } |
| 208 }; | 209 }; |
| 209 | 210 |
| 210 TEST_F(LayerPositionConstraintTest, | 211 TEST_F(LayerPositionConstraintTest, |
| 211 ScrollCompensationForFixedPositionLayerWithDirectContainer) { | 212 ScrollCompensationForFixedPositionLayerWithDirectContainer) { |
| 212 // This test checks for correct scroll compensation when the fixed-position | 213 // This test checks for correct scroll compensation when the fixed-position |
| 213 // container is the direct parent of the fixed-position layer. | 214 // container is the direct parent of the fixed-position layer. |
| 214 child_->SetIsContainerForFixedPositionLayers(true); | |
| 215 grand_child_->SetPositionConstraint(fixed_to_top_left_); | 215 grand_child_->SetPositionConstraint(fixed_to_top_left_); |
| 216 | 216 |
| 217 CommitAndUpdateImplPointers(); | 217 CommitAndUpdateImplPointers(); |
| 218 | 218 |
| 219 // Case 1: scroll delta of 0, 0 | 219 // Case 1: scroll delta of 0, 0 |
| 220 SetScrollOffsetDelta(child_impl_, gfx::Vector2d(0, 0)); | 220 SetScrollOffsetDelta(child_impl_, gfx::Vector2d(0, 0)); |
| 221 ExecuteCalculateDrawProperties(root_impl_); | 221 ExecuteCalculateDrawProperties(root_impl_); |
| 222 | 222 |
| 223 gfx::Transform expected_child_transform; | 223 gfx::Transform expected_child_transform; |
| 224 gfx::Transform expected_grand_child_transform = expected_child_transform; | 224 gfx::Transform expected_grand_child_transform = expected_child_transform; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | 271 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 272 child_impl_->DrawTransform()); | 272 child_impl_->DrawTransform()); |
| 273 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | 273 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, |
| 274 grand_child_impl_->DrawTransform()); | 274 grand_child_impl_->DrawTransform()); |
| 275 } | 275 } |
| 276 | 276 |
| 277 TEST_F(LayerPositionConstraintTest, | 277 TEST_F(LayerPositionConstraintTest, |
| 278 ScrollCompensationForFixedPositionLayerWithDistantContainer) { | 278 ScrollCompensationForFixedPositionLayerWithDistantContainer) { |
| 279 // This test checks for correct scroll compensation when the fixed-position | 279 // This test checks for correct scroll compensation when the fixed-position |
| 280 // container is NOT the direct parent of the fixed-position layer. | 280 // container is NOT the direct parent of the fixed-position layer. |
| 281 child_->SetIsContainerForFixedPositionLayers(true); | |
| 282 grand_child_->SetPosition(gfx::PointF(8.f, 6.f)); | 281 grand_child_->SetPosition(gfx::PointF(8.f, 6.f)); |
| 283 great_grand_child_->SetPositionConstraint(fixed_to_top_left_); | 282 great_grand_child_->SetPositionConstraint(fixed_to_top_left_); |
| 284 | 283 |
| 285 CommitAndUpdateImplPointers(); | 284 CommitAndUpdateImplPointers(); |
| 286 | 285 |
| 287 // Case 1: scroll delta of 0, 0 | 286 // Case 1: scroll delta of 0, 0 |
| 288 SetScrollOffsetDelta(child_impl_, gfx::Vector2d(0, 0)); | 287 SetScrollOffsetDelta(child_impl_, gfx::Vector2d(0, 0)); |
| 289 child_impl_->SetDrawsContent(true); | 288 child_impl_->SetDrawsContent(true); |
| 290 ExecuteCalculateDrawProperties(root_impl_); | 289 ExecuteCalculateDrawProperties(root_impl_); |
| 291 | 290 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | 422 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, |
| 424 great_grand_child_impl_->DrawTransform()); | 423 great_grand_child_impl_->DrawTransform()); |
| 425 } | 424 } |
| 426 | 425 |
| 427 TEST_F(LayerPositionConstraintTest, | 426 TEST_F(LayerPositionConstraintTest, |
| 428 ScrollCompensationForFixedPositionWithIntermediateSurfaceAndTransforms) { | 427 ScrollCompensationForFixedPositionWithIntermediateSurfaceAndTransforms) { |
| 429 // This test checks for correct scroll compensation when the fixed-position | 428 // This test checks for correct scroll compensation when the fixed-position |
| 430 // container contributes to a different render surface than the fixed-position | 429 // container contributes to a different render surface than the fixed-position |
| 431 // layer. In this case, the surface draw transforms also have to be accounted | 430 // layer. In this case, the surface draw transforms also have to be accounted |
| 432 // for when checking the scroll delta. | 431 // for when checking the scroll delta. |
| 433 child_->SetIsContainerForFixedPositionLayers(true); | |
| 434 grand_child_->SetPosition(gfx::PointF(8.f, 6.f)); | 432 grand_child_->SetPosition(gfx::PointF(8.f, 6.f)); |
| 435 grand_child_->SetForceRenderSurfaceForTesting(true); | 433 grand_child_->SetForceRenderSurfaceForTesting(true); |
| 436 great_grand_child_->SetPositionConstraint(fixed_to_top_left_); | 434 great_grand_child_->SetPositionConstraint(fixed_to_top_left_); |
| 437 | 435 |
| 438 gfx::Transform rotation_about_z; | 436 gfx::Transform rotation_about_z; |
| 439 rotation_about_z.RotateAboutZAxis(90.0); | 437 rotation_about_z.RotateAboutZAxis(90.0); |
| 440 great_grand_child_->SetTransform(rotation_about_z); | 438 great_grand_child_->SetTransform(rotation_about_z); |
| 441 | 439 |
| 442 CommitAndUpdateImplPointers(); | 440 CommitAndUpdateImplPointers(); |
| 443 | 441 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 | 547 |
| 550 // Add one more layer to the test tree for this scenario. | 548 // Add one more layer to the test tree for this scenario. |
| 551 scoped_refptr<Layer> fixed_position_child = | 549 scoped_refptr<Layer> fixed_position_child = |
| 552 make_scoped_refptr(new LayerWithForcedDrawsContent()); | 550 make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 553 SetLayerPropertiesForTesting(fixed_position_child.get(), gfx::Transform(), | 551 SetLayerPropertiesForTesting(fixed_position_child.get(), gfx::Transform(), |
| 554 gfx::Point3F(), gfx::PointF(), | 552 gfx::Point3F(), gfx::PointF(), |
| 555 gfx::Size(100, 100), true); | 553 gfx::Size(100, 100), true); |
| 556 great_grand_child_->AddChild(fixed_position_child); | 554 great_grand_child_->AddChild(fixed_position_child); |
| 557 | 555 |
| 558 // Actually set up the scenario here. | 556 // Actually set up the scenario here. |
| 559 child_->SetIsContainerForFixedPositionLayers(true); | |
| 560 grand_child_->SetPosition(gfx::PointF(8.f, 6.f)); | 557 grand_child_->SetPosition(gfx::PointF(8.f, 6.f)); |
| 561 grand_child_->SetForceRenderSurfaceForTesting(true); | 558 grand_child_->SetForceRenderSurfaceForTesting(true); |
| 562 great_grand_child_->SetPosition(gfx::PointF(40.f, 60.f)); | 559 great_grand_child_->SetPosition(gfx::PointF(40.f, 60.f)); |
| 563 great_grand_child_->SetForceRenderSurfaceForTesting(true); | 560 great_grand_child_->SetForceRenderSurfaceForTesting(true); |
| 564 fixed_position_child->SetPositionConstraint(fixed_to_top_left_); | 561 fixed_position_child->SetPositionConstraint(fixed_to_top_left_); |
| 565 | 562 |
| 566 // The additional rotation, which is non-commutative with translations, helps | 563 // The additional rotation, which is non-commutative with translations, helps |
| 567 // to verify that we have correct order-of-operations in the final scroll | 564 // to verify that we have correct order-of-operations in the final scroll |
| 568 // compensation. Note that rotating about the center of the layer ensures we | 565 // compensation. Note that rotating about the center of the layer ensures we |
| 569 // do not accidentally clip away layers that we want to test. | 566 // do not accidentally clip away layers that we want to test. |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 fixed_position_child_impl->DrawTransform()); | 821 fixed_position_child_impl->DrawTransform()); |
| 825 } | 822 } |
| 826 | 823 |
| 827 TEST_F(LayerPositionConstraintTest, | 824 TEST_F(LayerPositionConstraintTest, |
| 828 ScrollCompensationForFixedPositionLayerWithContainerLayerThatHasSurface) { | 825 ScrollCompensationForFixedPositionLayerWithContainerLayerThatHasSurface) { |
| 829 // This test checks for correct scroll compensation when the fixed-position | 826 // This test checks for correct scroll compensation when the fixed-position |
| 830 // container itself has a render surface. In this case, the container layer | 827 // container itself has a render surface. In this case, the container layer |
| 831 // should be treated like a layer that contributes to a render target, and | 828 // should be treated like a layer that contributes to a render target, and |
| 832 // that render target is completely irrelevant; it should not affect the | 829 // that render target is completely irrelevant; it should not affect the |
| 833 // scroll compensation. | 830 // scroll compensation. |
| 834 child_->SetIsContainerForFixedPositionLayers(true); | |
| 835 child_->SetForceRenderSurfaceForTesting(true); | 831 child_->SetForceRenderSurfaceForTesting(true); |
| 836 grand_child_->SetPositionConstraint(fixed_to_top_left_); | 832 grand_child_->SetPositionConstraint(fixed_to_top_left_); |
| 837 | 833 |
| 838 CommitAndUpdateImplPointers(); | 834 CommitAndUpdateImplPointers(); |
| 839 | 835 |
| 840 // Case 1: scroll delta of 0, 0 | 836 // Case 1: scroll delta of 0, 0 |
| 841 SetScrollOffsetDelta(child_impl_, gfx::Vector2d(0, 0)); | 837 SetScrollOffsetDelta(child_impl_, gfx::Vector2d(0, 0)); |
| 842 ExecuteCalculateDrawProperties(root_impl_); | 838 ExecuteCalculateDrawProperties(root_impl_); |
| 843 | 839 |
| 844 gfx::Transform expected_surface_draw_transform; | 840 gfx::Transform expected_surface_draw_transform; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 child_impl_->DrawTransform()); | 902 child_impl_->DrawTransform()); |
| 907 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | 903 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, |
| 908 grand_child_impl_->DrawTransform()); | 904 grand_child_impl_->DrawTransform()); |
| 909 } | 905 } |
| 910 | 906 |
| 911 TEST_F(LayerPositionConstraintTest, | 907 TEST_F(LayerPositionConstraintTest, |
| 912 ScrollCompensationForFixedPositionLayerThatIsAlsoFixedPositionContainer) { | 908 ScrollCompensationForFixedPositionLayerThatIsAlsoFixedPositionContainer) { |
| 913 // This test checks the scenario where a fixed-position layer also happens to | 909 // This test checks the scenario where a fixed-position layer also happens to |
| 914 // be a container itself for a descendant fixed position layer. In particular, | 910 // be a container itself for a descendant fixed position layer. In particular, |
| 915 // the layer should not accidentally be fixed to itself. | 911 // the layer should not accidentally be fixed to itself. |
| 916 child_->SetIsContainerForFixedPositionLayers(true); | |
| 917 grand_child_->SetPositionConstraint(fixed_to_top_left_); | 912 grand_child_->SetPositionConstraint(fixed_to_top_left_); |
| 918 | |
| 919 // This should not confuse the grand_child. If correct, the grand_child would | |
| 920 // still be considered fixed to its container (i.e. "child"). | |
| 921 grand_child_->SetIsContainerForFixedPositionLayers(true); | 913 grand_child_->SetIsContainerForFixedPositionLayers(true); |
| 922 | 914 |
| 923 CommitAndUpdateImplPointers(); | 915 CommitAndUpdateImplPointers(); |
| 924 | 916 |
| 925 // Case 1: scroll delta of 0, 0 | 917 // Case 1: scroll delta of 0, 0 |
| 926 SetScrollOffsetDelta(child_impl_, gfx::Vector2d(0, 0)); | 918 SetScrollOffsetDelta(child_impl_, gfx::Vector2d(0, 0)); |
| 927 child_impl_->SetDrawsContent(true); | 919 child_impl_->SetDrawsContent(true); |
| 928 ExecuteCalculateDrawProperties(root_impl_); | 920 ExecuteCalculateDrawProperties(root_impl_); |
| 929 | 921 |
| 930 gfx::Transform expected_child_transform; | 922 gfx::Transform expected_child_transform; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 grand_child_impl_->DrawTransform()); | 970 grand_child_impl_->DrawTransform()); |
| 979 } | 971 } |
| 980 | 972 |
| 981 TEST_F(LayerPositionConstraintTest, | 973 TEST_F(LayerPositionConstraintTest, |
| 982 ScrollCompensationForFixedWithinFixedWithSameContainer) { | 974 ScrollCompensationForFixedWithinFixedWithSameContainer) { |
| 983 // This test checks scroll compensation for a fixed-position layer that is | 975 // This test checks scroll compensation for a fixed-position layer that is |
| 984 // inside of another fixed-position layer and both share the same container. | 976 // inside of another fixed-position layer and both share the same container. |
| 985 // In this situation, the parent fixed-position layer will receive | 977 // In this situation, the parent fixed-position layer will receive |
| 986 // the scroll compensation, and the child fixed-position layer does not | 978 // the scroll compensation, and the child fixed-position layer does not |
| 987 // need to compensate further. | 979 // need to compensate further. |
| 988 child_->SetIsContainerForFixedPositionLayers(true); | |
| 989 grand_child_->SetPositionConstraint(fixed_to_top_left_); | 980 grand_child_->SetPositionConstraint(fixed_to_top_left_); |
| 990 | 981 |
| 991 // Note carefully - great_grand_child is fixed to bottom right, to test | 982 // Note carefully - great_grand_child is fixed to bottom right, to test |
| 992 // sizeDelta being applied correctly; the compensation skips the grand_child | 983 // sizeDelta being applied correctly; the compensation skips the grand_child |
| 993 // because it is fixed to top left. | 984 // because it is fixed to top left. |
| 994 great_grand_child_->SetPositionConstraint(fixed_to_bottom_right_); | 985 great_grand_child_->SetPositionConstraint(fixed_to_bottom_right_); |
| 995 | 986 |
| 996 CommitAndUpdateImplPointers(); | 987 CommitAndUpdateImplPointers(); |
| 997 | 988 |
| 998 // Case 1: scrollDelta | 989 // Case 1: scrollDelta |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 // This test checks scroll compensation for a fixed-position layer that is | 1033 // This test checks scroll compensation for a fixed-position layer that is |
| 1043 // inside of another fixed-position layer, but they have different fixed | 1034 // inside of another fixed-position layer, but they have different fixed |
| 1044 // position containers. In this situation, the child fixed-position element | 1035 // position containers. In this situation, the child fixed-position element |
| 1045 // would still have to compensate with respect to its container. | 1036 // would still have to compensate with respect to its container. |
| 1046 | 1037 |
| 1047 // Add one more layer to the hierarchy for this test. | 1038 // Add one more layer to the hierarchy for this test. |
| 1048 scoped_refptr<Layer> great_great_grand_child = | 1039 scoped_refptr<Layer> great_great_grand_child = |
| 1049 make_scoped_refptr(new LayerWithForcedDrawsContent()); | 1040 make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1050 great_grand_child_->AddChild(great_great_grand_child); | 1041 great_grand_child_->AddChild(great_great_grand_child); |
| 1051 | 1042 |
| 1052 child_->SetIsContainerForFixedPositionLayers(true); | |
| 1053 grand_child_->SetPositionConstraint(fixed_to_top_left_); | 1043 grand_child_->SetPositionConstraint(fixed_to_top_left_); |
| 1054 great_grand_child_->SetIsContainerForFixedPositionLayers(true); | 1044 grand_child_->SetIsContainerForFixedPositionLayers(true); |
| 1055 great_grand_child_->SetScrollClipLayerId(root_->id()); | 1045 great_grand_child_->SetScrollClipLayerId(root_->id()); |
| 1056 great_great_grand_child->SetPositionConstraint(fixed_to_top_left_); | 1046 great_great_grand_child->SetPositionConstraint(fixed_to_top_left_); |
| 1057 | 1047 |
| 1058 CommitAndUpdateImplPointers(); | 1048 CommitAndUpdateImplPointers(); |
| 1059 | 1049 |
| 1060 LayerImpl* container1 = child_impl_; | 1050 LayerImpl* container1 = child_impl_; |
| 1061 LayerImpl* fixed_to_container1 = grand_child_impl_; | 1051 LayerImpl* fixed_to_container1 = grand_child_impl_; |
| 1062 LayerImpl* container2 = great_grand_child_impl_; | 1052 LayerImpl* container2 = great_grand_child_impl_; |
| 1063 LayerImpl* fixed_to_container2 = | 1053 LayerImpl* fixed_to_container2 = |
| 1064 layer_tree_impl_->LayerById(great_great_grand_child->id()); | 1054 layer_tree_impl_->LayerById(great_great_grand_child->id()); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1144 expected_fixed_child_transform.Translate(20.0, 20.0); | 1134 expected_fixed_child_transform.Translate(20.0, 20.0); |
| 1145 | 1135 |
| 1146 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_layer_transform, | 1136 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_layer_transform, |
| 1147 scroll_layer_impl_->DrawTransform()); | 1137 scroll_layer_impl_->DrawTransform()); |
| 1148 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_child_transform, | 1138 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_child_transform, |
| 1149 fixed_child_impl->DrawTransform()); | 1139 fixed_child_impl->DrawTransform()); |
| 1150 } | 1140 } |
| 1151 | 1141 |
| 1152 } // namespace | 1142 } // namespace |
| 1153 } // namespace cc | 1143 } // namespace cc |
| OLD | NEW |