Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 { | 13 namespace { |
| 14 | 14 |
| 15 // The threshold before engaging overview on a three finger swipe on the | 15 // The threshold before engaging overview on a three finger swipe on the |
| 16 // touchpad. | 16 // touchpad. |
| 17 const float kSwipeThresholdPixels = 300; | 17 const float kVerticalSwipeThresholdPixels = 300; |
| 18 | |
| 19 // The threshold before moving selector horizontally when swiping with the | |
| 20 // three fingers on the touchpad. | |
| 21 const float kHorizontalSwipeThresholdPixels = 150; | |
|
tdanderson
2017/02/06 20:13:57
As I understand it you're processing ui::ET_SCROLL
varkha
2017/02/08 20:41:13
Done.
| |
| 18 | 22 |
| 19 } // namespace | 23 } // namespace |
| 20 | 24 |
| 21 OverviewGestureHandler::OverviewGestureHandler() : scroll_x_(0), scroll_y_(0) {} | 25 OverviewGestureHandler::OverviewGestureHandler() : scroll_x_(0), scroll_y_(0) {} |
| 22 | 26 |
| 23 OverviewGestureHandler::~OverviewGestureHandler() {} | 27 OverviewGestureHandler::~OverviewGestureHandler() {} |
| 24 | 28 |
| 25 bool OverviewGestureHandler::ProcessScrollEvent(const ui::ScrollEvent& event) { | 29 bool OverviewGestureHandler::ProcessScrollEvent(const ui::ScrollEvent& event) { |
| 26 if (event.type() == ui::ET_SCROLL_FLING_START || | 30 if (event.type() == ui::ET_SCROLL_FLING_START || |
| 27 event.type() == ui::ET_SCROLL_FLING_CANCEL || event.finger_count() != 3) { | 31 event.type() == ui::ET_SCROLL_FLING_CANCEL || event.finger_count() != 3) { |
| 28 scroll_x_ = scroll_y_ = 0; | 32 scroll_x_ = scroll_y_ = 0; |
| 29 return false; | 33 return false; |
| 30 } | 34 } |
| 31 | 35 |
| 32 scroll_x_ += event.x_offset(); | 36 scroll_x_ += event.x_offset(); |
| 33 scroll_y_ += event.y_offset(); | 37 scroll_y_ += event.y_offset(); |
|
tdanderson
2017/02/06 20:13:58
In the .h these two members are documented as "The
varkha
2017/02/08 20:41:13
Done.
| |
| 34 | 38 |
| 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 | 39 // Only allow swipe up to enter overview, down to exit. Ignore extra swiping |
| 42 // in the wrong direction. | 40 // in the wrong direction. |
| 43 WindowSelectorController* window_selector_controller = | 41 WindowSelectorController* window_selector_controller = |
| 44 WmShell::Get()->window_selector_controller(); | 42 WmShell::Get()->window_selector_controller(); |
| 43 | |
| 44 // Horizontal swiping moves selection when overview mode is active. | |
| 45 if (std::fabs(scroll_x_) >= std::fabs(scroll_y_)) { | |
| 46 if (!window_selector_controller->IsSelecting()) { | |
| 47 scroll_x_ = scroll_y_ = 0; | |
| 48 return false; | |
| 49 } | |
| 50 | |
| 51 if (std::fabs(scroll_x_) < kHorizontalSwipeThresholdPixels) | |
| 52 return false; | |
| 53 window_selector_controller->IncrementSelection( | |
| 54 scroll_x_ / kHorizontalSwipeThresholdPixels); | |
| 55 scroll_x_ = scroll_y_ = 0; | |
| 56 return true; | |
| 57 } | |
| 58 | |
| 45 if (window_selector_controller->IsSelecting()) { | 59 if (window_selector_controller->IsSelecting()) { |
| 46 if (scroll_y_ < 0) | 60 if (scroll_y_ < 0) |
| 47 scroll_x_ = scroll_y_ = 0; | 61 scroll_x_ = scroll_y_ = 0; |
| 48 if (scroll_y_ < kSwipeThresholdPixels) | 62 if (scroll_y_ < kVerticalSwipeThresholdPixels) |
| 49 return false; | 63 return false; |
| 50 } else { | 64 } else { |
| 51 if (scroll_y_ > 0) | 65 if (scroll_y_ > 0) |
| 52 scroll_x_ = scroll_y_ = 0; | 66 scroll_x_ = scroll_y_ = 0; |
| 53 if (scroll_y_ > -kSwipeThresholdPixels) | 67 if (scroll_y_ > -kVerticalSwipeThresholdPixels) |
| 54 return false; | 68 return false; |
| 55 } | 69 } |
| 56 | 70 |
| 57 // Reset scroll amount on toggling. | 71 // Reset scroll amount on toggling. |
| 58 scroll_x_ = scroll_y_ = 0; | 72 scroll_x_ = scroll_y_ = 0; |
| 59 WmShell::Get()->RecordUserMetricsAction(UMA_TOUCHPAD_GESTURE_OVERVIEW); | 73 WmShell::Get()->RecordUserMetricsAction(UMA_TOUCHPAD_GESTURE_OVERVIEW); |
| 74 if (window_selector_controller->IsSelecting() && | |
|
tdanderson
2017/02/06 20:13:58
Is checking IsSelecting() necessary here given how
varkha
2017/02/08 20:41:13
Yes, we can get here when not already in selection
tdanderson
2017/02/08 23:14:19
Acknowledged.
| |
| 75 window_selector_controller->AcceptSelection()) { | |
| 76 return true; | |
| 77 } | |
| 60 window_selector_controller->ToggleOverview(); | 78 window_selector_controller->ToggleOverview(); |
| 61 return true; | 79 return true; |
| 62 } | 80 } |
| 63 | 81 |
| 64 } // namespace ash | 82 } // namespace ash |
| OLD | NEW |