OLD | NEW |
1 // Copyright (c) 2011 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_MANAGER_H_ | 5 #ifndef ASH_WM_WORKSPACE_MANAGER_H_ |
6 #define ASH_WM_WORKSPACE_MANAGER_H_ | 6 #define ASH_WM_WORKSPACE_MANAGER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/observer_list.h" | |
13 #include "ash/ash_export.h" | 12 #include "ash/ash_export.h" |
| 13 #include "ui/aura/window_observer.h" |
14 #include "ui/gfx/insets.h" | 14 #include "ui/gfx/insets.h" |
15 #include "ui/gfx/size.h" | 15 #include "ui/gfx/size.h" |
16 | 16 |
17 namespace aura { | 17 namespace aura { |
18 class Window; | 18 class Window; |
19 } | 19 } |
20 | 20 |
21 namespace gfx { | 21 namespace gfx { |
22 class Point; | 22 class Point; |
23 class Rect; | 23 class Rect; |
24 } | 24 } |
25 | 25 |
26 namespace ash { | 26 namespace ash { |
27 namespace internal { | 27 namespace internal { |
28 class Workspace; | 28 class Workspace; |
29 class WorkspaceObserver; | 29 class WorkspaceManagerTest; |
30 | 30 |
31 // WorkspaceManager manages multiple workspaces in the desktop. | 31 // WorkspaceManager manages multiple workspaces in the desktop. |
32 class ASH_EXPORT WorkspaceManager { | 32 class ASH_EXPORT WorkspaceManager : public aura::WindowObserver{ |
33 public: | 33 public: |
34 explicit WorkspaceManager(aura::Window* viewport); | 34 explicit WorkspaceManager(aura::Window* viewport); |
35 virtual ~WorkspaceManager(); | 35 virtual ~WorkspaceManager(); |
36 | 36 |
| 37 // Returns true if |window| should be managed by the WorkspaceManager. |
| 38 bool IsManagedWindow(aura::Window* window) const; |
| 39 |
| 40 // Adds/removes a window creating/destroying workspace as necessary. |
| 41 void AddWindow(aura::Window* window); |
| 42 void RemoveWindow(aura::Window* window); |
| 43 |
| 44 // Activates the workspace containing |window|. Does nothing if |window| is |
| 45 // NULL or not contained in a workspace. |
| 46 void SetActiveWorkspaceByWindow(aura::Window* window); |
| 47 |
37 // Returns the Window this WorkspaceManager controls. | 48 // Returns the Window this WorkspaceManager controls. |
38 aura::Window* contents_view() { return contents_view_; } | 49 aura::Window* contents_view() { return contents_view_; } |
39 | 50 |
40 // Create new workspace. Workspace objects are managed by | |
41 // this WorkspaceManager. Deleting workspace will automatically | |
42 // remove the workspace from the workspace_manager. | |
43 Workspace* CreateWorkspace(); | |
44 | |
45 // Returns the active workspace. | |
46 Workspace* GetActiveWorkspace() const; | |
47 | |
48 // Returns the workspace that contanis the |window|. | |
49 Workspace* FindBy(aura::Window* window) const; | |
50 | |
51 // Returns the window for rotate operation based on the |location|. | 51 // Returns the window for rotate operation based on the |location|. |
| 52 // TODO: this isn't currently used; remove if we do away with overview. |
52 aura::Window* FindRotateWindowForLocation(const gfx::Point& location); | 53 aura::Window* FindRotateWindowForLocation(const gfx::Point& location); |
53 | 54 |
54 // Sets the bounds of all workspaces. | |
55 void LayoutWorkspaces(); | |
56 | |
57 // Returns the bounds in which a window can be moved/resized. | 55 // Returns the bounds in which a window can be moved/resized. |
58 gfx::Rect GetDragAreaBounds(); | 56 gfx::Rect GetDragAreaBounds(); |
59 | 57 |
60 // Turn on/off overview mode. | 58 // Turn on/off overview mode. |
61 void SetOverview(bool overview); | 59 void SetOverview(bool overview); |
62 bool is_overview() const { return is_overview_; } | 60 bool is_overview() const { return is_overview_; } |
63 | 61 |
64 // Rotate windows by moving |source| window to the position of |target|. | |
65 void RotateWindows(aura::Window* source, aura::Window* target); | |
66 | |
67 // Sets the size of a single workspace (all workspaces have the same size). | 62 // Sets the size of a single workspace (all workspaces have the same size). |
68 void SetWorkspaceSize(const gfx::Size& workspace_size); | 63 void SetWorkspaceSize(const gfx::Size& workspace_size); |
69 | 64 |
70 // Adds/Removes workspace observer. | |
71 void AddObserver(WorkspaceObserver* observer); | |
72 void RemoveObserver(WorkspaceObserver* observer); | |
73 | |
74 // Returns true if this workspace manager is laying out windows. | |
75 // When true, LayoutManager must give windows their requested bounds. | |
76 bool layout_in_progress() const { return layout_in_progress_; } | |
77 | |
78 // Sets the |layout_in_progress_| flag. | |
79 void set_layout_in_progress(bool layout_in_progress) { | |
80 layout_in_progress_ = layout_in_progress; | |
81 } | |
82 | |
83 // Sets/Returns the ignored window that the workspace manager does not | 65 // Sets/Returns the ignored window that the workspace manager does not |
84 // set bounds on. | 66 // set bounds on. |
85 void set_ignored_window(aura::Window* ignored_window) { | 67 void set_ignored_window(aura::Window* ignored_window) { |
86 ignored_window_ = ignored_window; | 68 ignored_window_ = ignored_window; |
87 } | 69 } |
88 aura::Window* ignored_window() { return ignored_window_; } | 70 aura::Window* ignored_window() { return ignored_window_; } |
89 | 71 |
| 72 // Overriden from aura::WindowObserver: |
| 73 virtual void OnWindowPropertyChanged(aura::Window* window, |
| 74 const char* name, |
| 75 void* old) OVERRIDE; |
| 76 |
90 private: | 77 private: |
91 friend class Workspace; | 78 friend class Workspace; |
| 79 friend class WorkspaceManagerTest; |
92 | 80 |
93 void AddWorkspace(Workspace* workspace); | 81 void AddWorkspace(Workspace* workspace); |
94 void RemoveWorkspace(Workspace* workspace); | 82 void RemoveWorkspace(Workspace* workspace); |
95 | 83 |
| 84 // Returns the active workspace. |
| 85 Workspace* GetActiveWorkspace() const; |
| 86 |
| 87 // Returns the workspace that contanis the |window|. |
| 88 Workspace* FindBy(aura::Window* window) const; |
| 89 |
96 // Sets the active workspace. | 90 // Sets the active workspace. |
97 void SetActiveWorkspace(Workspace* workspace); | 91 void SetActiveWorkspace(Workspace* workspace); |
98 | 92 |
99 // Returns the bounds of the work are given |workspace_bounds|. | 93 // Returns the bounds of the work area. |
100 gfx::Rect GetWorkAreaBounds(const gfx::Rect& workspace_bounds); | 94 gfx::Rect GetWorkAreaBounds(); |
101 | 95 |
102 // Returns the index of the workspace that contains the |window|. | 96 // Returns the index of the workspace that contains the |window|. |
103 int GetWorkspaceIndexContaining(aura::Window* window) const; | 97 int GetWorkspaceIndexContaining(aura::Window* window) const; |
104 | 98 |
105 // Update contents_view size and move the viewport to the active workspace. | 99 // Sets the bounds of |window|. This sets |ignored_window_| to |window| so |
106 void UpdateContentsView(); | 100 // that the bounds change is allowed through. |
| 101 void SetWindowBounds(aura::Window* window, const gfx::Rect& bounds); |
| 102 |
| 103 // Resets the bounds of |window| to its restored bounds (if set), ensuring |
| 104 // it fits in the the windows current workspace. |
| 105 void SetWindowBoundsFromRestoreBounds(aura::Window* window); |
| 106 |
| 107 // Invoked when the maximized state of |window| changes. |
| 108 void MaximizedStateChanged(aura::Window* window); |
| 109 |
| 110 // Returns the Workspace whose type is TYPE_NORMAL, or NULL if there isn't |
| 111 // one. |
| 112 Workspace* GetNormalWorkspace(); |
107 | 113 |
108 aura::Window* contents_view_; | 114 aura::Window* contents_view_; |
109 | 115 |
110 Workspace* active_workspace_; | 116 Workspace* active_workspace_; |
111 | 117 |
112 std::vector<Workspace*> workspaces_; | 118 std::vector<Workspace*> workspaces_; |
113 | 119 |
114 // The size of a single workspace. This is generally the same as the size of | 120 // The size of a single workspace. This is generally the same as the size of |
115 // monitor. | 121 // monitor. |
116 gfx::Size workspace_size_; | 122 gfx::Size workspace_size_; |
117 | 123 |
118 // True if the workspace manager is in overview mode. | 124 // True if the workspace manager is in overview mode. |
119 bool is_overview_; | 125 bool is_overview_; |
120 | 126 |
121 // True if this layout manager is laying out windows. | |
122 bool layout_in_progress_; | |
123 | |
124 // The window that WorkspaceManager does not set the bounds on. | 127 // The window that WorkspaceManager does not set the bounds on. |
125 aura::Window* ignored_window_; | 128 aura::Window* ignored_window_; |
126 | 129 |
127 ObserverList<WorkspaceObserver> observers_; | |
128 | |
129 DISALLOW_COPY_AND_ASSIGN(WorkspaceManager); | 130 DISALLOW_COPY_AND_ASSIGN(WorkspaceManager); |
130 }; | 131 }; |
131 | 132 |
132 } // namespace internal | 133 } // namespace internal |
133 } // namespace ash | 134 } // namespace ash |
134 | 135 |
135 #endif // ASH_WM_WORKSPACE_MANAGER_H_ | 136 #endif // ASH_WM_WORKSPACE_MANAGER_H_ |
OLD | NEW |