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

Side by Side Diff: ash/common/wm/workspace/workspace_layout_manager.cc

Issue 2234033002: mash: Remove WorkspaceLayoutManagerDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove WmRootWindowControllerObserver::OnFullscreenStateChanged; use ShellObserver. 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/workspace/workspace_layout_manager.h" 5 #include "ash/common/wm/workspace/workspace_layout_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/common/ash_switches.h" 9 #include "ash/common/ash_switches.h"
10 #include "ash/common/session/session_state_delegate.h" 10 #include "ash/common/session/session_state_delegate.h"
11 #include "ash/common/shelf/wm_shelf.h"
12 #include "ash/common/shell_window_ids.h"
11 #include "ash/common/wm/always_on_top_controller.h" 13 #include "ash/common/wm/always_on_top_controller.h"
12 #include "ash/common/wm/fullscreen_window_finder.h" 14 #include "ash/common/wm/fullscreen_window_finder.h"
13 #include "ash/common/wm/window_positioner.h" 15 #include "ash/common/wm/window_positioner.h"
14 #include "ash/common/wm/window_state.h" 16 #include "ash/common/wm/window_state.h"
15 #include "ash/common/wm/wm_event.h" 17 #include "ash/common/wm/wm_event.h"
16 #include "ash/common/wm/wm_screen_util.h" 18 #include "ash/common/wm/wm_screen_util.h"
17 #include "ash/common/wm/workspace/workspace_layout_manager_backdrop_delegate.h" 19 #include "ash/common/wm/workspace/workspace_layout_manager_backdrop_delegate.h"
18 #include "ash/common/wm/workspace/workspace_layout_manager_delegate.h"
19 #include "ash/common/wm_root_window_controller.h" 20 #include "ash/common/wm_root_window_controller.h"
20 #include "ash/common/wm_shell.h" 21 #include "ash/common/wm_shell.h"
21 #include "ash/common/wm_window.h" 22 #include "ash/common/wm_window.h"
22 #include "ash/common/wm_window_property.h" 23 #include "ash/common/wm_window_property.h"
23 #include "base/command_line.h" 24 #include "base/command_line.h"
24 #include "ui/compositor/layer.h" 25 #include "ui/compositor/layer.h"
25 #include "ui/keyboard/keyboard_controller.h" 26 #include "ui/keyboard/keyboard_controller.h"
26 #include "ui/keyboard/keyboard_controller_observer.h" 27 #include "ui/keyboard/keyboard_controller_observer.h"
27 28
28 namespace ash { 29 namespace ash {
29 30
30 WorkspaceLayoutManager::WorkspaceLayoutManager( 31 WorkspaceLayoutManager::WorkspaceLayoutManager(WmWindow* window)
31 WmWindow* window,
32 std::unique_ptr<wm::WorkspaceLayoutManagerDelegate> delegate)
33 : window_(window), 32 : window_(window),
34 root_window_(window->GetRootWindow()), 33 root_window_(window->GetRootWindow()),
35 root_window_controller_(root_window_->GetRootWindowController()), 34 root_window_controller_(root_window_->GetRootWindowController()),
36 shell_(window_->GetShell()), 35 shell_(window_->GetShell()),
37 delegate_(std::move(delegate)),
38 work_area_in_parent_(wm::GetDisplayWorkAreaBounds(window_)), 36 work_area_in_parent_(wm::GetDisplayWorkAreaBounds(window_)),
39 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr) { 37 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr) {
40 shell_->AddShellObserver(this); 38 shell_->AddShellObserver(this);
41 shell_->AddActivationObserver(this); 39 shell_->AddActivationObserver(this);
42 root_window_->AddObserver(this); 40 root_window_->AddObserver(this);
43 root_window_controller_->AddObserver(this); 41 root_window_controller_->AddObserver(this);
44 DCHECK(window->GetBoolProperty( 42 DCHECK(window->GetBoolProperty(
45 WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY)); 43 WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY));
46 } 44 }
47 45
48 WorkspaceLayoutManager::~WorkspaceLayoutManager() { 46 WorkspaceLayoutManager::~WorkspaceLayoutManager() {
49 if (root_window_) 47 if (root_window_)
50 root_window_->RemoveObserver(this); 48 root_window_->RemoveObserver(this);
51 for (WmWindow* window : windows_) { 49 for (WmWindow* window : windows_) {
52 wm::WindowState* window_state = window->GetWindowState(); 50 wm::WindowState* window_state = window->GetWindowState();
53 window_state->RemoveObserver(this); 51 window_state->RemoveObserver(this);
54 window->RemoveObserver(this); 52 window->RemoveObserver(this);
55 } 53 }
56 root_window_->GetRootWindowController()->RemoveObserver(this); 54 root_window_->GetRootWindowController()->RemoveObserver(this);
57 shell_->RemoveActivationObserver(this); 55 shell_->RemoveActivationObserver(this);
58 shell_->RemoveShellObserver(this); 56 shell_->RemoveShellObserver(this);
59 } 57 }
60 58
61 void WorkspaceLayoutManager::DeleteDelegate() {
62 delegate_.reset();
63 }
64
65 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate( 59 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate(
66 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { 60 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) {
67 backdrop_delegate_.reset(delegate.release()); 61 backdrop_delegate_.reset(delegate.release());
68 } 62 }
69 63
70 ////////////////////////////////////////////////////////////////////////////// 64 //////////////////////////////////////////////////////////////////////////////
71 // WorkspaceLayoutManager, aura::LayoutManager implementation: 65 // WorkspaceLayoutManager, aura::LayoutManager implementation:
72 66
73 void WorkspaceLayoutManager::OnWindowResized() {} 67 void WorkspaceLayoutManager::OnWindowResized() {}
74 68
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 void WorkspaceLayoutManager::OnWorkAreaChanged() { 179 void WorkspaceLayoutManager::OnWorkAreaChanged() {
186 const gfx::Rect work_area(wm::GetDisplayWorkAreaBounds(window_)); 180 const gfx::Rect work_area(wm::GetDisplayWorkAreaBounds(window_));
187 if (work_area != work_area_in_parent_) { 181 if (work_area != work_area_in_parent_) {
188 const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); 182 const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED);
189 AdjustAllWindowsBoundsForWorkAreaChange(&event); 183 AdjustAllWindowsBoundsForWorkAreaChange(&event);
190 } 184 }
191 if (backdrop_delegate_) 185 if (backdrop_delegate_)
192 backdrop_delegate_->OnDisplayWorkAreaInsetsChanged(); 186 backdrop_delegate_->OnDisplayWorkAreaInsetsChanged();
193 } 187 }
194 188
195 void WorkspaceLayoutManager::OnFullscreenStateChanged(bool is_fullscreen) {
196 if (is_fullscreen_ == is_fullscreen)
197 return;
198
199 is_fullscreen_ = is_fullscreen;
200 if (WmShell::Get()->IsPinned()) {
201 // If this is in pinned mode, then this event does not trigger the
202 // always-on-top state change, because it is kept disabled regardless of
203 // the fullscreen state change.
204 return;
205 }
206
207 UpdateAlwaysOnTop(is_fullscreen_ ? wm::GetWindowForFullscreenMode(window_)
208 : nullptr);
209 }
210
211 ////////////////////////////////////////////////////////////////////////////// 189 //////////////////////////////////////////////////////////////////////////////
212 // WorkspaceLayoutManager, aura::WindowObserver implementation: 190 // WorkspaceLayoutManager, aura::WindowObserver implementation:
213 191
214 void WorkspaceLayoutManager::OnWindowTreeChanged( 192 void WorkspaceLayoutManager::OnWindowTreeChanged(
215 WmWindow* window, 193 WmWindow* window,
216 const WmWindowObserver::TreeChangeParams& params) { 194 const WmWindowObserver::TreeChangeParams& params) {
217 if (!params.target->GetWindowState()->IsActive()) 195 if (!params.target->GetWindowState()->IsActive())
218 return; 196 return;
219 // If the window is already tracked by the workspace this update would be 197 // If the window is already tracked by the workspace this update would be
220 // redundant as the fullscreen and shelf state would have been handled in 198 // redundant as the fullscreen and shelf state would have been handled in
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 277 }
300 278
301 UpdateShelfVisibility(); 279 UpdateShelfVisibility();
302 if (backdrop_delegate_) 280 if (backdrop_delegate_)
303 backdrop_delegate_->OnPostWindowStateTypeChange(window_state, old_type); 281 backdrop_delegate_->OnPostWindowStateTypeChange(window_state, old_type);
304 } 282 }
305 283
306 ////////////////////////////////////////////////////////////////////////////// 284 //////////////////////////////////////////////////////////////////////////////
307 // WorkspaceLayoutManager, ShellObserver implementation: 285 // WorkspaceLayoutManager, ShellObserver implementation:
308 286
287 void WorkspaceLayoutManager::OnFullscreenStateChanged(bool is_fullscreen,
288 WmWindow* root_window) {
289 if (root_window != root_window_ || is_fullscreen_ == is_fullscreen)
290 return;
291
292 is_fullscreen_ = is_fullscreen;
293 if (WmShell::Get()->IsPinned()) {
294 // If this is in pinned mode, then this event does not trigger the
295 // always-on-top state change, because it is kept disabled regardless of
296 // the fullscreen state change.
297 return;
298 }
299
300 UpdateAlwaysOnTop(is_fullscreen_ ? wm::GetWindowForFullscreenMode(window_)
301 : nullptr);
302 }
303
309 void WorkspaceLayoutManager::OnPinnedStateChanged(WmWindow* pinned_window) { 304 void WorkspaceLayoutManager::OnPinnedStateChanged(WmWindow* pinned_window) {
310 if (!WmShell::Get()->IsPinned() && is_fullscreen_) { 305 if (!WmShell::Get()->IsPinned() && is_fullscreen_) {
311 // On exiting from pinned mode, if the workspace is still in fullscreen 306 // On exiting from pinned mode, if the workspace is still in fullscreen
312 // mode, then this event does not trigger the restoring yet. On exiting 307 // mode, then this event does not trigger the restoring yet. On exiting
313 // from fullscreen, the temporarily disabled always-on-top property will be 308 // from fullscreen, the temporarily disabled always-on-top property will be
314 // restored. 309 // restored.
315 return; 310 return;
316 } 311 }
317 312
318 UpdateAlwaysOnTop(WmShell::Get()->IsPinned() ? pinned_window : nullptr); 313 UpdateAlwaysOnTop(WmShell::Get()->IsPinned() ? pinned_window : nullptr);
(...skipping 19 matching lines...) Expand all
338 // If a user plugs an external display into a laptop running Aura the 333 // If a user plugs an external display into a laptop running Aura the
339 // display size will change. Maximized windows need to resize to match. 334 // display size will change. Maximized windows need to resize to match.
340 // We also do this when developers running Aura on a desktop manually resize 335 // We also do this when developers running Aura on a desktop manually resize
341 // the host window. 336 // the host window.
342 // We also need to do this when the work area insets changes. 337 // We also need to do this when the work area insets changes.
343 for (WmWindow* window : windows_) 338 for (WmWindow* window : windows_)
344 window->GetWindowState()->OnWMEvent(event); 339 window->GetWindowState()->OnWMEvent(event);
345 } 340 }
346 341
347 void WorkspaceLayoutManager::UpdateShelfVisibility() { 342 void WorkspaceLayoutManager::UpdateShelfVisibility() {
348 if (delegate_) 343 if (root_window_controller_->HasShelf())
349 delegate_->UpdateShelfVisibility(); 344 root_window_controller_->GetShelf()->UpdateVisibilityState();
350 } 345 }
351 346
352 void WorkspaceLayoutManager::UpdateFullscreenState() { 347 void WorkspaceLayoutManager::UpdateFullscreenState() {
353 // TODO(flackr): The fullscreen state is currently tracked per workspace 348 // TODO(flackr): The fullscreen state is currently tracked per workspace
354 // but the shell notification implies a per root window state. Currently 349 // but the shell notification implies a per root window state. Currently
355 // only windows in the default workspace container will go fullscreen but 350 // only windows in the default workspace container will go fullscreen but
356 // this should really be tracked by the RootWindowController since 351 // this should really be tracked by the RootWindowController since
357 // technically any container could get a fullscreen window. 352 // technically any container could get a fullscreen window.
358 if (!delegate_) 353 if (window_->GetShellWindowId() != kShellWindowId_DefaultContainer)
359 return; 354 return;
360 bool is_fullscreen = wm::GetWindowForFullscreenMode(window_) != nullptr; 355 bool is_fullscreen = wm::GetWindowForFullscreenMode(window_) != nullptr;
361 if (is_fullscreen != is_fullscreen_) { 356 if (is_fullscreen != is_fullscreen_) {
362 delegate_->OnFullscreenStateChanged(is_fullscreen); 357 WmShell::Get()->NotifyFullscreenStateChanged(is_fullscreen, root_window_);
363 is_fullscreen_ = is_fullscreen; 358 is_fullscreen_ = is_fullscreen;
364 } 359 }
365 } 360 }
366 361
367 void WorkspaceLayoutManager::UpdateAlwaysOnTop(WmWindow* window_on_top) { 362 void WorkspaceLayoutManager::UpdateAlwaysOnTop(WmWindow* window_on_top) {
368 // Changing always on top state may change window's parent. Iterate on a copy 363 // Changing always on top state may change window's parent. Iterate on a copy
369 // of |windows_| to avoid invalidating an iterator. Since both workspace and 364 // of |windows_| to avoid invalidating an iterator. Since both workspace and
370 // always_on_top containers' layouts are managed by this class all the 365 // always_on_top containers' layouts are managed by this class all the
371 // appropriate windows will be included in the iteration. 366 // appropriate windows will be included in the iteration.
372 WindowSet windows(windows_); 367 WindowSet windows(windows_);
373 for (auto* window : windows) { 368 for (auto* window : windows) {
374 wm::WindowState* window_state = window->GetWindowState(); 369 wm::WindowState* window_state = window->GetWindowState();
375 if (window_on_top) 370 if (window_on_top)
376 window_state->DisableAlwaysOnTop(window_on_top); 371 window_state->DisableAlwaysOnTop(window_on_top);
377 else 372 else
378 window_state->RestoreAlwaysOnTop(); 373 window_state->RestoreAlwaysOnTop();
379 } 374 }
380 } 375 }
381 376
382 } // namespace ash 377 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/workspace/workspace_layout_manager.h ('k') | ash/common/wm/workspace/workspace_layout_manager_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698