Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: ash/wm/workspace/two_step_edge_cycler.cc

Issue 1127133003: Adjusts dragging logic to be less likely to trigger false positive switch from snapping to docking (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.
16 // . The mouse moves |kMaxPixels| horizontal pixels. 16 // . The mouse moves |kMaxPixels| horizontal pixels.
17 // . The mouse is moved |kMaxMoves| times. 17 // . The mouse is moved |kMaxMoves| times.
pkotwicz 2015/05/07 17:10:28 Can you please update this comment?
varkha 2015/05/07 20:27:28 Done.
18 const int kMaxDelay = 500; 18 const int kMaxDelay = 400;
19 const int kMaxPixels = 100; 19 const int kMaxPixels = 100;
20 const int kMaxPixelsAfterPause = 20;
20 const int kMaxMoves = 25; 21 const int kMaxMoves = 25;
21 22
22 } // namespace 23 } // namespace
23 24
24 TwoStepEdgeCycler::TwoStepEdgeCycler(const gfx::Point& start) 25 TwoStepEdgeCycler::TwoStepEdgeCycler(const gfx::Point& start,
26 SnapType snap_type)
25 : second_mode_(false), 27 : second_mode_(false),
26 time_last_move_(base::TimeTicks::Now()), 28 time_last_move_(base::TimeTicks::Now()),
27 num_moves_(0), 29 num_moves_(0),
28 start_x_(start.x()) { 30 start_x_(start.x()),
31 paused_x_(start.x()),
32 paused_(false),
33 snap_type_(snap_type) {
29 } 34 }
30 35
31 TwoStepEdgeCycler::~TwoStepEdgeCycler() { 36 TwoStepEdgeCycler::~TwoStepEdgeCycler() {
32 } 37 }
33 38
34 void TwoStepEdgeCycler::OnMove(const gfx::Point& location) { 39 void TwoStepEdgeCycler::OnMove(const gfx::Point& location) {
35 if (second_mode_) 40 if (second_mode_)
36 return; 41 return;
37 42
38 ++num_moves_; 43 ++num_moves_;
39 second_mode_ = 44 if ((base::TimeTicks::Now() - time_last_move_).InMilliseconds() > kMaxDelay) {
40 (base::TimeTicks::Now() - time_last_move_).InMilliseconds() > 45 paused_ = true;
41 kMaxDelay || 46 paused_x_ = location.x();
42 std::abs(location.x() - start_x_) >= kMaxPixels || 47 num_moves_ = 0;
43 num_moves_ >= kMaxMoves; 48 }
49 bool moved_in_the_same_direction_after_pause =
50 paused_ && ((snap_type_ == SNAP_RIGHT &&
51 (location.x() - paused_x_) >= kMaxPixelsAfterPause) ||
52 (snap_type_ == SNAP_LEFT &&
53 (paused_x_ - location.x()) >= kMaxPixelsAfterPause));
54 second_mode_ = moved_in_the_same_direction_after_pause ||
55 std::abs(location.x() - start_x_) >= kMaxPixels ||
56 num_moves_ >= kMaxMoves;
44 time_last_move_ = base::TimeTicks::Now(); 57 time_last_move_ = base::TimeTicks::Now();
45 } 58 }
46 59
47 } // namespace ash 60 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698