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 #include "ash/wm/workspace/workspace_layout_manager2.h" | 5 #include "ash/wm/workspace/workspace_layout_manager2.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/screen_ash.h" | 9 #include "ash/screen_ash.h" |
10 #include "ash/wm/always_on_top_controller.h" | 10 #include "ash/wm/always_on_top_controller.h" |
11 #include "ash/wm/window_animations.h" | 11 #include "ash/wm/window_animations.h" |
12 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
13 #include "ash/wm/window_properties.h" | 13 #include "ash/wm/window_properties.h" |
14 #include "ash/wm/workspace/workspace2.h" | 14 #include "ash/wm/workspace/workspace2.h" |
15 #include "ash/wm/workspace/workspace_manager2.h" | 15 #include "ash/wm/workspace/workspace_manager2.h" |
16 #include "base/auto_reset.h" | 16 #include "base/auto_reset.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "ui/aura/client/aura_constants.h" | 18 #include "ui/aura/client/aura_constants.h" |
19 #include "ui/aura/root_window.h" | 19 #include "ui/aura/root_window.h" |
20 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
21 #include "ui/aura/window_observer.h" | 21 #include "ui/aura/window_observer.h" |
22 #include "ui/base/event.h" | 22 #include "ui/base/event.h" |
23 #include "ui/base/ui_base_types.h" | 23 #include "ui/base/ui_base_types.h" |
24 #include "ui/gfx/rect.h" | |
25 | 24 |
26 using aura::Window; | 25 using aura::Window; |
27 | 26 |
28 namespace ash { | 27 namespace ash { |
29 namespace internal { | 28 namespace internal { |
30 | 29 |
31 namespace { | 30 namespace { |
32 | 31 |
33 gfx::Rect BoundsWithScreenEdgeVisible( | 32 gfx::Rect BoundsWithScreenEdgeVisible( |
34 aura::Window* window, | 33 aura::Window* window, |
35 const gfx::Rect& restore_bounds) { | 34 const gfx::Rect& restore_bounds) { |
36 // If the restore_bounds are more than 1 grid step away from the size the | 35 // If the restore_bounds are more than 1 grid step away from the size the |
37 // window would be when maximized, inset it. | 36 // window would be when maximized, inset it. |
38 int grid_size = ash::Shell::GetInstance()->GetGridSize(); | 37 int grid_size = ash::Shell::GetInstance()->GetGridSize(); |
39 gfx::Rect max_bounds = ash::ScreenAsh::GetMaximizedWindowBoundsInParent( | 38 gfx::Rect max_bounds = ash::ScreenAsh::GetMaximizedWindowBoundsInParent( |
40 window->parent()->parent()); | 39 window->parent()->parent()); |
41 max_bounds.Inset(grid_size, grid_size); | 40 max_bounds.Inset(grid_size, grid_size); |
42 // TODO(sky): this looks totally wrong! | 41 // TODO(sky): this looks totally wrong! |
43 if (restore_bounds.Contains(max_bounds)) | 42 if (restore_bounds.Contains(max_bounds)) |
44 return max_bounds; | 43 return max_bounds; |
45 return restore_bounds; | 44 return restore_bounds; |
46 } | 45 } |
47 | 46 |
48 } // namespace | 47 } // namespace |
49 | 48 |
50 WorkspaceLayoutManager2::WorkspaceLayoutManager2(Workspace2* workspace) | 49 WorkspaceLayoutManager2::WorkspaceLayoutManager2(Workspace2* workspace) |
51 : root_window_(workspace->window()->GetRootWindow()), | 50 : root_window_(workspace->window()->GetRootWindow()), |
52 workspace_(workspace) { | 51 workspace_(workspace), |
| 52 work_area_(ScreenAsh::GetDisplayWorkAreaBoundsInParent( |
| 53 workspace->window()->parent())) { |
53 Shell::GetInstance()->AddShellObserver(this); | 54 Shell::GetInstance()->AddShellObserver(this); |
54 root_window_->AddRootWindowObserver(this); | 55 root_window_->AddRootWindowObserver(this); |
55 root_window_->AddObserver(this); | 56 root_window_->AddObserver(this); |
56 } | 57 } |
57 | 58 |
58 WorkspaceLayoutManager2::~WorkspaceLayoutManager2() { | 59 WorkspaceLayoutManager2::~WorkspaceLayoutManager2() { |
59 if (root_window_) { | 60 if (root_window_) { |
60 root_window_->RemoveObserver(this); | 61 root_window_->RemoveObserver(this); |
61 root_window_->RemoveRootWindowObserver(this); | 62 root_window_->RemoveRootWindowObserver(this); |
62 } | 63 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 SetChildBoundsDirect(child, child_bounds); | 109 SetChildBoundsDirect(child, child_bounds); |
109 workspace_manager()->OnWorkspaceWindowChildBoundsChanged(workspace_, child); | 110 workspace_manager()->OnWorkspaceWindowChildBoundsChanged(workspace_, child); |
110 } | 111 } |
111 | 112 |
112 void WorkspaceLayoutManager2::OnRootWindowResized(const aura::RootWindow* root, | 113 void WorkspaceLayoutManager2::OnRootWindowResized(const aura::RootWindow* root, |
113 const gfx::Size& old_size) { | 114 const gfx::Size& old_size) { |
114 AdjustWindowSizesForScreenChange(); | 115 AdjustWindowSizesForScreenChange(); |
115 } | 116 } |
116 | 117 |
117 void WorkspaceLayoutManager2::OnDisplayWorkAreaInsetsChanged() { | 118 void WorkspaceLayoutManager2::OnDisplayWorkAreaInsetsChanged() { |
118 if (workspace_manager()->active_workspace_ == workspace_) | 119 if (workspace_manager()->active_workspace_ == workspace_) { |
119 AdjustWindowSizesForScreenChange(); | 120 const gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( |
| 121 workspace_->window()->parent())); |
| 122 if (work_area != work_area_) |
| 123 AdjustWindowSizesForScreenChange(); |
| 124 } |
120 } | 125 } |
121 | 126 |
122 void WorkspaceLayoutManager2::OnWindowPropertyChanged(Window* window, | 127 void WorkspaceLayoutManager2::OnWindowPropertyChanged(Window* window, |
123 const void* key, | 128 const void* key, |
124 intptr_t old) { | 129 intptr_t old) { |
125 if (key == aura::client::kShowStateKey) { | 130 if (key == aura::client::kShowStateKey) { |
126 ui::WindowShowState old_state = static_cast<ui::WindowShowState>(old); | 131 ui::WindowShowState old_state = static_cast<ui::WindowShowState>(old); |
127 ui::WindowShowState new_state = | 132 ui::WindowShowState new_state = |
128 window->GetProperty(aura::client::kShowStateKey); | 133 window->GetProperty(aura::client::kShowStateKey); |
129 if (old_state == ui::SHOW_STATE_MINIMIZED) { | 134 if (old_state == ui::SHOW_STATE_MINIMIZED) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 // The layer may be hidden if the window was previously minimized. Make | 196 // The layer may be hidden if the window was previously minimized. Make |
192 // sure it's visible. | 197 // sure it's visible. |
193 window->Show(); | 198 window->Show(); |
194 } | 199 } |
195 workspace_manager()->OnWorkspaceWindowShowStateChanged( | 200 workspace_manager()->OnWorkspaceWindowShowStateChanged( |
196 workspace_, window, last_show_state, cloned_layer); | 201 workspace_, window, last_show_state, cloned_layer); |
197 } | 202 } |
198 } | 203 } |
199 | 204 |
200 void WorkspaceLayoutManager2::AdjustWindowSizesForScreenChange() { | 205 void WorkspaceLayoutManager2::AdjustWindowSizesForScreenChange() { |
| 206 work_area_ = ScreenAsh::GetDisplayWorkAreaBoundsInParent( |
| 207 workspace_->window()->parent()); |
201 // If a user plugs an external display into a laptop running Aura the | 208 // If a user plugs an external display into a laptop running Aura the |
202 // display size will change. Maximized windows need to resize to match. | 209 // display size will change. Maximized windows need to resize to match. |
203 // We also do this when developers running Aura on a desktop manually resize | 210 // We also do this when developers running Aura on a desktop manually resize |
204 // the host window. | 211 // the host window. |
205 // We also need to do this when the work area insets changes. | 212 // We also need to do this when the work area insets changes. |
206 for (WindowSet::const_iterator it = windows_.begin(); | 213 for (WindowSet::const_iterator it = windows_.begin(); |
207 it != windows_.end(); | 214 it != windows_.end(); |
208 ++it) { | 215 ++it) { |
209 AdjustWindowSizeForScreenChange(*it); | 216 AdjustWindowSizeForScreenChange(*it); |
210 } | 217 } |
211 } | 218 } |
212 | 219 |
213 void WorkspaceLayoutManager2::AdjustWindowSizeForScreenChange(Window* window) { | 220 void WorkspaceLayoutManager2::AdjustWindowSizeForScreenChange(Window* window) { |
214 if (!SetMaximizedOrFullscreenBounds(window)) { | 221 if (!SetMaximizedOrFullscreenBounds(window)) { |
215 // The work area may be smaller than the full screen. | 222 // The work area may be smaller than the full screen. Put as much of the |
216 gfx::Rect display_rect = | 223 // window as possible within the display area. |
217 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window->parent()->parent()); | 224 window->SetBounds(window->bounds().AdjustToFit(work_area_)); |
218 // Put as much of the window as possible within the display area. | |
219 window->SetBounds(window->bounds().AdjustToFit(display_rect)); | |
220 } | 225 } |
221 } | 226 } |
222 | 227 |
223 void WorkspaceLayoutManager2::UpdateBoundsFromShowState(Window* window) { | 228 void WorkspaceLayoutManager2::UpdateBoundsFromShowState(Window* window) { |
224 // See comment in SetMaximizedOrFullscreenBounds() as to why we use parent in | 229 // See comment in SetMaximizedOrFullscreenBounds() as to why we use parent in |
225 // these calculation. | 230 // these calculation. |
226 switch (window->GetProperty(aura::client::kShowStateKey)) { | 231 switch (window->GetProperty(aura::client::kShowStateKey)) { |
227 case ui::SHOW_STATE_DEFAULT: | 232 case ui::SHOW_STATE_DEFAULT: |
228 case ui::SHOW_STATE_NORMAL: { | 233 case ui::SHOW_STATE_NORMAL: { |
229 const gfx::Rect* restore = GetRestoreBoundsInScreen(window); | 234 const gfx::Rect* restore = GetRestoreBoundsInScreen(window); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 } | 273 } |
269 return false; | 274 return false; |
270 } | 275 } |
271 | 276 |
272 WorkspaceManager2* WorkspaceLayoutManager2::workspace_manager() { | 277 WorkspaceManager2* WorkspaceLayoutManager2::workspace_manager() { |
273 return workspace_->workspace_manager(); | 278 return workspace_->workspace_manager(); |
274 } | 279 } |
275 | 280 |
276 } // namespace internal | 281 } // namespace internal |
277 } // namespace ash | 282 } // namespace ash |
OLD | NEW |