Index: cc/trees/layer_tree_host_impl_unittest.cc |
diff --git a/cc/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc |
index 29a1afb320e8699de0c3c8519323b3deeee51a1b..9599accd42274223d40563b3c3ad4f612fe96948 100644 |
--- a/cc/trees/layer_tree_host_impl_unittest.cc |
+++ b/cc/trees/layer_tree_host_impl_unittest.cc |
@@ -257,6 +257,71 @@ class LayerTreeHostImplTest : public testing::Test, |
return scroll_layer; |
} |
+ void SetupVirtualViewportLayers(const gfx::Size& content_size) { |
danakj
2014/02/19 22:49:24
Can you make a subclass of this class to put the m
bokan
2014/02/20 16:30:49
Done.
|
+ LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); |
+ const int kOuterViewportClipLayerId = 6; |
+ const int kOuterViewportScrollLayerId = 7; |
+ const int kInnerViewportScrollLayerId = 2; |
+ const int kInnerViewportClipLayerId = 4; |
+ const int kPageScaleLayerId = 5; |
+ |
+ scoped_ptr<LayerImpl> inner_scroll = |
+ LayerImpl::Create(layer_tree_impl, kInnerViewportScrollLayerId); |
+ inner_scroll->SetIsContainerForFixedPositionLayers(true); |
+ inner_scroll->SetScrollOffset(gfx::Vector2d()); |
+ |
+ scoped_ptr<LayerImpl> inner_clip = |
+ LayerImpl::Create(layer_tree_impl, kInnerViewportClipLayerId); |
+ inner_clip->SetBounds( |
+ gfx::Size(content_size.width() / 4, content_size.height() / 4)); |
danakj
2014/02/19 22:49:24
can you make the content_size/4 and content_size/2
bokan
2014/02/20 16:30:49
Done.
|
+ |
+ scoped_ptr<LayerImpl> page_scale = |
+ LayerImpl::Create(layer_tree_impl, kPageScaleLayerId); |
+ |
+ inner_scroll->SetScrollClipLayer(inner_clip->id()); |
+ inner_scroll->SetBounds(gfx::Size( |
+ content_size.width() / 2, content_size.height() / 2)); |
+ inner_scroll->SetContentBounds(gfx::Size( |
+ content_size.width() / 2, content_size.height() / 2)); |
+ inner_scroll->SetPosition(gfx::PointF()); |
+ inner_scroll->SetAnchorPoint(gfx::PointF()); |
+ |
+ scoped_ptr<LayerImpl> outer_clip = |
+ LayerImpl::Create(layer_tree_impl, kOuterViewportClipLayerId); |
+ outer_clip->SetBounds( |
+ gfx::Size(content_size.width() / 2, content_size.height() / 2)); |
+ outer_clip->SetIsContainerForFixedPositionLayers(true); |
+ |
+ scoped_ptr<LayerImpl> outer_scroll = |
+ LayerImpl::Create(layer_tree_impl, kOuterViewportScrollLayerId); |
+ outer_scroll->SetScrollClipLayer(outer_clip->id()); |
+ outer_scroll->SetScrollOffset(gfx::Vector2d()); |
+ outer_scroll->SetBounds(content_size); |
+ outer_scroll->SetContentBounds(content_size); |
+ outer_scroll->SetPosition(gfx::PointF()); |
+ outer_scroll->SetAnchorPoint(gfx::PointF()); |
+ |
+ scoped_ptr<LayerImpl> contents = |
+ LayerImpl::Create(layer_tree_impl, 8); |
+ contents->SetDrawsContent(true); |
+ contents->SetBounds(content_size); |
+ contents->SetContentBounds(content_size); |
+ contents->SetPosition(gfx::PointF()); |
+ contents->SetAnchorPoint(gfx::PointF()); |
+ |
+ outer_scroll->AddChild(contents.Pass()); |
+ outer_clip->AddChild(outer_scroll.Pass()); |
+ inner_scroll->AddChild(outer_clip.Pass()); |
+ page_scale->AddChild(inner_scroll.Pass()); |
+ inner_clip->AddChild(page_scale.Pass()); |
+ |
+ layer_tree_impl->SetRootLayer(inner_clip.Pass()); |
+ layer_tree_impl->SetViewportLayersFromIds(kPageScaleLayerId, |
+ kInnerViewportScrollLayerId, kOuterViewportScrollLayerId); |
+ |
+ host_impl_->active_tree()->DidBecomeActive(); |
+ } |
+ |
LayerImpl* SetupScrollAndContentsLayers(const gfx::Size& content_size) { |
LayerImpl* scroll_layer = CreateScrollAndContentsLayers( |
host_impl_->active_tree(), content_size); |
@@ -492,6 +557,38 @@ TEST_F(LayerTreeHostImplTest, ScrollRootCallsCommitAndRedraw) { |
EXPECT_TRUE(did_request_commit_); |
} |
+TEST_F(LayerTreeHostImplTest, FlingScrollBubblesToInner) { |
+ SetupVirtualViewportLayers(gfx::Size(100, 100)); |
+ LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
+ LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
+ DrawFrame(); |
+ { |
+ // Make sure the fling goes to the outer viewport first |
+ EXPECT_EQ(InputHandler::ScrollStarted, |
+ host_impl_->ScrollBegin(gfx::Point(), |
+ InputHandler::Gesture)); |
+ EXPECT_EQ(InputHandler::ScrollStarted, |
+ host_impl_->FlingScrollBegin()); |
+ gfx::Vector2d scroll_delta(25, 25); |
+ host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
+ host_impl_->ScrollEnd(); |
+ EXPECT_VECTOR_EQ(gfx::Vector2dF(), inner_scroll->TotalScrollOffset()); |
+ EXPECT_VECTOR_EQ(gfx::Vector2dF(25, 25), outer_scroll->TotalScrollOffset()); |
+ |
+ // Fling past the outer viewport boundry, make sure inner viewport scrolls. |
+ EXPECT_EQ(InputHandler::ScrollStarted, |
+ host_impl_->ScrollBegin(gfx::Point(), |
+ InputHandler::Gesture)); |
+ EXPECT_EQ(InputHandler::ScrollStarted, |
+ host_impl_->FlingScrollBegin()); |
+ host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
+ host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
+ host_impl_->ScrollEnd(); |
+ EXPECT_VECTOR_EQ(gfx::Vector2dF(25, 25), inner_scroll->TotalScrollOffset()); |
wjmaclean
2014/02/10 14:31:47
In order to see the bubbling happening in a 'singl
bokan
2014/02/10 15:04:52
I think that each ScrollUpdate from a fling can on
|
+ EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 50), outer_scroll->TotalScrollOffset()); |
+ } |
+} |
+ |
TEST_F(LayerTreeHostImplTest, ScrollWithoutRootLayer) { |
// We should not crash when trying to scroll an empty layer tree. |
EXPECT_EQ(InputHandler::ScrollIgnored, |