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

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

Issue 2237433002: ash: Use stl utilities from the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 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/common/accelerators/accelerator_router.cc ('k') | ash/display/display_animator_chromeos.cc » ('j') | 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/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/shell_window_ids.h" 9 #include "ash/common/shell_window_ids.h"
10 #include "ash/common/wm/maximize_mode/maximize_mode_event_handler.h" 10 #include "ash/common/wm/maximize_mode/maximize_mode_event_handler.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 RestoreAllWindows(); 50 RestoreAllWindows();
51 } 51 }
52 52
53 int MaximizeModeWindowManager::GetNumberOfManagedWindows() { 53 int MaximizeModeWindowManager::GetNumberOfManagedWindows() {
54 return window_state_map_.size(); 54 return window_state_map_.size();
55 } 55 }
56 56
57 void MaximizeModeWindowManager::AddWindow(WmWindow* window) { 57 void MaximizeModeWindowManager::AddWindow(WmWindow* window) {
58 // 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
59 // and not yet tracked. 59 // and not yet tracked.
60 if (!ShouldHandleWindow(window) || ContainsKey(window_state_map_, window) || 60 if (!ShouldHandleWindow(window) ||
61 base::ContainsKey(window_state_map_, window) ||
61 !IsContainerWindow(window->GetParent())) { 62 !IsContainerWindow(window->GetParent())) {
62 return; 63 return;
63 } 64 }
64 65
65 MaximizeAndTrackWindow(window); 66 MaximizeAndTrackWindow(window);
66 } 67 }
67 68
68 void MaximizeModeWindowManager::WindowStateDestroyed(WmWindow* window) { 69 void MaximizeModeWindowManager::WindowStateDestroyed(WmWindow* window) {
69 // At this time ForgetWindow() should already have been called. If not, 70 // At this time ForgetWindow() should already have been called. If not,
70 // someone else must have replaced the "window manager's state object". 71 // someone else must have replaced the "window manager's state object".
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // it. 104 // it.
104 ForgetWindow(window); 105 ForgetWindow(window);
105 } 106 }
106 } 107 }
107 108
108 void MaximizeModeWindowManager::OnWindowTreeChanged( 109 void MaximizeModeWindowManager::OnWindowTreeChanged(
109 WmWindow* window, 110 WmWindow* window,
110 const TreeChangeParams& params) { 111 const TreeChangeParams& params) {
111 // A window can get removed and then re-added by a drag and drop operation. 112 // A window can get removed and then re-added by a drag and drop operation.
112 if (params.new_parent && IsContainerWindow(params.new_parent) && 113 if (params.new_parent && IsContainerWindow(params.new_parent) &&
113 !ContainsKey(window_state_map_, params.target)) { 114 !base::ContainsKey(window_state_map_, params.target)) {
114 MaximizeAndTrackWindow(params.target); 115 MaximizeAndTrackWindow(params.target);
115 // 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
116 // already sent and we have to notify our state again. 117 // already sent and we have to notify our state again.
117 if (ContainsKey(window_state_map_, params.target)) { 118 if (base::ContainsKey(window_state_map_, params.target)) {
118 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); 119 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE);
119 params.target->GetWindowState()->OnWMEvent(&event); 120 params.target->GetWindowState()->OnWMEvent(&event);
120 } 121 }
121 } 122 }
122 } 123 }
123 124
124 void MaximizeModeWindowManager::OnWindowPropertyChanged( 125 void MaximizeModeWindowManager::OnWindowPropertyChanged(
125 WmWindow* window, 126 WmWindow* window,
126 WmWindowProperty property) { 127 WmWindowProperty property) {
127 // Stop managing |window| if the always-on-top property is added. 128 // Stop managing |window| if the always-on-top property is added.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 void MaximizeModeWindowManager::SetDeferBoundsUpdates( 186 void MaximizeModeWindowManager::SetDeferBoundsUpdates(
186 bool defer_bounds_updates) { 187 bool defer_bounds_updates) {
187 for (auto& pair : window_state_map_) 188 for (auto& pair : window_state_map_)
188 pair.second->SetDeferBoundsUpdates(defer_bounds_updates); 189 pair.second->SetDeferBoundsUpdates(defer_bounds_updates);
189 } 190 }
190 191
191 void MaximizeModeWindowManager::MaximizeAndTrackWindow(WmWindow* window) { 192 void MaximizeModeWindowManager::MaximizeAndTrackWindow(WmWindow* window) {
192 if (!ShouldHandleWindow(window)) 193 if (!ShouldHandleWindow(window))
193 return; 194 return;
194 195
195 DCHECK(!ContainsKey(window_state_map_, window)); 196 DCHECK(!base::ContainsKey(window_state_map_, window));
196 window->AddObserver(this); 197 window->AddObserver(this);
197 198
198 // 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
199 // the provided state object. 200 // the provided state object.
200 window_state_map_[window] = new MaximizeModeWindowState(window, this); 201 window_state_map_[window] = new MaximizeModeWindowState(window, this);
201 } 202 }
202 203
203 void MaximizeModeWindowManager::ForgetWindow(WmWindow* window) { 204 void MaximizeModeWindowManager::ForgetWindow(WmWindow* window) {
204 WindowToState::iterator it = window_state_map_.find(window); 205 WindowToState::iterator it = window_state_map_.find(window);
205 206
206 // 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
207 // 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
208 // which replaces the state object and therefore this should not happen. 209 // which replaces the state object and therefore this should not happen.
209 DCHECK(it != window_state_map_.end()); 210 DCHECK(it != window_state_map_.end());
210 window->RemoveObserver(this); 211 window->RemoveObserver(this);
211 212
212 // 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
213 // State object and destroy itself, calling WindowStateDestroyed(). 214 // State object and destroy itself, calling WindowStateDestroyed().
214 it->second->LeaveMaximizeMode(it->first->GetWindowState()); 215 it->second->LeaveMaximizeMode(it->first->GetWindowState());
215 DCHECK(!ContainsKey(window_state_map_, window)); 216 DCHECK(!base::ContainsKey(window_state_map_, window));
216 } 217 }
217 218
218 bool MaximizeModeWindowManager::ShouldHandleWindow(WmWindow* window) { 219 bool MaximizeModeWindowManager::ShouldHandleWindow(WmWindow* window) {
219 DCHECK(window); 220 DCHECK(window);
220 221
221 // 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
222 // not managed by us. 223 // not managed by us.
223 if (window->IsAlwaysOnTop()) 224 if (window->IsAlwaysOnTop())
224 return false; 225 return false;
225 226
226 // Windows in the dock should not be managed by us. 227 // Windows in the dock should not be managed by us.
227 if (window->GetWindowState()->IsDocked()) 228 if (window->GetWindowState()->IsDocked())
228 return false; 229 return false;
229 230
230 return window->GetType() == ui::wm::WINDOW_TYPE_NORMAL; 231 return window->GetType() == ui::wm::WINDOW_TYPE_NORMAL;
231 } 232 }
232 233
233 void MaximizeModeWindowManager::AddWindowCreationObservers() { 234 void MaximizeModeWindowManager::AddWindowCreationObservers() {
234 DCHECK(observed_container_windows_.empty()); 235 DCHECK(observed_container_windows_.empty());
235 // Observe window activations/creations in the default containers on all root 236 // Observe window activations/creations in the default containers on all root
236 // windows. 237 // windows.
237 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) { 238 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) {
238 WmWindow* default_container = 239 WmWindow* default_container =
239 root->GetChildByShellWindowId(kShellWindowId_DefaultContainer); 240 root->GetChildByShellWindowId(kShellWindowId_DefaultContainer);
240 DCHECK(!ContainsKey(observed_container_windows_, default_container)); 241 DCHECK(!base::ContainsKey(observed_container_windows_, default_container));
241 default_container->AddObserver(this); 242 default_container->AddObserver(this);
242 observed_container_windows_.insert(default_container); 243 observed_container_windows_.insert(default_container);
243 } 244 }
244 } 245 }
245 246
246 void MaximizeModeWindowManager::RemoveWindowCreationObservers() { 247 void MaximizeModeWindowManager::RemoveWindowCreationObservers() {
247 for (WmWindow* window : observed_container_windows_) 248 for (WmWindow* window : observed_container_windows_)
248 window->RemoveObserver(this); 249 window->RemoveObserver(this);
249 observed_container_windows_.clear(); 250 observed_container_windows_.clear();
250 } 251 }
251 252
252 void MaximizeModeWindowManager::DisplayConfigurationChanged() { 253 void MaximizeModeWindowManager::DisplayConfigurationChanged() {
253 EnableBackdropBehindTopWindowOnEachDisplay(false); 254 EnableBackdropBehindTopWindowOnEachDisplay(false);
254 RemoveWindowCreationObservers(); 255 RemoveWindowCreationObservers();
255 AddWindowCreationObservers(); 256 AddWindowCreationObservers();
256 EnableBackdropBehindTopWindowOnEachDisplay(true); 257 EnableBackdropBehindTopWindowOnEachDisplay(true);
257 } 258 }
258 259
259 bool MaximizeModeWindowManager::IsContainerWindow(WmWindow* window) { 260 bool MaximizeModeWindowManager::IsContainerWindow(WmWindow* window) {
260 return ContainsKey(observed_container_windows_, window); 261 return base::ContainsKey(observed_container_windows_, window);
261 } 262 }
262 263
263 void MaximizeModeWindowManager::EnableBackdropBehindTopWindowOnEachDisplay( 264 void MaximizeModeWindowManager::EnableBackdropBehindTopWindowOnEachDisplay(
264 bool enable) { 265 bool enable) {
265 // 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.
266 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 267 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
267 switches::kAshDisableMaximizeModeWindowBackdrop)) { 268 switches::kAshDisableMaximizeModeWindowBackdrop)) {
268 return; 269 return;
269 } 270 }
270 271
271 if (backdrops_hidden_) 272 if (backdrops_hidden_)
272 return; 273 return;
273 274
274 // Inform the WorkspaceLayoutManager that we want to show a backdrop behind 275 // Inform the WorkspaceLayoutManager that we want to show a backdrop behind
275 // the topmost window of its container. 276 // the topmost window of its container.
276 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) { 277 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) {
277 WmRootWindowController* controller = root->GetRootWindowController(); 278 WmRootWindowController* controller = root->GetRootWindowController();
278 WmWindow* default_container = 279 WmWindow* default_container =
279 root->GetChildByShellWindowId(kShellWindowId_DefaultContainer); 280 root->GetChildByShellWindowId(kShellWindowId_DefaultContainer);
280 controller->SetMaximizeBackdropDelegate(base::WrapUnique( 281 controller->SetMaximizeBackdropDelegate(base::WrapUnique(
281 enable ? new WorkspaceBackdropDelegate(default_container) : nullptr)); 282 enable ? new WorkspaceBackdropDelegate(default_container) : nullptr));
282 } 283 }
283 } 284 }
284 285
285 } // namespace ash 286 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/accelerators/accelerator_router.cc ('k') | ash/display/display_animator_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698