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_MANAGER_H_ | 5 #ifndef ASH_WM_WORKSPACE_WORKSPACE_MANAGER_H_ |
6 #define ASH_WM_WORKSPACE_WORKSPACE_MANAGER_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> |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // implicitly created as windows are maximized (or made fullscreen), and | 51 // implicitly created as windows are maximized (or made fullscreen), and |
52 // destroyed when maximized windows are closed or restored. There is always one | 52 // destroyed when maximized windows are closed or restored. There is always one |
53 // workspace for the desktop. | 53 // workspace for the desktop. |
54 // Internally WorkspaceManager creates a Window for each Workspace. As windows | 54 // Internally WorkspaceManager creates a Window for each Workspace. As windows |
55 // are maximized and restored they are reparented to the right Window. | 55 // are maximized and restored they are reparented to the right Window. |
56 class ASH_EXPORT WorkspaceManager : public ash::ShellObserver { | 56 class ASH_EXPORT WorkspaceManager : public ash::ShellObserver { |
57 public: | 57 public: |
58 explicit WorkspaceManager(aura::Window* viewport); | 58 explicit WorkspaceManager(aura::Window* viewport); |
59 virtual ~WorkspaceManager(); | 59 virtual ~WorkspaceManager(); |
60 | 60 |
61 // Returns true if |window| is minimized and will restore to a window which | |
62 // exists in its own workspace. | |
63 static bool WillRestoreToWorkspace(aura::Window* window); | |
64 | |
65 // Returns the current window state. | 61 // Returns the current window state. |
66 WorkspaceWindowState GetWindowState() const; | 62 WorkspaceWindowState GetWindowState() const; |
67 | 63 |
68 void SetShelf(ShelfLayoutManager* shelf); | 64 void SetShelf(ShelfLayoutManager* shelf); |
69 | 65 |
70 // Activates the workspace containing |window|. Does nothing if |window| is | 66 // Activates the workspace containing |window|. Does nothing if |window| is |
71 // NULL or not contained in a workspace. | 67 // NULL or not contained in a workspace. |
72 void SetActiveWorkspaceByWindow(aura::Window* window); | 68 void SetActiveWorkspaceByWindow(aura::Window* window); |
73 | 69 |
74 // Returns the container window for the active workspace, never NULL. | 70 // Returns the container window for the active workspace, never NULL. |
(...skipping 27 matching lines...) Expand all Loading... |
102 friend class WorkspaceManagerTest; | 98 friend class WorkspaceManagerTest; |
103 | 99 |
104 class LayoutManagerImpl; | 100 class LayoutManagerImpl; |
105 | 101 |
106 typedef std::vector<Workspace*> Workspaces; | 102 typedef std::vector<Workspace*> Workspaces; |
107 | 103 |
108 // Reason for the workspace switch. Used to determine the characteristics of | 104 // Reason for the workspace switch. Used to determine the characteristics of |
109 // the animation. | 105 // the animation. |
110 enum SwitchReason { | 106 enum SwitchReason { |
111 SWITCH_WINDOW_MADE_ACTIVE, | 107 SWITCH_WINDOW_MADE_ACTIVE, |
112 SWITCH_WINDOW_REMOVED, | |
113 SWITCH_VISIBILITY_CHANGED, | |
114 SWITCH_MINIMIZED, | |
115 SWITCH_MAXIMIZED_OR_RESTORED, | 108 SWITCH_MAXIMIZED_OR_RESTORED, |
116 // Switch a normal window in a fullscreen workspace to get fullscreen. | |
117 // TODO(mukai): this should be removed in the future. Normal windows should | |
118 // not be in a fullscreen workspace. See crbug.com/249154 | |
119 SWITCH_FULLSCREEN_FROM_FULLSCREEN_WORKSPACE, | |
120 SWITCH_TRACKED_BY_WORKSPACE_CHANGED, | 109 SWITCH_TRACKED_BY_WORKSPACE_CHANGED, |
121 | 110 |
122 // Switch as the result of DoInitialAnimation(). This isn't a real switch, | 111 // Switch as the result of DoInitialAnimation(). This isn't a real switch, |
123 // rather we run the animations as if a switch occurred. | 112 // rather we run the animations as if a switch occurred. |
124 SWITCH_INITIAL, | 113 SWITCH_INITIAL, |
125 | 114 |
126 // Switch as the result of the user selecting a new active workspace via the | 115 // Switch as the result of the user selecting a new active workspace via the |
127 // workspace cycler. | 116 // workspace cycler. |
128 SWITCH_WORKSPACE_CYCLER, | 117 SWITCH_WORKSPACE_CYCLER, |
129 | 118 |
(...skipping 14 matching lines...) Expand all Loading... |
144 | 133 |
145 // Returns the bounds of the work area. | 134 // Returns the bounds of the work area. |
146 gfx::Rect GetWorkAreaBounds() const; | 135 gfx::Rect GetWorkAreaBounds() const; |
147 | 136 |
148 // Returns an iterator into |workspaces_| for |workspace|. | 137 // Returns an iterator into |workspaces_| for |workspace|. |
149 Workspaces::iterator FindWorkspace(Workspace* workspace); | 138 Workspaces::iterator FindWorkspace(Workspace* workspace); |
150 | 139 |
151 Workspace* desktop_workspace() { return workspaces_[0]; } | 140 Workspace* desktop_workspace() { return workspaces_[0]; } |
152 const Workspace* desktop_workspace() const { return workspaces_[0]; } | 141 const Workspace* desktop_workspace() const { return workspaces_[0]; } |
153 | 142 |
154 // Creates a new workspace. The Workspace is not added to anything and is | 143 // Creates a new workspace to test multiple workspaces. The Workspace is not |
155 // owned by the caller. | 144 // added to anything and is owned by the caller. |
156 Workspace* CreateWorkspace(bool fullscren); | 145 Workspace* CreateWorkspaceForTest(); |
157 | 146 |
158 // Moves all the non-maximized child windows of |workspace| to the desktop | 147 // Moves all the non-maximized child windows of |workspace| to the desktop |
159 // stacked beneath |stack_beneath| (if non-NULL). After moving child windows | 148 // stacked beneath |stack_beneath| (if non-NULL). After moving child windows |
160 // if |workspace| contains no children it is deleted, otherwise it it moved to | 149 // if |workspace| contains no children it is deleted, otherwise it it moved to |
161 // |pending_workspaces_|. | 150 // |pending_workspaces_|. |
162 void MoveWorkspaceToPendingOrDelete(Workspace* workspace, | 151 void MoveWorkspaceToPendingOrDelete(Workspace* workspace, |
163 aura::Window* stack_beneath, | 152 aura::Window* stack_beneath, |
164 SwitchReason reason); | 153 SwitchReason reason); |
165 | 154 |
166 // Moves the children of |window| to the desktop. This excludes certain | 155 // Moves the children of |window| to the desktop. This excludes certain |
167 // windows. If |stack_beneath| is non-NULL the windows are stacked beneath it. | 156 // windows. If |stack_beneath| is non-NULL the windows are stacked beneath it. |
168 void MoveChildrenToDesktop(aura::Window* window, aura::Window* stack_beneath); | 157 void MoveChildrenToDesktop(aura::Window* window, aura::Window* stack_beneath); |
169 | 158 |
170 // Selects the next workspace. | 159 // Selects the next workspace. |
171 void SelectNextWorkspace(SwitchReason reason); | 160 void SelectNextWorkspace(SwitchReason reason); |
172 | 161 |
173 // Schedules |workspace| for deletion when it no longer contains any layers. | 162 // Schedules |workspace| for deletion when it no longer contains any layers. |
174 // See comments above |to_delete_| as to why we do this. | 163 // See comments above |to_delete_| as to why we do this. |
175 void ScheduleDelete(Workspace* workspace); | 164 void ScheduleDelete(Workspace* workspace); |
176 | 165 |
177 // Deletes any workspaces scheduled via ScheduleDelete() that don't contain | 166 // Deletes any workspaces scheduled via ScheduleDelete() that don't contain |
178 // any layers. | 167 // any layers. |
179 void ProcessDeletion(); | 168 void ProcessDeletion(); |
180 | 169 |
181 // Sets |unminimizing_workspace_| to |workspace|. | |
182 void SetUnminimizingWorkspace(Workspace* workspace); | |
183 | |
184 // Fades the desktop. This is only used when maximizing or restoring a | 170 // Fades the desktop. This is only used when maximizing or restoring a |
185 // window. The actual fade is handled by | 171 // window. The actual fade is handled by |
186 // DesktopBackgroundFadeController. |window| is used when restoring and | 172 // DesktopBackgroundFadeController. |window| is used when restoring and |
187 // indicates the window to stack the DesktopBackgroundFadeController's window | 173 // indicates the window to stack the DesktopBackgroundFadeController's window |
188 // above. | 174 // above. |
189 void FadeDesktop(aura::Window* window, base::TimeDelta duration); | 175 void FadeDesktop(aura::Window* window, base::TimeDelta duration); |
190 | 176 |
191 // Shows/hides |workspace| animating as necessary. | 177 // Shows/hides |workspace| animating as necessary. |
192 void ShowWorkspace(Workspace* workspace, | 178 void ShowWorkspace(Workspace* workspace, |
193 Workspace* last_active, | 179 Workspace* last_active, |
194 SwitchReason reason) const; | 180 SwitchReason reason) const; |
195 void HideWorkspace(Workspace* workspace, | 181 void HideWorkspace(Workspace* workspace, SwitchReason reason) const; |
196 SwitchReason reason, | |
197 bool is_unminimizing_maximized_window) const; | |
198 | 182 |
199 // These methods are forwarded from the LayoutManager installed on the | 183 // These methods are forwarded from the LayoutManager installed on the |
200 // Workspace's window. | 184 // Workspace's window. |
201 void OnWindowAddedToWorkspace(Workspace* workspace, aura::Window* child); | 185 void OnWindowAddedToWorkspace(Workspace* workspace, aura::Window* child); |
202 void OnWillRemoveWindowFromWorkspace(Workspace* workspace, | 186 void OnWillRemoveWindowFromWorkspace(Workspace* workspace, |
203 aura::Window* child); | 187 aura::Window* child); |
204 void OnWindowRemovedFromWorkspace(Workspace* workspace, aura::Window* child); | 188 void OnWindowRemovedFromWorkspace(Workspace* workspace, aura::Window* child); |
205 void OnWorkspaceChildWindowVisibilityChanged(Workspace* workspace, | 189 void OnWorkspaceChildWindowVisibilityChanged(Workspace* workspace, |
206 aura::Window* child); | 190 aura::Window* child); |
207 void OnWorkspaceWindowChildBoundsChanged(Workspace* workspace, | 191 void OnWorkspaceWindowChildBoundsChanged(Workspace* workspace, |
208 aura::Window* child); | 192 aura::Window* child); |
209 void OnWorkspaceWindowShowStateChanged(Workspace* workspace, | 193 void OnWorkspaceWindowShowStateChanged(Workspace* workspace, |
210 aura::Window* child, | 194 aura::Window* child, |
211 ui::WindowShowState last_show_state, | 195 ui::WindowShowState last_show_state); |
212 ui::Layer* old_layer); | |
213 void OnTrackedByWorkspaceChanged(Workspace* workspace, | 196 void OnTrackedByWorkspaceChanged(Workspace* workspace, |
214 aura::Window* window); | 197 aura::Window* window); |
215 | 198 |
216 aura::Window* contents_window_; | 199 aura::Window* contents_window_; |
217 | 200 |
218 Workspace* active_workspace_; | 201 Workspace* active_workspace_; |
219 | 202 |
220 // The set of active workspaces. There is always at least one in this stack, | 203 // The set of active workspaces. There is always at least one in this stack, |
221 // which identifies the desktop. | 204 // which identifies the desktop. |
222 Workspaces workspaces_; | 205 Workspaces workspaces_; |
(...skipping 16 matching lines...) Expand all Loading... |
239 // already in MoveWorkspaceToPendingOrDelete(). | 222 // already in MoveWorkspaceToPendingOrDelete(). |
240 bool in_move_; | 223 bool in_move_; |
241 | 224 |
242 // Ideally we would delete workspaces when not needed. Unfortunately doing so | 225 // Ideally we would delete workspaces when not needed. Unfortunately doing so |
243 // would effectively cancel animations. Instead when a workspace is no longer | 226 // would effectively cancel animations. Instead when a workspace is no longer |
244 // needed we add it here and start a timer. When the timer fires any windows | 227 // needed we add it here and start a timer. When the timer fires any windows |
245 // no longer contain layers are deleted. | 228 // no longer contain layers are deleted. |
246 std::set<Workspace*> to_delete_; | 229 std::set<Workspace*> to_delete_; |
247 base::OneShotTimer<WorkspaceManager> delete_timer_; | 230 base::OneShotTimer<WorkspaceManager> delete_timer_; |
248 | 231 |
249 // See comments in SetUnminimizingWorkspace() for details. | |
250 base::WeakPtrFactory<WorkspaceManager> clear_unminimizing_workspace_factory_; | |
251 | |
252 // See comments in SetUnminimizingWorkspace() for details. | |
253 Workspace* unminimizing_workspace_; | |
254 | |
255 // Set to true if the app is terminating. If true we don't animate the | 232 // Set to true if the app is terminating. If true we don't animate the |
256 // background, otherwise it can get stuck in the fading position when chrome | 233 // background, otherwise it can get stuck in the fading position when chrome |
257 // exits (as the last frame we draw before exiting is a frame from the | 234 // exits (as the last frame we draw before exiting is a frame from the |
258 // animation). | 235 // animation). |
259 bool app_terminating_; | 236 bool app_terminating_; |
260 | 237 |
261 scoped_ptr<DesktopBackgroundFadeController> desktop_fade_controller_; | 238 scoped_ptr<DesktopBackgroundFadeController> desktop_fade_controller_; |
262 | 239 |
263 // Set to true while in the process of creating a | 240 // Set to true while in the process of creating a |
264 // DesktopBackgroundFadeController. | 241 // DesktopBackgroundFadeController. |
265 bool creating_fade_; | 242 bool creating_fade_; |
266 | 243 |
267 // Cycles through the workspace manager's workspaces in response to a three | 244 // Cycles through the workspace manager's workspaces in response to a three |
268 // finger vertical scroll. | 245 // finger vertical scroll. |
269 scoped_ptr<WorkspaceCycler> workspace_cycler_; | 246 scoped_ptr<WorkspaceCycler> workspace_cycler_; |
270 | 247 |
271 DISALLOW_COPY_AND_ASSIGN(WorkspaceManager); | 248 DISALLOW_COPY_AND_ASSIGN(WorkspaceManager); |
272 }; | 249 }; |
273 | 250 |
274 } // namespace internal | 251 } // namespace internal |
275 } // namespace ash | 252 } // namespace ash |
276 | 253 |
277 #endif // ASH_WM_WORKSPACE_WORKSPACE_MANAGER_H_ | 254 #endif // ASH_WM_WORKSPACE_WORKSPACE_MANAGER_H_ |
OLD | NEW |