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

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

Issue 2103913003: Converts MaximizeModeWindowManager to use ash/common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@maximize_mode_event_handler
Patch Set: fix chrome Created 4 years, 5 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/wm/maximize_mode/maximize_mode_window_manager.h" 5 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h"
6 6
7 #include "ash/aura/wm_window_aura.h"
8 #include "ash/common/ash_switches.h" 7 #include "ash/common/ash_switches.h"
9 #include "ash/common/session/session_state_delegate.h" 8 #include "ash/common/session/session_state_delegate.h"
10 #include "ash/common/shell_window_ids.h" 9 #include "ash/common/shell_window_ids.h"
11 #include "ash/common/wm/maximize_mode/maximize_mode_event_handler.h" 10 #include "ash/common/wm/maximize_mode/maximize_mode_event_handler.h"
12 #include "ash/common/wm/mru_window_tracker.h" 11 #include "ash/common/wm/mru_window_tracker.h"
13 #include "ash/common/wm/overview/window_selector_controller.h" 12 #include "ash/common/wm/overview/window_selector_controller.h"
14 #include "ash/common/wm/window_state.h" 13 #include "ash/common/wm/window_state.h"
15 #include "ash/common/wm/wm_event.h" 14 #include "ash/common/wm/wm_event.h"
15 #include "ash/common/wm_root_window_controller.h"
16 #include "ash/common/wm_shell.h" 16 #include "ash/common/wm_shell.h"
17 #include "ash/root_window_controller.h" 17 #include "ash/common/wm_window.h"
18 #include "ash/shell.h" 18 #include "ash/common/wm_window_property.h"
19 #include "ash/wm/maximize_mode/maximize_mode_window_state.h" 19 #include "ash/wm/maximize_mode/maximize_mode_window_state.h"
20 #include "ash/wm/maximize_mode/workspace_backdrop_delegate.h" 20 #include "ash/wm/maximize_mode/workspace_backdrop_delegate.h"
21 #include "ash/wm/window_state_aura.h"
22 #include "ash/wm/window_util.h"
23 #include "ash/wm/workspace_controller.h"
24 #include "base/command_line.h" 21 #include "base/command_line.h"
25 #include "ui/aura/client/aura_constants.h" 22 #include "base/memory/ptr_util.h"
26 #include "ui/aura/window.h" 23 #include "base/stl_util.h"
27 #include "ui/display/screen.h" 24 #include "ui/display/screen.h"
28 25
29 namespace ash { 26 namespace ash {
30 27
31 namespace { 28 namespace {
32 29
33 // Exits overview mode if it is currently active. 30 // Exits overview mode if it is currently active.
34 void CancelOverview() { 31 void CancelOverview() {
35 WindowSelectorController* controller = 32 WindowSelectorController* controller =
36 WmShell::Get()->window_selector_controller(); 33 WmShell::Get()->window_selector_controller();
(...skipping 13 matching lines...) Expand all
50 display::Screen::GetScreen()->RemoveObserver(this); 47 display::Screen::GetScreen()->RemoveObserver(this);
51 EnableBackdropBehindTopWindowOnEachDisplay(false); 48 EnableBackdropBehindTopWindowOnEachDisplay(false);
52 RemoveWindowCreationObservers(); 49 RemoveWindowCreationObservers();
53 RestoreAllWindows(); 50 RestoreAllWindows();
54 } 51 }
55 52
56 int MaximizeModeWindowManager::GetNumberOfManagedWindows() { 53 int MaximizeModeWindowManager::GetNumberOfManagedWindows() {
57 return window_state_map_.size(); 54 return window_state_map_.size();
58 } 55 }
59 56
60 void MaximizeModeWindowManager::AddWindow(aura::Window* window) { 57 void MaximizeModeWindowManager::AddWindow(WmWindow* window) {
61 // Only add the window if it is a direct dependent of a container window 58 // Only add the window if it is a direct dependent of a container window
62 // and not yet tracked. 59 // and not yet tracked.
63 if (!ShouldHandleWindow(window) || 60 if (!ShouldHandleWindow(window) || ContainsKey(window_state_map_, window) ||
64 window_state_map_.find(window) != window_state_map_.end() || 61 !IsContainerWindow(window->GetParent())) {
65 !IsContainerWindow(window->parent())) {
66 return; 62 return;
67 } 63 }
68 64
69 MaximizeAndTrackWindow(window); 65 MaximizeAndTrackWindow(window);
70 } 66 }
71 67
72 void MaximizeModeWindowManager::WindowStateDestroyed(WmWindow* wm_window) { 68 void MaximizeModeWindowManager::WindowStateDestroyed(WmWindow* window) {
73 aura::Window* window = WmWindowAura::GetAuraWindow(wm_window);
74 // At this time ForgetWindow() should already have been called. If not, 69 // At this time ForgetWindow() should already have been called. If not,
75 // someone else must have replaced the "window manager's state object". 70 // someone else must have replaced the "window manager's state object".
76 DCHECK(!window->HasObserver(this)); 71 DCHECK(!window->HasObserver(this));
77 72
78 WindowToState::iterator it = window_state_map_.find(window); 73 auto it = window_state_map_.find(window);
79 DCHECK(it != window_state_map_.end()); 74 DCHECK(it != window_state_map_.end());
80 window_state_map_.erase(it); 75 window_state_map_.erase(it);
81 } 76 }
82 77
83 void MaximizeModeWindowManager::OnOverviewModeStarting() { 78 void MaximizeModeWindowManager::OnOverviewModeStarting() {
84 if (backdrops_hidden_) 79 if (backdrops_hidden_)
85 return; 80 return;
86 81
87 EnableBackdropBehindTopWindowOnEachDisplay(false); 82 EnableBackdropBehindTopWindowOnEachDisplay(false);
88 SetDeferBoundsUpdates(true); 83 SetDeferBoundsUpdates(true);
89 backdrops_hidden_ = true; 84 backdrops_hidden_ = true;
90 } 85 }
91 86
92 void MaximizeModeWindowManager::OnOverviewModeEnded() { 87 void MaximizeModeWindowManager::OnOverviewModeEnded() {
93 if (!backdrops_hidden_) 88 if (!backdrops_hidden_)
94 return; 89 return;
95 90
96 backdrops_hidden_ = false; 91 backdrops_hidden_ = false;
97 EnableBackdropBehindTopWindowOnEachDisplay(true); 92 EnableBackdropBehindTopWindowOnEachDisplay(true);
98 SetDeferBoundsUpdates(false); 93 SetDeferBoundsUpdates(false);
99 } 94 }
100 95
101 void MaximizeModeWindowManager::OnWindowDestroying(aura::Window* window) { 96 void MaximizeModeWindowManager::OnWindowDestroying(WmWindow* window) {
102 if (IsContainerWindow(window)) { 97 if (IsContainerWindow(window)) {
103 // container window can be removed on display destruction. 98 // container window can be removed on display destruction.
104 window->RemoveObserver(this); 99 window->RemoveObserver(this);
105 observed_container_windows_.erase(window); 100 observed_container_windows_.erase(window);
106 } else { 101 } else {
107 // If a known window gets destroyed we need to remove all knowledge about 102 // If a known window gets destroyed we need to remove all knowledge about
108 // it. 103 // it.
109 ForgetWindow(window); 104 ForgetWindow(window);
110 } 105 }
111 } 106 }
112 107
113 void MaximizeModeWindowManager::OnWindowAdded(aura::Window* window) { 108 void MaximizeModeWindowManager::OnWindowTreeChanged(
109 WmWindow* window,
110 const TreeChangeParams& params) {
114 // A window can get removed and then re-added by a drag and drop operation. 111 // A window can get removed and then re-added by a drag and drop operation.
115 if (IsContainerWindow(window->parent()) && 112 if (params.new_parent && IsContainerWindow(params.new_parent) &&
116 window_state_map_.find(window) == window_state_map_.end()) { 113 !ContainsKey(window_state_map_, params.target)) {
117 MaximizeAndTrackWindow(window); 114 MaximizeAndTrackWindow(params.target);
118 // When the state got added, the "WM_EVENT_ADDED_TO_WORKSPACE" event got 115 // When the state got added, the "WM_EVENT_ADDED_TO_WORKSPACE" event got
119 // already sent and we have to notify our state again. 116 // already sent and we have to notify our state again.
120 if (window_state_map_.find(window) != window_state_map_.end()) { 117 if (ContainsKey(window_state_map_, params.target)) {
121 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); 118 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE);
122 wm::GetWindowState(window)->OnWMEvent(&event); 119 params.target->GetWindowState()->OnWMEvent(&event);
123 } 120 }
124 } 121 }
125 } 122 }
126 123
127 void MaximizeModeWindowManager::OnWindowPropertyChanged(aura::Window* window, 124 void MaximizeModeWindowManager::OnWindowPropertyChanged(
128 const void* key, 125 WmWindow* window,
129 intptr_t old) { 126 WmWindowProperty property) {
130 // Stop managing |window| if the always-on-top property is added. 127 // Stop managing |window| if the always-on-top property is added.
131 if (key == aura::client::kAlwaysOnTopKey && 128 if (property == WmWindowProperty::ALWAYS_ON_TOP && window->IsAlwaysOnTop())
132 window->GetProperty(aura::client::kAlwaysOnTopKey)) {
133 ForgetWindow(window); 129 ForgetWindow(window);
134 }
135 } 130 }
136 131
137 void MaximizeModeWindowManager::OnWindowBoundsChanged( 132 void MaximizeModeWindowManager::OnWindowBoundsChanged(
138 aura::Window* window, 133 WmWindow* window,
139 const gfx::Rect& old_bounds, 134 const gfx::Rect& old_bounds,
140 const gfx::Rect& new_bounds) { 135 const gfx::Rect& new_bounds) {
141 if (!IsContainerWindow(window)) 136 if (!IsContainerWindow(window))
142 return; 137 return;
143 // Reposition all non maximizeable windows. 138 // Reposition all non maximizeable windows.
144 for (WindowToState::iterator it = window_state_map_.begin(); 139 for (auto& pair : window_state_map_)
145 it != window_state_map_.end(); ++it) { 140 pair.second->UpdateWindowPosition(pair.first->GetWindowState());
146 it->second->UpdateWindowPosition(wm::GetWindowState(it->first));
147 }
148 } 141 }
149 142
150 void MaximizeModeWindowManager::OnDisplayAdded( 143 void MaximizeModeWindowManager::OnDisplayAdded(
151 const display::Display& display) { 144 const display::Display& display) {
152 DisplayConfigurationChanged(); 145 DisplayConfigurationChanged();
153 } 146 }
154 147
155 void MaximizeModeWindowManager::OnDisplayRemoved( 148 void MaximizeModeWindowManager::OnDisplayRemoved(
156 const display::Display& display) { 149 const display::Display& display) {
157 DisplayConfigurationChanged(); 150 DisplayConfigurationChanged();
(...skipping 12 matching lines...) Expand all
170 163
171 MaximizeAllWindows(); 164 MaximizeAllWindows();
172 AddWindowCreationObservers(); 165 AddWindowCreationObservers();
173 EnableBackdropBehindTopWindowOnEachDisplay(true); 166 EnableBackdropBehindTopWindowOnEachDisplay(true);
174 display::Screen::GetScreen()->AddObserver(this); 167 display::Screen::GetScreen()->AddObserver(this);
175 WmShell::Get()->AddShellObserver(this); 168 WmShell::Get()->AddShellObserver(this);
176 event_handler_ = WmShell::Get()->CreateMaximizeModeEventHandler(); 169 event_handler_ = WmShell::Get()->CreateMaximizeModeEventHandler();
177 } 170 }
178 171
179 void MaximizeModeWindowManager::MaximizeAllWindows() { 172 void MaximizeModeWindowManager::MaximizeAllWindows() {
180 MruWindowTracker::WindowList windows = ash::Shell::GetInstance() 173 MruWindowTracker::WindowList windows =
181 ->mru_window_tracker() 174 WmShell::Get()->GetMruWindowTracker()->BuildWindowListIgnoreModal();
182 ->BuildWindowListIgnoreModal();
183 // Add all existing Mru windows. 175 // Add all existing Mru windows.
184 for (WmWindow* window : windows) 176 for (WmWindow* window : windows)
185 MaximizeAndTrackWindow(WmWindowAura::GetAuraWindow(window)); 177 MaximizeAndTrackWindow(window);
186 } 178 }
187 179
188 void MaximizeModeWindowManager::RestoreAllWindows() { 180 void MaximizeModeWindowManager::RestoreAllWindows() {
189 while (window_state_map_.size()) 181 while (window_state_map_.size())
190 ForgetWindow(window_state_map_.begin()->first); 182 ForgetWindow(window_state_map_.begin()->first);
191 } 183 }
192 184
193 void MaximizeModeWindowManager::SetDeferBoundsUpdates( 185 void MaximizeModeWindowManager::SetDeferBoundsUpdates(
194 bool defer_bounds_updates) { 186 bool defer_bounds_updates) {
195 for (WindowToState::iterator it = window_state_map_.begin(); 187 for (auto& pair : window_state_map_)
196 it != window_state_map_.end(); ++it) { 188 pair.second->SetDeferBoundsUpdates(defer_bounds_updates);
197 it->second->SetDeferBoundsUpdates(defer_bounds_updates);
198 }
199 } 189 }
200 190
201 void MaximizeModeWindowManager::MaximizeAndTrackWindow(aura::Window* window) { 191 void MaximizeModeWindowManager::MaximizeAndTrackWindow(WmWindow* window) {
202 if (!ShouldHandleWindow(window)) 192 if (!ShouldHandleWindow(window))
203 return; 193 return;
204 194
205 DCHECK(window_state_map_.find(window) == window_state_map_.end()); 195 DCHECK(!ContainsKey(window_state_map_, window));
206 window->AddObserver(this); 196 window->AddObserver(this);
207 197
208 // We create and remember a maximize mode state which will attach itself to 198 // We create and remember a maximize mode state which will attach itself to
209 // the provided state object. 199 // the provided state object.
210 window_state_map_[window] = 200 window_state_map_[window] = new MaximizeModeWindowState(window, this);
211 new MaximizeModeWindowState(WmWindowAura::Get(window), this);
212 } 201 }
213 202
214 void MaximizeModeWindowManager::ForgetWindow(aura::Window* window) { 203 void MaximizeModeWindowManager::ForgetWindow(WmWindow* window) {
215 WindowToState::iterator it = window_state_map_.find(window); 204 WindowToState::iterator it = window_state_map_.find(window);
216 205
217 // The following DCHECK could fail if our window state object was destroyed 206 // The following DCHECK could fail if our window state object was destroyed
218 // earlier by someone else. However - at this point there is no other client 207 // earlier by someone else. However - at this point there is no other client
219 // which replaces the state object and therefore this should not happen. 208 // which replaces the state object and therefore this should not happen.
220 DCHECK(it != window_state_map_.end()); 209 DCHECK(it != window_state_map_.end());
221 window->RemoveObserver(this); 210 window->RemoveObserver(this);
222 211
223 // By telling the state object to revert, it will switch back the old 212 // By telling the state object to revert, it will switch back the old
224 // State object and destroy itself, calling WindowStateDestroyed(). 213 // State object and destroy itself, calling WindowStateDestroyed().
225 it->second->LeaveMaximizeMode(wm::GetWindowState(it->first)); 214 it->second->LeaveMaximizeMode(it->first->GetWindowState());
226 DCHECK(window_state_map_.find(window) == window_state_map_.end()); 215 DCHECK(!ContainsKey(window_state_map_, window));
227 } 216 }
228 217
229 bool MaximizeModeWindowManager::ShouldHandleWindow(aura::Window* window) { 218 bool MaximizeModeWindowManager::ShouldHandleWindow(WmWindow* window) {
230 DCHECK(window); 219 DCHECK(window);
231 220
232 // Windows with the always-on-top property should be free-floating and thus 221 // Windows with the always-on-top property should be free-floating and thus
233 // not managed by us. 222 // not managed by us.
234 if (window->GetProperty(aura::client::kAlwaysOnTopKey)) 223 if (window->IsAlwaysOnTop())
235 return false; 224 return false;
236 225
237 // Windows in the dock should not be managed by us. 226 // Windows in the dock should not be managed by us.
238 if (wm::GetWindowState(window)->IsDocked()) 227 if (window->GetWindowState()->IsDocked())
239 return false; 228 return false;
240 229
241 return window->type() == ui::wm::WINDOW_TYPE_NORMAL; 230 return window->GetType() == ui::wm::WINDOW_TYPE_NORMAL;
242 } 231 }
243 232
244 void MaximizeModeWindowManager::AddWindowCreationObservers() { 233 void MaximizeModeWindowManager::AddWindowCreationObservers() {
245 DCHECK(observed_container_windows_.empty()); 234 DCHECK(observed_container_windows_.empty());
246 // Observe window activations/creations in the default containers on all root 235 // Observe window activations/creations in the default containers on all root
247 // windows. 236 // windows.
248 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 237 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) {
249 for (aura::Window::Windows::const_iterator iter = root_windows.begin(); 238 WmWindow* default_container =
250 iter != root_windows.end(); ++iter) { 239 root->GetChildByShellWindowId(kShellWindowId_DefaultContainer);
251 aura::Window* container = 240 DCHECK(!ContainsKey(observed_container_windows_, default_container));
252 Shell::GetContainer(*iter, kShellWindowId_DefaultContainer); 241 default_container->AddObserver(this);
253 DCHECK(observed_container_windows_.find(container) == 242 observed_container_windows_.insert(default_container);
254 observed_container_windows_.end());
255 container->AddObserver(this);
256 observed_container_windows_.insert(container);
257 } 243 }
258 } 244 }
259 245
260 void MaximizeModeWindowManager::RemoveWindowCreationObservers() { 246 void MaximizeModeWindowManager::RemoveWindowCreationObservers() {
261 for (std::set<aura::Window*>::iterator iter = 247 for (WmWindow* window : observed_container_windows_)
262 observed_container_windows_.begin(); 248 window->RemoveObserver(this);
263 iter != observed_container_windows_.end(); ++iter) {
264 (*iter)->RemoveObserver(this);
265 }
266 observed_container_windows_.clear(); 249 observed_container_windows_.clear();
267 } 250 }
268 251
269 void MaximizeModeWindowManager::DisplayConfigurationChanged() { 252 void MaximizeModeWindowManager::DisplayConfigurationChanged() {
270 EnableBackdropBehindTopWindowOnEachDisplay(false); 253 EnableBackdropBehindTopWindowOnEachDisplay(false);
271 RemoveWindowCreationObservers(); 254 RemoveWindowCreationObservers();
272 AddWindowCreationObservers(); 255 AddWindowCreationObservers();
273 EnableBackdropBehindTopWindowOnEachDisplay(true); 256 EnableBackdropBehindTopWindowOnEachDisplay(true);
274 } 257 }
275 258
276 bool MaximizeModeWindowManager::IsContainerWindow(aura::Window* window) { 259 bool MaximizeModeWindowManager::IsContainerWindow(WmWindow* window) {
277 return observed_container_windows_.find(window) != 260 return ContainsKey(observed_container_windows_, window);
278 observed_container_windows_.end();
279 } 261 }
280 262
281 void MaximizeModeWindowManager::EnableBackdropBehindTopWindowOnEachDisplay( 263 void MaximizeModeWindowManager::EnableBackdropBehindTopWindowOnEachDisplay(
282 bool enable) { 264 bool enable) {
283 // This function should be a no-op if backdrops have been disabled. 265 // This function should be a no-op if backdrops have been disabled.
284 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 266 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
285 switches::kAshDisableMaximizeModeWindowBackdrop)) { 267 switches::kAshDisableMaximizeModeWindowBackdrop)) {
286 return; 268 return;
287 } 269 }
288 270
289 if (backdrops_hidden_) 271 if (backdrops_hidden_)
290 return; 272 return;
291 273
292 // Inform the WorkspaceLayoutManager that we want to show a backdrop behind 274 // Inform the WorkspaceLayoutManager that we want to show a backdrop behind
293 // the topmost window of its container. 275 // the topmost window of its container.
294 Shell::RootWindowControllerList controllers = 276 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) {
295 Shell::GetAllRootWindowControllers(); 277 WmRootWindowController* controller = root->GetRootWindowController();
296 for (Shell::RootWindowControllerList::iterator iter = controllers.begin(); 278 WmWindow* default_container =
297 iter != controllers.end(); ++iter) { 279 root->GetChildByShellWindowId(kShellWindowId_DefaultContainer);
298 RootWindowController* controller = *iter; 280 controller->SetMaximizeBackdropDelegate(base::WrapUnique(
299 aura::Window* container = Shell::GetContainer( 281 enable ? new WorkspaceBackdropDelegate(default_container) : nullptr));
300 controller->GetRootWindow(), kShellWindowId_DefaultContainer);
301 controller->workspace_controller()->SetMaximizeBackdropDelegate(
302 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate>(
303 enable ? new WorkspaceBackdropDelegate(WmWindowAura::Get(container))
304 : nullptr));
305 } 282 }
306 } 283 }
307 284
308 } // namespace ash 285 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698