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 |
| 25 namespace internal { |
| 26 class ActivationController; |
| 27 } |
| 28 |
21 class WindowCycleList; | 29 class WindowCycleList; |
22 | 30 |
23 // Controls cycling through windows with the keyboard, for example, via alt-tab. | 31 // Controls cycling through windows with the keyboard, for example, via alt-tab. |
| 32 // 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 | 33 // 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 | 34 // may change during the gesture, but the most recently used list isn't updated |
| 35 // 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 | 36 // at the beginning of the gesture so you can cycle through in a consistent |
27 // order. | 37 // order. |
28 class ASH_EXPORT WindowCycleController { | 38 class ASH_EXPORT WindowCycleController |
| 39 : public aura::client::ActivationChangeObserver, |
| 40 public aura::WindowObserver { |
29 public: | 41 public: |
30 enum Direction { | 42 enum Direction { |
31 FORWARD, | 43 FORWARD, |
32 BACKWARD | 44 BACKWARD |
33 }; | 45 }; |
34 WindowCycleController(); | 46 explicit WindowCycleController( |
35 ~WindowCycleController(); | 47 internal::ActivationController* activation_controller); |
| 48 virtual ~WindowCycleController(); |
36 | 49 |
37 // Returns true if cycling through windows is enabled. This is false at | 50 // Returns true if cycling through windows is enabled. This is false at |
38 // certain times, such as when the lock screen is visible. | 51 // certain times, such as when the lock screen is visible. |
39 static bool CanCycle(); | 52 static bool CanCycle(); |
40 | 53 |
41 // Cycles between windows in the given |direction|. If |is_alt_down| then | 54 // 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 | 55 // interprets this call as the start of a multi-step cycle sequence and |
43 // installs a key filter to watch for alt being released. | 56 // installs a key filter to watch for alt being released. |
44 void HandleCycleWindow(Direction direction, bool is_alt_down); | 57 void HandleCycleWindow(Direction direction, bool is_alt_down); |
45 | 58 |
46 // Informs the controller that the Alt key has been released and it can | 59 // Informs the controller that the Alt key has been released and it can |
47 // terminate the existing multi-step cycle. | 60 // terminate the existing multi-step cycle. |
48 void AltKeyReleased(); | 61 void AltKeyReleased(); |
49 | 62 |
50 // Returns true if we are in the middle of a window cycling gesture. | 63 // Returns true if we are in the middle of a window cycling gesture. |
51 bool IsCycling() const { return windows_.get() != NULL; } | 64 bool IsCycling() const { return windows_.get() != NULL; } |
52 | 65 |
53 // Returns the WindowCycleList. Really only useful for testing. | 66 // Returns the WindowCycleList. Really only useful for testing. |
54 const WindowCycleList* windows() const { return windows_.get(); } | 67 const WindowCycleList* windows() const { return windows_.get(); } |
55 | 68 |
| 69 // Set up the observers to handle window changes for the containers we care |
| 70 // about. Called when a new root window is added. |
| 71 void OnRootWindowAdded(aura::RootWindow* root_window); |
| 72 |
56 // Returns the set of windows to cycle through. This method creates | 73 // 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 | 74 // 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 | 75 // windows. As a result it is not necessarily the same as the set of |
59 // windows being iterated over. | 76 // windows being iterated over. |
60 static std::vector<aura::Window*> BuildWindowList(); | 77 // If |mru_windows| is not NULL, windows in this list are put at the head of |
| 78 // the window list. |
| 79 static std::vector<aura::Window*> BuildWindowList( |
| 80 const std::list<aura::Window*>* mru_windows); |
61 | 81 |
62 private: | 82 private: |
63 // Call to start cycling windows. You must call StopCycling() when done. | 83 // Call to start cycling windows. You must call StopCycling() when done. |
64 void StartCycling(); | 84 void StartCycling(); |
65 | 85 |
66 // Cycles to the next or previous window based on |direction|. | 86 // Cycles to the next or previous window based on |direction|. |
67 void Step(Direction direction); | 87 void Step(Direction direction); |
68 | 88 |
69 // Installs an event filter to watch for release of the alt key. | 89 // Installs an event filter to watch for release of the alt key. |
70 void InstallEventFilter(); | 90 void InstallEventFilter(); |
71 | 91 |
72 // Stops the current window cycle and cleans up the event filter. | 92 // Stops the current window cycle and cleans up the event filter. |
73 void StopCycling(); | 93 void StopCycling(); |
74 | 94 |
| 95 // Checks if the window represents a container whose children we track. |
| 96 static bool IsTrackedContainer(aura::Window* window); |
| 97 |
| 98 // Overridden from ActivationChangeObserver: |
| 99 virtual void OnWindowActivated(aura::Window* active, |
| 100 aura::Window* old_active) OVERRIDE; |
| 101 |
| 102 // Overridden from WindowObserver: |
| 103 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE; |
| 104 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; |
| 105 |
75 scoped_ptr<WindowCycleList> windows_; | 106 scoped_ptr<WindowCycleList> windows_; |
76 | 107 |
77 // Event filter to watch for release of alt key. | 108 // Event filter to watch for release of alt key. |
78 scoped_ptr<aura::EventFilter> event_filter_; | 109 scoped_ptr<aura::EventFilter> event_filter_; |
79 | 110 |
| 111 // List of windows that have been activated in containers that we cycle |
| 112 // through, sorted by most recently used. |
| 113 std::list<aura::Window*> mru_windows_; |
| 114 |
| 115 internal::ActivationController* activation_controller_; |
| 116 |
80 DISALLOW_COPY_AND_ASSIGN(WindowCycleController); | 117 DISALLOW_COPY_AND_ASSIGN(WindowCycleController); |
81 }; | 118 }; |
82 | 119 |
83 } // namespace ash | 120 } // namespace ash |
84 | 121 |
85 #endif // ASH_WM_WINDOW_CYCLE_CONTROLLER_H_ | 122 #endif // ASH_WM_WINDOW_CYCLE_CONTROLLER_H_ |
OLD | NEW |