From f879188e71ae17348b4174c09f59bfbdfdb2f26b Mon Sep 17 00:00:00 2001 From: "xiyuan@chromium.org" Date: Tue, 23 Oct 2012 21:27:12 +0000 Subject: [PATCH] app_list: Starts touch drag via long press. Touch drag starts on long press event and context menu shows up if no drag actually happens. BUG=117090 TEST=Manual per description above. R=sadrul@chromium.org,sky@chromium.org Review URL: https://chromiumcodereview.appspot.com/11232052 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@163685 0039d316-1c4b-4281-b951-d872f2087c98 --- ui/app_list/app_list_item_view.cc | 38 +++++++++++++++----------------------- ui/app_list/app_list_item_view.h | 9 --------- ui/views/view.cc | 12 +++++++++--- 3 files changed, 24 insertions(+), 35 deletions(-) diff --git a/ui/app_list/app_list_item_view.cc b/ui/app_list/app_list_item_view.cc index 0a14059102ca..2e54825cc762 100644 --- a/ui/app_list/app_list_item_view.cc +++ b/ui/app_list/app_list_item_view.cc @@ -42,11 +42,8 @@ const SkColor kHighlightedColor = kHoverAndPushedColor; const int kTitleFontSize = 11; const int kLeftRightPaddingChars = 1; -// Delay in milliseconds of when a touch drag should start after tap down. -const int kTouchDragStartDelayInMs = 200; - -// Scale to transform when touch drag starts. -const float kTouchDraggingScale = 1.5f; +// Scale to transform the icon when a drag starts. +const float kDraggingIconScale = 1.5f; // Delay in milliseconds of when the dragging UI should be shown for mouse drag. const int kMouseDragUIDelayInMs = 100; @@ -143,7 +140,7 @@ void AppListItemView::SetUIState(UIState state) { #if !defined(OS_WIN) ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); - switch(ui_state_) { + switch (ui_state_) { case UI_STATE_NORMAL: title_->SetVisible(true); layer()->SetTransform(gfx::Transform()); @@ -153,16 +150,12 @@ void AppListItemView::SetUIState(UIState state) { const gfx::Rect bounds(layer()->bounds().size()); layer()->SetTransform(gfx::GetScaleTransform( bounds.CenterPoint(), - kTouchDraggingScale)); + kDraggingIconScale)); break; } #endif } -void AppListItemView::OnTouchDragTimer() { - SetTouchDragging(true); -} - void AppListItemView::SetTouchDragging(bool touch_dragging) { if (touch_dragging_ == touch_dragging) return; @@ -317,19 +310,10 @@ bool AppListItemView::OnMouseDragged(const ui::MouseEvent& event) { ui::EventResult AppListItemView::OnGestureEvent( const ui::GestureEvent& event) { switch (event.type()) { - case ui::ET_GESTURE_TAP_DOWN: - if (!apps_grid_view_->has_dragged_view()) { - touch_drag_timer_.Start(FROM_HERE, - base::TimeDelta::FromMilliseconds(kTouchDragStartDelayInMs), - this, &AppListItemView::OnTouchDragTimer); - } - break; case ui::ET_GESTURE_SCROLL_BEGIN: if (touch_dragging_) { apps_grid_view_->InitiateDrag(this, AppsGridView::TOUCH, event); return ui::ER_CONSUMED; - } else { - touch_drag_timer_.Stop(); } break; case ui::ET_GESTURE_SCROLL_UPDATE: @@ -346,10 +330,18 @@ ui::EventResult AppListItemView::OnGestureEvent( return ui::ER_CONSUMED; } break; - case ui::ET_GESTURE_END: case ui::ET_GESTURE_LONG_PRESS: - touch_drag_timer_.Stop(); - SetTouchDragging(false); + if (!apps_grid_view_->has_dragged_view()) + SetTouchDragging(true); + return ui::ER_CONSUMED; + case ui::ET_GESTURE_END: + if (touch_dragging_) { + SetTouchDragging(false); + + gfx::Point location(event.location()); + ConvertPointToScreen(this, &location); + ShowContextMenu(location, true); + } break; default: break; diff --git a/ui/app_list/app_list_item_view.h b/ui/app_list/app_list_item_view.h index 40198ad6cc88..42f2493cb7db 100644 --- a/ui/app_list/app_list_item_view.h +++ b/ui/app_list/app_list_item_view.h @@ -54,10 +54,6 @@ class APP_LIST_EXPORT AppListItemView : public views::CustomButton, void SetUIState(UIState state); - // Invoked when |touch_drag_timer_| fires. It sets touch dragging flag so - // that further touch scroll gestures contribute to drag. - void OnTouchDragTimer(); - // Sets |touch_dragging_| flag and updates UI. void SetTouchDragging(bool touch_dragging); @@ -104,11 +100,6 @@ class APP_LIST_EXPORT AppListItemView : public views::CustomButton, UIState ui_state_; - // A timer to track whether user has pressed on the item long enough. When it - // fires, subsequent scroll gesture events will contribute to drag instead - // scrolling. - base::OneShotTimer touch_drag_timer_; - // True if scroll gestures should contribute to dragging. bool touch_dragging_; diff --git a/ui/views/view.cc b/ui/views/view.cc index d2830f7f239f..fd1ac7f79ab0 100644 --- a/ui/views/view.cc +++ b/ui/views/view.cc @@ -1909,7 +1909,8 @@ void View::DestroyLayer() { // Input ----------------------------------------------------------------------- -bool View::ProcessMousePressed(const ui::MouseEvent& event, DragInfo* drag_info) { +bool View::ProcessMousePressed(const ui::MouseEvent& event, + DragInfo* drag_info) { int drag_operations = (enabled_ && event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) ? @@ -1931,7 +1932,8 @@ bool View::ProcessMousePressed(const ui::MouseEvent& event, DragInfo* drag_info) return !!context_menu_controller || result; } -bool View::ProcessMouseDragged(const ui::MouseEvent& event, DragInfo* drag_info) { +bool View::ProcessMouseDragged(const ui::MouseEvent& event, + DragInfo* drag_info) { // Copy the field, that way if we're deleted after drag and drop no harm is // done. ContextMenuController* context_menu_controller = context_menu_controller_; @@ -1975,6 +1977,10 @@ ui::TouchStatus View::ProcessTouchEvent(const ui::TouchEvent& event) { } ui::EventResult View::ProcessGestureEvent(const ui::GestureEvent& event) { + ui::EventResult status = OnGestureEvent(event); + if (status != ui::ER_UNHANDLED) + return status; + if (context_menu_controller_ && (event.type() == ui::ET_GESTURE_LONG_PRESS || event.type() == ui::ET_GESTURE_TWO_FINGER_TAP)) { @@ -1983,7 +1989,7 @@ ui::EventResult View::ProcessGestureEvent(const ui::GestureEvent& event) { ShowContextMenu(location, true); return ui::ER_CONSUMED; } - return OnGestureEvent(event); + return status; } // Accelerators ---------------------------------------------------------------- -- 2.11.4.GIT