| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/trees/layer_tree_host_common.h" | 5 #include "cc/trees/layer_tree_host_common.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 6847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6858 | 6858 |
| 6859 LayerStickyPositionConstraint sticky_position; | 6859 LayerStickyPositionConstraint sticky_position; |
| 6860 sticky_position.is_sticky = true; | 6860 sticky_position.is_sticky = true; |
| 6861 sticky_position.is_anchored_top = true; | 6861 sticky_position.is_anchored_top = true; |
| 6862 sticky_position.top_offset = 10.0f; | 6862 sticky_position.top_offset = 10.0f; |
| 6863 sticky_position.scroll_container_relative_sticky_box_rect = | 6863 sticky_position.scroll_container_relative_sticky_box_rect = |
| 6864 gfx::Rect(10, 20, 10, 10); | 6864 gfx::Rect(10, 20, 10, 10); |
| 6865 sticky_position.scroll_container_relative_containing_block_rect = | 6865 sticky_position.scroll_container_relative_containing_block_rect = |
| 6866 gfx::Rect(0, 0, 50, 50); | 6866 gfx::Rect(0, 0, 50, 50); |
| 6867 sticky_pos->SetStickyPositionConstraint(sticky_position); | 6867 sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6868 sticky_pos->SetElementId(LayerIdToElementIdForTesting(sticky_pos->id())); | |
| 6869 | 6868 |
| 6870 root->SetBounds(gfx::Size(100, 100)); | 6869 root->SetBounds(gfx::Size(100, 100)); |
| 6871 container->SetBounds(gfx::Size(100, 100)); | 6870 container->SetBounds(gfx::Size(100, 100)); |
| 6872 scroller->SetBounds(gfx::Size(1000, 1000)); | 6871 scroller->SetBounds(gfx::Size(1000, 1000)); |
| 6873 sticky_pos->SetBounds(gfx::Size(10, 10)); | 6872 sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6874 sticky_pos->SetPosition(gfx::PointF(10, 20)); | 6873 sticky_pos->SetPosition(gfx::PointF(10, 20)); |
| 6875 | 6874 |
| 6876 ExecuteCalculateDrawProperties(root.get()); | 6875 ExecuteCalculateDrawProperties(root.get()); |
| 6877 host()->host_impl()->CreatePendingTree(); | 6876 host()->host_impl()->CreatePendingTree(); |
| 6878 host()->CommitAndCreatePendingTree(); | 6877 host()->CommitAndCreatePendingTree(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 6898 | 6897 |
| 6899 // Scroll past the sticking point, the Y coordinate should now be clamped. | 6898 // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 6900 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f)); | 6899 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f)); |
| 6901 ExecuteCalculateDrawProperties(root_impl); | 6900 ExecuteCalculateDrawProperties(root_impl); |
| 6902 EXPECT_VECTOR2DF_EQ( | 6901 EXPECT_VECTOR2DF_EQ( |
| 6903 gfx::Vector2dF(-5.f, 10.f), | 6902 gfx::Vector2dF(-5.f, 10.f), |
| 6904 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 6903 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6905 | 6904 |
| 6906 // Now the main thread commits the new position of the sticky element. | 6905 // Now the main thread commits the new position of the sticky element. |
| 6907 scroller->SetScrollOffset(gfx::ScrollOffset(15, 15)); | 6906 scroller->SetScrollOffset(gfx::ScrollOffset(15, 15)); |
| 6908 sticky_pos->SetPosition(gfx::PointF(10, 25)); | 6907 // Shift the layer by -offset_for_position_sticky. |
| 6909 sticky_pos->SetOffsetForStickyPositionFromMainThread(gfx::Size(0, 5)); | 6908 sticky_pos->SetPosition(gfx::PointF(10, 25) - gfx::Vector2dF(0, 5)); |
| 6910 ExecuteCalculateDrawProperties(root.get()); | 6909 ExecuteCalculateDrawProperties(root.get()); |
| 6911 host()->host_impl()->CreatePendingTree(); | 6910 host()->host_impl()->CreatePendingTree(); |
| 6912 host()->CommitAndCreatePendingTree(); | 6911 host()->CommitAndCreatePendingTree(); |
| 6913 host()->host_impl()->ActivateSyncTree(); | 6912 host()->host_impl()->ActivateSyncTree(); |
| 6914 layer_tree_impl = host()->host_impl()->active_tree(); | 6913 layer_tree_impl = host()->host_impl()->active_tree(); |
| 6915 root_impl = layer_tree_impl->LayerById(root->id()); | 6914 root_impl = layer_tree_impl->LayerById(root->id()); |
| 6916 scroller_impl = layer_tree_impl->LayerById(scroller->id()); | 6915 scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6917 sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); | 6916 sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6918 | 6917 |
| 6919 // The element should still be where it was before. We reset the delta to | 6918 // The element should still be where it was before. We reset the delta to |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6951 | 6950 |
| 6952 LayerStickyPositionConstraint sticky_position; | 6951 LayerStickyPositionConstraint sticky_position; |
| 6953 sticky_position.is_sticky = true; | 6952 sticky_position.is_sticky = true; |
| 6954 sticky_position.is_anchored_top = true; | 6953 sticky_position.is_anchored_top = true; |
| 6955 sticky_position.top_offset = 10.0f; | 6954 sticky_position.top_offset = 10.0f; |
| 6956 sticky_position.scroll_container_relative_sticky_box_rect = | 6955 sticky_position.scroll_container_relative_sticky_box_rect = |
| 6957 gfx::Rect(20, 30, 10, 10); | 6956 gfx::Rect(20, 30, 10, 10); |
| 6958 sticky_position.scroll_container_relative_containing_block_rect = | 6957 sticky_position.scroll_container_relative_containing_block_rect = |
| 6959 gfx::Rect(20, 20, 30, 30); | 6958 gfx::Rect(20, 20, 30, 30); |
| 6960 sticky_pos->SetStickyPositionConstraint(sticky_position); | 6959 sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6961 sticky_pos->SetElementId(LayerIdToElementIdForTesting(sticky_pos->id())); | |
| 6962 | 6960 |
| 6963 root->SetBounds(gfx::Size(100, 100)); | 6961 root->SetBounds(gfx::Size(100, 100)); |
| 6964 container->SetBounds(gfx::Size(100, 100)); | 6962 container->SetBounds(gfx::Size(100, 100)); |
| 6965 scroller->SetBounds(gfx::Size(1000, 1000)); | 6963 scroller->SetBounds(gfx::Size(1000, 1000)); |
| 6966 sticky_container->SetPosition(gfx::PointF(20, 20)); | 6964 sticky_container->SetPosition(gfx::PointF(20, 20)); |
| 6967 sticky_container->SetBounds(gfx::Size(30, 30)); | 6965 sticky_container->SetBounds(gfx::Size(30, 30)); |
| 6968 sticky_pos->SetBounds(gfx::Size(10, 10)); | 6966 sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6969 sticky_pos->SetPosition(gfx::PointF(0, 10)); | 6967 sticky_pos->SetPosition(gfx::PointF(0, 10)); |
| 6970 | 6968 |
| 6971 ExecuteCalculateDrawProperties(root.get()); | 6969 ExecuteCalculateDrawProperties(root.get()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 6993 | 6991 |
| 6994 // Scroll past the sticking point, the Y coordinate should now be clamped. | 6992 // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 6995 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); | 6993 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 6996 ExecuteCalculateDrawProperties(root_impl); | 6994 ExecuteCalculateDrawProperties(root_impl); |
| 6997 EXPECT_VECTOR2DF_EQ( | 6995 EXPECT_VECTOR2DF_EQ( |
| 6998 gfx::Vector2dF(20.f, 10.f), | 6996 gfx::Vector2dF(20.f, 10.f), |
| 6999 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 6997 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7000 | 6998 |
| 7001 // Now the main thread commits the new position of the sticky element. | 6999 // Now the main thread commits the new position of the sticky element. |
| 7002 scroller->SetScrollOffset(gfx::ScrollOffset(0, 25)); | 7000 scroller->SetScrollOffset(gfx::ScrollOffset(0, 25)); |
| 7003 sticky_pos->SetPosition(gfx::PointF(0, 15)); | 7001 // Shift the layer by -offset_for_position_sticky. |
| 7004 sticky_pos->SetOffsetForStickyPositionFromMainThread(gfx::Size(0, 5)); | 7002 sticky_pos->SetPosition(gfx::PointF(0, 15) - gfx::Vector2dF(0, 5)); |
| 7005 ExecuteCalculateDrawProperties(root.get()); | 7003 ExecuteCalculateDrawProperties(root.get()); |
| 7006 host()->host_impl()->CreatePendingTree(); | 7004 host()->host_impl()->CreatePendingTree(); |
| 7007 host()->CommitAndCreatePendingTree(); | 7005 host()->CommitAndCreatePendingTree(); |
| 7008 host()->host_impl()->ActivateSyncTree(); | 7006 host()->host_impl()->ActivateSyncTree(); |
| 7009 layer_tree_impl = host()->host_impl()->active_tree(); | 7007 layer_tree_impl = host()->host_impl()->active_tree(); |
| 7010 root_impl = layer_tree_impl->LayerById(root->id()); | 7008 root_impl = layer_tree_impl->LayerById(root->id()); |
| 7011 scroller_impl = layer_tree_impl->LayerById(scroller->id()); | 7009 scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7012 sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); | 7010 sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7013 | 7011 |
| 7014 // The element should still be where it was before. We reset the delta to | 7012 // The element should still be where it was before. We reset the delta to |
| (...skipping 3191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10206 | 10204 |
| 10207 // Check child layer draw properties. | 10205 // Check child layer draw properties. |
| 10208 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); | 10206 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
| 10209 EXPECT_EQ(gfx::Transform(), child->DrawTransform()); | 10207 EXPECT_EQ(gfx::Transform(), child->DrawTransform()); |
| 10210 EXPECT_EQ(gfx::Rect(10, 10), child->clip_rect()); | 10208 EXPECT_EQ(gfx::Rect(10, 10), child->clip_rect()); |
| 10211 EXPECT_EQ(gfx::Rect(10, 10), child->drawable_content_rect()); | 10209 EXPECT_EQ(gfx::Rect(10, 10), child->drawable_content_rect()); |
| 10212 } | 10210 } |
| 10213 | 10211 |
| 10214 } // namespace | 10212 } // namespace |
| 10215 } // namespace cc | 10213 } // namespace cc |
| OLD | NEW |