diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-28 02:21:16 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-28 02:21:16 +0000 |
commit | 9bf222b0ada03412fbbb61a5dcf2f6205bb1f0d8 (patch) | |
tree | 53fcc8ebf49a49eebf69e019ea61caf6466b5286 /ash | |
parent | 581b4fe3dfb307de6ea1e82040f5db279cf3a226 (diff) | |
download | chromium_src-9bf222b0ada03412fbbb61a5dcf2f6205bb1f0d8.zip chromium_src-9bf222b0ada03412fbbb61a5dcf2f6205bb1f0d8.tar.gz chromium_src-9bf222b0ada03412fbbb61a5dcf2f6205bb1f0d8.tar.bz2 |
ash: Hide the launcher if it's pulled up from a visible state.
BUG=161352
Review URL: https://codereview.chromium.org/11413195
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169821 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/wm/shelf_layout_manager.cc | 49 | ||||
-rw-r--r-- | ash/wm/shelf_layout_manager_unittest.cc | 24 |
2 files changed, 42 insertions, 31 deletions
diff --git a/ash/wm/shelf_layout_manager.cc b/ash/wm/shelf_layout_manager.cc index 4df054d..c8b070e 100644 --- a/ash/wm/shelf_layout_manager.cc +++ b/ash/wm/shelf_layout_manager.cc @@ -359,27 +359,40 @@ void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { bool horizontal = alignment() == SHELF_ALIGNMENT_BOTTOM; bool should_change = false; if (gesture.type() == ui::ET_GESTURE_SCROLL_END) { - // If the shelf was dragged X% towards the correct direction, then it is - // hidden/shown. + // The visibility of the shelf changes only if the shelf was dragged X% + // along the correct axis. If the shelf was already visible, then the + // direction of the drag does not matter. const float kDragHideThreshold = 0.4f; gfx::Rect bounds = GetIdealBounds(); - float drag_amount = gesture_drag_auto_hide_state_ == AUTO_HIDE_SHOWN ? - gesture_drag_amount_ : -gesture_drag_amount_; - if (horizontal) - should_change = drag_amount > kDragHideThreshold * bounds.height(); - else if (alignment() == SHELF_ALIGNMENT_LEFT) - should_change = -drag_amount > kDragHideThreshold * bounds.width(); - else - should_change = drag_amount > kDragHideThreshold * bounds.width(); + float drag_ratio = fabs(gesture_drag_amount_) / + (horizontal ? bounds.height() : bounds.width()); + if (gesture_drag_auto_hide_state_ == AUTO_HIDE_SHOWN) { + should_change = drag_ratio > kDragHideThreshold; + } else { + bool correct_direction = false; + switch (alignment()) { + case SHELF_ALIGNMENT_BOTTOM: + case SHELF_ALIGNMENT_RIGHT: + correct_direction = gesture_drag_amount_ < 0; + break; + case SHELF_ALIGNMENT_LEFT: + correct_direction = gesture_drag_amount_ > 0; + break; + } + should_change = correct_direction && drag_ratio > kDragHideThreshold; + } } else if (gesture.type() == ui::ET_SCROLL_FLING_START) { - if (horizontal) - should_change = gesture.details().velocity_y() > 0; - else if (alignment() == SHELF_ALIGNMENT_LEFT) - should_change = gesture.details().velocity_x() < 0; - else - should_change = gesture.details().velocity_x() > 0; - if (gesture_drag_auto_hide_state_ == AUTO_HIDE_HIDDEN) - should_change = !should_change; + if (gesture_drag_auto_hide_state_ == AUTO_HIDE_SHOWN) { + should_change = horizontal ? fabs(gesture.details().velocity_y()) > 0 : + fabs(gesture.details().velocity_x()) > 0; + } else { + if (horizontal) + should_change = gesture.details().velocity_y() < 0; + else if (alignment() == SHELF_ALIGNMENT_LEFT) + should_change = gesture.details().velocity_x() > 0; + else + should_change = gesture.details().velocity_x() < 0; + } } else { NOTREACHED(); } diff --git a/ash/wm/shelf_layout_manager_unittest.cc b/ash/wm/shelf_layout_manager_unittest.cc index 2c031d9..e0a6158 100644 --- a/ash/wm/shelf_layout_manager_unittest.cc +++ b/ash/wm/shelf_layout_manager_unittest.cc @@ -695,14 +695,7 @@ TEST_F(ShelfLayoutManagerTest, GestureDrag) { // Swipe up on the shelf. This should not change any state. gfx::Point start = shelf->launcher_widget()->GetWindowBoundsInScreen().CenterPoint(); - gfx::Point end(start.x(), start.y() - 100); - generator.GestureScrollSequence(start, end, - base::TimeDelta::FromMilliseconds(10), 1); - EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); - EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); - EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString()); - EXPECT_EQ(shelf_shown.ToString(), - shelf->launcher_widget()->GetWindowBoundsInScreen().ToString()); + gfx::Point end(start.x(), start.y() + 100); // Swipe down on the shelf to hide it. end.set_y(start.y() + 100); @@ -727,16 +720,21 @@ TEST_F(ShelfLayoutManagerTest, GestureDrag) { EXPECT_EQ(shelf_shown.ToString(), shelf->launcher_widget()->GetWindowBoundsInScreen().ToString()); - // Swipe up again. This should not change any state. + // Swipe up again. The shelf should hide. end.set_y(start.y() - 100); generator.GestureScrollSequence(start, end, base::TimeDelta::FromMilliseconds(10), 1); - EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); - EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); - EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString()); - EXPECT_EQ(shelf_shown.ToString(), + EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state()); + EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); + EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); + EXPECT_EQ(shelf_hidden.ToString(), shelf->launcher_widget()->GetWindowBoundsInScreen().ToString()); + // Swipe up yet again to show it. + end.set_y(start.y() + 100); + generator.GestureScrollSequence(end, start, + base::TimeDelta::FromMilliseconds(10), 1); + // Swipe down very little. It shouldn't change any state. end.set_y(start.y() + shelf_shown.height() * 3 / 10); generator.GestureScrollSequence(start, end, |