cc: Initialize wait_for_beginframe_interval in tests.
[chromium-blink-merge.git] / ash / wm / window_cycle_controller.h
blob8cfd2a5820ee33541f7480806ea0b39d1ee124cf
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.
5 #ifndef ASH_WM_WINDOW_CYCLE_CONTROLLER_H_
6 #define ASH_WM_WINDOW_CYCLE_CONTROLLER_H_
8 #include "ash/ash_export.h"
9 #include "base/basictypes.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/time/time.h"
13 namespace ui {
14 class EventHandler;
17 namespace aura {
18 class Window;
19 } // namespace aura
21 namespace ash {
23 class WindowCycleList;
25 // Controls cycling through windows with the keyboard via alt-tab.
26 // Windows are sorted primarily by most recently used, and then by screen order.
27 // We activate windows as you cycle through them, so the order on the screen
28 // may change during the gesture, but the most recently used list isn't updated
29 // until the cycling ends. Thus we maintain the state of the windows
30 // at the beginning of the gesture so you can cycle through in a consistent
31 // order.
32 class ASH_EXPORT WindowCycleController {
33 public:
34 enum Direction {
35 FORWARD,
36 BACKWARD
39 WindowCycleController();
40 virtual ~WindowCycleController();
42 // Returns true if cycling through windows is enabled. This is false at
43 // certain times, such as when the lock screen is visible.
44 static bool CanCycle();
46 // Cycles between windows in the given |direction|.
47 void HandleCycleWindow(Direction direction);
49 // Returns true if we are in the middle of a window cycling gesture.
50 bool IsCycling() const { return window_cycle_list_.get() != NULL; }
52 // Call to start cycling windows. This funtion adds a pre-target handler to
53 // listen to the alt key release.
54 void StartCycling();
56 // Stops the current window cycle and removes the event filter.
57 void StopCycling();
59 // Returns the WindowCycleList. Really only useful for testing.
60 const WindowCycleList* window_cycle_list() const {
61 return window_cycle_list_.get();
64 private:
65 // Cycles to the next or previous window based on |direction|.
66 void Step(Direction direction);
68 scoped_ptr<WindowCycleList> window_cycle_list_;
70 // Tracks what Window was active when starting to cycle and used to determine
71 // if the active Window changed in when ending cycling.
72 aura::Window* active_window_before_window_cycle_ = nullptr;
74 // Event handler to watch for release of alt key.
75 scoped_ptr<ui::EventHandler> event_handler_;
77 base::Time cycle_start_time_;
79 DISALLOW_COPY_AND_ASSIGN(WindowCycleController);
82 } // namespace ash
84 #endif // ASH_WM_WINDOW_CYCLE_CONTROLLER_H_