Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(560)

Side by Side Diff: ash/wm/gestures/overview_gesture_handler.cc

Issue 2667293002: [ash-md] Adds support for gesture to move selection in overview mode (Closed)
Patch Set: [ash-md] Adds support for gesture to move selection in overview mode (comments) Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/gestures/overview_gesture_handler.h" 5 #include "ash/wm/gestures/overview_gesture_handler.h"
6 6
7 #include "ash/common/wm/overview/window_selector_controller.h" 7 #include "ash/common/wm/overview/window_selector_controller.h"
8 #include "ash/common/wm_shell.h" 8 #include "ash/common/wm_shell.h"
9 #include "ui/events/event.h" 9 #include "ui/events/event.h"
10 #include "ui/events/event_constants.h" 10 #include "ui/events/event_constants.h"
11 11
12 namespace ash { 12 namespace ash {
13 namespace {
14 13
15 // The threshold before engaging overview on a three finger swipe on the 14 // The threshold before engaging overview with a touchpad three-finger scroll.
16 // touchpad. 15 float OverviewGestureHandler::vertical_threshold_pixels_ = 300;
17 const float kSwipeThresholdPixels = 300;
18 16
19 } // namespace 17 // The threshold before moving selector horizontally when using a touchpad
18 // two or three-finger scroll.
19 float OverviewGestureHandler::horizontal_threshold_pixels_ = 150;
20 20
21 OverviewGestureHandler::OverviewGestureHandler() : scroll_x_(0), scroll_y_(0) {} 21 OverviewGestureHandler::OverviewGestureHandler() : scroll_x_(0), scroll_y_(0) {}
22 22
23 OverviewGestureHandler::~OverviewGestureHandler() {} 23 OverviewGestureHandler::~OverviewGestureHandler() {}
24 24
25 bool OverviewGestureHandler::ProcessScrollEvent(const ui::ScrollEvent& event) { 25 bool OverviewGestureHandler::ProcessScrollEvent(const ui::ScrollEvent& event) {
26 if (event.type() == ui::ET_SCROLL_FLING_START || 26 if (event.type() == ui::ET_SCROLL_FLING_START ||
27 event.type() == ui::ET_SCROLL_FLING_CANCEL || event.finger_count() != 3) { 27 event.type() == ui::ET_SCROLL_FLING_CANCEL ||
28 (event.finger_count() != 2 && event.finger_count() != 3)) {
tdanderson 2017/02/08 23:14:19 If you're going to start permitting two-finger scr
varkha 2017/02/09 21:54:42 Convinced - going back to requiring 3-finger gestu
28 scroll_x_ = scroll_y_ = 0; 29 scroll_x_ = scroll_y_ = 0;
29 return false; 30 return false;
30 } 31 }
31 32
32 scroll_x_ += event.x_offset(); 33 scroll_x_ += event.x_offset();
33 scroll_y_ += event.y_offset(); 34 scroll_y_ += event.y_offset();
34 35
35 // Horizontal swiping is ignored.
36 if (std::fabs(scroll_x_) >= std::fabs(scroll_y_)) {
37 scroll_x_ = scroll_y_ = 0;
38 return false;
39 }
40
41 // Only allow swipe up to enter overview, down to exit. Ignore extra swiping 36 // Only allow swipe up to enter overview, down to exit. Ignore extra swiping
tdanderson 2017/02/08 23:14:19 nit: update documentation and probably just merge
varkha 2017/02/09 21:54:42 Done.
42 // in the wrong direction. 37 // in the wrong direction.
43 WindowSelectorController* window_selector_controller = 38 WindowSelectorController* window_selector_controller =
44 WmShell::Get()->window_selector_controller(); 39 WmShell::Get()->window_selector_controller();
40
41 // Horizontal 2 or 3 finger scroll moves selection when in overview mode.
42 if (std::fabs(scroll_x_) >= std::fabs(scroll_y_)) {
43 if (!window_selector_controller->IsSelecting()) {
44 scroll_x_ = scroll_y_ = 0;
45 return false;
46 }
47
48 if (std::fabs(scroll_x_) < horizontal_threshold_pixels_)
49 return false;
tdanderson 2017/02/08 23:14:19 nit: newline
varkha 2017/02/09 21:54:42 Done.
50 window_selector_controller->IncrementSelection(
51 scroll_x_ / horizontal_threshold_pixels_);
52 scroll_x_ = scroll_y_ = 0;
53 return true;
54 }
55
56 // For the vertical scroll 3 fingers are required.
57 if (event.finger_count() != 3) {
58 scroll_x_ = scroll_y_ = 0;
59 return false;
60 }
61
45 if (window_selector_controller->IsSelecting()) { 62 if (window_selector_controller->IsSelecting()) {
46 if (scroll_y_ < 0) 63 if (scroll_y_ < 0)
47 scroll_x_ = scroll_y_ = 0; 64 scroll_x_ = scroll_y_ = 0;
48 if (scroll_y_ < kSwipeThresholdPixels) 65 if (scroll_y_ < vertical_threshold_pixels_)
49 return false; 66 return false;
50 } else { 67 } else {
51 if (scroll_y_ > 0) 68 if (scroll_y_ > 0)
52 scroll_x_ = scroll_y_ = 0; 69 scroll_x_ = scroll_y_ = 0;
53 if (scroll_y_ > -kSwipeThresholdPixels) 70 if (scroll_y_ > -vertical_threshold_pixels_)
54 return false; 71 return false;
55 } 72 }
56 73
57 // Reset scroll amount on toggling. 74 // Reset scroll amount on toggling.
58 scroll_x_ = scroll_y_ = 0; 75 scroll_x_ = scroll_y_ = 0;
59 WmShell::Get()->RecordUserMetricsAction(UMA_TOUCHPAD_GESTURE_OVERVIEW); 76 WmShell::Get()->RecordUserMetricsAction(UMA_TOUCHPAD_GESTURE_OVERVIEW);
77 if (window_selector_controller->IsSelecting() &&
78 window_selector_controller->AcceptSelection()) {
79 return true;
80 }
60 window_selector_controller->ToggleOverview(); 81 window_selector_controller->ToggleOverview();
61 return true; 82 return true;
62 } 83 }
63 84
64 } // namespace ash 85 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698