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_WORKSPACE_WORKSPACE_MANAGER2_H_ | 5 #ifndef ASH_WM_WORKSPACE_WORKSPACE_MANAGER_H_ |
6 #define ASH_WM_WORKSPACE_WORKSPACE_MANAGER2_H_ | 6 #define ASH_WM_WORKSPACE_WORKSPACE_MANAGER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "ash/ash_export.h" | 12 #include "ash/ash_export.h" |
13 #include "ash/shell_observer.h" | 13 #include "ash/shell_observer.h" |
14 #include "ash/wm/workspace/workspace_types.h" | 14 #include "ash/wm/workspace/workspace_types.h" |
15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
(...skipping 17 matching lines...) Expand all Loading... |
34 | 34 |
35 namespace ui { | 35 namespace ui { |
36 class Layer; | 36 class Layer; |
37 } | 37 } |
38 | 38 |
39 namespace ash { | 39 namespace ash { |
40 namespace internal { | 40 namespace internal { |
41 | 41 |
42 class DesktopBackgroundFadeController; | 42 class DesktopBackgroundFadeController; |
43 class ShelfLayoutManager; | 43 class ShelfLayoutManager; |
44 class WorkspaceLayoutManager2; | 44 class WorkspaceLayoutManager; |
45 class WorkspaceManagerTest2; | 45 class WorkspaceManagerTest2; |
46 class Workspace2; | 46 class Workspace; |
47 | 47 |
48 // WorkspaceManager manages multiple workspaces in the desktop. Workspaces are | 48 // WorkspaceManager manages multiple workspaces in the desktop. Workspaces are |
49 // implicitly created as windows are maximized (or made fullscreen), and | 49 // implicitly created as windows are maximized (or made fullscreen), and |
50 // destroyed when maximized windows are closed or restored. There is always one | 50 // destroyed when maximized windows are closed or restored. There is always one |
51 // workspace for the desktop. | 51 // workspace for the desktop. |
52 // Internally WorkspaceManager2 creates a Window for each Workspace. As windows | 52 // Internally WorkspaceManager creates a Window for each Workspace. As windows |
53 // are maximized and restored they are reparented to the right Window. | 53 // are maximized and restored they are reparented to the right Window. |
54 class ASH_EXPORT WorkspaceManager2 : public ash::ShellObserver { | 54 class ASH_EXPORT WorkspaceManager : public ash::ShellObserver { |
55 public: | 55 public: |
56 explicit WorkspaceManager2(aura::Window* viewport); | 56 explicit WorkspaceManager(aura::Window* viewport); |
57 virtual ~WorkspaceManager2(); | 57 virtual ~WorkspaceManager(); |
58 | 58 |
59 // Returns true if |window| is considered maximized and should exist in its | 59 // Returns true if |window| is considered maximized and should exist in its |
60 // own workspace. | 60 // own workspace. |
61 static bool IsMaximized(aura::Window* window); | 61 static bool IsMaximized(aura::Window* window); |
62 static bool IsMaximizedState(ui::WindowShowState state); | 62 static bool IsMaximizedState(ui::WindowShowState state); |
63 | 63 |
64 // Returns true if |window| is minimized and will restore to a maximized | 64 // Returns true if |window| is minimized and will restore to a maximized |
65 // window. | 65 // window. |
66 static bool WillRestoreMaximized(aura::Window* window); | 66 static bool WillRestoreMaximized(aura::Window* window); |
67 | 67 |
(...skipping 10 matching lines...) Expand all Loading... |
78 // when a new Window is being added. | 78 // when a new Window is being added. |
79 aura::Window* GetParentForNewWindow(aura::Window* window); | 79 aura::Window* GetParentForNewWindow(aura::Window* window); |
80 | 80 |
81 // Starts the animation that occurs on first login. | 81 // Starts the animation that occurs on first login. |
82 void DoInitialAnimation(); | 82 void DoInitialAnimation(); |
83 | 83 |
84 // ShellObserver overrides: | 84 // ShellObserver overrides: |
85 virtual void OnAppTerminating() OVERRIDE; | 85 virtual void OnAppTerminating() OVERRIDE; |
86 | 86 |
87 private: | 87 private: |
88 friend class WorkspaceLayoutManager2; | 88 friend class WorkspaceLayoutManager; |
89 friend class WorkspaceManager2Test; | 89 friend class WorkspaceManagerTest; |
90 | 90 |
91 class LayoutManagerImpl; | 91 class LayoutManagerImpl; |
92 | 92 |
93 typedef std::vector<Workspace2*> Workspaces; | 93 typedef std::vector<Workspace*> Workspaces; |
94 | 94 |
95 // Reason for the workspace switch. Used to determine the characterstics of | 95 // Reason for the workspace switch. Used to determine the characterstics of |
96 // the animation. | 96 // the animation. |
97 enum SwitchReason { | 97 enum SwitchReason { |
98 SWITCH_WINDOW_MADE_ACTIVE, | 98 SWITCH_WINDOW_MADE_ACTIVE, |
99 SWITCH_WINDOW_REMOVED, | 99 SWITCH_WINDOW_REMOVED, |
100 SWITCH_VISIBILITY_CHANGED, | 100 SWITCH_VISIBILITY_CHANGED, |
101 SWITCH_MINIMIZED, | 101 SWITCH_MINIMIZED, |
102 SWITCH_MAXIMIZED_OR_RESTORED, | 102 SWITCH_MAXIMIZED_OR_RESTORED, |
103 SWITCH_TRACKED_BY_WORKSPACE_CHANGED, | 103 SWITCH_TRACKED_BY_WORKSPACE_CHANGED, |
104 | 104 |
105 // Switch as the result of DoInitialAnimation(). This isn't a real switch, | 105 // Switch as the result of DoInitialAnimation(). This isn't a real switch, |
106 // rather we run the animations as if a switch occurred. | 106 // rather we run the animations as if a switch occurred. |
107 SWITCH_INITIAL, | 107 SWITCH_INITIAL, |
108 | 108 |
109 // Edge case. See comment in OnWorkspaceWindowShowStateChanged(). Don't | 109 // Edge case. See comment in OnWorkspaceWindowShowStateChanged(). Don't |
110 // make other types randomly use this! | 110 // make other types randomly use this! |
111 SWITCH_OTHER, | 111 SWITCH_OTHER, |
112 }; | 112 }; |
113 | 113 |
114 // Updates the visibility and whether any windows overlap the shelf. | 114 // Updates the visibility and whether any windows overlap the shelf. |
115 void UpdateShelfVisibility(); | 115 void UpdateShelfVisibility(); |
116 | 116 |
117 // Returns the workspace that contains |window|. | 117 // Returns the workspace that contains |window|. |
118 Workspace2* FindBy(aura::Window* window) const; | 118 Workspace* FindBy(aura::Window* window) const; |
119 | 119 |
120 // Sets the active workspace. | 120 // Sets the active workspace. |
121 void SetActiveWorkspace(Workspace2* workspace, | 121 void SetActiveWorkspace(Workspace* workspace, |
122 SwitchReason reason, | 122 SwitchReason reason, |
123 base::TimeDelta duration); | 123 base::TimeDelta duration); |
124 | 124 |
125 // Returns the bounds of the work area. | 125 // Returns the bounds of the work area. |
126 gfx::Rect GetWorkAreaBounds() const; | 126 gfx::Rect GetWorkAreaBounds() const; |
127 | 127 |
128 // Returns an iterator into |workspaces_| for |workspace|. | 128 // Returns an iterator into |workspaces_| for |workspace|. |
129 Workspaces::iterator FindWorkspace(Workspace2* workspace); | 129 Workspaces::iterator FindWorkspace(Workspace* workspace); |
130 | 130 |
131 Workspace2* desktop_workspace() { return workspaces_[0]; } | 131 Workspace* desktop_workspace() { return workspaces_[0]; } |
132 const Workspace2* desktop_workspace() const { return workspaces_[0]; } | 132 const Workspace* desktop_workspace() const { return workspaces_[0]; } |
133 | 133 |
134 // Creates a new workspace. The Workspace is not added to anything and is | 134 // Creates a new workspace. The Workspace is not added to anything and is |
135 // owned by the caller. | 135 // owned by the caller. |
136 Workspace2* CreateWorkspace(bool maximized); | 136 Workspace* CreateWorkspace(bool maximized); |
137 | 137 |
138 // Moves all the non-maximized child windows of |workspace| to the desktop | 138 // Moves all the non-maximized child windows of |workspace| to the desktop |
139 // stacked beneath |stack_beneath| (if non-NULL). After moving child windows | 139 // stacked beneath |stack_beneath| (if non-NULL). After moving child windows |
140 // if |workspace| contains no children it is deleted, otherwise it it moved to | 140 // if |workspace| contains no children it is deleted, otherwise it it moved to |
141 // |pending_workspaces_|. | 141 // |pending_workspaces_|. |
142 void MoveWorkspaceToPendingOrDelete(Workspace2* workspace, | 142 void MoveWorkspaceToPendingOrDelete(Workspace* workspace, |
143 aura::Window* stack_beneath, | 143 aura::Window* stack_beneath, |
144 SwitchReason reason); | 144 SwitchReason reason); |
145 | 145 |
146 // Moves the children of |window| to the desktop. This excludes certain | 146 // Moves the children of |window| to the desktop. This excludes certain |
147 // windows. If |stack_beneath| is non-NULL the windows are stacked beneath it. | 147 // windows. If |stack_beneath| is non-NULL the windows are stacked beneath it. |
148 void MoveChildrenToDesktop(aura::Window* window, aura::Window* stack_beneath); | 148 void MoveChildrenToDesktop(aura::Window* window, aura::Window* stack_beneath); |
149 | 149 |
150 // Selects the next workspace. | 150 // Selects the next workspace. |
151 void SelectNextWorkspace(SwitchReason reason); | 151 void SelectNextWorkspace(SwitchReason reason); |
152 | 152 |
153 // Schedules |workspace| for deletion when it no longer contains any layers. | 153 // Schedules |workspace| for deletion when it no longer contains any layers. |
154 // See comments above |to_delete_| as to why we do this. | 154 // See comments above |to_delete_| as to why we do this. |
155 void ScheduleDelete(Workspace2* workspace); | 155 void ScheduleDelete(Workspace* workspace); |
156 | 156 |
157 // Deletes any workspaces scheduled via ScheduleDelete() that don't contain | 157 // Deletes any workspaces scheduled via ScheduleDelete() that don't contain |
158 // any layers. | 158 // any layers. |
159 void ProcessDeletion(); | 159 void ProcessDeletion(); |
160 | 160 |
161 // Sets |unminimizing_workspace_| to |workspace|. | 161 // Sets |unminimizing_workspace_| to |workspace|. |
162 void SetUnminimizingWorkspace(Workspace2* workspace); | 162 void SetUnminimizingWorkspace(Workspace* workspace); |
163 | 163 |
164 // Fades the desktop. This is only used when maximizing or restoring a | 164 // Fades the desktop. This is only used when maximizing or restoring a |
165 // window. The actual fade is handled by | 165 // window. The actual fade is handled by |
166 // DesktopBackgroundFadeController. |window| is used when restoring and | 166 // DesktopBackgroundFadeController. |window| is used when restoring and |
167 // indicates the window to stack the DesktopBackgroundFadeController's window | 167 // indicates the window to stack the DesktopBackgroundFadeController's window |
168 // above. | 168 // above. |
169 void FadeDesktop(aura::Window* window, base::TimeDelta duration); | 169 void FadeDesktop(aura::Window* window, base::TimeDelta duration); |
170 | 170 |
171 // Shows or hides the desktop Window |window|. | 171 // Shows or hides the desktop Window |window|. |
172 void ShowOrHideDesktopBackground(aura::Window* window, | 172 void ShowOrHideDesktopBackground(aura::Window* window, |
173 SwitchReason reason, | 173 SwitchReason reason, |
174 base::TimeDelta duration, | 174 base::TimeDelta duration, |
175 bool show) const; | 175 bool show) const; |
176 | 176 |
177 // Shows/hides |workspace| animating as necessary. | 177 // Shows/hides |workspace| animating as necessary. |
178 void ShowWorkspace(Workspace2* workspace, | 178 void ShowWorkspace(Workspace* workspace, |
179 Workspace2* last_active, | 179 Workspace* last_active, |
180 SwitchReason reason) const; | 180 SwitchReason reason) const; |
181 void HideWorkspace(Workspace2* workspace, | 181 void HideWorkspace(Workspace* workspace, |
182 SwitchReason reason, | 182 SwitchReason reason, |
183 bool is_unminimizing_maximized_window) const; | 183 bool is_unminimizing_maximized_window) const; |
184 | 184 |
185 // These methods are forwarded from the LayoutManager installed on the | 185 // These methods are forwarded from the LayoutManager installed on the |
186 // Workspace's window. | 186 // Workspace's window. |
187 void OnWindowAddedToWorkspace(Workspace2* workspace, aura::Window* child); | 187 void OnWindowAddedToWorkspace(Workspace* workspace, aura::Window* child); |
188 void OnWillRemoveWindowFromWorkspace(Workspace2* workspace, | 188 void OnWillRemoveWindowFromWorkspace(Workspace* workspace, |
189 aura::Window* child); | 189 aura::Window* child); |
190 void OnWindowRemovedFromWorkspace(Workspace2* workspace, aura::Window* child); | 190 void OnWindowRemovedFromWorkspace(Workspace* workspace, aura::Window* child); |
191 void OnWorkspaceChildWindowVisibilityChanged(Workspace2* workspace, | 191 void OnWorkspaceChildWindowVisibilityChanged(Workspace* workspace, |
192 aura::Window* child); | 192 aura::Window* child); |
193 void OnWorkspaceWindowChildBoundsChanged(Workspace2* workspace, | 193 void OnWorkspaceWindowChildBoundsChanged(Workspace* workspace, |
194 aura::Window* child); | 194 aura::Window* child); |
195 void OnWorkspaceWindowShowStateChanged(Workspace2* workspace, | 195 void OnWorkspaceWindowShowStateChanged(Workspace* workspace, |
196 aura::Window* child, | 196 aura::Window* child, |
197 ui::WindowShowState last_show_state, | 197 ui::WindowShowState last_show_state, |
198 ui::Layer* old_layer); | 198 ui::Layer* old_layer); |
199 void OnTrackedByWorkspaceChanged(Workspace2* workspace, | 199 void OnTrackedByWorkspaceChanged(Workspace* workspace, |
200 aura::Window* window); | 200 aura::Window* window); |
201 | 201 |
202 aura::Window* contents_view_; | 202 aura::Window* contents_view_; |
203 | 203 |
204 Workspace2* active_workspace_; | 204 Workspace* active_workspace_; |
205 | 205 |
206 // The set of active workspaces. There is always at least one in this stack, | 206 // The set of active workspaces. There is always at least one in this stack, |
207 // which identifies the desktop. | 207 // which identifies the desktop. |
208 Workspaces workspaces_; | 208 Workspaces workspaces_; |
209 | 209 |
210 // The set of workspaces not currently active. Workspaces ended up here in | 210 // The set of workspaces not currently active. Workspaces ended up here in |
211 // two scenarios: | 211 // two scenarios: |
212 // . Prior to adding a window a new worskpace is created for it. The | 212 // . Prior to adding a window a new worskpace is created for it. The |
213 // Workspace is added to this set. | 213 // Workspace is added to this set. |
214 // . When the maximized window is minimized the workspace is added here. | 214 // . When the maximized window is minimized the workspace is added here. |
215 // Once any window in the workspace is activated the workspace is moved to | 215 // Once any window in the workspace is activated the workspace is moved to |
216 // |workspaces_|. | 216 // |workspaces_|. |
217 std::set<Workspace2*> pending_workspaces_; | 217 std::set<Workspace*> pending_workspaces_; |
218 | 218 |
219 // Owned by the Shell. May be NULL. | 219 // Owned by the Shell. May be NULL. |
220 ShelfLayoutManager* shelf_; | 220 ShelfLayoutManager* shelf_; |
221 | 221 |
222 // Whether or not we're in MoveWorkspaceToPendingOrDelete(). As | 222 // Whether or not we're in MoveWorkspaceToPendingOrDelete(). As |
223 // MoveWorkspaceToPendingOrDelete() may trigger another call to | 223 // MoveWorkspaceToPendingOrDelete() may trigger another call to |
224 // MoveWorkspaceToPendingOrDelete() we use this to avoid doing anything if | 224 // MoveWorkspaceToPendingOrDelete() we use this to avoid doing anything if |
225 // already in MoveWorkspaceToPendingOrDelete(). | 225 // already in MoveWorkspaceToPendingOrDelete(). |
226 bool in_move_; | 226 bool in_move_; |
227 | 227 |
228 // Ideally we would delete workspaces when not needed. Unfortunately doing so | 228 // Ideally we would delete workspaces when not needed. Unfortunately doing so |
229 // would effectively cancel animations. Instead when a workspace is no longer | 229 // would effectively cancel animations. Instead when a workspace is no longer |
230 // needed we add it here and start a timer. When the timer fires any windows | 230 // needed we add it here and start a timer. When the timer fires any windows |
231 // no longer contain layers are deleted. | 231 // no longer contain layers are deleted. |
232 std::set<Workspace2*> to_delete_; | 232 std::set<Workspace*> to_delete_; |
233 base::OneShotTimer<WorkspaceManager2> delete_timer_; | 233 base::OneShotTimer<WorkspaceManager> delete_timer_; |
234 | 234 |
235 // See comments in SetUnminimizingWorkspace() for details. | 235 // See comments in SetUnminimizingWorkspace() for details. |
236 base::WeakPtrFactory<WorkspaceManager2> clear_unminimizing_workspace_factory_; | 236 base::WeakPtrFactory<WorkspaceManager> clear_unminimizing_workspace_factory_; |
237 | 237 |
238 // See comments in SetUnminimizingWorkspace() for details. | 238 // See comments in SetUnminimizingWorkspace() for details. |
239 Workspace2* unminimizing_workspace_; | 239 Workspace* unminimizing_workspace_; |
240 | 240 |
241 // Set to true if the app is terminating. If true we don't animate the | 241 // Set to true if the app is terminating. If true we don't animate the |
242 // background, otherwise it can get stuck in the fading position when chrome | 242 // background, otherwise it can get stuck in the fading position when chrome |
243 // exits (as the last frame we draw before exiting is a frame from the | 243 // exits (as the last frame we draw before exiting is a frame from the |
244 // animation). | 244 // animation). |
245 bool app_terminating_; | 245 bool app_terminating_; |
246 | 246 |
247 scoped_ptr<DesktopBackgroundFadeController> desktop_fade_controller_; | 247 scoped_ptr<DesktopBackgroundFadeController> desktop_fade_controller_; |
248 | 248 |
249 // Set to true while in the process of creating a | 249 // Set to true while in the process of creating a |
250 // DesktopBackgroundFadeController. | 250 // DesktopBackgroundFadeController. |
251 bool creating_fade_; | 251 bool creating_fade_; |
252 | 252 |
253 DISALLOW_COPY_AND_ASSIGN(WorkspaceManager2); | 253 DISALLOW_COPY_AND_ASSIGN(WorkspaceManager); |
254 }; | 254 }; |
255 | 255 |
256 } // namespace internal | 256 } // namespace internal |
257 } // namespace ash | 257 } // namespace ash |
258 | 258 |
259 #endif // ASH_WM_WORKSPACE_WORKSPACE_MANAGER2_H_ | 259 #endif // ASH_WM_WORKSPACE_WORKSPACE_MANAGER_H_ |
OLD | NEW |