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

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

Issue 169643005: Adding a gray semi transparent backdrop behind the topmost window within the default container (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing build problem Created 6 years, 9 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 | Annotate | Revision Log
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/root_window_controller.h"
7 #include "ash/shell.h" 8 #include "ash/shell.h"
8 #include "ash/switchable_windows.h" 9 #include "ash/shell_window_ids.h"
10 #include "ash/wm/maximize_mode/workspace_backdrop_delegate.h"
9 #include "ash/wm/mru_window_tracker.h" 11 #include "ash/wm/mru_window_tracker.h"
12 #include "ash/wm/workspace_controller.h"
10 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
11 #include "ui/gfx/screen.h" 14 #include "ui/gfx/screen.h"
12 15
13 namespace ash { 16 namespace ash {
14 namespace internal { 17 namespace internal {
15 18
16 MaximizeModeWindowManager::~MaximizeModeWindowManager() { 19 MaximizeModeWindowManager::~MaximizeModeWindowManager() {
20 Shell::GetInstance()->RemoveShellObserver(this);
17 Shell::GetScreen()->RemoveObserver(this); 21 Shell::GetScreen()->RemoveObserver(this);
22 EnableBackdropBehindTopWindowOnEachDisplay(false);
18 RemoveWindowCreationObservers(); 23 RemoveWindowCreationObservers();
19 RestoreAllWindows(); 24 RestoreAllWindows();
20 } 25 }
21 26
22 int MaximizeModeWindowManager::GetNumberOfManagedWindows() { 27 int MaximizeModeWindowManager::GetNumberOfManagedWindows() {
23 return initial_state_type_.size(); 28 return initial_state_type_.size();
24 } 29 }
25 30
31 void MaximizeModeWindowManager::OnOverviewModeStarted() {
32 if (backdrops_hidden_)
33 return;
34
35 EnableBackdropBehindTopWindowOnEachDisplay(false);
36 backdrops_hidden_ = true;
37 }
38
39 void MaximizeModeWindowManager::OnOverviewModeEnded() {
40 if (!backdrops_hidden_)
41 return;
42
43 backdrops_hidden_ = false;
44 EnableBackdropBehindTopWindowOnEachDisplay(true);
45 }
46
26 void MaximizeModeWindowManager::OnWindowDestroying(aura::Window* window) { 47 void MaximizeModeWindowManager::OnWindowDestroying(aura::Window* window) {
27 // If a known window gets destroyed we need to remove all knowledge about it. 48 // If a known window gets destroyed we need to remove all knowledge about it.
28 if (!IsContainerWindow(window)) 49 if (!IsContainerWindow(window))
29 ForgetWindow(window); 50 ForgetWindow(window);
30 } 51 }
31 52
32 void MaximizeModeWindowManager::OnWindowAdded( 53 void MaximizeModeWindowManager::OnWindowAdded(
33 aura::Window* window) { 54 aura::Window* window) {
34 // A window can get removed and then re-added by a drag and drop operation. 55 // A window can get removed and then re-added by a drag and drop operation.
35 if (IsContainerWindow(window->parent()) && 56 if (IsContainerWindow(window->parent()) &&
(...skipping 22 matching lines...) Expand all
58 } 79 }
59 80
60 void MaximizeModeWindowManager::OnDisplayAdded(const gfx::Display& display) { 81 void MaximizeModeWindowManager::OnDisplayAdded(const gfx::Display& display) {
61 DisplayConfigurationChanged(); 82 DisplayConfigurationChanged();
62 } 83 }
63 84
64 void MaximizeModeWindowManager::OnDisplayRemoved(const gfx::Display& display) { 85 void MaximizeModeWindowManager::OnDisplayRemoved(const gfx::Display& display) {
65 DisplayConfigurationChanged(); 86 DisplayConfigurationChanged();
66 } 87 }
67 88
68 MaximizeModeWindowManager::MaximizeModeWindowManager() { 89 MaximizeModeWindowManager::MaximizeModeWindowManager()
90 : backdrops_hidden_(false) {
91 // TODO(skuhne): Turn off the overview mode and full screen modes before
92 // entering the MaximzieMode.
69 MaximizeAllWindows(); 93 MaximizeAllWindows();
70 AddWindowCreationObservers(); 94 AddWindowCreationObservers();
95 EnableBackdropBehindTopWindowOnEachDisplay(true);
71 Shell::GetScreen()->AddObserver(this); 96 Shell::GetScreen()->AddObserver(this);
97 Shell::GetInstance()->AddShellObserver(this);
72 } 98 }
73 99
74 void MaximizeModeWindowManager::MaximizeAllWindows() { 100 void MaximizeModeWindowManager::MaximizeAllWindows() {
75 MruWindowTracker::WindowList windows = 101 MruWindowTracker::WindowList windows =
76 MruWindowTracker::BuildWindowList(false); 102 MruWindowTracker::BuildWindowList(false);
77 // Add all existing Mru windows. 103 // Add all existing Mru windows.
78 for (MruWindowTracker::WindowList::iterator window = windows.begin(); 104 for (MruWindowTracker::WindowList::iterator window = windows.begin();
79 window != windows.end(); ++window) { 105 window != windows.end(); ++window) {
80 MaximizeAndTrackWindow(*window); 106 MaximizeAndTrackWindow(*window);
81 } 107 }
(...skipping 21 matching lines...) Expand all
103 // This window type should not be able to have a restore state set (since 129 // This window type should not be able to have a restore state set (since
104 // it cannot maximize). 130 // it cannot maximize).
105 DCHECK(!window_state->HasRestoreBounds()); 131 DCHECK(!window_state->HasRestoreBounds());
106 // Store the coordinates as restore coordinates. 132 // Store the coordinates as restore coordinates.
107 gfx::Rect initial_rect = window->bounds(); 133 gfx::Rect initial_rect = window->bounds();
108 if (window->parent()) 134 if (window->parent())
109 window_state->SetRestoreBoundsInParent(initial_rect); 135 window_state->SetRestoreBoundsInParent(initial_rect);
110 else 136 else
111 window_state->SetRestoreBoundsInScreen(initial_rect); 137 window_state->SetRestoreBoundsInScreen(initial_rect);
112 CenterWindow(window); 138 CenterWindow(window);
113 // TODO(skuhne): Add a background cover layer.
114 } else { 139 } else {
115 // Minimized windows can remain as they are. 140 // Minimized windows can remain as they are.
116 if (state != wm::WINDOW_STATE_TYPE_MINIMIZED) 141 if (state != wm::WINDOW_STATE_TYPE_MINIMIZED)
117 wm::GetWindowState(window)->Maximize(); 142 wm::GetWindowState(window)->Maximize();
118 } 143 }
119 } 144 }
120 window_state->set_can_be_dragged(false); 145 window_state->set_can_be_dragged(false);
121 } 146 }
122 147
123 void MaximizeModeWindowManager::RestoreAndForgetWindow( 148 void MaximizeModeWindowManager::RestoreAndForgetWindow(
124 aura::Window* window) { 149 aura::Window* window) {
125 wm::WindowStateType state = ForgetWindow(window); 150 wm::WindowStateType state = ForgetWindow(window);
126 wm::WindowState* window_state = wm::GetWindowState(window); 151 wm::WindowState* window_state = wm::GetWindowState(window);
127 window_state->set_can_be_dragged(true); 152 window_state->set_can_be_dragged(true);
128 // Restore window if it can be restored. 153 // Restore window if it can be restored.
129 if (state != wm::WINDOW_STATE_TYPE_MAXIMIZED) { 154 if (state != wm::WINDOW_STATE_TYPE_MAXIMIZED) {
130 if (!CanMaximize(window)) { 155 if (!CanMaximize(window)) {
131 // TODO(skuhne): Remove the background cover layer.
132 if (window_state->HasRestoreBounds()) { 156 if (window_state->HasRestoreBounds()) {
133 // TODO(skuhne): If the system shuts down in maximized mode, the proper 157 // TODO(skuhne): If the system shuts down in maximized mode, the proper
134 // restore coordinates should get saved. 158 // restore coordinates should get saved.
135 gfx::Rect initial_bounds = 159 gfx::Rect initial_bounds =
136 window->parent() ? window_state->GetRestoreBoundsInParent() : 160 window->parent() ? window_state->GetRestoreBoundsInParent() :
137 window_state->GetRestoreBoundsInScreen(); 161 window_state->GetRestoreBoundsInScreen();
138 window_state->ClearRestoreBounds(); 162 window_state->ClearRestoreBounds();
139 // TODO(skuhne): The screen might have changed and we should make sure 163 // TODO(skuhne): The screen might have changed and we should make sure
140 // that the bounds are in a visible area. 164 // that the bounds are in a visible area.
141 window->SetBounds(initial_bounds); 165 window->SetBounds(initial_bounds);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 work_area.x() + (work_area.width() - window_size.width()) / 2, 204 work_area.x() + (work_area.width() - window_size.width()) / 2,
181 work_area.y() + (work_area.height() - window_size.height()) / 2, 205 work_area.y() + (work_area.height() - window_size.height()) / 2,
182 window_size.width(), 206 window_size.width(),
183 window_size.height()); 207 window_size.height());
184 208
185 window->SetBounds(window_bounds); 209 window->SetBounds(window_bounds);
186 } 210 }
187 211
188 void MaximizeModeWindowManager::AddWindowCreationObservers() { 212 void MaximizeModeWindowManager::AddWindowCreationObservers() {
189 DCHECK(observed_container_windows_.empty()); 213 DCHECK(observed_container_windows_.empty());
190 // Observe window activations and switchable containers on all root windows 214 // Observe window activations/creations in the default containers on all root
191 // for newly created windows during overview. 215 // windows.
192 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 216 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
193 for (aura::Window::Windows::const_iterator iter = root_windows.begin(); 217 for (aura::Window::Windows::const_iterator iter = root_windows.begin();
194 iter != root_windows.end(); ++iter) { 218 iter != root_windows.end(); ++iter) {
195 for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) { 219 aura::Window* container = Shell::GetContainer(*iter,
196 aura::Window* container = Shell::GetContainer(*iter, 220 internal::kShellWindowId_DefaultContainer);
197 kSwitchableWindowContainerIds[i]); 221 DCHECK(observed_container_windows_.find(container) ==
198 DCHECK(observed_container_windows_.find(container) == 222 observed_container_windows_.end());
199 observed_container_windows_.end()); 223 container->AddObserver(this);
200 container->AddObserver(this); 224 observed_container_windows_.insert(container);
201 observed_container_windows_.insert(container);
202 }
203 } 225 }
204 } 226 }
205 227
206 void MaximizeModeWindowManager::RemoveWindowCreationObservers() { 228 void MaximizeModeWindowManager::RemoveWindowCreationObservers() {
207 for (std::set<aura::Window*>::iterator iter = 229 for (std::set<aura::Window*>::iterator iter =
208 observed_container_windows_.begin(); 230 observed_container_windows_.begin();
209 iter != observed_container_windows_.end(); ++iter) { 231 iter != observed_container_windows_.end(); ++iter) {
210 (*iter)->RemoveObserver(this); 232 (*iter)->RemoveObserver(this);
211 } 233 }
212 observed_container_windows_.clear(); 234 observed_container_windows_.clear();
213 } 235 }
214 236
215 void MaximizeModeWindowManager::DisplayConfigurationChanged() { 237 void MaximizeModeWindowManager::DisplayConfigurationChanged() {
238 EnableBackdropBehindTopWindowOnEachDisplay(false);
216 RemoveWindowCreationObservers(); 239 RemoveWindowCreationObservers();
217 AddWindowCreationObservers(); 240 AddWindowCreationObservers();
241 EnableBackdropBehindTopWindowOnEachDisplay(true);
218 } 242 }
219 243
220 bool MaximizeModeWindowManager::IsContainerWindow(aura::Window* window) { 244 bool MaximizeModeWindowManager::IsContainerWindow(aura::Window* window) {
221 return observed_container_windows_.find(window) != 245 return observed_container_windows_.find(window) !=
222 observed_container_windows_.end(); 246 observed_container_windows_.end();
223 } 247 }
224 248
249 void MaximizeModeWindowManager::EnableBackdropBehindTopWindowOnEachDisplay(
250 bool enable) {
251 if (backdrops_hidden_)
252 return;
253 // Inform the WorkspaceLayoutManager that we want to show a backdrop behind
254 // the topmost window of its container.
255 Shell::RootWindowControllerList controllers =
256 Shell::GetAllRootWindowControllers();
257 for (Shell::RootWindowControllerList::iterator iter = controllers.begin();
258 iter != controllers.end(); ++iter) {
259 RootWindowController* controller = *iter;
260 aura::Window* container = Shell::GetContainer(
261 controller->root_window(),
262 internal::kShellWindowId_DefaultContainer);
263 controller->workspace_controller()->SetMaximizeBackdropDelegate(
264 scoped_ptr<WorkspaceLayoutManagerDelegate>(
265 enable ? new WorkspaceBackdropDelegate(container) : NULL));
266 }
267 }
268
225 } // namespace internal 269 } // namespace internal
226 } // namespace ash 270 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_window_manager.h ('k') | ash/wm/maximize_mode/workspace_backdrop_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698