OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/maximize_mode/maximize_mode_window_manager.h" | 5 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/public/cpp/shell_window_ids.h" | 8 #include "ash/public/cpp/shell_window_ids.h" |
9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
10 #include "ash/session/session_state_delegate.h" | 10 #include "ash/session/session_state_delegate.h" |
11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
12 #include "ash/shell_port.h" | 12 #include "ash/shell_port.h" |
13 #include "ash/wm/maximize_mode/maximize_mode_backdrop_delegate_impl.h" | 13 #include "ash/wm/maximize_mode/maximize_mode_backdrop_delegate_impl.h" |
14 #include "ash/wm/maximize_mode/maximize_mode_event_handler.h" | 14 #include "ash/wm/maximize_mode/maximize_mode_event_handler.h" |
15 #include "ash/wm/maximize_mode/maximize_mode_window_state.h" | 15 #include "ash/wm/maximize_mode/maximize_mode_window_state.h" |
16 #include "ash/wm/mru_window_tracker.h" | 16 #include "ash/wm/mru_window_tracker.h" |
17 #include "ash/wm/overview/window_selector_controller.h" | 17 #include "ash/wm/overview/window_selector_controller.h" |
18 #include "ash/wm/window_state.h" | 18 #include "ash/wm/window_state.h" |
19 #include "ash/wm/wm_event.h" | 19 #include "ash/wm/wm_event.h" |
20 #include "ash/wm/workspace_controller.h" | 20 #include "ash/wm/workspace_controller.h" |
21 #include "ash/wm_window.h" | |
22 #include "base/command_line.h" | 21 #include "base/command_line.h" |
23 #include "base/memory/ptr_util.h" | 22 #include "base/memory/ptr_util.h" |
24 #include "base/stl_util.h" | 23 #include "base/stl_util.h" |
25 #include "ui/aura/client/aura_constants.h" | 24 #include "ui/aura/client/aura_constants.h" |
26 #include "ui/display/screen.h" | 25 #include "ui/display/screen.h" |
27 | 26 |
28 namespace ash { | 27 namespace ash { |
29 | 28 |
30 namespace { | 29 namespace { |
31 | 30 |
(...skipping 19 matching lines...) Expand all Loading... | |
51 display::Screen::GetScreen()->RemoveObserver(this); | 50 display::Screen::GetScreen()->RemoveObserver(this); |
52 EnableBackdropBehindTopWindowOnEachDisplay(false); | 51 EnableBackdropBehindTopWindowOnEachDisplay(false); |
53 RemoveWindowCreationObservers(); | 52 RemoveWindowCreationObservers(); |
54 RestoreAllWindows(); | 53 RestoreAllWindows(); |
55 } | 54 } |
56 | 55 |
57 int MaximizeModeWindowManager::GetNumberOfManagedWindows() { | 56 int MaximizeModeWindowManager::GetNumberOfManagedWindows() { |
58 return window_state_map_.size(); | 57 return window_state_map_.size(); |
59 } | 58 } |
60 | 59 |
61 void MaximizeModeWindowManager::AddWindow(WmWindow* window) { | 60 void MaximizeModeWindowManager::AddWindow(aura::Window* window) { |
62 // Only add the window if it is a direct dependent of a container window | 61 // Only add the window if it is a direct dependent of a container window |
63 // and not yet tracked. | 62 // and not yet tracked. |
64 if (!ShouldHandleWindow(window) || | 63 if (!ShouldHandleWindow(window) || |
65 base::ContainsKey(window_state_map_, window) || | 64 base::ContainsKey(window_state_map_, window) || |
66 !IsContainerWindow(window->GetParent()->aura_window())) { | 65 !IsContainerWindow(window->parent())) { |
67 return; | 66 return; |
68 } | 67 } |
69 | 68 |
70 MaximizeAndTrackWindow(window); | 69 MaximizeAndTrackWindow(window); |
71 } | 70 } |
72 | 71 |
73 void MaximizeModeWindowManager::WindowStateDestroyed(WmWindow* window) { | 72 void MaximizeModeWindowManager::WindowStateDestroyed(aura::Window* window) { |
74 // At this time ForgetWindow() should already have been called. If not, | 73 // At this time ForgetWindow() should already have been called. If not, |
75 // someone else must have replaced the "window manager's state object". | 74 // someone else must have replaced the "window manager's state object". |
76 DCHECK(!window->aura_window()->HasObserver(this)); | 75 DCHECK(!window->HasObserver(this)); |
77 | 76 |
78 auto it = window_state_map_.find(window); | 77 auto it = window_state_map_.find(window); |
79 DCHECK(it != window_state_map_.end()); | 78 DCHECK(it != window_state_map_.end()); |
80 window_state_map_.erase(it); | 79 window_state_map_.erase(it); |
81 } | 80 } |
82 | 81 |
83 void MaximizeModeWindowManager::OnOverviewModeStarting() { | 82 void MaximizeModeWindowManager::OnOverviewModeStarting() { |
84 SetDeferBoundsUpdates(true); | 83 SetDeferBoundsUpdates(true); |
85 } | 84 } |
86 | 85 |
87 void MaximizeModeWindowManager::OnOverviewModeEnded() { | 86 void MaximizeModeWindowManager::OnOverviewModeEnded() { |
88 SetDeferBoundsUpdates(false); | 87 SetDeferBoundsUpdates(false); |
89 } | 88 } |
90 | 89 |
91 void MaximizeModeWindowManager::OnWindowDestroying(aura::Window* window) { | 90 void MaximizeModeWindowManager::OnWindowDestroying(aura::Window* window) { |
92 if (IsContainerWindow(window)) { | 91 if (IsContainerWindow(window)) { |
93 // container window can be removed on display destruction. | 92 // container window can be removed on display destruction. |
94 window->RemoveObserver(this); | 93 window->RemoveObserver(this); |
95 observed_container_windows_.erase(window); | 94 observed_container_windows_.erase(window); |
96 } else if (base::ContainsValue(added_windows_, window)) { | 95 } else if (base::ContainsValue(added_windows_, window)) { |
97 // Added window was destroyed before being shown. | 96 // Added window was destroyed before being shown. |
98 added_windows_.erase(window); | 97 added_windows_.erase(window); |
99 window->RemoveObserver(this); | 98 window->RemoveObserver(this); |
100 } else { | 99 } else { |
101 // If a known window gets destroyed we need to remove all knowledge about | 100 // If a known window gets destroyed we need to remove all knowledge about |
102 // it. | 101 // it. |
103 ForgetWindow(WmWindow::Get(window)); | 102 ForgetWindow(window); |
104 } | 103 } |
105 } | 104 } |
106 | 105 |
107 void MaximizeModeWindowManager::OnWindowHierarchyChanged( | 106 void MaximizeModeWindowManager::OnWindowHierarchyChanged( |
108 const HierarchyChangeParams& params) { | 107 const HierarchyChangeParams& params) { |
109 // A window can get removed and then re-added by a drag and drop operation. | 108 // A window can get removed and then re-added by a drag and drop operation. |
110 if (params.new_parent && IsContainerWindow(params.new_parent) && | 109 if (params.new_parent && IsContainerWindow(params.new_parent) && |
111 !base::ContainsKey(window_state_map_, WmWindow::Get(params.target))) { | 110 !base::ContainsKey(window_state_map_, params.target)) { |
112 // Don't register the window if the window is invisible. Instead, | 111 // Don't register the window if the window is invisible. Instead, |
113 // wait until it becomes visible because the client may update the | 112 // wait until it becomes visible because the client may update the |
114 // flag to control if the window should be added. | 113 // flag to control if the window should be added. |
115 if (!params.target->IsVisible()) { | 114 if (!params.target->IsVisible()) { |
116 if (!base::ContainsValue(added_windows_, params.target)) { | 115 if (!base::ContainsValue(added_windows_, params.target)) { |
117 added_windows_.insert(params.target); | 116 added_windows_.insert(params.target); |
118 params.target->AddObserver(this); | 117 params.target->AddObserver(this); |
119 } | 118 } |
120 return; | 119 return; |
121 } | 120 } |
122 MaximizeAndTrackWindow(WmWindow::Get(params.target)); | 121 MaximizeAndTrackWindow(params.target); |
123 // When the state got added, the "WM_EVENT_ADDED_TO_WORKSPACE" event got | 122 // When the state got added, the "WM_EVENT_ADDED_TO_WORKSPACE" event got |
124 // already sent and we have to notify our state again. | 123 // already sent and we have to notify our state again. |
125 if (base::ContainsKey(window_state_map_, WmWindow::Get(params.target))) { | 124 if (base::ContainsKey(window_state_map_, params.target)) { |
126 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); | 125 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); |
127 wm::GetWindowState(params.target)->OnWMEvent(&event); | 126 wm::GetWindowState(params.target)->OnWMEvent(&event); |
128 } | 127 } |
129 } | 128 } |
130 } | 129 } |
131 | 130 |
132 void MaximizeModeWindowManager::OnWindowPropertyChanged(aura::Window* window, | 131 void MaximizeModeWindowManager::OnWindowPropertyChanged(aura::Window* window, |
133 const void* key, | 132 const void* key, |
134 intptr_t old) { | 133 intptr_t old) { |
135 // Stop managing |window| if the always-on-top property is added. | 134 // Stop managing |window| if the always-on-top property is added. |
136 if (key == aura::client::kAlwaysOnTopKey && | 135 if (key == aura::client::kAlwaysOnTopKey && |
137 window->GetProperty(aura::client::kAlwaysOnTopKey)) { | 136 window->GetProperty(aura::client::kAlwaysOnTopKey)) { |
138 ForgetWindow(WmWindow::Get(window)); | 137 ForgetWindow(window); |
139 } | 138 } |
140 } | 139 } |
141 | 140 |
142 void MaximizeModeWindowManager::OnWindowBoundsChanged( | 141 void MaximizeModeWindowManager::OnWindowBoundsChanged( |
143 aura::Window* window, | 142 aura::Window* window, |
144 const gfx::Rect& old_bounds, | 143 const gfx::Rect& old_bounds, |
145 const gfx::Rect& new_bounds) { | 144 const gfx::Rect& new_bounds) { |
146 if (!IsContainerWindow(window)) | 145 if (!IsContainerWindow(window)) |
147 return; | 146 return; |
148 // Reposition all non maximizeable windows. | 147 // Reposition all non maximizeable windows. |
149 for (auto& pair : window_state_map_) | 148 for (auto& pair : window_state_map_) |
150 pair.second->UpdateWindowPosition(pair.first->GetWindowState()); | 149 pair.second->UpdateWindowPosition(wm::GetWindowState(pair.first)); |
151 } | 150 } |
152 | 151 |
153 void MaximizeModeWindowManager::OnWindowVisibilityChanged(aura::Window* window, | 152 void MaximizeModeWindowManager::OnWindowVisibilityChanged(aura::Window* window, |
154 bool visible) { | 153 bool visible) { |
155 // Skip if it's already managed. | 154 // Skip if it's already managed. |
156 if (base::ContainsKey(window_state_map_, WmWindow::Get(window))) | 155 if (base::ContainsKey(window_state_map_, window)) |
157 return; | 156 return; |
158 | 157 |
159 if (IsContainerWindow(window->parent()) && | 158 if (IsContainerWindow(window->parent()) && |
160 base::ContainsValue(added_windows_, window) && visible) { | 159 base::ContainsValue(added_windows_, window) && visible) { |
161 added_windows_.erase(window); | 160 added_windows_.erase(window); |
162 window->RemoveObserver(this); | 161 window->RemoveObserver(this); |
163 MaximizeAndTrackWindow(WmWindow::Get(window)); | 162 MaximizeAndTrackWindow(window); |
164 // When the state got added, the "WM_EVENT_ADDED_TO_WORKSPACE" event got | 163 // When the state got added, the "WM_EVENT_ADDED_TO_WORKSPACE" event got |
165 // already sent and we have to notify our state again. | 164 // already sent and we have to notify our state again. |
166 if (base::ContainsKey(window_state_map_, WmWindow::Get(window))) { | 165 if (base::ContainsKey(window_state_map_, window)) { |
167 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); | 166 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); |
168 wm::GetWindowState(window)->OnWMEvent(&event); | 167 wm::GetWindowState(window)->OnWMEvent(&event); |
169 } | 168 } |
170 } | 169 } |
171 } | 170 } |
172 | 171 |
173 void MaximizeModeWindowManager::OnDisplayAdded( | 172 void MaximizeModeWindowManager::OnDisplayAdded( |
174 const display::Display& display) { | 173 const display::Display& display) { |
175 DisplayConfigurationChanged(); | 174 DisplayConfigurationChanged(); |
176 } | 175 } |
(...skipping 23 matching lines...) Expand all Loading... | |
200 AddWindowCreationObservers(); | 199 AddWindowCreationObservers(); |
201 EnableBackdropBehindTopWindowOnEachDisplay(true); | 200 EnableBackdropBehindTopWindowOnEachDisplay(true); |
202 display::Screen::GetScreen()->AddObserver(this); | 201 display::Screen::GetScreen()->AddObserver(this); |
203 Shell::Get()->AddShellObserver(this); | 202 Shell::Get()->AddShellObserver(this); |
204 event_handler_ = ShellPort::Get()->CreateMaximizeModeEventHandler(); | 203 event_handler_ = ShellPort::Get()->CreateMaximizeModeEventHandler(); |
205 } | 204 } |
206 | 205 |
207 void MaximizeModeWindowManager::MaximizeAllWindows() { | 206 void MaximizeModeWindowManager::MaximizeAllWindows() { |
208 MruWindowTracker::WindowList windows = | 207 MruWindowTracker::WindowList windows = |
209 Shell::Get()->mru_window_tracker()->BuildWindowListIgnoreModal(); | 208 Shell::Get()->mru_window_tracker()->BuildWindowListIgnoreModal(); |
210 // Add all existing Mru windows. | 209 // Add all existing MRU windows. |
211 for (WmWindow* window : windows) | 210 for (auto* window : windows) |
James Cook
2017/05/24 15:50:22
Aside: This is fine, but in general I prefer to sp
varkha
2017/05/24 16:00:07
Acknowledged.
| |
212 MaximizeAndTrackWindow(window); | 211 MaximizeAndTrackWindow(window); |
213 } | 212 } |
214 | 213 |
215 void MaximizeModeWindowManager::RestoreAllWindows() { | 214 void MaximizeModeWindowManager::RestoreAllWindows() { |
216 while (window_state_map_.size()) | 215 while (window_state_map_.size()) |
217 ForgetWindow(window_state_map_.begin()->first); | 216 ForgetWindow(window_state_map_.begin()->first); |
218 } | 217 } |
219 | 218 |
220 void MaximizeModeWindowManager::SetDeferBoundsUpdates( | 219 void MaximizeModeWindowManager::SetDeferBoundsUpdates( |
221 bool defer_bounds_updates) { | 220 bool defer_bounds_updates) { |
222 for (auto& pair : window_state_map_) | 221 for (auto& pair : window_state_map_) |
223 pair.second->SetDeferBoundsUpdates(defer_bounds_updates); | 222 pair.second->SetDeferBoundsUpdates(defer_bounds_updates); |
224 } | 223 } |
225 | 224 |
226 void MaximizeModeWindowManager::MaximizeAndTrackWindow(WmWindow* window) { | 225 void MaximizeModeWindowManager::MaximizeAndTrackWindow(aura::Window* window) { |
227 if (!ShouldHandleWindow(window)) | 226 if (!ShouldHandleWindow(window)) |
228 return; | 227 return; |
229 | 228 |
230 DCHECK(!base::ContainsKey(window_state_map_, window)); | 229 DCHECK(!base::ContainsKey(window_state_map_, window)); |
231 window->aura_window()->AddObserver(this); | 230 window->AddObserver(this); |
232 | 231 |
233 // We create and remember a maximize mode state which will attach itself to | 232 // We create and remember a maximize mode state which will attach itself to |
234 // the provided state object. | 233 // the provided state object. |
235 window_state_map_[window] = new MaximizeModeWindowState(window, this); | 234 window_state_map_[window] = new MaximizeModeWindowState(window, this); |
236 } | 235 } |
237 | 236 |
238 void MaximizeModeWindowManager::ForgetWindow(WmWindow* window) { | 237 void MaximizeModeWindowManager::ForgetWindow(aura::Window* window) { |
239 WindowToState::iterator it = window_state_map_.find(window); | 238 WindowToState::iterator it = window_state_map_.find(window); |
240 | 239 |
241 // The following DCHECK could fail if our window state object was destroyed | 240 // The following DCHECK could fail if our window state object was destroyed |
242 // earlier by someone else. However - at this point there is no other client | 241 // earlier by someone else. However - at this point there is no other client |
243 // which replaces the state object and therefore this should not happen. | 242 // which replaces the state object and therefore this should not happen. |
244 DCHECK(it != window_state_map_.end()); | 243 DCHECK(it != window_state_map_.end()); |
245 window->aura_window()->RemoveObserver(this); | 244 window->RemoveObserver(this); |
246 | 245 |
247 // By telling the state object to revert, it will switch back the old | 246 // By telling the state object to revert, it will switch back the old |
248 // State object and destroy itself, calling WindowStateDestroyed(). | 247 // State object and destroy itself, calling WindowStateDestroyed(). |
249 it->second->LeaveMaximizeMode(it->first->GetWindowState()); | 248 it->second->LeaveMaximizeMode(wm::GetWindowState(it->first)); |
250 DCHECK(!base::ContainsKey(window_state_map_, window)); | 249 DCHECK(!base::ContainsKey(window_state_map_, window)); |
251 } | 250 } |
252 | 251 |
253 bool MaximizeModeWindowManager::ShouldHandleWindow(WmWindow* window) { | 252 bool MaximizeModeWindowManager::ShouldHandleWindow(aura::Window* window) { |
254 DCHECK(window); | 253 DCHECK(window); |
255 | 254 |
256 // Windows with the always-on-top property should be free-floating and thus | 255 // Windows with the always-on-top property should be free-floating and thus |
257 // not managed by us. | 256 // not managed by us. |
258 if (window->IsAlwaysOnTop()) | 257 if (window->GetProperty(aura::client::kAlwaysOnTopKey)) |
259 return false; | 258 return false; |
260 | 259 |
261 // If the changing bounds in the maximized/fullscreen is allowed, then | 260 // If the changing bounds in the maximized/fullscreen is allowed, then |
262 // let the client manage it even in maximized mode. | 261 // let the client manage it even in maximized mode. |
263 if (window->GetWindowState()->allow_set_bounds_direct()) | 262 if (wm::GetWindowState(window)->allow_set_bounds_direct()) |
264 return false; | 263 return false; |
265 | 264 |
266 return window->GetType() == ui::wm::WINDOW_TYPE_NORMAL; | 265 return window->type() == ui::wm::WINDOW_TYPE_NORMAL; |
267 } | 266 } |
268 | 267 |
269 void MaximizeModeWindowManager::AddWindowCreationObservers() { | 268 void MaximizeModeWindowManager::AddWindowCreationObservers() { |
270 DCHECK(observed_container_windows_.empty()); | 269 DCHECK(observed_container_windows_.empty()); |
271 // Observe window activations/creations in the default containers on all root | 270 // Observe window activations/creations in the default containers on all root |
272 // windows. | 271 // windows. |
273 for (aura::Window* root : Shell::Get()->GetAllRootWindows()) { | 272 for (aura::Window* root : Shell::GetAllRootWindows()) { |
274 aura::Window* default_container = | 273 aura::Window* default_container = |
275 root->GetChildById(kShellWindowId_DefaultContainer); | 274 root->GetChildById(kShellWindowId_DefaultContainer); |
276 DCHECK(!base::ContainsKey(observed_container_windows_, default_container)); | 275 DCHECK(!base::ContainsKey(observed_container_windows_, default_container)); |
277 default_container->AddObserver(this); | 276 default_container->AddObserver(this); |
278 observed_container_windows_.insert(default_container); | 277 observed_container_windows_.insert(default_container); |
279 } | 278 } |
280 } | 279 } |
281 | 280 |
282 void MaximizeModeWindowManager::RemoveWindowCreationObservers() { | 281 void MaximizeModeWindowManager::RemoveWindowCreationObservers() { |
283 for (aura::Window* window : observed_container_windows_) | 282 for (aura::Window* window : observed_container_windows_) |
284 window->RemoveObserver(this); | 283 window->RemoveObserver(this); |
285 observed_container_windows_.clear(); | 284 observed_container_windows_.clear(); |
286 } | 285 } |
287 | 286 |
288 void MaximizeModeWindowManager::DisplayConfigurationChanged() { | 287 void MaximizeModeWindowManager::DisplayConfigurationChanged() { |
289 EnableBackdropBehindTopWindowOnEachDisplay(false); | 288 EnableBackdropBehindTopWindowOnEachDisplay(false); |
290 RemoveWindowCreationObservers(); | 289 RemoveWindowCreationObservers(); |
291 AddWindowCreationObservers(); | 290 AddWindowCreationObservers(); |
292 EnableBackdropBehindTopWindowOnEachDisplay(true); | 291 EnableBackdropBehindTopWindowOnEachDisplay(true); |
293 } | 292 } |
294 | 293 |
295 bool MaximizeModeWindowManager::IsContainerWindow(aura::Window* window) { | 294 bool MaximizeModeWindowManager::IsContainerWindow(aura::Window* window) { |
296 return base::ContainsKey(observed_container_windows_, window); | 295 return base::ContainsKey(observed_container_windows_, window); |
297 } | 296 } |
298 | 297 |
299 void MaximizeModeWindowManager::EnableBackdropBehindTopWindowOnEachDisplay( | 298 void MaximizeModeWindowManager::EnableBackdropBehindTopWindowOnEachDisplay( |
300 bool enable) { | 299 bool enable) { |
301 // Inform the WorkspaceLayoutManager that we want to show a backdrop behind | 300 // Inform the WorkspaceLayoutManager that we want to show a backdrop behind |
302 // the topmost window of its container. | 301 // the topmost window of its container. |
303 for (WmWindow* root : ShellPort::Get()->GetAllRootWindows()) { | 302 for (auto* controller : Shell::GetAllRootWindowControllers()) { |
304 RootWindowController* controller = root->GetRootWindowController(); | |
305 controller->workspace_controller()->SetBackdropDelegate( | 303 controller->workspace_controller()->SetBackdropDelegate( |
306 enable ? base::MakeUnique<MaximizeModeBackdropDelegateImpl>() | 304 enable ? base::MakeUnique<MaximizeModeBackdropDelegateImpl>() |
307 : nullptr); | 305 : nullptr); |
308 } | 306 } |
309 } | 307 } |
310 | 308 |
311 } // namespace ash | 309 } // namespace ash |
OLD | NEW |