OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef UI_AURA_SHELL_WORKSPACE_WORKSPACE_H_ | |
6 #define UI_AURA_SHELL_WORKSPACE_WORKSPACE_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/gtest_prod_util.h" | |
12 #include "ui/aura_shell/aura_shell_export.h" | |
13 #include "ui/gfx/rect.h" | |
14 | |
15 namespace aura { | |
16 class Window; | |
17 } | |
18 | |
19 namespace aura_shell { | |
20 namespace internal { | |
21 | |
22 class WorkspaceManager; | |
23 class WorkspaceTest; | |
24 | |
25 // A workspace is a partial area of the entire desktop (viewport) that | |
26 // is visible to the user at a given time. The size of the workspace is | |
27 // generally the same as the size of the monitor, and the desktop can | |
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 AURA_SHELL_EXPORT Workspace { | |
33 public: | |
34 explicit Workspace(WorkspaceManager* manager); | |
35 virtual ~Workspace(); | |
36 | |
37 // Specifies the direction to shift windows in |ShiftWindows()|. | |
38 enum ShiftDirection { | |
39 SHIFT_TO_RIGHT, | |
40 SHIFT_TO_LEFT | |
41 }; | |
42 | |
43 // Returns true if this workspace has no windows. | |
44 bool is_empty() const { return windows_.empty(); } | |
45 | |
46 // Sets/gets bounds of this workspace. | |
47 const gfx::Rect& bounds() { return bounds_; } | |
48 void SetBounds(const gfx::Rect& bounds); | |
49 | |
50 // Returns the work area bounds of this workspace in viewport | |
51 // coordinates. | |
52 gfx::Rect GetWorkAreaBounds() const; | |
53 | |
54 // Adds the |window| at the position after the window |after|. It | |
55 // inserts at the end if |after| is NULL. Return true if the | |
56 // |window| was successfully added to this workspace, or false if it | |
57 // failed. | |
58 bool AddWindowAfter(aura::Window* window, aura::Window* after); | |
59 | |
60 // Removes |window| from this workspace. | |
61 void RemoveWindow(aura::Window* window); | |
62 | |
63 // Return true if this workspace has |window|. | |
64 bool Contains(aura::Window* window) const; | |
65 | |
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. | |
86 void Activate(); | |
87 | |
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. | |
96 bool ContainsFullscreenWindow() const; | |
97 | |
98 private: | |
99 FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, WorkspaceBasic); | |
100 FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, RotateWindows); | |
101 FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, ShiftWindowsSingle); | |
102 FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, ShiftWindowsMultiple); | |
103 FRIEND_TEST_ALL_PREFIXES(WorkspaceManagerTest, RotateWindows); | |
104 | |
105 // Returns the index in layout order of |window| in this workspace. | |
106 int GetIndexOf(aura::Window* window) const; | |
107 | |
108 // Returns true if the given |window| can be added to this workspace. | |
109 bool CanAdd(aura::Window* window) const; | |
110 | |
111 // Moves |window| to the given point. It performs animation when | |
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 | |
125 WorkspaceManager* workspace_manager_; | |
126 | |
127 gfx::Rect bounds_; | |
128 | |
129 // Windows in the workspace in layout order. | |
130 std::vector<aura::Window*> windows_; | |
131 | |
132 DISALLOW_COPY_AND_ASSIGN(Workspace); | |
133 }; | |
134 | |
135 typedef std::vector<Workspace*> Workspaces; | |
136 | |
137 } // namespace internal | |
138 } // namespace aura_shell | |
139 | |
140 #endif // UI_AURA_SHELL_WORKSPACE_WORKSPACE_H_ | |
OLD | NEW |