diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 20:11:02 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 20:11:02 +0000 |
commit | a97109682bce86ab91f99ab6bb4ab79b3df72820 (patch) | |
tree | ce6f72de444fe15daa350d75710f0cdfa3e75973 | |
parent | a2ac2864d48491b47068d5c30922329dfd135d0c (diff) | |
download | chromium_src-a97109682bce86ab91f99ab6bb4ab79b3df72820.zip chromium_src-a97109682bce86ab91f99ab6bb4ab79b3df72820.tar.gz chromium_src-a97109682bce86ab91f99ab6bb4ab79b3df72820.tar.bz2 |
cc: Return whether any layer was scrolled from InputHandlerClient::scrollBy.
BUG=none
Review URL: https://codereview.chromium.org/11365238
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167721 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | cc/input_handler.h | 8 | ||||
-rw-r--r-- | cc/layer_tree_host_impl.cc | 7 | ||||
-rw-r--r-- | cc/layer_tree_host_impl.h | 2 | ||||
-rw-r--r-- | cc/layer_tree_host_impl_unittest.cc | 29 | ||||
-rw-r--r-- | webkit/compositor_bindings/web_to_ccinput_handler_adapter.cc | 9 |
5 files changed, 47 insertions, 8 deletions
diff --git a/cc/input_handler.h b/cc/input_handler.h index 6898c1f..0a2a542 100644 --- a/cc/input_handler.h +++ b/cc/input_handler.h @@ -41,9 +41,11 @@ public: // should be in viewport (logical pixel) coordinates. Otherwise they are in // scrolling layer's (logical pixel) space. If there is no room to move the // layer in the requested direction, its first ancestor layer that can be - // scrolled will be moved instead. Should only be called if scrollBegin() - // returned ScrollStarted. - virtual void scrollBy(gfx::Point, gfx::Vector2d) = 0; + // scrolled will be moved instead. If no layer can be moved in the requested + // direction at all, then false is returned. If any layer is moved, then + // true is returned. + // Should only be called if scrollBegin() returned ScrollStarted. + virtual bool scrollBy(const gfx::Point&, const gfx::Vector2d&) = 0; // Stop scrolling the selected layer. Should only be called if scrollBegin() // returned ScrollStarted. diff --git a/cc/layer_tree_host_impl.cc b/cc/layer_tree_host_impl.cc index 32366d3..21207b1 100644 --- a/cc/layer_tree_host_impl.cc +++ b/cc/layer_tree_host_impl.cc @@ -1145,11 +1145,12 @@ static gfx::Vector2dF scrollLayerWithLocalDelta(LayerImpl& layerImpl, gfx::Vecto return layerImpl.scrollDelta() - previousDelta; } -void LayerTreeHostImpl::scrollBy(gfx::Point viewportPoint, gfx::Vector2d scrollDelta) +bool LayerTreeHostImpl::scrollBy(const gfx::Point& viewportPoint, + const gfx::Vector2d& scrollDelta) { TRACE_EVENT0("cc", "LayerTreeHostImpl::scrollBy"); if (!m_currentlyScrollingLayerImpl) - return; + return false; gfx::Vector2dF pendingDelta = scrollDelta; @@ -1190,7 +1191,9 @@ void LayerTreeHostImpl::scrollBy(gfx::Point viewportPoint, gfx::Vector2d scrollD if (!scrollDelta.IsZero() && gfx::ToFlooredVector2d(pendingDelta).IsZero()) { m_client->setNeedsCommitOnImplThread(); m_client->setNeedsRedrawOnImplThread(); + return true; } + return false; } void LayerTreeHostImpl::clearCurrentlyScrollingLayer() diff --git a/cc/layer_tree_host_impl.h b/cc/layer_tree_host_impl.h index 10020c8..8e59c62 100644 --- a/cc/layer_tree_host_impl.h +++ b/cc/layer_tree_host_impl.h @@ -111,7 +111,7 @@ public: // InputHandlerClient implementation virtual InputHandlerClient::ScrollStatus scrollBegin(gfx::Point, InputHandlerClient::ScrollInputType) OVERRIDE; - virtual void scrollBy(gfx::Point, gfx::Vector2d) OVERRIDE; + virtual bool scrollBy(const gfx::Point&, const gfx::Vector2d&) OVERRIDE; virtual void scrollEnd() OVERRIDE; virtual void pinchGestureBegin() OVERRIDE; virtual void pinchGestureUpdate(float, gfx::Point) OVERRIDE; diff --git a/cc/layer_tree_host_impl_unittest.cc b/cc/layer_tree_host_impl_unittest.cc index ce71ced..9ac8970 100644 --- a/cc/layer_tree_host_impl_unittest.cc +++ b/cc/layer_tree_host_impl_unittest.cc @@ -479,6 +479,35 @@ TEST_P(LayerTreeHostImplTest, nonFastScrollableRegionWithOffset) EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(10, 10), InputHandlerClient::Wheel), InputHandlerClient::ScrollOnMainThread); } +TEST_P(LayerTreeHostImplTest, scrollByReturnsCorrectValue) +{ + setupScrollAndContentsLayers(gfx::Size(200, 200)); + m_hostImpl->setViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); + + initializeRendererAndDrawFrame(); + + EXPECT_EQ(InputHandlerClient::ScrollStarted, + m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Gesture)); + + // Trying to scroll to the left/top will not succeed. + EXPECT_FALSE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(-10, 0))); + EXPECT_FALSE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, -10))); + EXPECT_FALSE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(-10, -10))); + + // Scrolling to the right/bottom will succeed. + EXPECT_TRUE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(10, 0))); + EXPECT_TRUE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, 10))); + EXPECT_TRUE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(10, 10))); + + // Scrolling to left/top will now succeed. + EXPECT_TRUE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(-10, 0))); + EXPECT_TRUE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, -10))); + EXPECT_TRUE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(-10, -10))); + + // Trying to scroll more than the available space will also succeed. + EXPECT_TRUE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(5000, 5000))); +} + TEST_P(LayerTreeHostImplTest, maxScrollOffsetChangedByDeviceScaleFactor) { setupScrollAndContentsLayers(gfx::Size(100, 100)); diff --git a/webkit/compositor_bindings/web_to_ccinput_handler_adapter.cc b/webkit/compositor_bindings/web_to_ccinput_handler_adapter.cc index 9d68cf3..30d105a 100644 --- a/webkit/compositor_bindings/web_to_ccinput_handler_adapter.cc +++ b/webkit/compositor_bindings/web_to_ccinput_handler_adapter.cc @@ -47,9 +47,14 @@ public: return static_cast<WebInputHandlerClient::ScrollStatus>(m_client->scrollBegin(point, static_cast<cc::InputHandlerClient::ScrollInputType>(type))); } - virtual void scrollBy(WebPoint point, WebSize offset) OVERRIDE + virtual void scrollBy(WebPoint point, WebSize offset) { - m_client->scrollBy(point, offset); + scrollByIfPossible(point, offset); + } + + virtual bool scrollByIfPossible(WebPoint point, WebSize offset) + { + return m_client->scrollBy(point, offset); } virtual void scrollEnd() OVERRIDE |