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 pixels. | |
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. | |
pkotwicz
2015/05/11 21:35:20
Nit: Can you remove the comments about the movemen
varkha
2015/05/11 22:09:31
Done.
| |
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 |
46 if ((base::TimeTicks::Now() - time_last_move_).InMilliseconds() > kMaxDelay) { | |
47 paused_ = true; | |
48 paused_x_ = location.x(); | |
49 num_moves_ = 0; | |
50 } | |
51 time_last_move_ = base::TimeTicks::Now(); | |
52 | |
53 int compare_x = paused_ ? paused_x_ : start_x_; | |
54 if (location.x() != compare_x && | |
55 (location.x() < compare_x) != (direction_ == DIRECTION_LEFT)) { | |
56 return; | |
57 } | |
58 | |
38 ++num_moves_; | 59 ++num_moves_; |
39 second_mode_ = | 60 bool moved_in_the_same_direction_after_pause = |
40 (base::TimeTicks::Now() - time_last_move_).InMilliseconds() > | 61 paused_ && ((direction_ == DIRECTION_RIGHT && |
41 kMaxDelay || | 62 (location.x() - paused_x_) >= kMaxPixelsAfterPause) || |
42 std::abs(location.x() - start_x_) >= kMaxPixels || | 63 (direction_ == DIRECTION_LEFT && |
43 num_moves_ >= kMaxMoves; | 64 (paused_x_ - location.x()) >= kMaxPixelsAfterPause)); |
pkotwicz
2015/05/11 21:35:20
Can't this become simpler now? i.e. std::abs(locat
varkha
2015/05/11 22:09:31
Done.
| |
44 time_last_move_ = base::TimeTicks::Now(); | 65 second_mode_ = moved_in_the_same_direction_after_pause || |
66 std::abs(location.x() - start_x_) >= kMaxPixels || | |
67 num_moves_ >= kMaxMoves; | |
45 } | 68 } |
46 | 69 |
47 } // namespace ash | 70 } // namespace ash |
OLD | NEW |