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_H_ | 5 #ifndef ASH_WM_WORKSPACE_H_ |
6 #define ASH_WM_WORKSPACE_H_ | 6 #define ASH_WM_WORKSPACE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "ash/ash_export.h" | 12 #include "ash/ash_export.h" |
13 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
14 | 14 |
15 namespace aura { | 15 namespace aura { |
16 class Window; | 16 class Window; |
17 } | 17 } |
18 | 18 |
19 namespace ash { | 19 namespace ash { |
20 namespace internal { | 20 namespace internal { |
21 | 21 |
22 class WorkspaceManager; | 22 class WorkspaceManager; |
23 class WorkspaceTest; | 23 class WorkspaceTest; |
24 | 24 |
25 // A workspace is a partial area of the entire desktop (viewport) that | 25 // A workspace contains a number of windows. The number of windows a Workspace |
26 // is visible to the user at a given time. The size of the workspace is | 26 // may contain is dictated by the type. Typically only one workspace is visible |
27 // generally the same as the size of the monitor, and the desktop can | 27 // at a time. The exception to that is when overview mode is active. |
28 // have multiple workspaces. | |
29 // A workspace contains a limited number of windows and the workspace | |
30 // manager may create a new workspace if there is not enough room for | |
31 // a new window. | |
32 class ASH_EXPORT Workspace { | 28 class ASH_EXPORT Workspace { |
33 public: | 29 public: |
34 explicit Workspace(WorkspaceManager* manager); | 30 // Type of workspace. The type of workspace dictates the types of windows the |
35 virtual ~Workspace(); | 31 // workspace can contain. |
| 32 enum Type { |
| 33 // The workspace holds a single maximized or full screen window. |
| 34 TYPE_MAXIMIZED, |
| 35 |
| 36 // Workspace contains multiple windows that are split (also known as |
| 37 // co-maximized). |
| 38 TYPE_SPLIT, |
| 39 |
| 40 // Workspace contains non-maximized windows that can be moved in anyway. |
| 41 TYPE_NORMAL, |
| 42 }; |
36 | 43 |
37 // Specifies the direction to shift windows in |ShiftWindows()|. | 44 // Specifies the direction to shift windows in |ShiftWindows()|. |
38 enum ShiftDirection { | 45 enum ShiftDirection { |
39 SHIFT_TO_RIGHT, | 46 SHIFT_TO_RIGHT, |
40 SHIFT_TO_LEFT | 47 SHIFT_TO_LEFT |
41 }; | 48 }; |
42 | 49 |
43 // Returns true if this workspace has no windows. | 50 explicit Workspace(WorkspaceManager* manager); |
| 51 virtual ~Workspace(); |
| 52 |
| 53 // Returns the type of workspace that can contain |window|. |
| 54 static Type TypeForWindow(aura::Window* window); |
| 55 |
| 56 // The type of this Workspace. |
| 57 void SetType(Type type); |
| 58 Type type() const { return type_; } |
| 59 |
| 60 // Returns true if this workspace has no windows. |
44 bool is_empty() const { return windows_.empty(); } | 61 bool is_empty() const { return windows_.empty(); } |
| 62 size_t num_windows() const { return windows_.size(); } |
| 63 const std::vector<aura::Window*>& windows() const { return windows_; } |
45 | 64 |
46 // Sets/gets bounds of this workspace. | 65 // Invoked when the size of the workspace changes. |
47 const gfx::Rect& bounds() { return bounds_; } | 66 void WorkspaceSizeChanged(); |
48 void SetBounds(const gfx::Rect& bounds); | |
49 | 67 |
50 // Returns the work area bounds of this workspace in viewport | 68 // Returns the work area bounds of this workspace in viewport coordinates. |
51 // coordinates. | |
52 gfx::Rect GetWorkAreaBounds() const; | 69 gfx::Rect GetWorkAreaBounds() const; |
53 | 70 |
54 // Adds the |window| at the position after the window |after|. It | 71 // Adds the |window| at the position after the window |after|. It |
55 // inserts at the end if |after| is NULL. Return true if the | 72 // inserts at the end if |after| is NULL. Return true if the |
56 // |window| was successfully added to this workspace, or false if it | 73 // |window| was successfully added to this workspace, or false if it |
57 // failed. | 74 // failed. |
58 bool AddWindowAfter(aura::Window* window, aura::Window* after); | 75 bool AddWindowAfter(aura::Window* window, aura::Window* after); |
59 | 76 |
60 // Removes |window| from this workspace. | 77 // Removes |window| from this workspace. |
61 void RemoveWindow(aura::Window* window); | 78 void RemoveWindow(aura::Window* window); |
62 | 79 |
63 // Return true if this workspace has |window|. | 80 // Return true if this workspace has |window|. |
64 bool Contains(aura::Window* window) const; | 81 bool Contains(aura::Window* window) const; |
65 | 82 |
66 // Returns a window to rotate to based on |position|. | |
67 aura::Window* FindRotateWindowForLocation(const gfx::Point& position); | |
68 | |
69 // Rotates the windows by removing |source| and inserting it to the | |
70 // position that |target| was in. It re-layouts windows except for |source|. | |
71 void RotateWindows(aura::Window* source, aura::Window* target); | |
72 | |
73 // Shift the windows in the workspace by inserting |window| until it | |
74 // reaches |until|. If |direction| is |SHIFT_TO_RIGHT|, |insert| is | |
75 // inserted at the position of |target| or at the beginning if | |
76 // |target| is NULL. If |direction| is |SHIFT_TO_LEFT|, |insert| is | |
77 // inserted after the position of |target|, or at the end if | |
78 // |target| is NULL. It returns the window that is overflowed by | |
79 // shifting, or NULL if shifting stopped at |until|. | |
80 aura::Window* ShiftWindows(aura::Window* insert, | |
81 aura::Window* until, | |
82 aura::Window* target, | |
83 ShiftDirection direction); | |
84 | |
85 // Activates this workspace. | 83 // Activates this workspace. |
86 void Activate(); | 84 void Activate(); |
87 | 85 |
88 // Layout windows. The workspace doesn't set bounds on | |
89 // |WorkspaceManager::ignored_window| if it's set. It still uses the window's | |
90 // bounds to calculate bounds for other windows. Moving animation is | |
91 // applied to all windows except for the window specified by |no_animation| | |
92 // and |ignore|. | |
93 void Layout(aura::Window* no_animation); | |
94 | |
95 // Returns true if the workspace contains a fullscreen window. | 86 // Returns true if the workspace contains a fullscreen window. |
96 bool ContainsFullscreenWindow() const; | 87 bool ContainsFullscreenWindow() const; |
97 | 88 |
98 private: | 89 private: |
99 FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, WorkspaceBasic); | 90 FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, WorkspaceBasic); |
100 FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, RotateWindows); | 91 FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, RotateWindows); |
101 FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, ShiftWindowsSingle); | 92 FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, ShiftWindowsSingle); |
102 FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, ShiftWindowsMultiple); | 93 FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, ShiftWindowsMultiple); |
103 FRIEND_TEST_ALL_PREFIXES(WorkspaceManagerTest, RotateWindows); | 94 FRIEND_TEST_ALL_PREFIXES(WorkspaceManagerTest, RotateWindows); |
104 | 95 |
105 // Returns the index in layout order of |window| in this workspace. | 96 // Returns the index in layout order of |window| in this workspace. |
106 int GetIndexOf(aura::Window* window) const; | 97 int GetIndexOf(aura::Window* window) const; |
107 | 98 |
108 // Returns true if the given |window| can be added to this workspace. | 99 // Returns true if the given |window| can be added to this workspace. |
109 bool CanAdd(aura::Window* window) const; | 100 bool CanAdd(aura::Window* window) const; |
110 | 101 |
111 // Moves |window| to the given point. It performs animation when | 102 Type type_; |
112 // |animate| is true. | |
113 void MoveWindowTo(aura::Window* window, | |
114 const gfx::Point& origin, | |
115 bool animate); | |
116 | |
117 // Returns the sum of all window's width. | |
118 int GetTotalWindowsWidth() const; | |
119 | |
120 // Test only: Changes how may windows workspace can have. | |
121 // Returns the current value so that it can be reverted back to | |
122 // original value. | |
123 static size_t SetMaxWindowsCount(size_t max); | |
124 | 103 |
125 WorkspaceManager* workspace_manager_; | 104 WorkspaceManager* workspace_manager_; |
126 | 105 |
127 gfx::Rect bounds_; | |
128 | |
129 // Windows in the workspace in layout order. | 106 // Windows in the workspace in layout order. |
130 std::vector<aura::Window*> windows_; | 107 std::vector<aura::Window*> windows_; |
131 | 108 |
132 DISALLOW_COPY_AND_ASSIGN(Workspace); | 109 DISALLOW_COPY_AND_ASSIGN(Workspace); |
133 }; | 110 }; |
134 | 111 |
135 typedef std::vector<Workspace*> Workspaces; | 112 typedef std::vector<Workspace*> Workspaces; |
136 | 113 |
137 } // namespace internal | 114 } // namespace internal |
138 } // namespace ash | 115 } // namespace ash |
139 | 116 |
140 #endif // ASH_WM_WORKSPACE_H_ | 117 #endif // ASH_WM_WORKSPACE_H_ |
OLD | NEW |