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