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 <vector> | 9 #include <vector> |
9 | 10 |
10 #include "ash/ash_export.h" | 11 #include "ash/ash_export.h" |
11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "ui/aura/client/activation_change_observer.h" | |
15 #include "ui/aura/window_observer.h" | |
13 | 16 |
14 namespace aura { | 17 namespace aura { |
15 class EventFilter; | 18 class EventFilter; |
19 class RootWindow; | |
16 class Window; | 20 class Window; |
17 } | 21 } |
18 | 22 |
19 namespace ash { | 23 namespace ash { |
20 | 24 |
21 class WindowCycleList; | 25 class WindowCycleList; |
22 | 26 |
23 // Controls cycling through windows with the keyboard, for example, via alt-tab. | 27 // Controls cycling through windows with the keyboard, for example, via alt-tab. |
28 // Windows are sorted primarily by most recently used, and then by screen order. | |
24 // We activate windows as you cycle through them, so the order on the screen | 29 // We activate windows as you cycle through them, so the order on the screen |
25 // may change during the gesture. Thus we maintain the state of the windows | 30 // may change during the gesture, but the most recently used list isn't updated |
31 // until the cycling ends. Thus we maintain the state of the windows | |
26 // at the beginning of the gesture so you can cycle through in a consistent | 32 // at the beginning of the gesture so you can cycle through in a consistent |
27 // order. | 33 // order. |
28 class ASH_EXPORT WindowCycleController { | 34 class ASH_EXPORT WindowCycleController |
35 : public aura::client::ActivationChangeObserver, | |
36 public aura::WindowObserver { | |
29 public: | 37 public: |
30 enum Direction { | 38 enum Direction { |
31 FORWARD, | 39 FORWARD, |
32 BACKWARD | 40 BACKWARD |
33 }; | 41 }; |
34 WindowCycleController(); | 42 WindowCycleController(); |
35 ~WindowCycleController(); | 43 ~WindowCycleController(); |
36 | 44 |
37 // Returns true if cycling through windows is enabled. This is false at | 45 // Returns true if cycling through windows is enabled. This is false at |
38 // certain times, such as when the lock screen is visible. | 46 // certain times, such as when the lock screen is visible. |
39 static bool CanCycle(); | 47 static bool CanCycle(); |
40 | 48 |
41 // Cycles between windows in the given |direction|. If |is_alt_down| then | 49 // Cycles between windows in the given |direction|. If |is_alt_down| then |
42 // interprets this call as the start of a multi-step cycle sequence and | 50 // interprets this call as the start of a multi-step cycle sequence and |
43 // installs a key filter to watch for alt being released. | 51 // installs a key filter to watch for alt being released. |
44 void HandleCycleWindow(Direction direction, bool is_alt_down); | 52 void HandleCycleWindow(Direction direction, bool is_alt_down); |
45 | 53 |
46 // Informs the controller that the Alt key has been released and it can | 54 // Informs the controller that the Alt key has been released and it can |
47 // terminate the existing multi-step cycle. | 55 // terminate the existing multi-step cycle. |
48 void AltKeyReleased(); | 56 void AltKeyReleased(); |
49 | 57 |
50 // Returns true if we are in the middle of a window cycling gesture. | 58 // Returns true if we are in the middle of a window cycling gesture. |
51 bool IsCycling() const { return windows_.get() != NULL; } | 59 bool IsCycling() const { return windows_.get() != NULL; } |
52 | 60 |
53 // Returns the WindowCycleList. Really only useful for testing. | 61 // Returns the WindowCycleList. Really only useful for testing. |
54 const WindowCycleList* windows() const { return windows_.get(); } | 62 const WindowCycleList* windows() const { return windows_.get(); } |
55 | 63 |
64 // Setup the observers to handle window changes for the containers we care | |
65 // about. Called when a new root window is added. | |
66 void OnRootWindowAdded(aura::RootWindow* root_window); | |
67 | |
56 // Returns the set of windows to cycle through. This method creates | 68 // Returns the set of windows to cycle through. This method creates |
57 // the vector based on the current set of windows across all valid root | 69 // the vector based on the current set of windows across all valid root |
58 // windows. As a result it is not necessarily the same as the set of | 70 // windows. As a result it is not necessarily the same as the set of |
59 // windows being iterated over. | 71 // windows being iterated over. |
60 static std::vector<aura::Window*> BuildWindowList(); | 72 // If |mru_windows| is not NULL, windows in this list are put at the head of |
73 // the window list. | |
74 static std::vector<aura::Window*> BuildWindowList( | |
75 std::list<aura::Window*>* mru_windows); | |
61 | 76 |
62 private: | 77 private: |
63 // Call to start cycling windows. You must call StopCycling() when done. | 78 // Call to start cycling windows. You must call StopCycling() when done. |
64 void StartCycling(); | 79 void StartCycling(); |
65 | 80 |
66 // Cycles to the next or previous window based on |direction|. | 81 // Cycles to the next or previous window based on |direction|. |
67 void Step(Direction direction); | 82 void Step(Direction direction); |
68 | 83 |
69 // Installs an event filter to watch for release of the alt key. | 84 // Installs an event filter to watch for release of the alt key. |
70 void InstallEventFilter(); | 85 void InstallEventFilter(); |
71 | 86 |
72 // Stops the current window cycle and cleans up the event filter. | 87 // Stops the current window cycle and cleans up the event filter. |
73 void StopCycling(); | 88 void StopCycling(); |
74 | 89 |
90 // Overridden from ActivationChangeObserver: | |
91 virtual void OnWindowActivated(aura::Window* active, | |
92 aura::Window* old_active) OVERRIDE; | |
93 | |
94 // Overridden from WindowObserver: | |
95 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE; | |
96 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; | |
97 | |
75 scoped_ptr<WindowCycleList> windows_; | 98 scoped_ptr<WindowCycleList> windows_; |
76 | 99 |
77 // Event filter to watch for release of alt key. | 100 // Event filter to watch for release of alt key. |
78 scoped_ptr<aura::EventFilter> event_filter_; | 101 scoped_ptr<aura::EventFilter> event_filter_; |
79 | 102 |
103 // List of windows that have been activated in containers that we cycle | |
104 // through, sorted by most recently used. | |
105 std::list<aura::Window*> mru_windows_; | |
106 | |
107 // Indicates that we should not update the mru_windows_ list when windows are | |
sky
2012/07/24 03:53:31
|mru_windows_|
Zachary Kuznia
2012/07/30 07:49:48
Removed.
On 2012/07/24 03:53:31, sky wrote:
| |
108 // activated. This is set while cycles with alt+tab. | |
109 bool mru_ignore_; | |
sky
2012/07/24 03:53:31
I think this should be is cycling. Do you even nee
Zachary Kuznia
2012/07/30 07:49:48
Done.
| |
110 | |
80 DISALLOW_COPY_AND_ASSIGN(WindowCycleController); | 111 DISALLOW_COPY_AND_ASSIGN(WindowCycleController); |
81 }; | 112 }; |
82 | 113 |
83 } // namespace ash | 114 } // namespace ash |
84 | 115 |
85 #endif // ASH_WM_WINDOW_CYCLE_CONTROLLER_H_ | 116 #endif // ASH_WM_WINDOW_CYCLE_CONTROLLER_H_ |
OLD | NEW |