diff options
author | tedchoc@chromium.org <tedchoc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-07 04:10:35 +0000 |
---|---|---|
committer | tedchoc@chromium.org <tedchoc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-07 04:10:35 +0000 |
commit | 7dccbf4e6fee3019caca95d01ce5b9486723d315 (patch) | |
tree | aece32e1ea00ab08608401c9c70f5b87c0bbca1e /cc | |
parent | f9e1f5654c12ba3e7a164374720a9bfe8848c4fb (diff) | |
download | chromium_src-7dccbf4e6fee3019caca95d01ce5b9486723d315.zip chromium_src-7dccbf4e6fee3019caca95d01ce5b9486723d315.tar.gz chromium_src-7dccbf4e6fee3019caca95d01ce5b9486723d315.tar.bz2 |
Rework top controls movement to simplify the logic.
This should further prevent large jumps in the controls
when it was previously trying to quickly correct itself
when it didn't really need to.
BUG=161303,174459,172649
R=dtrainor,yusufo,jamesr
Review URL: https://chromiumcodereview.appspot.com/12217046
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181189 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r-- | cc/layer_tree_host_impl.cc | 2 | ||||
-rw-r--r-- | cc/top_controls_manager.cc | 56 | ||||
-rw-r--r-- | cc/top_controls_manager.h | 4 | ||||
-rw-r--r-- | cc/top_controls_manager_unittest.cc | 16 |
4 files changed, 18 insertions, 60 deletions
diff --git a/cc/layer_tree_host_impl.cc b/cc/layer_tree_host_impl.cc index 691c0ae..23d3a2e 100644 --- a/cc/layer_tree_host_impl.cc +++ b/cc/layer_tree_host_impl.cc @@ -658,8 +658,6 @@ bool LayerTreeHostImpl::prepareToDraw(FrameData& frame) { TRACE_EVENT0("cc", "LayerTreeHostImpl::prepareToDraw"); - if (m_topControlsManager) - m_topControlsManager->UpdateDrawPositions(); activeTree()->UpdateDrawProperties(LayerTreeImpl::UPDATE_ACTIVE_TREE_FOR_DRAW); frame.renderSurfaceLayerList = &activeTree()->RenderSurfaceLayerList(); diff --git a/cc/top_controls_manager.cc b/cc/top_controls_manager.cc index c75797d..0cdaadec 100644 --- a/cc/top_controls_manager.cc +++ b/cc/top_controls_manager.cc @@ -33,7 +33,6 @@ TopControlsManager::TopControlsManager(TopControlsManagerClient* client, float top_controls_height) : client_(client), animation_direction_(NO_ANIMATION), - is_overlay_mode_(false), in_scroll_gesture_(false), top_controls_height_(top_controls_height), controls_top_offset_(0), @@ -46,21 +45,6 @@ TopControlsManager::TopControlsManager(TopControlsManagerClient* client, TopControlsManager::~TopControlsManager() { } -void TopControlsManager::UpdateDrawPositions() { - if (!client_->haveRootScrollLayer()) - return; - - // If the scroll position has changed underneath us (i.e. a javascript - // scroll), then simulate a scroll that covers the delta. - float scroll_total_y = RootScrollLayerTotalScrollY(); - if (!in_scroll_gesture_ - && scroll_total_y != previous_root_scroll_offset_) { - ScrollBy(gfx::Vector2dF(0, scroll_total_y - previous_root_scroll_offset_)); - StartAnimationIfNecessary(); - previous_root_scroll_offset_ = RootScrollLayerTotalScrollY(); - } -} - void TopControlsManager::ScrollBegin() { ResetAnimations(); in_scroll_gesture_ = true; @@ -91,40 +75,34 @@ gfx::Vector2dF TopControlsManager::ScrollInternal( float previous_controls_offset = controls_top_offset_; float previous_content_offset = content_top_offset_; - bool previous_was_overlay = is_overlay_mode_; controls_top_offset_ -= scroll_delta_y; controls_top_offset_ = std::min( std::max(controls_top_offset_, -top_controls_height_), 0.f); - if (scroll_total_y > 0 || (scroll_total_y == 0 - && content_top_offset_ < scroll_delta_y)) { - is_overlay_mode_ = true; - - // The first case is where the page applies a scroll (javascript) and is - // being re-adjusted in a call to UpdateDrawPositions. Instead of slamming - // the controls to the top, we adjust by the scroll delta until we reach - // zero as we expect. - if (scroll_total_y > 0 && content_top_offset_ != 0) - content_top_offset_ -= scroll_delta_y; - else - content_top_offset_ = 0; - } else if (scroll_total_y <= 0 && (scroll_delta_y < 0 - || (scroll_delta_y > 0 && content_top_offset_ > 0))) { - is_overlay_mode_ = false; - content_top_offset_ -= scroll_delta_y; + // To determine if the scroll delta should be applied to the content position + // as well, we check the following: + // 1.) Scrolling down the page and the content position isn't already at 0. + // This case handles corrections where the page content shifts outside of + // the knowledge of the top controls manager. + // 2.) Scrolling either direction while the root scroll layer is scrolled to + // the very top. + if ((scroll_delta_y > 0 && content_top_offset_ > 0) || scroll_total_y <= 0) { + float content_scroll_delta_y = scroll_delta_y; + if (content_scroll_delta_y > 0) + content_scroll_delta_y -= previous_controls_offset - controls_top_offset_; + content_top_offset_ -= content_scroll_delta_y; } + content_top_offset_ = std::max( std::min(content_top_offset_, controls_top_offset_ + top_controls_height_), 0.f); - gfx::Vector2dF applied_delta; - if (!previous_was_overlay) - applied_delta.set_y(previous_content_offset - content_top_offset_); + gfx::Vector2dF applied_delta( + 0.f, previous_content_offset - content_top_offset_); - if (is_overlay_mode_ != previous_was_overlay - || previous_controls_offset != controls_top_offset_ - || previous_content_offset != content_top_offset_) { + if (previous_controls_offset != controls_top_offset_ || + previous_content_offset != content_top_offset_) { client_->setNeedsRedraw(); client_->setActiveTreeNeedsUpdateDrawProperties(); } diff --git a/cc/top_controls_manager.h b/cc/top_controls_manager.h index a690003..d08031e 100644 --- a/cc/top_controls_manager.h +++ b/cc/top_controls_manager.h @@ -36,14 +36,11 @@ class CC_EXPORT TopControlsManager { float controls_top_offset() { return controls_top_offset_; } float content_top_offset() { return content_top_offset_; } - float is_overlay_mode() { return is_overlay_mode_; } KeyframedFloatAnimationCurve* animation() { return top_controls_animation_.get(); } AnimationDirection animation_direction() { return animation_direction_; } - void UpdateDrawPositions(); - void ScrollBegin(); gfx::Vector2dF ScrollBy(const gfx::Vector2dF pending_delta); void ScrollEnd(); @@ -67,7 +64,6 @@ class CC_EXPORT TopControlsManager { scoped_ptr<KeyframedFloatAnimationCurve> top_controls_animation_; AnimationDirection animation_direction_; - bool is_overlay_mode_; bool in_scroll_gesture_; float controls_top_offset_; float content_top_offset_; diff --git a/cc/top_controls_manager_unittest.cc b/cc/top_controls_manager_unittest.cc index cdce1bd..1418be3 100644 --- a/cc/top_controls_manager_unittest.cc +++ b/cc/top_controls_manager_unittest.cc @@ -80,7 +80,6 @@ TEST(TopControlsManagerTest, overlayModeDetection) { EXPECT_EQ(0.f, remaining_scroll.y()); EXPECT_EQ(-30.f, manager->controls_top_offset()); EXPECT_EQ(70.f, manager->content_top_offset()); - EXPECT_FALSE(manager->is_overlay_mode()); client.rootScrollLayer()->setScrollDelta( client.rootScrollLayer()->scrollDelta() + remaining_scroll); @@ -88,7 +87,6 @@ TEST(TopControlsManagerTest, overlayModeDetection) { EXPECT_EQ(0.f, remaining_scroll.y()); EXPECT_EQ(-99.f, manager->controls_top_offset()); EXPECT_EQ(1.f, manager->content_top_offset()); - EXPECT_FALSE(manager->is_overlay_mode()); client.rootScrollLayer()->setScrollDelta( client.rootScrollLayer()->scrollDelta() + remaining_scroll); @@ -96,7 +94,6 @@ TEST(TopControlsManagerTest, overlayModeDetection) { EXPECT_EQ(0.f, remaining_scroll.y()); EXPECT_EQ(-79.f, manager->controls_top_offset()); EXPECT_EQ(21.f, manager->content_top_offset()); - EXPECT_FALSE(manager->is_overlay_mode()); client.rootScrollLayer()->setScrollDelta( client.rootScrollLayer()->scrollDelta() + remaining_scroll); @@ -105,7 +102,6 @@ TEST(TopControlsManagerTest, overlayModeDetection) { EXPECT_EQ(0.f, remaining_scroll.y()); EXPECT_EQ(-100.f, manager->controls_top_offset()); EXPECT_EQ(0.f, manager->content_top_offset()); - EXPECT_FALSE(manager->is_overlay_mode()); client.rootScrollLayer()->setScrollDelta( client.rootScrollLayer()->scrollDelta() + remaining_scroll); @@ -113,7 +109,6 @@ TEST(TopControlsManagerTest, overlayModeDetection) { EXPECT_EQ(1.f, remaining_scroll.y()); EXPECT_EQ(-100.f, manager->controls_top_offset()); EXPECT_EQ(0.f, manager->content_top_offset()); - EXPECT_TRUE(manager->is_overlay_mode()); client.rootScrollLayer()->setScrollDelta( client.rootScrollLayer()->scrollDelta() + remaining_scroll); @@ -121,22 +116,19 @@ TEST(TopControlsManagerTest, overlayModeDetection) { EXPECT_EQ(-1.f, remaining_scroll.y()); EXPECT_EQ(-99.f, manager->controls_top_offset()); EXPECT_EQ(0.f, manager->content_top_offset()); - EXPECT_TRUE(manager->is_overlay_mode()); client.rootScrollLayer()->setScrollDelta( client.rootScrollLayer()->scrollDelta() + remaining_scroll); remaining_scroll = manager->ScrollBy(gfx::Vector2dF(0.f, -50.f)); - EXPECT_EQ(-50.f, remaining_scroll.y()); + EXPECT_EQ(0.f, remaining_scroll.y()); EXPECT_EQ(-49.f, manager->controls_top_offset()); EXPECT_EQ(50.f, manager->content_top_offset()); - EXPECT_FALSE(manager->is_overlay_mode()); client.rootScrollLayer()->setScrollDelta( client.rootScrollLayer()->scrollDelta() + remaining_scroll); remaining_scroll = manager->ScrollBy(gfx::Vector2dF(0.f, -50.f)); EXPECT_EQ(0.f, manager->controls_top_offset()); EXPECT_EQ(100.f, manager->content_top_offset()); - EXPECT_FALSE(manager->is_overlay_mode()); client.rootScrollLayer()->setScrollDelta( client.rootScrollLayer()->scrollDelta() + remaining_scroll); } @@ -198,13 +190,11 @@ TEST(TopControlsManagerTest, partialShownHideAnimation) { manager->ScrollBy(gfx::Vector2dF(0.f, 300.f)); EXPECT_EQ(-100.f, manager->controls_top_offset()); EXPECT_EQ(0.f, manager->content_top_offset()); - EXPECT_TRUE(manager->is_overlay_mode()); client.rootScrollLayer()->setScrollOffset(gfx::Vector2d(0, 270)); manager->ScrollBy(gfx::Vector2dF(0.f, -15.f)); EXPECT_EQ(-85.f, manager->controls_top_offset()); EXPECT_EQ(0.f, manager->content_top_offset()); - EXPECT_TRUE(manager->is_overlay_mode()); manager->ScrollEnd(); EXPECT_TRUE(manager->animation()); @@ -220,7 +210,6 @@ TEST(TopControlsManagerTest, partialShownHideAnimation) { EXPECT_FALSE(manager->animation()); EXPECT_EQ(-100.f, manager->controls_top_offset()); EXPECT_EQ(0.f, manager->content_top_offset()); - EXPECT_TRUE(manager->is_overlay_mode()); } TEST(TopControlsManagerTest, partialShownShowAnimation) { @@ -230,13 +219,11 @@ TEST(TopControlsManagerTest, partialShownShowAnimation) { manager->ScrollBy(gfx::Vector2dF(0.f, 300.f)); EXPECT_EQ(-100.f, manager->controls_top_offset()); EXPECT_EQ(0.f, manager->content_top_offset()); - EXPECT_TRUE(manager->is_overlay_mode()); client.rootScrollLayer()->setScrollOffset(gfx::Vector2d(0, 230)); manager->ScrollBy(gfx::Vector2dF(0.f, -70.f)); EXPECT_EQ(-30.f, manager->controls_top_offset()); EXPECT_EQ(0.f, manager->content_top_offset()); - EXPECT_TRUE(manager->is_overlay_mode()); manager->ScrollEnd(); EXPECT_TRUE(manager->animation()); @@ -252,7 +239,6 @@ TEST(TopControlsManagerTest, partialShownShowAnimation) { EXPECT_FALSE(manager->animation()); EXPECT_EQ(0.f, manager->controls_top_offset()); EXPECT_EQ(0.f, manager->content_top_offset()); - EXPECT_TRUE(manager->is_overlay_mode()); } } // namespace |