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/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. 16 // . The mouse moves |kMaxPixels| horizontal pixels. 17 // . The mouse is moved |kMaxMoves| times. 18 const int kMaxDelay = 500; 19 const int kMaxPixels = 100; 20 const int kMaxMoves = 25; 21 22 } // namespace 23 24 TwoStepEdgeCycler::TwoStepEdgeCycler(const gfx::Point& start) 25 : second_mode_(false), 26 time_last_move_(base::TimeTicks::Now()), 27 num_moves_(0), 28 start_x_(start.x()) { 29 } 30 31 TwoStepEdgeCycler::~TwoStepEdgeCycler() { 32 } 33 34 void TwoStepEdgeCycler::OnMove(const gfx::Point& location) { 35 if (second_mode_) 36 return; 37 38 ++num_moves_; 39 second_mode_ = 40 (base::TimeTicks::Now() - time_last_move_).InMilliseconds() > 41 kMaxDelay || 42 std::abs(location.x() - start_x_) >= kMaxPixels || 43 num_moves_ >= kMaxMoves; 44 time_last_move_ = base::TimeTicks::Now(); 45 } 46 47 } // namespace ash 48