Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / ash / wm / gestures / overview_gesture_handler.cc
blobbc8829b914291be39868543339518dc732d0a6b5
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
3 // found in the LICENSE file.
5 #include "ash/wm/gestures/overview_gesture_handler.h"
7 #include "ash/metrics/user_metrics_recorder.h"
8 #include "ash/shell.h"
9 #include "ash/wm/overview/window_selector_controller.h"
10 #include "ui/events/event.h"
11 #include "ui/events/event_constants.h"
13 namespace ash {
14 namespace {
16 // The threshold before engaging overview on a three finger swipe on the
17 // touchpad.
18 const float kSwipeThresholdPixels = 300;
20 } // namespace;
22 OverviewGestureHandler::OverviewGestureHandler() : scroll_x_(0), scroll_y_(0) {}
24 OverviewGestureHandler::~OverviewGestureHandler() {
27 bool OverviewGestureHandler::ProcessScrollEvent(const ui::ScrollEvent& event) {
28 if (event.type() == ui::ET_SCROLL_FLING_START ||
29 event.type() == ui::ET_SCROLL_FLING_CANCEL ||
30 event.finger_count() != 3) {
31 scroll_x_ = scroll_y_ = 0;
32 return false;
35 scroll_x_ += event.x_offset();
36 scroll_y_ += event.y_offset();
38 // Horizontal swiping is ignored.
39 if (std::fabs(scroll_x_) >= std::fabs(scroll_y_)) {
40 scroll_x_ = scroll_y_ = 0;
41 return false;
44 // Only allow swipe up to enter overview, down to exit. Ignore extra swiping
45 // in the wrong direction.
46 Shell* shell = Shell::GetInstance();
47 if (shell->window_selector_controller()->IsSelecting()) {
48 if (scroll_y_ < 0)
49 scroll_x_ = scroll_y_ = 0;
50 if (scroll_y_ < kSwipeThresholdPixels)
51 return false;
52 } else {
53 if (scroll_y_ > 0)
54 scroll_x_ = scroll_y_ = 0;
55 if (scroll_y_ > -kSwipeThresholdPixels)
56 return false;
59 // Reset scroll amount on toggling.
60 scroll_x_ = scroll_y_ = 0;
61 shell->metrics()->RecordUserMetricsAction(UMA_TOUCHPAD_GESTURE_OVERVIEW);
62 shell->window_selector_controller()->ToggleOverview();
63 return true;
66 } // namespace ash