Chromium Code Reviews| 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 7030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7041 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, | 7041 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, |
| 7042 scroller_impl->ScreenSpaceTransform().To2dTranslation()); | 7042 scroller_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7043 | 7043 |
| 7044 gfx::Transform expected_scroll_child_screen_space_transform; | 7044 gfx::Transform expected_scroll_child_screen_space_transform; |
| 7045 expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f); | 7045 expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f); |
| 7046 expected_scroll_child_screen_space_transform.RotateAboutYAxis(30); | 7046 expected_scroll_child_screen_space_transform.RotateAboutYAxis(30); |
| 7047 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform, | 7047 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform, |
| 7048 scroll_child_impl->ScreenSpaceTransform()); | 7048 scroll_child_impl->ScreenSpaceTransform()); |
| 7049 } | 7049 } |
| 7050 | 7050 |
| 7051 TEST_F(LayerTreeHostCommonTest, StickyPositionNested) { | |
| 7052 scoped_refptr<Layer> root = Layer::Create(); | |
| 7053 scoped_refptr<Layer> container = Layer::Create(); | |
| 7054 scoped_refptr<Layer> scroller = Layer::Create(); | |
| 7055 scoped_refptr<Layer> outer_sticky = Layer::Create(); | |
| 7056 scoped_refptr<Layer> inner_sticky = Layer::Create(); | |
| 7057 | |
| 7058 root->AddChild(container); | |
| 7059 container->AddChild(scroller); | |
| 7060 scroller->AddChild(outer_sticky); | |
| 7061 outer_sticky->AddChild(inner_sticky); | |
| 7062 host()->SetRootLayer(root); | |
| 7063 scroller->SetScrollClipLayerId(container->id()); | |
| 7064 | |
| 7065 root->SetBounds(gfx::Size(100, 100)); | |
| 7066 container->SetBounds(gfx::Size(100, 100)); | |
| 7067 scroller->SetBounds(gfx::Size(100, 1000)); | |
| 7068 outer_sticky->SetBounds(gfx::Size(10, 50)); | |
| 7069 outer_sticky->SetPosition(gfx::PointF(0, 50)); | |
| 7070 inner_sticky->SetBounds(gfx::Size(10, 10)); | |
| 7071 inner_sticky->SetPosition(gfx::PointF(0, 0)); | |
| 7072 | |
| 7073 LayerStickyPositionConstraint outer_sticky_pos; | |
| 7074 outer_sticky_pos.is_sticky = true; | |
| 7075 outer_sticky_pos.is_anchored_top = true; | |
| 7076 outer_sticky_pos.top_offset = 10.0f; | |
| 7077 outer_sticky_pos.parent_relative_sticky_box_offset = gfx::Point(0, 50); | |
| 7078 outer_sticky_pos.scroll_container_relative_sticky_box_rect = | |
| 7079 gfx::Rect(0, 50, 50, 50); | |
| 7080 outer_sticky_pos.scroll_container_relative_containing_block_rect = | |
| 7081 gfx::Rect(0, 0, 50, 200); | |
| 7082 outer_sticky->SetStickyPositionConstraint(outer_sticky_pos); | |
| 7083 | |
| 7084 LayerStickyPositionConstraint inner_sticky_pos; | |
| 7085 inner_sticky_pos.is_sticky = true; | |
| 7086 inner_sticky_pos.is_anchored_top = true; | |
| 7087 inner_sticky_pos.top_offset = 25.0f; | |
| 7088 inner_sticky_pos.parent_relative_sticky_box_offset = gfx::Point(0, 0); | |
| 7089 inner_sticky_pos.scroll_container_relative_sticky_box_rect = | |
| 7090 gfx::Rect(0, 50, 10, 10); | |
| 7091 inner_sticky_pos.scroll_container_relative_containing_block_rect = | |
| 7092 gfx::Rect(0, 50, 10, 50); | |
| 7093 inner_sticky->SetStickyPositionConstraint(inner_sticky_pos); | |
| 7094 | |
| 7095 ExecuteCalculateDrawProperties(root.get()); | |
| 7096 host()->host_impl()->CreatePendingTree(); | |
| 7097 host()->CommitAndCreatePendingTree(); | |
| 7098 host()->host_impl()->ActivateSyncTree(); | |
| 7099 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); | |
| 7100 | |
| 7101 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); | |
| 7102 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); | |
| 7103 LayerImpl* outer_sticky_impl = layer_tree_impl->LayerById(outer_sticky->id()); | |
| 7104 LayerImpl* inner_sticky_impl = layer_tree_impl->LayerById(inner_sticky->id()); | |
| 7105 | |
| 7106 ExecuteCalculateDrawProperties(root_impl); | |
| 7107 | |
| 7108 // Before any scrolling is done, the sticky elements should still be at their | |
| 7109 // original positions. | |
| 7110 EXPECT_VECTOR2DF_EQ( | |
| 7111 gfx::Vector2dF(0.f, 50.f), | |
| 7112 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation()); | |
| 7113 EXPECT_VECTOR2DF_EQ( | |
| 7114 gfx::Vector2dF(0.f, 50.f), | |
| 7115 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation()); | |
| 7116 | |
| 7117 // Scroll less than the sticking point. Both sticky elements should move with | |
| 7118 // scroll as we haven't gotten to the sticky item locations yet. | |
| 7119 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); | |
| 7120 ExecuteCalculateDrawProperties(root_impl); | |
| 7121 EXPECT_VECTOR2DF_EQ( | |
| 7122 gfx::Vector2dF(0.f, 45.f), | |
| 7123 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation()); | |
| 7124 EXPECT_VECTOR2DF_EQ( | |
| 7125 gfx::Vector2dF(0.f, 45.f), | |
| 7126 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation()); | |
| 7127 | |
| 7128 // Scroll such that the inner sticky should stick, but the outer one should | |
| 7129 // keep going as it hasnt reached its position yet. | |
| 7130 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); | |
| 7131 ExecuteCalculateDrawProperties(root_impl); | |
| 7132 EXPECT_VECTOR2DF_EQ( | |
| 7133 gfx::Vector2dF(0.f, 20.f), | |
| 7134 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation()); | |
| 7135 EXPECT_VECTOR2DF_EQ( | |
| 7136 gfx::Vector2dF(0.f, 25.f), | |
| 7137 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation()); | |
| 7138 | |
| 7139 // Keep going, both should stick. | |
| 7140 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 100.f)); | |
| 7141 ExecuteCalculateDrawProperties(root_impl); | |
| 7142 EXPECT_VECTOR2DF_EQ( | |
| 7143 gfx::Vector2dF(0.f, 10.f), | |
| 7144 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation()); | |
| 7145 // TODO(smcgruer): Fails. I'm not sure why. Value is actually [0,50]. | |
|
smcgruer
2017/02/14 17:02:06
flackr : Not sure why this fails. I'd expect it to
| |
| 7146 EXPECT_VECTOR2DF_EQ( | |
| 7147 gfx::Vector2dF(0.f, 25.f), | |
| 7148 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation()); | |
| 7149 } | |
| 7150 | |
| 7051 TEST_F(LayerTreeHostCommonTest, StickyPositionTop) { | 7151 TEST_F(LayerTreeHostCommonTest, StickyPositionTop) { |
| 7052 scoped_refptr<Layer> root = Layer::Create(); | 7152 scoped_refptr<Layer> root = Layer::Create(); |
| 7053 scoped_refptr<Layer> container = Layer::Create(); | 7153 scoped_refptr<Layer> container = Layer::Create(); |
| 7054 scoped_refptr<Layer> scroller = Layer::Create(); | 7154 scoped_refptr<Layer> scroller = Layer::Create(); |
| 7055 scoped_refptr<Layer> sticky_pos = Layer::Create(); | 7155 scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7056 root->AddChild(container); | 7156 root->AddChild(container); |
| 7057 container->AddChild(scroller); | 7157 container->AddChild(scroller); |
| 7058 scroller->AddChild(sticky_pos); | 7158 scroller->AddChild(sticky_pos); |
| 7059 host()->SetRootLayer(root); | 7159 host()->SetRootLayer(root); |
| 7060 scroller->SetScrollClipLayerId(container->id()); | 7160 scroller->SetScrollClipLayerId(container->id()); |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7728 root_impl = layer_tree_impl->LayerById(root->id()); | 7828 root_impl = layer_tree_impl->LayerById(root->id()); |
| 7729 scroller_impl = layer_tree_impl->LayerById(scroller->id()); | 7829 scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7730 sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); | 7830 sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7731 | 7831 |
| 7732 // The element should still be where it was before. We reset the delta to | 7832 // The element should still be where it was before. We reset the delta to |
| 7733 // (0, 0) because we have synced a scroll offset of (0, 25) from the main | 7833 // (0, 0) because we have synced a scroll offset of (0, 25) from the main |
| 7734 // thread. | 7834 // thread. |
| 7735 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f)); | 7835 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f)); |
| 7736 ExecuteCalculateDrawProperties(root_impl); | 7836 ExecuteCalculateDrawProperties(root_impl); |
| 7737 EXPECT_VECTOR2DF_EQ( | 7837 EXPECT_VECTOR2DF_EQ( |
| 7738 gfx::Vector2dF(20.f, 10.f), | 7838 gfx::Vector2dF(20.f, -15.f), |
|
smcgruer
2017/02/14 17:02:06
flackr : These changes are also suspicious. I just
| |
| 7739 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7839 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7740 | 7840 |
| 7741 // And if we scroll a little further it remains there. | 7841 // And if we scroll a little further it remains there. |
| 7742 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); | 7842 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); |
| 7743 ExecuteCalculateDrawProperties(root_impl); | 7843 ExecuteCalculateDrawProperties(root_impl); |
| 7744 EXPECT_VECTOR2DF_EQ( | 7844 EXPECT_VECTOR2DF_EQ( |
| 7745 gfx::Vector2dF(20.f, 10.f), | 7845 gfx::Vector2dF(20.f, -15.f), |
| 7746 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7846 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7747 | 7847 |
| 7748 // And hits the bottom of the container. | 7848 // And hits the bottom of the container. |
| 7749 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f)); | 7849 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f)); |
| 7750 ExecuteCalculateDrawProperties(root_impl); | 7850 ExecuteCalculateDrawProperties(root_impl); |
| 7751 EXPECT_VECTOR2DF_EQ( | 7851 EXPECT_VECTOR2DF_EQ( |
| 7752 gfx::Vector2dF(20.f, 5.f), | 7852 gfx::Vector2dF(20.f, -20.f), |
| 7753 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7853 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7754 } | 7854 } |
| 7755 | 7855 |
| 7756 // A transform on a sticky element should not affect its sticky position. | 7856 // A transform on a sticky element should not affect its sticky position. |
| 7757 TEST_F(LayerTreeHostCommonTest, StickyPositionScaledStickyBox) { | 7857 TEST_F(LayerTreeHostCommonTest, StickyPositionScaledStickyBox) { |
| 7758 scoped_refptr<Layer> root = Layer::Create(); | 7858 scoped_refptr<Layer> root = Layer::Create(); |
| 7759 scoped_refptr<Layer> container = Layer::Create(); | 7859 scoped_refptr<Layer> container = Layer::Create(); |
| 7760 scoped_refptr<Layer> scroller = Layer::Create(); | 7860 scoped_refptr<Layer> scroller = Layer::Create(); |
| 7761 scoped_refptr<Layer> sticky_pos = Layer::Create(); | 7861 scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7762 root->AddChild(container); | 7862 root->AddChild(container); |
| (...skipping 2989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10752 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); | 10852 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 10753 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); | 10853 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 10754 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); | 10854 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 10755 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); | 10855 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 10756 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); | 10856 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 10757 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); | 10857 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 10758 } | 10858 } |
| 10759 | 10859 |
| 10760 } // namespace | 10860 } // namespace |
| 10761 } // namespace cc | 10861 } // namespace cc |
| OLD | NEW |