OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef ASH_WM_WINDOW_CYCLE_CONTROLLER_H_ | 5 #ifndef ASH_WM_WINDOW_CYCLE_CONTROLLER_H_ |
6 #define ASH_WM_WINDOW_CYCLE_CONTROLLER_H_ | 6 #define ASH_WM_WINDOW_CYCLE_CONTROLLER_H_ |
7 | 7 |
8 #include <list> | |
9 #include <vector> | |
10 | |
11 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
12 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
13 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
14 #include "ui/aura/client/activation_change_observer.h" | |
15 #include "ui/aura/window_observer.h" | |
16 | |
17 namespace aura { | |
18 class RootWindow; | |
19 class Window; | |
20 namespace client { | |
21 class ActivationClient; | |
22 } | |
23 } | |
24 | 11 |
25 namespace ui { | 12 namespace ui { |
26 class EventHandler; | 13 class EventHandler; |
27 } | 14 } |
28 | 15 |
29 namespace ash { | 16 namespace ash { |
30 | 17 |
31 class WindowCycleList; | 18 class WindowCycleList; |
32 | 19 |
33 // Controls cycling through windows with the keyboard, for example, via alt-tab. | 20 // Controls cycling through windows with the keyboard, for example, via alt-tab. |
34 // Windows are sorted primarily by most recently used, and then by screen order. | 21 // Windows are sorted primarily by most recently used, and then by screen order. |
35 // We activate windows as you cycle through them, so the order on the screen | 22 // We activate windows as you cycle through them, so the order on the screen |
36 // may change during the gesture, but the most recently used list isn't updated | 23 // may change during the gesture, but the most recently used list isn't updated |
37 // until the cycling ends. Thus we maintain the state of the windows | 24 // until the cycling ends. Thus we maintain the state of the windows |
38 // at the beginning of the gesture so you can cycle through in a consistent | 25 // at the beginning of the gesture so you can cycle through in a consistent |
39 // order. | 26 // order. |
40 class ASH_EXPORT WindowCycleController | 27 class ASH_EXPORT WindowCycleController { |
41 : public aura::client::ActivationChangeObserver, | |
42 public aura::WindowObserver { | |
43 public: | 28 public: |
44 enum Direction { | 29 enum Direction { |
45 FORWARD, | 30 FORWARD, |
46 BACKWARD | 31 BACKWARD |
47 }; | 32 }; |
48 explicit WindowCycleController( | 33 WindowCycleController(); |
49 aura::client::ActivationClient* activation_client); | |
50 virtual ~WindowCycleController(); | 34 virtual ~WindowCycleController(); |
51 | 35 |
52 // Returns true if cycling through windows is enabled. This is false at | 36 // Returns true if cycling through windows is enabled. This is false at |
53 // certain times, such as when the lock screen is visible. | 37 // certain times, such as when the lock screen is visible. |
54 static bool CanCycle(); | 38 static bool CanCycle(); |
55 | 39 |
56 // Cycles between windows in the given |direction|. If |is_alt_down| then | 40 // Cycles between windows in the given |direction|. If |is_alt_down| then |
57 // interprets this call as the start of a multi-step cycle sequence and | 41 // interprets this call as the start of a multi-step cycle sequence and |
58 // installs a key filter to watch for alt being released. | 42 // installs a key filter to watch for alt being released. |
59 void HandleCycleWindow(Direction direction, bool is_alt_down); | 43 void HandleCycleWindow(Direction direction, bool is_alt_down); |
60 | 44 |
61 // Cycles between windows without maintaining a multi-step cycle sequence | 45 // Cycles between windows without maintaining a multi-step cycle sequence |
62 // (see above). | 46 // (see above). |
63 void HandleLinearCycleWindow(); | 47 void HandleLinearCycleWindow(); |
64 | 48 |
65 // Informs the controller that the Alt key has been released and it can | 49 // Informs the controller that the Alt key has been released and it can |
66 // terminate the existing multi-step cycle. | 50 // terminate the existing multi-step cycle. |
67 void AltKeyReleased(); | 51 void AltKeyReleased(); |
68 | 52 |
69 // Returns true if we are in the middle of a window cycling gesture. | 53 // Returns true if we are in the middle of a window cycling gesture. |
70 bool IsCycling() const { return windows_.get() != NULL; } | 54 bool IsCycling() const { return windows_.get() != NULL; } |
71 | 55 |
72 // Returns the WindowCycleList. Really only useful for testing. | 56 // Returns the WindowCycleList. Really only useful for testing. |
73 const WindowCycleList* windows() const { return windows_.get(); } | 57 const WindowCycleList* windows() const { return windows_.get(); } |
74 | 58 |
75 // Set up the observers to handle window changes for the containers we care | |
76 // about. Called when a new root window is added. | |
77 void OnRootWindowAdded(aura::RootWindow* root_window); | |
78 | |
79 // Returns the set of windows to cycle through. This method creates | |
80 // the vector based on the current set of windows across all valid root | |
81 // windows. As a result it is not necessarily the same as the set of | |
82 // windows being iterated over. | |
83 // If |mru_windows| is not NULL, windows in this list are put at the head of | |
84 // the window list. | |
85 // If |top_most_at_end| the window list will return in ascending order instead | |
86 // of the default descending. | |
87 static std::vector<aura::Window*> BuildWindowList( | |
88 const std::list<aura::Window*>* mru_windows, | |
89 bool top_most_at_end); | |
90 | |
91 private: | 59 private: |
92 // Call to start cycling windows. You must call StopCycling() when done. | 60 // Call to start cycling windows. You must call StopCycling() when done. |
93 void StartCycling(); | 61 void StartCycling(); |
94 | 62 |
95 // Cycles to the next or previous window based on |direction|. | 63 // Cycles to the next or previous window based on |direction|. |
96 void Step(Direction direction); | 64 void Step(Direction direction); |
97 | 65 |
98 // Installs an event filter to watch for release of the alt key. | 66 // Installs an event filter to watch for release of the alt key. |
99 void InstallEventFilter(); | 67 void InstallEventFilter(); |
100 | 68 |
101 // Stops the current window cycle and cleans up the event filter. | 69 // Stops the current window cycle and cleans up the event filter. |
102 void StopCycling(); | 70 void StopCycling(); |
103 | 71 |
104 // Checks if the window represents a container whose children we track. | |
105 static bool IsTrackedContainer(aura::Window* window); | |
106 | |
107 // Overridden from aura::client::ActivationChangeObserver: | |
108 virtual void OnWindowActivated(aura::Window* gained_active, | |
109 aura::Window* lost_active) OVERRIDE; | |
110 | |
111 // Overridden from WindowObserver: | |
112 virtual void OnWindowAdded(aura::Window* window) OVERRIDE; | |
113 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE; | |
114 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; | |
115 | |
116 scoped_ptr<WindowCycleList> windows_; | 72 scoped_ptr<WindowCycleList> windows_; |
117 | 73 |
118 // Event handler to watch for release of alt key. | 74 // Event handler to watch for release of alt key. |
119 scoped_ptr<ui::EventHandler> event_handler_; | 75 scoped_ptr<ui::EventHandler> event_handler_; |
120 | 76 |
121 // List of windows that have been activated in containers that we cycle | |
122 // through, sorted by most recently used. | |
123 std::list<aura::Window*> mru_windows_; | |
124 | |
125 aura::client::ActivationClient* activation_client_; | |
126 | |
127 DISALLOW_COPY_AND_ASSIGN(WindowCycleController); | 77 DISALLOW_COPY_AND_ASSIGN(WindowCycleController); |
128 }; | 78 }; |
129 | 79 |
130 } // namespace ash | 80 } // namespace ash |
131 | 81 |
132 #endif // ASH_WM_WINDOW_CYCLE_CONTROLLER_H_ | 82 #endif // ASH_WM_WINDOW_CYCLE_CONTROLLER_H_ |
OLD | NEW |