1cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// found in the LICENSE file.
4cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
5cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#ifndef ASH_WM_WINDOW_CYCLE_CONTROLLER_H_
6cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#define ASH_WM_WINDOW_CYCLE_CONTROLLER_H_
7cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
8cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ash/ash_export.h"
9cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "base/basictypes.h"
10cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
11f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "base/time/time.h"
12cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
13cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)namespace ui {
14cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class EventHandler;
15cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
16cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
17cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)namespace ash {
18cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
19cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class WindowCycleList;
20cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
21cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Controls cycling through windows with the keyboard via alt-tab.
22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Windows are sorted primarily by most recently used, and then by screen order.
23cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// We activate windows as you cycle through them, so the order on the screen
24cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// may change during the gesture, but the most recently used list isn't updated
25cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// until the cycling ends.  Thus we maintain the state of the windows
26cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// at the beginning of the gesture so you can cycle through in a consistent
27cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// order.
28cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class ASH_EXPORT WindowCycleController {
29cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) public:
30cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  enum Direction {
31cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    FORWARD,
32cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    BACKWARD
33cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  };
34cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
35cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  WindowCycleController();
36cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual ~WindowCycleController();
37cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
38cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Returns true if cycling through windows is enabled. This is false at
39cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // certain times, such as when the lock screen is visible.
40cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  static bool CanCycle();
41cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
42cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Cycles between windows in the given |direction|.
43cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void HandleCycleWindow(Direction direction);
44cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
45cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Returns true if we are in the middle of a window cycling gesture.
46cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  bool IsCycling() const { return window_cycle_list_.get() != NULL; }
47cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
48cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Call to start cycling windows. This funtion adds a pre-target handler to
49cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // listen to the alt key release.
50cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void StartCycling();
51cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
52cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Stops the current window cycle and removes the event filter.
53cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void StopCycling();
54cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
55cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Returns the WindowCycleList. Really only useful for testing.
56cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  const WindowCycleList* window_cycle_list() const {
57cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    return window_cycle_list_.get();
58cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
59cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
60cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) private:
61cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Cycles to the next or previous window based on |direction|.
62cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void Step(Direction direction);
63cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
64cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  scoped_ptr<WindowCycleList> window_cycle_list_;
65cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
66cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Event handler to watch for release of alt key.
67cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  scoped_ptr<ui::EventHandler> event_handler_;
68cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
69f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  base::Time cycle_start_time_;
70f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
71cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(WindowCycleController);
72cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)};
73cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
74cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}  // namespace ash
75cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
76cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#endif  // ASH_WM_WINDOW_CYCLE_CONTROLLER_H_
77