Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: cc/trees/layer_tree_host_impl_unittest.cc

Issue 140413007: Made fling gestures always bubble between inner and outer viewports. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up test Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_impl.h" 5 #include "cc/trees/layer_tree_host_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 5830 matching lines...) Expand 10 before | Expand all | Expand 10 after
5841 } 5841 }
5842 }; 5842 };
5843 5843
5844 TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) { 5844 TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) {
5845 SetupScrollAndContentsLayers(gfx::Size(100, 100)) 5845 SetupScrollAndContentsLayers(gfx::Size(100, 100))
5846 ->SetScrollOffset(gfx::Vector2d(0, 10)); 5846 ->SetScrollOffset(gfx::Vector2d(0, 10));
5847 host_impl_->Animate(base::TimeTicks(), base::Time()); 5847 host_impl_->Animate(base::TimeTicks(), base::Time());
5848 EXPECT_FALSE(did_request_redraw_); 5848 EXPECT_FALSE(did_request_redraw_);
5849 } 5849 }
5850 5850
5851 class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest {
5852 public:
5853 void SetupVirtualViewportLayers(const gfx::Size& content_size,
5854 const gfx::Size& outer_viewport,
5855 const gfx::Size& inner_viewport) {
5856 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree();
5857 const int kOuterViewportClipLayerId = 6;
5858 const int kOuterViewportScrollLayerId = 7;
5859 const int kInnerViewportScrollLayerId = 2;
5860 const int kInnerViewportClipLayerId = 4;
5861 const int kPageScaleLayerId = 5;
5862
5863 scoped_ptr<LayerImpl> inner_scroll =
5864 LayerImpl::Create(layer_tree_impl, kInnerViewportScrollLayerId);
5865 inner_scroll->SetIsContainerForFixedPositionLayers(true);
5866 inner_scroll->SetScrollOffset(gfx::Vector2d());
5867
5868 scoped_ptr<LayerImpl> inner_clip =
5869 LayerImpl::Create(layer_tree_impl, kInnerViewportClipLayerId);
5870 inner_clip->SetBounds(inner_viewport);
5871
5872 scoped_ptr<LayerImpl> page_scale =
5873 LayerImpl::Create(layer_tree_impl, kPageScaleLayerId);
5874
5875 inner_scroll->SetScrollClipLayer(inner_clip->id());
5876 inner_scroll->SetBounds(outer_viewport);
5877 inner_scroll->SetContentBounds(outer_viewport);
5878 inner_scroll->SetPosition(gfx::PointF());
5879 inner_scroll->SetAnchorPoint(gfx::PointF());
5880
5881 scoped_ptr<LayerImpl> outer_clip =
5882 LayerImpl::Create(layer_tree_impl, kOuterViewportClipLayerId);
5883 outer_clip->SetBounds(outer_viewport);
5884 outer_clip->SetIsContainerForFixedPositionLayers(true);
5885
5886 scoped_ptr<LayerImpl> outer_scroll =
5887 LayerImpl::Create(layer_tree_impl, kOuterViewportScrollLayerId);
5888 outer_scroll->SetScrollClipLayer(outer_clip->id());
5889 outer_scroll->SetScrollOffset(gfx::Vector2d());
5890 outer_scroll->SetBounds(content_size);
5891 outer_scroll->SetContentBounds(content_size);
5892 outer_scroll->SetPosition(gfx::PointF());
5893 outer_scroll->SetAnchorPoint(gfx::PointF());
5894
5895 scoped_ptr<LayerImpl> contents =
5896 LayerImpl::Create(layer_tree_impl, 8);
5897 contents->SetDrawsContent(true);
5898 contents->SetBounds(content_size);
5899 contents->SetContentBounds(content_size);
5900 contents->SetPosition(gfx::PointF());
5901 contents->SetAnchorPoint(gfx::PointF());
5902
5903 outer_scroll->AddChild(contents.Pass());
5904 outer_clip->AddChild(outer_scroll.Pass());
5905 inner_scroll->AddChild(outer_clip.Pass());
5906 page_scale->AddChild(inner_scroll.Pass());
5907 inner_clip->AddChild(page_scale.Pass());
5908
5909 layer_tree_impl->SetRootLayer(inner_clip.Pass());
5910 layer_tree_impl->SetViewportLayersFromIds(kPageScaleLayerId,
5911 kInnerViewportScrollLayerId, kOuterViewportScrollLayerId);
5912
5913 host_impl_->active_tree()->DidBecomeActive();
5914 }
5915 };
5916
5917 TEST_F(LayerTreeHostImplVirtualViewportTest, FlingScrollBubblesToInner) {
5918 gfx::Size content_size = gfx::Size(100, 100);
5919 gfx::Size outer_viewport = gfx::Size(50, 50);
danakj 2014/02/20 16:35:00 nit: mind making these non-symmetrical as well as
bokan 2014/02/20 16:42:46 Done.
5920 gfx::Size inner_viewport = gfx::Size(25, 25);
5921
5922 SetupVirtualViewportLayers(content_size, outer_viewport, inner_viewport);
5923
5924 LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer();
5925 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer();
5926 DrawFrame();
5927 {
5928 gfx::Vector2dF inner_expected;
5929 gfx::Vector2dF outer_expected;
5930 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->TotalScrollOffset());
5931 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->TotalScrollOffset());
5932
5933 // Make sure the fling goes to the outer viewport first
5934 EXPECT_EQ(InputHandler::ScrollStarted,
5935 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
5936 EXPECT_EQ(InputHandler::ScrollStarted, host_impl_->FlingScrollBegin());
5937
5938 gfx::Vector2d scroll_delta(inner_viewport.width(), inner_viewport.height());
5939 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
5940 outer_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y());
5941
5942 host_impl_->ScrollEnd();
5943
5944 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->TotalScrollOffset());
5945 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->TotalScrollOffset());
5946
5947 // Fling past the outer viewport boundry, make sure inner viewport scrolls.
5948 EXPECT_EQ(InputHandler::ScrollStarted,
5949 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
5950 EXPECT_EQ(InputHandler::ScrollStarted, host_impl_->FlingScrollBegin());
5951
5952 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
5953 outer_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y());
5954
5955 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
5956 inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y());
5957
5958 host_impl_->ScrollEnd();
5959
5960 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->TotalScrollOffset());
5961 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->TotalScrollOffset());
5962 }
5963 }
5964
5851 } // namespace 5965 } // namespace
5852 } // namespace cc 5966 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698