OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 UI_AURA_SHELL_WORKSPACE_WORKSPACE_H_ | 5 #ifndef UI_AURA_SHELL_WORKSPACE_WORKSPACE_H_ |
6 #define UI_AURA_SHELL_WORKSPACE_WORKSPACE_H_ | 6 #define UI_AURA_SHELL_WORKSPACE_WORKSPACE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 // generally the same as the size of the monitor, and the desktop can | 25 // generally the same as the size of the monitor, and the desktop can |
26 // have multiple workspaces. | 26 // have multiple workspaces. |
27 // A workspace contains a limited number of windows and the workspace | 27 // A workspace contains a limited number of windows and the workspace |
28 // manager may create a new workspace if there is not enough room for | 28 // manager may create a new workspace if there is not enough room for |
29 // a new window. | 29 // a new window. |
30 class AURA_SHELL_EXPORT Workspace { | 30 class AURA_SHELL_EXPORT Workspace { |
31 public: | 31 public: |
32 explicit Workspace(WorkspaceManager* manager); | 32 explicit Workspace(WorkspaceManager* manager); |
33 virtual ~Workspace(); | 33 virtual ~Workspace(); |
34 | 34 |
| 35 // Specifies the direction to shift windows in |ShiftWindows()|. |
| 36 enum ShiftDirection { |
| 37 SHIFT_TO_RIGHT, |
| 38 SHIFT_TO_LEFT |
| 39 }; |
| 40 |
35 // Returns true if this workspace has no windows. | 41 // Returns true if this workspace has no windows. |
36 bool is_empty() const { return windows_.empty(); } | 42 bool is_empty() const { return windows_.empty(); } |
37 | 43 |
38 // Sets/gets bounds of this workspace. | 44 // Sets/gets bounds of this workspace. |
39 const gfx::Rect& bounds() { return bounds_; } | 45 const gfx::Rect& bounds() { return bounds_; } |
40 void SetBounds(const gfx::Rect& bounds); | 46 void SetBounds(const gfx::Rect& bounds); |
41 | 47 |
42 // Returns the work area bounds of this workspace in viewport | 48 // Returns the work area bounds of this workspace in viewport |
43 // coordinates. | 49 // coordinates. |
44 gfx::Rect GetWorkAreaBounds() const; | 50 gfx::Rect GetWorkAreaBounds() const; |
45 | 51 |
46 // Adds the |window| at the position after the window |after|. It | 52 // Adds the |window| at the position after the window |after|. It |
47 // inserts at the end if |after| is NULL. Return true if the | 53 // inserts at the end if |after| is NULL. Return true if the |
48 // |window| was successfully added to this workspace, or false if it | 54 // |window| was successfully added to this workspace, or false if it |
49 // failed. | 55 // failed. |
50 bool AddWindowAfter(aura::Window* window, aura::Window* after); | 56 bool AddWindowAfter(aura::Window* window, aura::Window* after); |
51 | 57 |
52 // Removes the |window| from this workspace. | 58 // Removes |window| from this workspace. |
53 void RemoveWindow(aura::Window* window); | 59 void RemoveWindow(aura::Window* window); |
54 | 60 |
55 // Return true if this workspace has the |window|. | 61 // Return true if this workspace has |window|. |
56 bool Contains(aura::Window* window) const; | 62 bool Contains(aura::Window* window) const; |
57 | 63 |
| 64 // Returns a window to rotate to based on |position|. |
| 65 aura::Window* FindRotateWindowForLocation(const gfx::Point& position); |
| 66 |
| 67 // Rotates the windows by removing |source| and inserting it to the |
| 68 // position that |target| was in. It re-layouts windows except for |source|. |
| 69 void RotateWindows(aura::Window* source, aura::Window* target); |
| 70 |
| 71 // Shift the windows in the workspace by inserting |window| until it |
| 72 // reaches |until|. If |direction| is |SHIFT_TO_RIGHT|, |insert| is |
| 73 // inserted at the position of |target| or at the beginning if |
| 74 // |target| is NULL. If |direction| is |SHIFT_TO_LEFT|, |insert| is |
| 75 // inserted after the position of |target|, or at the end if |
| 76 // |target| is NULL. It returns the window that is overflowed by |
| 77 // shifting, or NULL if shifting stopped at |until|. |
| 78 aura::Window* ShiftWindows(aura::Window* insert, |
| 79 aura::Window* until, |
| 80 aura::Window* target, |
| 81 ShiftDirection direction); |
| 82 |
58 // Activates this workspace. | 83 // Activates this workspace. |
59 void Activate(); | 84 void Activate(); |
60 | 85 |
61 // Layout windows. Moving animation is applied to all windows except | 86 // Layout windows. The workspace doesn't set bounds on |ignore| if it's |
62 // for the window specified by |no_animation|. | 87 // given. It still uses |ignore| window's bounds to calculate |
63 void Layout(aura::Window* no_animation); | 88 // bounds for other windows. Moving animation is applied to all |
| 89 // windows except for the window specified by |no_animation| and |ignore|. |
| 90 void Layout(aura::Window* ignore, aura::Window* no_animation); |
64 | 91 |
65 private: | 92 private: |
66 FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, WorkspaceBasic); | 93 FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, WorkspaceBasic); |
| 94 FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, RotateWindows); |
| 95 FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, ShiftWindowsSingle); |
| 96 FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, ShiftWindowsMultiple); |
| 97 FRIEND_TEST_ALL_PREFIXES(WorkspaceManagerTest, RotateWindows); |
67 | 98 |
68 // Returns the index in layout order of the |window| in this workspace. | 99 // Returns the index in layout order of |window| in this workspace. |
69 int GetIndexOf(aura::Window* window) const; | 100 int GetIndexOf(aura::Window* window) const; |
70 | 101 |
71 // Returns true if the given |window| can be added to this workspace. | 102 // Returns true if the given |window| can be added to this workspace. |
72 bool CanAdd(aura::Window* window) const; | 103 bool CanAdd(aura::Window* window) const; |
73 | 104 |
74 // Moves |window| to the given point. It performs animation when | 105 // Moves |window| to the given point. It performs animation when |
75 // |animate| is true. | 106 // |animate| is true. |
76 void MoveWindowTo(aura::Window* window, | 107 void MoveWindowTo(aura::Window* window, |
77 const gfx::Point& origin, | 108 const gfx::Point& origin, |
78 bool animate); | 109 bool animate); |
79 | 110 |
| 111 // Returns the sum of all window's width. |
| 112 int GetTotalWindowsWidth() const; |
| 113 |
| 114 // Test only: Changes how may windows workspace can have. |
| 115 // Returns the current value so that it can be reverted back to |
| 116 // original value. |
| 117 static size_t SetMaxWindowsCount(size_t max); |
| 118 |
80 WorkspaceManager* workspace_manager_; | 119 WorkspaceManager* workspace_manager_; |
81 | 120 |
82 gfx::Rect bounds_; | 121 gfx::Rect bounds_; |
83 | 122 |
84 // Windows in the workspace in layout order. | 123 // Windows in the workspace in layout order. |
85 std::vector<aura::Window*> windows_; | 124 std::vector<aura::Window*> windows_; |
86 | 125 |
87 DISALLOW_COPY_AND_ASSIGN(Workspace); | 126 DISALLOW_COPY_AND_ASSIGN(Workspace); |
88 }; | 127 }; |
89 | 128 |
90 typedef std::vector<Workspace*> Workspaces; | 129 typedef std::vector<Workspace*> Workspaces; |
91 | 130 |
92 } // namespace aura_shell | 131 } // namespace aura_shell |
93 | 132 |
94 #endif // UI_AURA_SHELL_WORKSPACE_WORKSPACE_H_ | 133 #endif // UI_AURA_SHELL_WORKSPACE_WORKSPACE_H_ |
OLD | NEW |