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

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

Issue 2108223002: Moves handful of classes in ash/wm/maximize_mode to ash/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@maximize_mode_window_manager
Patch Set: remove extraneous 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h"
6
7 #include "ash/common/ash_switches.h"
8 #include "ash/common/session/session_state_delegate.h"
9 #include "ash/common/shell_window_ids.h"
10 #include "ash/common/wm/maximize_mode/maximize_mode_event_handler.h"
11 #include "ash/common/wm/mru_window_tracker.h"
12 #include "ash/common/wm/overview/window_selector_controller.h"
13 #include "ash/common/wm/window_state.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"
17 #include "ash/common/wm_window.h"
18 #include "ash/common/wm_window_property.h"
19 #include "ash/wm/maximize_mode/maximize_mode_window_state.h"
20 #include "ash/wm/maximize_mode/workspace_backdrop_delegate.h"
21 #include "base/command_line.h"
22 #include "base/memory/ptr_util.h"
23 #include "base/stl_util.h"
24 #include "ui/display/screen.h"
25
26 namespace ash {
27
28 namespace {
29
30 // Exits overview mode if it is currently active.
31 void CancelOverview() {
32 WindowSelectorController* controller =
33 WmShell::Get()->window_selector_controller();
34 if (controller->IsSelecting())
35 controller->OnSelectionEnded();
36 }
37
38 } // namespace
39
40 MaximizeModeWindowManager::~MaximizeModeWindowManager() {
41 // Overview mode needs to be ended before exiting maximize mode to prevent
42 // transforming windows which are currently in
43 // overview: http://crbug.com/366605
44 CancelOverview();
45
46 WmShell::Get()->RemoveShellObserver(this);
47 display::Screen::GetScreen()->RemoveObserver(this);
48 EnableBackdropBehindTopWindowOnEachDisplay(false);
49 RemoveWindowCreationObservers();
50 RestoreAllWindows();
51 }
52
53 int MaximizeModeWindowManager::GetNumberOfManagedWindows() {
54 return window_state_map_.size();
55 }
56
57 void MaximizeModeWindowManager::AddWindow(WmWindow* window) {
58 // Only add the window if it is a direct dependent of a container window
59 // and not yet tracked.
60 if (!ShouldHandleWindow(window) || ContainsKey(window_state_map_, window) ||
61 !IsContainerWindow(window->GetParent())) {
62 return;
63 }
64
65 MaximizeAndTrackWindow(window);
66 }
67
68 void MaximizeModeWindowManager::WindowStateDestroyed(WmWindow* window) {
69 // At this time ForgetWindow() should already have been called. If not,
70 // someone else must have replaced the "window manager's state object".
71 DCHECK(!window->HasObserver(this));
72
73 auto it = window_state_map_.find(window);
74 DCHECK(it != window_state_map_.end());
75 window_state_map_.erase(it);
76 }
77
78 void MaximizeModeWindowManager::OnOverviewModeStarting() {
79 if (backdrops_hidden_)
80 return;
81
82 EnableBackdropBehindTopWindowOnEachDisplay(false);
83 SetDeferBoundsUpdates(true);
84 backdrops_hidden_ = true;
85 }
86
87 void MaximizeModeWindowManager::OnOverviewModeEnded() {
88 if (!backdrops_hidden_)
89 return;
90
91 backdrops_hidden_ = false;
92 EnableBackdropBehindTopWindowOnEachDisplay(true);
93 SetDeferBoundsUpdates(false);
94 }
95
96 void MaximizeModeWindowManager::OnWindowDestroying(WmWindow* window) {
97 if (IsContainerWindow(window)) {
98 // container window can be removed on display destruction.
99 window->RemoveObserver(this);
100 observed_container_windows_.erase(window);
101 } else {
102 // If a known window gets destroyed we need to remove all knowledge about
103 // it.
104 ForgetWindow(window);
105 }
106 }
107
108 void MaximizeModeWindowManager::OnWindowTreeChanged(
109 WmWindow* window,
110 const TreeChangeParams& params) {
111 // 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 !ContainsKey(window_state_map_, params.target)) {
114 MaximizeAndTrackWindow(params.target);
115 // 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 if (ContainsKey(window_state_map_, params.target)) {
118 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE);
119 params.target->GetWindowState()->OnWMEvent(&event);
120 }
121 }
122 }
123
124 void MaximizeModeWindowManager::OnWindowPropertyChanged(
125 WmWindow* window,
126 WmWindowProperty property) {
127 // Stop managing |window| if the always-on-top property is added.
128 if (property == WmWindowProperty::ALWAYS_ON_TOP && window->IsAlwaysOnTop())
129 ForgetWindow(window);
130 }
131
132 void MaximizeModeWindowManager::OnWindowBoundsChanged(
133 WmWindow* window,
134 const gfx::Rect& old_bounds,
135 const gfx::Rect& new_bounds) {
136 if (!IsContainerWindow(window))
137 return;
138 // Reposition all non maximizeable windows.
139 for (auto& pair : window_state_map_)
140 pair.second->UpdateWindowPosition(pair.first->GetWindowState());
141 }
142
143 void MaximizeModeWindowManager::OnDisplayAdded(
144 const display::Display& display) {
145 DisplayConfigurationChanged();
146 }
147
148 void MaximizeModeWindowManager::OnDisplayRemoved(
149 const display::Display& display) {
150 DisplayConfigurationChanged();
151 }
152
153 void MaximizeModeWindowManager::OnDisplayMetricsChanged(const display::Display&,
154 uint32_t) {
155 // Nothing to do here.
156 }
157
158 MaximizeModeWindowManager::MaximizeModeWindowManager()
159 : backdrops_hidden_(false) {
160 // The overview mode needs to be ended before the maximize mode is started. To
161 // guarantee the proper order, it will be turned off from here.
162 CancelOverview();
163
164 MaximizeAllWindows();
165 AddWindowCreationObservers();
166 EnableBackdropBehindTopWindowOnEachDisplay(true);
167 display::Screen::GetScreen()->AddObserver(this);
168 WmShell::Get()->AddShellObserver(this);
169 event_handler_ = WmShell::Get()->CreateMaximizeModeEventHandler();
170 }
171
172 void MaximizeModeWindowManager::MaximizeAllWindows() {
173 MruWindowTracker::WindowList windows =
174 WmShell::Get()->GetMruWindowTracker()->BuildWindowListIgnoreModal();
175 // Add all existing Mru windows.
176 for (WmWindow* window : windows)
177 MaximizeAndTrackWindow(window);
178 }
179
180 void MaximizeModeWindowManager::RestoreAllWindows() {
181 while (window_state_map_.size())
182 ForgetWindow(window_state_map_.begin()->first);
183 }
184
185 void MaximizeModeWindowManager::SetDeferBoundsUpdates(
186 bool defer_bounds_updates) {
187 for (auto& pair : window_state_map_)
188 pair.second->SetDeferBoundsUpdates(defer_bounds_updates);
189 }
190
191 void MaximizeModeWindowManager::MaximizeAndTrackWindow(WmWindow* window) {
192 if (!ShouldHandleWindow(window))
193 return;
194
195 DCHECK(!ContainsKey(window_state_map_, window));
196 window->AddObserver(this);
197
198 // We create and remember a maximize mode state which will attach itself to
199 // the provided state object.
200 window_state_map_[window] = new MaximizeModeWindowState(window, this);
201 }
202
203 void MaximizeModeWindowManager::ForgetWindow(WmWindow* window) {
204 WindowToState::iterator it = window_state_map_.find(window);
205
206 // 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 // which replaces the state object and therefore this should not happen.
209 DCHECK(it != window_state_map_.end());
210 window->RemoveObserver(this);
211
212 // By telling the state object to revert, it will switch back the old
213 // State object and destroy itself, calling WindowStateDestroyed().
214 it->second->LeaveMaximizeMode(it->first->GetWindowState());
215 DCHECK(!ContainsKey(window_state_map_, window));
216 }
217
218 bool MaximizeModeWindowManager::ShouldHandleWindow(WmWindow* window) {
219 DCHECK(window);
220
221 // Windows with the always-on-top property should be free-floating and thus
222 // not managed by us.
223 if (window->IsAlwaysOnTop())
224 return false;
225
226 // Windows in the dock should not be managed by us.
227 if (window->GetWindowState()->IsDocked())
228 return false;
229
230 return window->GetType() == ui::wm::WINDOW_TYPE_NORMAL;
231 }
232
233 void MaximizeModeWindowManager::AddWindowCreationObservers() {
234 DCHECK(observed_container_windows_.empty());
235 // Observe window activations/creations in the default containers on all root
236 // windows.
237 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) {
238 WmWindow* default_container =
239 root->GetChildByShellWindowId(kShellWindowId_DefaultContainer);
240 DCHECK(!ContainsKey(observed_container_windows_, default_container));
241 default_container->AddObserver(this);
242 observed_container_windows_.insert(default_container);
243 }
244 }
245
246 void MaximizeModeWindowManager::RemoveWindowCreationObservers() {
247 for (WmWindow* window : observed_container_windows_)
248 window->RemoveObserver(this);
249 observed_container_windows_.clear();
250 }
251
252 void MaximizeModeWindowManager::DisplayConfigurationChanged() {
253 EnableBackdropBehindTopWindowOnEachDisplay(false);
254 RemoveWindowCreationObservers();
255 AddWindowCreationObservers();
256 EnableBackdropBehindTopWindowOnEachDisplay(true);
257 }
258
259 bool MaximizeModeWindowManager::IsContainerWindow(WmWindow* window) {
260 return ContainsKey(observed_container_windows_, window);
261 }
262
263 void MaximizeModeWindowManager::EnableBackdropBehindTopWindowOnEachDisplay(
264 bool enable) {
265 // This function should be a no-op if backdrops have been disabled.
266 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
267 switches::kAshDisableMaximizeModeWindowBackdrop)) {
268 return;
269 }
270
271 if (backdrops_hidden_)
272 return;
273
274 // Inform the WorkspaceLayoutManager that we want to show a backdrop behind
275 // the topmost window of its container.
276 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) {
277 WmRootWindowController* controller = root->GetRootWindowController();
278 WmWindow* default_container =
279 root->GetChildByShellWindowId(kShellWindowId_DefaultContainer);
280 controller->SetMaximizeBackdropDelegate(base::WrapUnique(
281 enable ? new WorkspaceBackdropDelegate(default_container) : nullptr));
282 }
283 }
284
285 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_window_manager.h ('k') | ash/wm/maximize_mode/maximize_mode_window_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698