| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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. | |
| 4 | |
| 5 #include "ash/common/wm/workspace/two_step_edge_cycler.h" | |
| 6 | |
| 7 #include <cstdlib> | |
| 8 | |
| 9 namespace ash { | |
| 10 namespace { | |
| 11 | |
| 12 // We cycle to the second mode if any of the following happens while the mouse | |
| 13 // is on the edge of the workspace: | |
| 14 // . The user stops moving the mouse for |kMaxDelay| and then moves the mouse | |
| 15 // again in the preferred direction from the last paused location for at least | |
| 16 // |kMaxPixelsAfterPause| horizontal pixels. | |
| 17 // . The mouse moves |kMaxPixels| horizontal pixels in the preferred direction. | |
| 18 // . The mouse is moved |kMaxMoves| times since the last pause. | |
| 19 const int kMaxDelay = 400; | |
| 20 const int kMaxPixels = 100; | |
| 21 const int kMaxPixelsAfterPause = 10; | |
| 22 const int kMaxMoves = 25; | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 TwoStepEdgeCycler::TwoStepEdgeCycler(const gfx::Point& start, | |
| 27 TwoStepEdgeCycler::Direction direction) | |
| 28 : second_mode_(false), | |
| 29 time_last_move_(base::TimeTicks::Now()), | |
| 30 num_moves_(0), | |
| 31 start_x_(start.x()), | |
| 32 paused_x_(start.x()), | |
| 33 paused_(false), | |
| 34 direction_(direction) {} | |
| 35 | |
| 36 TwoStepEdgeCycler::~TwoStepEdgeCycler() {} | |
| 37 | |
| 38 void TwoStepEdgeCycler::OnMove(const gfx::Point& location) { | |
| 39 if (second_mode_) | |
| 40 return; | |
| 41 | |
| 42 if ((base::TimeTicks::Now() - time_last_move_).InMilliseconds() > kMaxDelay) { | |
| 43 paused_ = true; | |
| 44 paused_x_ = location.x(); | |
| 45 num_moves_ = 0; | |
| 46 } | |
| 47 time_last_move_ = base::TimeTicks::Now(); | |
| 48 | |
| 49 int compare_x = paused_ ? paused_x_ : start_x_; | |
| 50 if (location.x() != compare_x && | |
| 51 (location.x() < compare_x) != (direction_ == DIRECTION_LEFT)) { | |
| 52 return; | |
| 53 } | |
| 54 | |
| 55 ++num_moves_; | |
| 56 bool moved_in_the_same_direction_after_pause = | |
| 57 paused_ && std::abs(location.x() - paused_x_) >= kMaxPixelsAfterPause; | |
| 58 second_mode_ = moved_in_the_same_direction_after_pause || | |
| 59 std::abs(location.x() - start_x_) >= kMaxPixels || | |
| 60 num_moves_ >= kMaxMoves; | |
| 61 } | |
| 62 | |
| 63 } // namespace ash | |
| OLD | NEW |