diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-04 22:16:10 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-04 22:16:10 +0000 |
commit | 4982ee1e81b6dc26a6f675b2104d9e083b2fe9fb (patch) | |
tree | 54376f826a5ed5b488c78d84f3202dc2ebe52598 /ash/wm/shelf_layout_manager.cc | |
parent | b71f1f6946e77a95fab70d6bb0941c0c5544bc32 (diff) | |
download | chromium_src-4982ee1e81b6dc26a6f675b2104d9e083b2fe9fb.zip chromium_src-4982ee1e81b6dc26a6f675b2104d9e083b2fe9fb.tar.gz chromium_src-4982ee1e81b6dc26a6f675b2104d9e083b2fe9fb.tar.bz2 |
ash: Allow the shelf to be dragged in from the bottom edge of the screen.
BUG=145406
Review URL: https://chromiumcodereview.appspot.com/10911075
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154823 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/wm/shelf_layout_manager.cc')
-rw-r--r-- | ash/wm/shelf_layout_manager.cc | 68 |
1 files changed, 50 insertions, 18 deletions
diff --git a/ash/wm/shelf_layout_manager.cc b/ash/wm/shelf_layout_manager.cc index 5bad6bb..7f63c1d 100644 --- a/ash/wm/shelf_layout_manager.cc +++ b/ash/wm/shelf_layout_manager.cc @@ -131,7 +131,8 @@ ShelfLayoutManager::ShelfLayoutManager(views::Widget* status) workspace_controller_(NULL), window_overlaps_shelf_(false), gesture_drag_status_(GESTURE_DRAG_NONE), - gesture_drag_amount_(0.f) { + gesture_drag_amount_(0.f), + gesture_drag_auto_hide_state_(AUTO_HIDE_SHOWN) { Shell::GetInstance()->AddShellObserver(this); aura::client::GetActivationClient(root_window_)->AddObserver(this); } @@ -231,7 +232,7 @@ void ShelfLayoutManager::UpdateVisibilityState() { ShellDelegate* delegate = Shell::GetInstance()->delegate(); if (delegate && delegate->IsScreenLocked()) { SetState(VISIBLE); - } else if (gesture_drag_status_ == GESTURE_DRAG_HIDE_IN_PROGRESS) { + } else if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) { SetState(AUTO_HIDE); } else { WorkspaceWindowState window_state(workspace_controller_->GetWindowState()); @@ -297,6 +298,8 @@ void ShelfLayoutManager::RemoveObserver(Observer* observer) { void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) { gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS; gesture_drag_amount_ = 0.f; + gesture_drag_auto_hide_state_ = visibility_state() == AUTO_HIDE ? + auto_hide_state() : AUTO_HIDE_SHOWN; UpdateShelfBackground(internal::BackgroundAnimator::CHANGE_ANIMATE); } @@ -307,37 +310,44 @@ void ShelfLayoutManager::UpdateGestureDrag(const ui::GestureEvent& gesture) { LayoutShelf(); } -void ShelfLayoutManager::HideFromGestureDrag(const ui::GestureEvent& gesture) { +void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { bool horizontal = alignment() == SHELF_ALIGNMENT_BOTTOM; - bool should_hide = false; + 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. + // hidden/shown. 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_hide = gesture_drag_amount_ > kDragHideThreshold * bounds.height(); + should_change = drag_amount > kDragHideThreshold * bounds.height(); else if (alignment() == SHELF_ALIGNMENT_LEFT) - should_hide = -gesture_drag_amount_ > kDragHideThreshold * bounds.width(); + should_change = -drag_amount > kDragHideThreshold * bounds.width(); else - should_hide = gesture_drag_amount_ > kDragHideThreshold * bounds.width(); + should_change = drag_amount > kDragHideThreshold * bounds.width(); } else if (gesture.type() == ui::ET_SCROLL_FLING_START) { if (horizontal) - should_hide = gesture.details().velocity_y() > 0; + should_change = gesture.details().velocity_y() > 0; else if (alignment() == SHELF_ALIGNMENT_LEFT) - should_hide = gesture.details().velocity_x() < 0; + should_change = gesture.details().velocity_x() < 0; else - should_hide = gesture.details().velocity_x() > 0; + should_change = gesture.details().velocity_x() > 0; + if (gesture_drag_auto_hide_state_ == AUTO_HIDE_HIDDEN) + should_change = !should_change; } else { NOTREACHED(); } - if (!should_hide) { + if (!should_change) { CancelGestureDrag(); return; } - gesture_drag_status_ = GESTURE_DRAG_HIDE_IN_PROGRESS; + gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; + gesture_drag_auto_hide_state_ = + gesture_drag_auto_hide_state_ == AUTO_HIDE_SHOWN ? AUTO_HIDE_HIDDEN : + AUTO_HIDE_SHOWN; if (launcher_widget()) launcher_widget()->Deactivate(); status_->Deactivate(); @@ -349,13 +359,14 @@ void ShelfLayoutManager::HideFromGestureDrag(const ui::GestureEvent& gesture) { } void ShelfLayoutManager::CancelGestureDrag() { - gesture_drag_status_ = GESTURE_DRAG_NONE; + gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; ui::ScopedLayerAnimationSettings launcher_settings(GetLayer(launcher_widget())->GetAnimator()), status_settings(GetLayer(status_)->GetAnimator()); LayoutShelf(); UpdateVisibilityState(); UpdateShelfBackground(internal::BackgroundAnimator::CHANGE_ANIMATE); + gesture_drag_status_ = GESTURE_DRAG_NONE; } //////////////////////////////////////////////////////////////////////////////// @@ -598,8 +609,29 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture( resist = gesture_drag_amount_ < 0; const float kDragResistanceFactor = 0.25f; - float translate = resist ? gesture_drag_amount_ * kDragResistanceFactor : - gesture_drag_amount_; + float translate = 0.f; + if (gesture_drag_auto_hide_state_ == AUTO_HIDE_HIDDEN) { + // If the shelf was hidden when the drag started, then allow the drag some + // resistance-free region at first to make sure the shelf sticks with the + // finger until the shelf is visible. + int resistance_free_region = horizontal ? + target_bounds->launcher_bounds_in_root.height() : + target_bounds->launcher_bounds_in_root.width(); + resist = resist && fabsf(gesture_drag_amount_) > resistance_free_region; + if (resist) { + float diff = fabsf(gesture_drag_amount_) - resistance_free_region; + if (gesture_drag_amount_ < 0) + translate = -resistance_free_region - diff * kDragResistanceFactor; + else + translate = resistance_free_region + diff * kDragResistanceFactor; + } else { + translate = gesture_drag_amount_; + } + } else { + translate = resist ? gesture_drag_amount_ * kDragResistanceFactor : + gesture_drag_amount_; + } + if (horizontal) { target_bounds->launcher_bounds_in_root.Offset(0, translate); target_bounds->status_bounds_in_root.Offset(0, translate); @@ -637,8 +669,8 @@ ShelfLayoutManager::AutoHideState ShelfLayoutManager::CalculateAutoHideState( if (visibility_state != AUTO_HIDE || !launcher_widget()) return AUTO_HIDE_HIDDEN; - if (gesture_drag_status_ == GESTURE_DRAG_HIDE_IN_PROGRESS) - return AUTO_HIDE_HIDDEN; + if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) + return gesture_drag_auto_hide_state_; Shell* shell = Shell::GetInstance(); if (shell->GetAppListTargetVisibility()) |