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