OLD | NEW |
| (Empty) |
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 #ifndef ASH_COMMON_WM_WINDOW_CYCLE_CONTROLLER_H_ | |
6 #define ASH_COMMON_WM_WINDOW_CYCLE_CONTROLLER_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "ash/ash_export.h" | |
11 #include "base/macros.h" | |
12 #include "base/time/time.h" | |
13 | |
14 namespace ash { | |
15 | |
16 class WindowCycleEventFilter; | |
17 class WindowCycleList; | |
18 class WmWindow; | |
19 | |
20 // Controls cycling through windows with the keyboard via alt-tab. | |
21 // Windows are sorted primarily by most recently used, and then by screen order. | |
22 // We activate windows as you cycle through them, so the order on the screen | |
23 // may change during the gesture, but the most recently used list isn't updated | |
24 // until the cycling ends. Thus we maintain the state of the windows | |
25 // at the beginning of the gesture so you can cycle through in a consistent | |
26 // order. | |
27 class ASH_EXPORT WindowCycleController { | |
28 public: | |
29 enum Direction { FORWARD, BACKWARD }; | |
30 | |
31 WindowCycleController(); | |
32 virtual ~WindowCycleController(); | |
33 | |
34 // Returns true if cycling through windows is enabled. This is false at | |
35 // certain times, such as when the lock screen is visible. | |
36 static bool CanCycle(); | |
37 | |
38 // Cycles between windows in the given |direction|. | |
39 void HandleCycleWindow(Direction direction); | |
40 | |
41 // Returns true if we are in the middle of a window cycling gesture. | |
42 bool IsCycling() const { return window_cycle_list_.get() != NULL; } | |
43 | |
44 // Call to start cycling windows. This funtion adds a pre-target handler to | |
45 // listen to the alt key release. | |
46 void StartCycling(); | |
47 | |
48 // Both of these functions stop the current window cycle and removes the event | |
49 // filter. The former indicates success (i.e. the new window should be | |
50 // activated) and the latter indicates that the interaction was cancelled (and | |
51 // the originally active window should remain active). | |
52 void CompleteCycling(); | |
53 void CancelCycling(); | |
54 | |
55 // Returns the WindowCycleList. | |
56 const WindowCycleList* window_cycle_list() const { | |
57 return window_cycle_list_.get(); | |
58 } | |
59 | |
60 private: | |
61 // Cycles to the next or previous window based on |direction|. | |
62 void Step(Direction direction); | |
63 | |
64 void StopCycling(); | |
65 | |
66 std::unique_ptr<WindowCycleList> window_cycle_list_; | |
67 | |
68 // Tracks what Window was active when starting to cycle and used to determine | |
69 // if the active Window changed in when ending cycling. | |
70 WmWindow* active_window_before_window_cycle_ = nullptr; | |
71 | |
72 // Non-null while actively cycling. | |
73 std::unique_ptr<WindowCycleEventFilter> event_filter_; | |
74 | |
75 base::Time cycle_start_time_; | |
76 | |
77 DISALLOW_COPY_AND_ASSIGN(WindowCycleController); | |
78 }; | |
79 | |
80 } // namespace ash | |
81 | |
82 #endif // ASH_COMMON_WM_WINDOW_CYCLE_CONTROLLER_H_ | |
OLD | NEW |