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_manager.h" | 5 #include "ash/wm/workspace/workspace_layout_manager.h" |
6 | 6 |
7 #include "ash/wm/property_util.h" | 7 #include "ash/wm/property_util.h" |
8 #include "ash/wm/window_util.h" | 8 #include "ash/wm/window_util.h" |
9 #include "ash/wm/workspace/workspace.h" | 9 #include "ash/wm/workspace/workspace.h" |
10 #include "ash/wm/workspace/workspace_manager.h" | 10 #include "ash/wm/workspace/workspace_manager.h" |
| 11 #include "ash/wm/workspace/workspace_window_resizer.h" |
11 #include "ui/aura/client/aura_constants.h" | 12 #include "ui/aura/client/aura_constants.h" |
12 #include "ui/aura/event.h" | 13 #include "ui/aura/event.h" |
13 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
14 #include "ui/aura/screen_aura.h" | 15 #include "ui/aura/screen_aura.h" |
15 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
16 #include "ui/aura/window_observer.h" | 17 #include "ui/aura/window_observer.h" |
17 #include "ui/base/ui_base_types.h" | 18 #include "ui/base/ui_base_types.h" |
18 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
19 #include "ui/views/widget/native_widget_aura.h" | 20 #include "ui/views/widget/native_widget_aura.h" |
20 | 21 |
21 namespace ash { | 22 namespace ash { |
22 namespace internal { | 23 namespace internal { |
23 | 24 |
24 //////////////////////////////////////////////////////////////////////////////// | 25 //////////////////////////////////////////////////////////////////////////////// |
25 // WorkspaceLayoutManager, public: | 26 // WorkspaceLayoutManager, public: |
26 | 27 |
27 WorkspaceLayoutManager::WorkspaceLayoutManager( | 28 WorkspaceLayoutManager::WorkspaceLayoutManager( |
28 WorkspaceManager* workspace_manager) | 29 WorkspaceManager* workspace_manager) |
29 : workspace_manager_(workspace_manager) { | 30 : workspace_manager_(workspace_manager) { |
30 } | 31 } |
31 | 32 |
32 WorkspaceLayoutManager::~WorkspaceLayoutManager() {} | 33 WorkspaceLayoutManager::~WorkspaceLayoutManager() { |
| 34 const aura::Window::Windows& windows( |
| 35 workspace_manager_->contents_view()->children()); |
| 36 for (size_t i = 0; i < windows.size(); ++i) |
| 37 windows[i]->RemoveObserver(this); |
| 38 } |
33 | 39 |
34 void WorkspaceLayoutManager::OnWindowResized() { | 40 void WorkspaceLayoutManager::OnWindowResized() { |
35 // Workspace is updated via RootWindowObserver::OnRootWindowResized. | 41 // Workspace is updated via RootWindowObserver::OnRootWindowResized. |
36 } | 42 } |
37 | 43 |
38 void WorkspaceLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 44 void WorkspaceLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
| 45 child->AddObserver(this); |
39 if (!workspace_manager_->IsManagedWindow(child)) | 46 if (!workspace_manager_->IsManagedWindow(child)) |
40 return; | 47 return; |
41 | 48 |
42 if (child->IsVisible()) { | 49 if (child->IsVisible()) { |
43 workspace_manager_->AddWindow(child); | 50 workspace_manager_->AddWindow(child); |
44 } else if (wm::IsWindowMaximized(child) || | 51 } else if (wm::IsWindowMaximized(child) || |
45 workspace_manager_->ShouldMaximize(child)) { | 52 workspace_manager_->ShouldMaximize(child)) { |
46 if (!wm::IsWindowMaximized(child)) { | 53 if (!wm::IsWindowMaximized(child)) { |
47 SetRestoreBoundsIfNotSet(child); | 54 SetRestoreBoundsIfNotSet(child); |
48 wm::MaximizeWindow(child); | 55 wm::MaximizeWindow(child); |
49 } | 56 } |
50 SetChildBoundsDirect(child, | 57 SetChildBoundsDirect(child, |
51 gfx::Screen::GetMonitorWorkAreaNearestWindow(child)); | 58 gfx::Screen::GetMonitorWorkAreaNearestWindow(child)); |
52 } else if (wm::IsWindowFullscreen(child)) { | 59 } else if (wm::IsWindowFullscreen(child)) { |
53 SetChildBoundsDirect(child, | 60 SetChildBoundsDirect(child, |
54 gfx::Screen::GetMonitorAreaNearestWindow(child)); | 61 gfx::Screen::GetMonitorAreaNearestWindow(child)); |
55 } else { | 62 } else { |
56 // Align non-maximized/fullscreen windows to a grid. | 63 // Align non-maximized/fullscreen windows to a grid. |
57 SetChildBoundsDirect( | 64 SetChildBoundsDirect( |
58 child, workspace_manager_->AlignBoundsToGrid(child->GetTargetBounds())); | 65 child, workspace_manager_->AlignBoundsToGrid(child->GetTargetBounds())); |
59 } | 66 } |
60 } | 67 } |
61 | 68 |
62 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout( | 69 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout( |
63 aura::Window* child) { | 70 aura::Window* child) { |
| 71 child->RemoveObserver(this); |
64 ClearRestoreBounds(child); | 72 ClearRestoreBounds(child); |
65 workspace_manager_->RemoveWindow(child); | 73 workspace_manager_->RemoveWindow(child); |
66 } | 74 } |
67 | 75 |
68 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged( | 76 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged( |
69 aura::Window* child, | 77 aura::Window* child, |
70 bool visible) { | 78 bool visible) { |
71 if (!workspace_manager_->IsManagedWindow(child)) | 79 if (!workspace_manager_->IsManagedWindow(child)) |
72 return; | 80 return; |
73 if (visible) | 81 if (visible) |
74 workspace_manager_->AddWindow(child); | 82 workspace_manager_->AddWindow(child); |
75 else | 83 else |
76 workspace_manager_->RemoveWindow(child); | 84 workspace_manager_->RemoveWindow(child); |
77 } | 85 } |
78 | 86 |
79 void WorkspaceLayoutManager::SetChildBounds( | 87 void WorkspaceLayoutManager::SetChildBounds( |
80 aura::Window* child, | 88 aura::Window* child, |
81 const gfx::Rect& requested_bounds) { | 89 const gfx::Rect& requested_bounds) { |
82 gfx::Rect child_bounds(requested_bounds); | 90 gfx::Rect child_bounds(requested_bounds); |
83 if (wm::IsWindowMaximized(child)) { | 91 if (GetTrackedByWorkspace(child)) { |
84 child_bounds = gfx::Screen::GetMonitorWorkAreaNearestWindow(child); | 92 if (wm::IsWindowMaximized(child)) { |
85 } else if (wm::IsWindowFullscreen(child)) { | 93 child_bounds = gfx::Screen::GetMonitorWorkAreaNearestWindow(child); |
86 child_bounds = gfx::Screen::GetMonitorAreaNearestWindow(child); | 94 } else if (wm::IsWindowFullscreen(child)) { |
87 } else { | 95 child_bounds = gfx::Screen::GetMonitorAreaNearestWindow(child); |
88 child_bounds = gfx::Screen::GetMonitorWorkAreaNearestWindow(child). | 96 } else { |
89 AdjustToFit(requested_bounds); | 97 child_bounds = gfx::Screen::GetMonitorWorkAreaNearestWindow(child). |
| 98 AdjustToFit(requested_bounds); |
| 99 } |
90 } | 100 } |
91 SetChildBoundsDirect(child, child_bounds); | 101 SetChildBoundsDirect(child, child_bounds); |
92 } | 102 } |
93 | 103 |
| 104 void WorkspaceLayoutManager::OnWindowPropertyChanged(aura::Window* window, |
| 105 const void* key, |
| 106 intptr_t old) { |
| 107 if (key == ash::kWindowTrackedByWorkspaceSplitPropKey && |
| 108 ash::GetTrackedByWorkspace(window)) { |
| 109 // We currently don't need to support transitioning from true to false, so |
| 110 // we ignore it. |
| 111 workspace_manager_->AddWindow(window); |
| 112 } |
| 113 } |
| 114 |
94 } // namespace internal | 115 } // namespace internal |
95 } // namespace ash | 116 } // namespace ash |
OLD | NEW |