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

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 (no skipping 1st) 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 const 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 // three-finger scroll.
19 const float OverviewGestureHandler::horizontal_threshold_pixels_ = 330;
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 || event.finger_count() != 3) {
28 scroll_x_ = scroll_y_ = 0; 28 scroll_x_ = scroll_y_ = 0;
29 return false; 29 return false;
30 } 30 }
31 31
32 scroll_x_ += event.x_offset(); 32 scroll_x_ += event.x_offset();
33 scroll_y_ += event.y_offset(); 33 scroll_y_ += event.y_offset();
34 34
35 // Horizontal swiping is ignored. 35 WindowSelectorController* window_selector_controller =
36 WmShell::Get()->window_selector_controller();
37
38 // Horizontal 3-finger scroll moves selection when already in overview mode.
36 if (std::fabs(scroll_x_) >= std::fabs(scroll_y_)) { 39 if (std::fabs(scroll_x_) >= std::fabs(scroll_y_)) {
40 if (!window_selector_controller->IsSelecting()) {
41 scroll_x_ = scroll_y_ = 0;
42 return false;
43 }
44 if (std::fabs(scroll_x_) < horizontal_threshold_pixels_)
45 return false;
46
47 const int increment = scroll_x_ > 0 ? 1 : -1;
37 scroll_x_ = scroll_y_ = 0; 48 scroll_x_ = scroll_y_ = 0;
38 return false; 49 window_selector_controller->IncrementSelection(increment);
50 return true;
39 } 51 }
40 52
41 // Only allow swipe up to enter overview, down to exit. Ignore extra swiping 53 // Use vertical 3-finger scroll gesture up to enter overview, down to exit.
42 // in the wrong direction.
43 WindowSelectorController* window_selector_controller =
44 WmShell::Get()->window_selector_controller();
45 if (window_selector_controller->IsSelecting()) { 54 if (window_selector_controller->IsSelecting()) {
46 if (scroll_y_ < 0) 55 if (scroll_y_ < 0)
47 scroll_x_ = scroll_y_ = 0; 56 scroll_x_ = scroll_y_ = 0;
48 if (scroll_y_ < kSwipeThresholdPixels) 57 if (scroll_y_ < vertical_threshold_pixels_)
49 return false; 58 return false;
50 } else { 59 } else {
51 if (scroll_y_ > 0) 60 if (scroll_y_ > 0)
52 scroll_x_ = scroll_y_ = 0; 61 scroll_x_ = scroll_y_ = 0;
53 if (scroll_y_ > -kSwipeThresholdPixels) 62 if (scroll_y_ > -vertical_threshold_pixels_)
54 return false; 63 return false;
55 } 64 }
56 65
57 // Reset scroll amount on toggling. 66 // Reset scroll amount on toggling.
58 scroll_x_ = scroll_y_ = 0; 67 scroll_x_ = scroll_y_ = 0;
59 WmShell::Get()->RecordUserMetricsAction(UMA_TOUCHPAD_GESTURE_OVERVIEW); 68 WmShell::Get()->RecordUserMetricsAction(UMA_TOUCHPAD_GESTURE_OVERVIEW);
69 if (window_selector_controller->IsSelecting() &&
70 window_selector_controller->AcceptSelection()) {
71 return true;
72 }
60 window_selector_controller->ToggleOverview(); 73 window_selector_controller->ToggleOverview();
61 return true; 74 return true;
62 } 75 }
63 76
64 } // namespace ash 77 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/gestures/overview_gesture_handler.h ('k') | ash/wm/gestures/overview_gesture_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698