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

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: cleanup 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
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_window_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 IsContainerWindow(window) &&
James Cook 2016/06/29 14:11:40 just to double-check: Is it necessary to check tha
sky 2016/06/29 15:41:11 Good eye. I was being extra cautious here as this
James Cook 2016/06/29 16:07:40 It sounds like it will work correctly either way,
117 MaximizeAndTrackWindow(window); 114 !ContainsKey(window_state_map_, params.target)) {
115 MaximizeAndTrackWindow(params.target);
118 // When the state got added, the "WM_EVENT_ADDED_TO_WORKSPACE" event got 116 // When the state got added, the "WM_EVENT_ADDED_TO_WORKSPACE" event got
119 // already sent and we have to notify our state again. 117 // already sent and we have to notify our state again.
120 if (window_state_map_.find(window) != window_state_map_.end()) { 118 if (ContainsKey(window_state_map_, params.target)) {
121 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); 119 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE);
122 wm::GetWindowState(window)->OnWMEvent(&event); 120 params.target->GetWindowState()->OnWMEvent(&event);
123 } 121 }
124 } 122 }
125 } 123 }
126 124
127 void MaximizeModeWindowManager::OnWindowPropertyChanged(aura::Window* window, 125 void MaximizeModeWindowManager::OnWindowPropertyChanged(
128 const void* key, 126 WmWindow* window,
129 intptr_t old) { 127 WmWindowProperty property) {
130 // Stop managing |window| if the always-on-top property is added. 128 // Stop managing |window| if the always-on-top property is added.
131 if (key == aura::client::kAlwaysOnTopKey && 129 if (property == WmWindowProperty::ALWAYS_ON_TOP && window->IsAlwaysOnTop())
132 window->GetProperty(aura::client::kAlwaysOnTopKey)) {
133 ForgetWindow(window); 130 ForgetWindow(window);
134 }
135 } 131 }
136 132
137 void MaximizeModeWindowManager::OnWindowBoundsChanged( 133 void MaximizeModeWindowManager::OnWindowBoundsChanged(
138 aura::Window* window, 134 WmWindow* window,
139 const gfx::Rect& old_bounds, 135 const gfx::Rect& old_bounds,
140 const gfx::Rect& new_bounds) { 136 const gfx::Rect& new_bounds) {
141 if (!IsContainerWindow(window)) 137 if (!IsContainerWindow(window))
142 return; 138 return;
143 // Reposition all non maximizeable windows. 139 // Reposition all non maximizeable windows.
144 for (WindowToState::iterator it = window_state_map_.begin(); 140 for (auto& pair : window_state_map_)
145 it != window_state_map_.end(); ++it) { 141 pair.second->UpdateWindowPosition(pair.first->GetWindowState());
146 it->second->UpdateWindowPosition(wm::GetWindowState(it->first));
147 }
148 } 142 }
149 143
150 void MaximizeModeWindowManager::OnDisplayAdded( 144 void MaximizeModeWindowManager::OnDisplayAdded(
151 const display::Display& display) { 145 const display::Display& display) {
152 DisplayConfigurationChanged(); 146 DisplayConfigurationChanged();
153 } 147 }
154 148
155 void MaximizeModeWindowManager::OnDisplayRemoved( 149 void MaximizeModeWindowManager::OnDisplayRemoved(
156 const display::Display& display) { 150 const display::Display& display) {
157 DisplayConfigurationChanged(); 151 DisplayConfigurationChanged();
(...skipping 12 matching lines...) Expand all
170 164
171 MaximizeAllWindows(); 165 MaximizeAllWindows();
172 AddWindowCreationObservers(); 166 AddWindowCreationObservers();
173 EnableBackdropBehindTopWindowOnEachDisplay(true); 167 EnableBackdropBehindTopWindowOnEachDisplay(true);
174 display::Screen::GetScreen()->AddObserver(this); 168 display::Screen::GetScreen()->AddObserver(this);
175 WmShell::Get()->AddShellObserver(this); 169 WmShell::Get()->AddShellObserver(this);
176 event_handler_ = WmShell::Get()->CreateMaximizeModeEventHandler(); 170 event_handler_ = WmShell::Get()->CreateMaximizeModeEventHandler();
177 } 171 }
178 172
179 void MaximizeModeWindowManager::MaximizeAllWindows() { 173 void MaximizeModeWindowManager::MaximizeAllWindows() {
180 MruWindowTracker::WindowList windows = ash::Shell::GetInstance() 174 MruWindowTracker::WindowList windows =
181 ->mru_window_tracker() 175 WmShell::Get()->GetMruWindowTracker()->BuildWindowListIgnoreModal();
182 ->BuildWindowListIgnoreModal();
183 // Add all existing Mru windows. 176 // Add all existing Mru windows.
184 for (WmWindow* window : windows) 177 for (WmWindow* window : windows)
185 MaximizeAndTrackWindow(WmWindowAura::GetAuraWindow(window)); 178 MaximizeAndTrackWindow(window);
186 } 179 }
187 180
188 void MaximizeModeWindowManager::RestoreAllWindows() { 181 void MaximizeModeWindowManager::RestoreAllWindows() {
189 while (window_state_map_.size()) 182 while (window_state_map_.size())
190 ForgetWindow(window_state_map_.begin()->first); 183 ForgetWindow(window_state_map_.begin()->first);
191 } 184 }
192 185
193 void MaximizeModeWindowManager::SetDeferBoundsUpdates( 186 void MaximizeModeWindowManager::SetDeferBoundsUpdates(
194 bool defer_bounds_updates) { 187 bool defer_bounds_updates) {
195 for (WindowToState::iterator it = window_state_map_.begin(); 188 for (auto& pair : window_state_map_)
196 it != window_state_map_.end(); ++it) { 189 pair.second->SetDeferBoundsUpdates(defer_bounds_updates);
197 it->second->SetDeferBoundsUpdates(defer_bounds_updates);
198 }
199 } 190 }
200 191
201 void MaximizeModeWindowManager::MaximizeAndTrackWindow(aura::Window* window) { 192 void MaximizeModeWindowManager::MaximizeAndTrackWindow(WmWindow* window) {
202 if (!ShouldHandleWindow(window)) 193 if (!ShouldHandleWindow(window))
203 return; 194 return;
204 195
205 DCHECK(window_state_map_.find(window) == window_state_map_.end()); 196 DCHECK(!ContainsKey(window_state_map_, window));
206 window->AddObserver(this); 197 window->AddObserver(this);
207 198
208 // We create and remember a maximize mode state which will attach itself to 199 // We create and remember a maximize mode state which will attach itself to
209 // the provided state object. 200 // the provided state object.
210 window_state_map_[window] = 201 window_state_map_[window] = new MaximizeModeWindowState(window, this);
211 new MaximizeModeWindowState(WmWindowAura::Get(window), this);
212 } 202 }
213 203
214 void MaximizeModeWindowManager::ForgetWindow(aura::Window* window) { 204 void MaximizeModeWindowManager::ForgetWindow(WmWindow* window) {
215 WindowToState::iterator it = window_state_map_.find(window); 205 WindowToState::iterator it = window_state_map_.find(window);
216 206
217 // The following DCHECK could fail if our window state object was destroyed 207 // 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 208 // 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. 209 // which replaces the state object and therefore this should not happen.
220 DCHECK(it != window_state_map_.end()); 210 DCHECK(it != window_state_map_.end());
221 window->RemoveObserver(this); 211 window->RemoveObserver(this);
222 212
223 // By telling the state object to revert, it will switch back the old 213 // By telling the state object to revert, it will switch back the old
224 // State object and destroy itself, calling WindowStateDestroyed(). 214 // State object and destroy itself, calling WindowStateDestroyed().
225 it->second->LeaveMaximizeMode(wm::GetWindowState(it->first)); 215 it->second->LeaveMaximizeMode(it->first->GetWindowState());
226 DCHECK(window_state_map_.find(window) == window_state_map_.end()); 216 DCHECK(!ContainsKey(window_state_map_, window));
227 } 217 }
228 218
229 bool MaximizeModeWindowManager::ShouldHandleWindow(aura::Window* window) { 219 bool MaximizeModeWindowManager::ShouldHandleWindow(WmWindow* window) {
230 DCHECK(window); 220 DCHECK(window);
231 221
232 // Windows with the always-on-top property should be free-floating and thus 222 // Windows with the always-on-top property should be free-floating and thus
233 // not managed by us. 223 // not managed by us.
234 if (window->GetProperty(aura::client::kAlwaysOnTopKey)) 224 if (window->IsAlwaysOnTop())
235 return false; 225 return false;
236 226
237 // Windows in the dock should not be managed by us. 227 // Windows in the dock should not be managed by us.
238 if (wm::GetWindowState(window)->IsDocked()) 228 if (window->GetWindowState()->IsDocked())
239 return false; 229 return false;
240 230
241 return window->type() == ui::wm::WINDOW_TYPE_NORMAL; 231 return window->GetType() == ui::wm::WINDOW_TYPE_NORMAL;
242 } 232 }
243 233
244 void MaximizeModeWindowManager::AddWindowCreationObservers() { 234 void MaximizeModeWindowManager::AddWindowCreationObservers() {
245 DCHECK(observed_container_windows_.empty()); 235 DCHECK(observed_container_windows_.empty());
246 // Observe window activations/creations in the default containers on all root 236 // Observe window activations/creations in the default containers on all root
247 // windows. 237 // windows.
248 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 238 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) {
249 for (aura::Window::Windows::const_iterator iter = root_windows.begin(); 239 WmWindow* default_container =
250 iter != root_windows.end(); ++iter) { 240 root->GetChildByShellWindowId(kShellWindowId_DefaultContainer);
251 aura::Window* container = 241 DCHECK(!ContainsKey(observed_container_windows_, default_container));
252 Shell::GetContainer(*iter, kShellWindowId_DefaultContainer); 242 default_container->AddObserver(this);
253 DCHECK(observed_container_windows_.find(container) == 243 observed_container_windows_.insert(default_container);
254 observed_container_windows_.end());
255 container->AddObserver(this);
256 observed_container_windows_.insert(container);
257 } 244 }
258 } 245 }
259 246
260 void MaximizeModeWindowManager::RemoveWindowCreationObservers() { 247 void MaximizeModeWindowManager::RemoveWindowCreationObservers() {
261 for (std::set<aura::Window*>::iterator iter = 248 for (WmWindow* window : observed_container_windows_)
262 observed_container_windows_.begin(); 249 window->RemoveObserver(this);
263 iter != observed_container_windows_.end(); ++iter) {
264 (*iter)->RemoveObserver(this);
265 }
266 observed_container_windows_.clear(); 250 observed_container_windows_.clear();
267 } 251 }
268 252
269 void MaximizeModeWindowManager::DisplayConfigurationChanged() { 253 void MaximizeModeWindowManager::DisplayConfigurationChanged() {
270 EnableBackdropBehindTopWindowOnEachDisplay(false); 254 EnableBackdropBehindTopWindowOnEachDisplay(false);
271 RemoveWindowCreationObservers(); 255 RemoveWindowCreationObservers();
272 AddWindowCreationObservers(); 256 AddWindowCreationObservers();
273 EnableBackdropBehindTopWindowOnEachDisplay(true); 257 EnableBackdropBehindTopWindowOnEachDisplay(true);
274 } 258 }
275 259
276 bool MaximizeModeWindowManager::IsContainerWindow(aura::Window* window) { 260 bool MaximizeModeWindowManager::IsContainerWindow(WmWindow* window) {
277 return observed_container_windows_.find(window) != 261 return ContainsKey(observed_container_windows_, window);
278 observed_container_windows_.end();
279 } 262 }
280 263
281 void MaximizeModeWindowManager::EnableBackdropBehindTopWindowOnEachDisplay( 264 void MaximizeModeWindowManager::EnableBackdropBehindTopWindowOnEachDisplay(
282 bool enable) { 265 bool enable) {
283 // This function should be a no-op if backdrops have been disabled. 266 // This function should be a no-op if backdrops have been disabled.
284 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 267 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
285 switches::kAshDisableMaximizeModeWindowBackdrop)) { 268 switches::kAshDisableMaximizeModeWindowBackdrop)) {
286 return; 269 return;
287 } 270 }
288 271
289 if (backdrops_hidden_) 272 if (backdrops_hidden_)
290 return; 273 return;
291 274
292 // Inform the WorkspaceLayoutManager that we want to show a backdrop behind 275 // Inform the WorkspaceLayoutManager that we want to show a backdrop behind
293 // the topmost window of its container. 276 // the topmost window of its container.
294 Shell::RootWindowControllerList controllers = 277 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) {
295 Shell::GetAllRootWindowControllers(); 278 WmRootWindowController* controller = root->GetRootWindowController();
296 for (Shell::RootWindowControllerList::iterator iter = controllers.begin(); 279 WmWindow* default_container =
297 iter != controllers.end(); ++iter) { 280 root->GetChildByShellWindowId(kShellWindowId_DefaultContainer);
298 RootWindowController* controller = *iter; 281 controller->SetMaximizeBackdropDelegate(base::WrapUnique(
299 aura::Window* container = Shell::GetContainer( 282 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 } 283 }
306 } 284 }
307 285
308 } // namespace ash 286 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_window_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698