Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(457)

Side by Side Diff: ash/common/wm/maximize_mode/maximize_mode_window_manager.cc

Issue 2699033002: Replace WmWindowObserver with aura::WindowObserver. (Closed)
Patch Set: Check for null images in ShelfWindowWatcher. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/wm/maximize_mode/maximize_mode_window_manager.h" 5 #include "ash/common/wm/maximize_mode/maximize_mode_window_manager.h"
6 6
7 #include "ash/common/ash_switches.h" 7 #include "ash/common/ash_switches.h"
8 #include "ash/common/session/session_state_delegate.h" 8 #include "ash/common/session/session_state_delegate.h"
9 #include "ash/common/wm/maximize_mode/maximize_mode_event_handler.h" 9 #include "ash/common/wm/maximize_mode/maximize_mode_event_handler.h"
10 #include "ash/common/wm/maximize_mode/maximize_mode_window_state.h" 10 #include "ash/common/wm/maximize_mode/maximize_mode_window_state.h"
11 #include "ash/common/wm/maximize_mode/workspace_backdrop_delegate.h" 11 #include "ash/common/wm/maximize_mode/workspace_backdrop_delegate.h"
12 #include "ash/common/wm/mru_window_tracker.h" 12 #include "ash/common/wm/mru_window_tracker.h"
13 #include "ash/common/wm/overview/window_selector_controller.h" 13 #include "ash/common/wm/overview/window_selector_controller.h"
14 #include "ash/common/wm/window_state.h" 14 #include "ash/common/wm/window_state.h"
15 #include "ash/common/wm/wm_event.h" 15 #include "ash/common/wm/wm_event.h"
16 #include "ash/common/wm/workspace_controller.h" 16 #include "ash/common/wm/workspace_controller.h"
17 #include "ash/common/wm_shell.h" 17 #include "ash/common/wm_shell.h"
18 #include "ash/common/wm_window.h" 18 #include "ash/common/wm_window.h"
19 #include "ash/common/wm_window_property.h" 19 #include "ash/common/wm_window_property.h"
20 #include "ash/public/cpp/shell_window_ids.h" 20 #include "ash/public/cpp/shell_window_ids.h"
21 #include "ash/root_window_controller.h" 21 #include "ash/root_window_controller.h"
22 #include "ash/shell.h"
23 #include "ash/wm/window_state_aura.h"
22 #include "base/command_line.h" 24 #include "base/command_line.h"
23 #include "base/memory/ptr_util.h" 25 #include "base/memory/ptr_util.h"
24 #include "base/stl_util.h" 26 #include "base/stl_util.h"
27 #include "ui/aura/client/aura_constants.h"
25 #include "ui/display/screen.h" 28 #include "ui/display/screen.h"
26 29
27 namespace ash { 30 namespace ash {
28 31
29 namespace { 32 namespace {
30 33
31 // Exits overview mode if it is currently active. 34 // Exits overview mode if it is currently active.
32 void CancelOverview() { 35 void CancelOverview() {
33 WindowSelectorController* controller = 36 WindowSelectorController* controller =
34 WmShell::Get()->window_selector_controller(); 37 WmShell::Get()->window_selector_controller();
35 if (controller->IsSelecting()) 38 if (controller->IsSelecting())
36 controller->OnSelectionEnded(); 39 controller->OnSelectionEnded();
37 } 40 }
38 41
39 } // namespace 42 } // namespace
40 43
41 MaximizeModeWindowManager::~MaximizeModeWindowManager() { 44 MaximizeModeWindowManager::~MaximizeModeWindowManager() {
42 // Overview mode needs to be ended before exiting maximize mode to prevent 45 // Overview mode needs to be ended before exiting maximize mode to prevent
43 // transforming windows which are currently in 46 // transforming windows which are currently in
44 // overview: http://crbug.com/366605 47 // overview: http://crbug.com/366605
45 CancelOverview(); 48 CancelOverview();
46 for (auto* window : added_windows_) 49 for (aura::Window* window : added_windows_)
47 window->RemoveObserver(this); 50 window->RemoveObserver(this);
48 added_windows_.clear(); 51 added_windows_.clear();
49 WmShell::Get()->RemoveShellObserver(this); 52 WmShell::Get()->RemoveShellObserver(this);
50 display::Screen::GetScreen()->RemoveObserver(this); 53 display::Screen::GetScreen()->RemoveObserver(this);
51 EnableBackdropBehindTopWindowOnEachDisplay(false); 54 EnableBackdropBehindTopWindowOnEachDisplay(false);
52 RemoveWindowCreationObservers(); 55 RemoveWindowCreationObservers();
53 RestoreAllWindows(); 56 RestoreAllWindows();
54 } 57 }
55 58
56 int MaximizeModeWindowManager::GetNumberOfManagedWindows() { 59 int MaximizeModeWindowManager::GetNumberOfManagedWindows() {
57 return window_state_map_.size(); 60 return window_state_map_.size();
58 } 61 }
59 62
60 void MaximizeModeWindowManager::AddWindow(WmWindow* window) { 63 void MaximizeModeWindowManager::AddWindow(WmWindow* window) {
61 // Only add the window if it is a direct dependent of a container window 64 // Only add the window if it is a direct dependent of a container window
62 // and not yet tracked. 65 // and not yet tracked.
63 if (!ShouldHandleWindow(window) || 66 if (!ShouldHandleWindow(window) ||
64 base::ContainsKey(window_state_map_, window) || 67 base::ContainsKey(window_state_map_, window) ||
65 !IsContainerWindow(window->GetParent())) { 68 !IsContainerWindow(window->GetParent()->aura_window())) {
66 return; 69 return;
67 } 70 }
68 71
69 MaximizeAndTrackWindow(window); 72 MaximizeAndTrackWindow(window);
70 } 73 }
71 74
72 void MaximizeModeWindowManager::WindowStateDestroyed(WmWindow* window) { 75 void MaximizeModeWindowManager::WindowStateDestroyed(WmWindow* window) {
73 // At this time ForgetWindow() should already have been called. If not, 76 // At this time ForgetWindow() should already have been called. If not,
74 // someone else must have replaced the "window manager's state object". 77 // someone else must have replaced the "window manager's state object".
75 DCHECK(!window->HasObserver(this)); 78 DCHECK(!window->aura_window()->HasObserver(this));
76 79
77 auto it = window_state_map_.find(window); 80 auto it = window_state_map_.find(window);
78 DCHECK(it != window_state_map_.end()); 81 DCHECK(it != window_state_map_.end());
79 window_state_map_.erase(it); 82 window_state_map_.erase(it);
80 } 83 }
81 84
82 void MaximizeModeWindowManager::OnOverviewModeStarting() { 85 void MaximizeModeWindowManager::OnOverviewModeStarting() {
83 if (backdrops_hidden_) 86 if (backdrops_hidden_)
84 return; 87 return;
85 88
86 EnableBackdropBehindTopWindowOnEachDisplay(false); 89 EnableBackdropBehindTopWindowOnEachDisplay(false);
87 SetDeferBoundsUpdates(true); 90 SetDeferBoundsUpdates(true);
88 backdrops_hidden_ = true; 91 backdrops_hidden_ = true;
89 } 92 }
90 93
91 void MaximizeModeWindowManager::OnOverviewModeEnded() { 94 void MaximizeModeWindowManager::OnOverviewModeEnded() {
92 if (!backdrops_hidden_) 95 if (!backdrops_hidden_)
93 return; 96 return;
94 97
95 backdrops_hidden_ = false; 98 backdrops_hidden_ = false;
96 EnableBackdropBehindTopWindowOnEachDisplay(true); 99 EnableBackdropBehindTopWindowOnEachDisplay(true);
97 SetDeferBoundsUpdates(false); 100 SetDeferBoundsUpdates(false);
98 } 101 }
99 102
100 void MaximizeModeWindowManager::OnWindowDestroying(WmWindow* window) { 103 void MaximizeModeWindowManager::OnWindowDestroying(aura::Window* window) {
101 if (IsContainerWindow(window)) { 104 if (IsContainerWindow(window)) {
102 // container window can be removed on display destruction. 105 // container window can be removed on display destruction.
103 window->RemoveObserver(this); 106 window->RemoveObserver(this);
104 observed_container_windows_.erase(window); 107 observed_container_windows_.erase(window);
105 } else if (base::ContainsValue(added_windows_, window)) { 108 } else if (base::ContainsValue(added_windows_, window)) {
106 // Added window was destroyed before being shown. 109 // Added window was destroyed before being shown.
107 added_windows_.erase(window); 110 added_windows_.erase(window);
108 window->RemoveObserver(this); 111 window->RemoveObserver(this);
109 } else { 112 } else {
110 // If a known window gets destroyed we need to remove all knowledge about 113 // If a known window gets destroyed we need to remove all knowledge about
111 // it. 114 // it.
112 ForgetWindow(window); 115 ForgetWindow(WmWindow::Get(window));
113 } 116 }
114 } 117 }
115 118
116 void MaximizeModeWindowManager::OnWindowTreeChanged( 119 void MaximizeModeWindowManager::OnWindowHierarchyChanged(
117 WmWindow* window, 120 const HierarchyChangeParams& params) {
118 const TreeChangeParams& params) {
119 // A window can get removed and then re-added by a drag and drop operation. 121 // A window can get removed and then re-added by a drag and drop operation.
120 if (params.new_parent && IsContainerWindow(params.new_parent) && 122 if (params.new_parent && IsContainerWindow(params.new_parent) &&
121 !base::ContainsKey(window_state_map_, params.target)) { 123 !base::ContainsKey(window_state_map_, WmWindow::Get(params.target))) {
122 // Don't register the window if the window is invisible. Instead, 124 // Don't register the window if the window is invisible. Instead,
123 // wait until it becomes visible because the client may update the 125 // wait until it becomes visible because the client may update the
124 // flag to control if the window should be added. 126 // flag to control if the window should be added.
125 if (!params.target->IsVisible()) { 127 if (!params.target->IsVisible()) {
126 if (!base::ContainsValue(added_windows_, params.target)) { 128 if (!base::ContainsValue(added_windows_, params.target)) {
127 added_windows_.insert(params.target); 129 added_windows_.insert(params.target);
128 params.target->AddObserver(this); 130 params.target->AddObserver(this);
129 } 131 }
130 return; 132 return;
131 } 133 }
132 MaximizeAndTrackWindow(params.target); 134 MaximizeAndTrackWindow(WmWindow::Get(params.target));
133 // When the state got added, the "WM_EVENT_ADDED_TO_WORKSPACE" event got 135 // When the state got added, the "WM_EVENT_ADDED_TO_WORKSPACE" event got
134 // already sent and we have to notify our state again. 136 // already sent and we have to notify our state again.
135 if (base::ContainsKey(window_state_map_, params.target)) { 137 if (base::ContainsKey(window_state_map_, WmWindow::Get(params.target))) {
136 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); 138 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE);
137 params.target->GetWindowState()->OnWMEvent(&event); 139 wm::GetWindowState(params.target)->OnWMEvent(&event);
138 } 140 }
139 } 141 }
140 } 142 }
141 143
142 void MaximizeModeWindowManager::OnWindowPropertyChanged( 144 void MaximizeModeWindowManager::OnWindowPropertyChanged(aura::Window* window,
143 WmWindow* window, 145 const void* key,
144 WmWindowProperty property) { 146 intptr_t old) {
145 // Stop managing |window| if the always-on-top property is added. 147 // Stop managing |window| if the always-on-top property is added.
146 if (property == WmWindowProperty::ALWAYS_ON_TOP && window->IsAlwaysOnTop()) 148 if (key == aura::client::kAlwaysOnTopKey &&
147 ForgetWindow(window); 149 window->GetProperty(aura::client::kAlwaysOnTopKey)) {
150 ForgetWindow(WmWindow::Get(window));
151 }
148 } 152 }
149 153
150 void MaximizeModeWindowManager::OnWindowBoundsChanged( 154 void MaximizeModeWindowManager::OnWindowBoundsChanged(
151 WmWindow* window, 155 aura::Window* window,
152 const gfx::Rect& old_bounds, 156 const gfx::Rect& old_bounds,
153 const gfx::Rect& new_bounds) { 157 const gfx::Rect& new_bounds) {
154 if (!IsContainerWindow(window)) 158 if (!IsContainerWindow(window))
155 return; 159 return;
156 // Reposition all non maximizeable windows. 160 // Reposition all non maximizeable windows.
157 for (auto& pair : window_state_map_) 161 for (auto& pair : window_state_map_)
158 pair.second->UpdateWindowPosition(pair.first->GetWindowState()); 162 pair.second->UpdateWindowPosition(pair.first->GetWindowState());
159 } 163 }
160 164
161 void MaximizeModeWindowManager::OnWindowVisibilityChanged(WmWindow* window, 165 void MaximizeModeWindowManager::OnWindowVisibilityChanged(aura::Window* window,
162 bool visible) { 166 bool visible) {
163 // Skip if it's already managed. 167 // Skip if it's already managed.
164 if (base::ContainsKey(window_state_map_, window)) 168 if (base::ContainsKey(window_state_map_, WmWindow::Get(window)))
165 return; 169 return;
166 170
167 if (IsContainerWindow(window->GetParent()) && 171 if (IsContainerWindow(window->parent()) &&
168 base::ContainsValue(added_windows_, window) && visible) { 172 base::ContainsValue(added_windows_, window) && visible) {
169 added_windows_.erase(window); 173 added_windows_.erase(window);
170 window->RemoveObserver(this); 174 window->RemoveObserver(this);
171 MaximizeAndTrackWindow(window); 175 MaximizeAndTrackWindow(WmWindow::Get(window));
172 // When the state got added, the "WM_EVENT_ADDED_TO_WORKSPACE" event got 176 // When the state got added, the "WM_EVENT_ADDED_TO_WORKSPACE" event got
173 // already sent and we have to notify our state again. 177 // already sent and we have to notify our state again.
174 if (base::ContainsKey(window_state_map_, window)) { 178 if (base::ContainsKey(window_state_map_, WmWindow::Get(window))) {
175 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); 179 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE);
176 window->GetWindowState()->OnWMEvent(&event); 180 wm::GetWindowState(window)->OnWMEvent(&event);
177 } 181 }
178 } 182 }
179 } 183 }
180 184
181 void MaximizeModeWindowManager::OnDisplayAdded( 185 void MaximizeModeWindowManager::OnDisplayAdded(
182 const display::Display& display) { 186 const display::Display& display) {
183 DisplayConfigurationChanged(); 187 DisplayConfigurationChanged();
184 } 188 }
185 189
186 void MaximizeModeWindowManager::OnDisplayRemoved( 190 void MaximizeModeWindowManager::OnDisplayRemoved(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 bool defer_bounds_updates) { 228 bool defer_bounds_updates) {
225 for (auto& pair : window_state_map_) 229 for (auto& pair : window_state_map_)
226 pair.second->SetDeferBoundsUpdates(defer_bounds_updates); 230 pair.second->SetDeferBoundsUpdates(defer_bounds_updates);
227 } 231 }
228 232
229 void MaximizeModeWindowManager::MaximizeAndTrackWindow(WmWindow* window) { 233 void MaximizeModeWindowManager::MaximizeAndTrackWindow(WmWindow* window) {
230 if (!ShouldHandleWindow(window)) 234 if (!ShouldHandleWindow(window))
231 return; 235 return;
232 236
233 DCHECK(!base::ContainsKey(window_state_map_, window)); 237 DCHECK(!base::ContainsKey(window_state_map_, window));
234 window->AddObserver(this); 238 window->aura_window()->AddObserver(this);
235 239
236 // We create and remember a maximize mode state which will attach itself to 240 // We create and remember a maximize mode state which will attach itself to
237 // the provided state object. 241 // the provided state object.
238 window_state_map_[window] = new MaximizeModeWindowState(window, this); 242 window_state_map_[window] = new MaximizeModeWindowState(window, this);
239 } 243 }
240 244
241 void MaximizeModeWindowManager::ForgetWindow(WmWindow* window) { 245 void MaximizeModeWindowManager::ForgetWindow(WmWindow* window) {
242 WindowToState::iterator it = window_state_map_.find(window); 246 WindowToState::iterator it = window_state_map_.find(window);
243 247
244 // The following DCHECK could fail if our window state object was destroyed 248 // The following DCHECK could fail if our window state object was destroyed
245 // earlier by someone else. However - at this point there is no other client 249 // earlier by someone else. However - at this point there is no other client
246 // which replaces the state object and therefore this should not happen. 250 // which replaces the state object and therefore this should not happen.
247 DCHECK(it != window_state_map_.end()); 251 DCHECK(it != window_state_map_.end());
248 window->RemoveObserver(this); 252 window->aura_window()->RemoveObserver(this);
249 253
250 // By telling the state object to revert, it will switch back the old 254 // By telling the state object to revert, it will switch back the old
251 // State object and destroy itself, calling WindowStateDestroyed(). 255 // State object and destroy itself, calling WindowStateDestroyed().
252 it->second->LeaveMaximizeMode(it->first->GetWindowState()); 256 it->second->LeaveMaximizeMode(it->first->GetWindowState());
253 DCHECK(!base::ContainsKey(window_state_map_, window)); 257 DCHECK(!base::ContainsKey(window_state_map_, window));
254 } 258 }
255 259
256 bool MaximizeModeWindowManager::ShouldHandleWindow(WmWindow* window) { 260 bool MaximizeModeWindowManager::ShouldHandleWindow(WmWindow* window) {
257 DCHECK(window); 261 DCHECK(window);
258 262
(...skipping 11 matching lines...) Expand all
270 if (window->GetWindowState()->allow_set_bounds_in_maximized()) 274 if (window->GetWindowState()->allow_set_bounds_in_maximized())
271 return false; 275 return false;
272 276
273 return window->GetType() == ui::wm::WINDOW_TYPE_NORMAL; 277 return window->GetType() == ui::wm::WINDOW_TYPE_NORMAL;
274 } 278 }
275 279
276 void MaximizeModeWindowManager::AddWindowCreationObservers() { 280 void MaximizeModeWindowManager::AddWindowCreationObservers() {
277 DCHECK(observed_container_windows_.empty()); 281 DCHECK(observed_container_windows_.empty());
278 // Observe window activations/creations in the default containers on all root 282 // Observe window activations/creations in the default containers on all root
279 // windows. 283 // windows.
280 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) { 284 for (aura::Window* root : Shell::GetInstance()->GetAllRootWindows()) {
281 WmWindow* default_container = 285 aura::Window* default_container =
282 root->GetChildByShellWindowId(kShellWindowId_DefaultContainer); 286 root->GetChildById(kShellWindowId_DefaultContainer);
283 DCHECK(!base::ContainsKey(observed_container_windows_, default_container)); 287 DCHECK(!base::ContainsKey(observed_container_windows_, default_container));
284 default_container->AddObserver(this); 288 default_container->AddObserver(this);
285 observed_container_windows_.insert(default_container); 289 observed_container_windows_.insert(default_container);
286 } 290 }
287 } 291 }
288 292
289 void MaximizeModeWindowManager::RemoveWindowCreationObservers() { 293 void MaximizeModeWindowManager::RemoveWindowCreationObservers() {
290 for (WmWindow* window : observed_container_windows_) 294 for (aura::Window* window : observed_container_windows_)
291 window->RemoveObserver(this); 295 window->RemoveObserver(this);
292 observed_container_windows_.clear(); 296 observed_container_windows_.clear();
293 } 297 }
294 298
295 void MaximizeModeWindowManager::DisplayConfigurationChanged() { 299 void MaximizeModeWindowManager::DisplayConfigurationChanged() {
296 EnableBackdropBehindTopWindowOnEachDisplay(false); 300 EnableBackdropBehindTopWindowOnEachDisplay(false);
297 RemoveWindowCreationObservers(); 301 RemoveWindowCreationObservers();
298 AddWindowCreationObservers(); 302 AddWindowCreationObservers();
299 EnableBackdropBehindTopWindowOnEachDisplay(true); 303 EnableBackdropBehindTopWindowOnEachDisplay(true);
300 } 304 }
301 305
302 bool MaximizeModeWindowManager::IsContainerWindow(WmWindow* window) { 306 bool MaximizeModeWindowManager::IsContainerWindow(aura::Window* window) {
303 return base::ContainsKey(observed_container_windows_, window); 307 return base::ContainsKey(observed_container_windows_, window);
304 } 308 }
305 309
306 void MaximizeModeWindowManager::EnableBackdropBehindTopWindowOnEachDisplay( 310 void MaximizeModeWindowManager::EnableBackdropBehindTopWindowOnEachDisplay(
307 bool enable) { 311 bool enable) {
308 // This function should be a no-op if backdrops have been disabled. 312 // This function should be a no-op if backdrops have been disabled.
309 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 313 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
310 switches::kAshDisableMaximizeModeWindowBackdrop)) { 314 switches::kAshDisableMaximizeModeWindowBackdrop)) {
311 return; 315 return;
312 } 316 }
313 317
314 if (backdrops_hidden_) 318 if (backdrops_hidden_)
315 return; 319 return;
316 320
317 // Inform the WorkspaceLayoutManager that we want to show a backdrop behind 321 // Inform the WorkspaceLayoutManager that we want to show a backdrop behind
318 // the topmost window of its container. 322 // the topmost window of its container.
319 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) { 323 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) {
320 RootWindowController* controller = root->GetRootWindowController(); 324 RootWindowController* controller = root->GetRootWindowController();
321 WmWindow* default_container = 325 WmWindow* default_container =
322 root->GetChildByShellWindowId(kShellWindowId_DefaultContainer); 326 root->GetChildByShellWindowId(kShellWindowId_DefaultContainer);
323 controller->workspace_controller()->SetMaximizeBackdropDelegate( 327 controller->workspace_controller()->SetMaximizeBackdropDelegate(
324 enable ? base::MakeUnique<WorkspaceBackdropDelegate>(default_container) 328 enable ? base::MakeUnique<WorkspaceBackdropDelegate>(default_container)
325 : nullptr); 329 : nullptr);
326 } 330 }
327 } 331 }
328 332
329 } // namespace ash 333 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/maximize_mode/maximize_mode_window_manager.h ('k') | ash/common/wm/maximize_mode/workspace_backdrop_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698