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

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

Issue 2887103002: Revert of Refactor backdrop (Closed)
Patch Set: Created 3 years, 7 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/wm/workspace/workspace_layout_manager.h" 5 #include "ash/wm/workspace/workspace_layout_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/keyboard/keyboard_observer_register.h" 9 #include "ash/keyboard/keyboard_observer_register.h"
10 #include "ash/public/cpp/shell_window_ids.h" 10 #include "ash/public/cpp/shell_window_ids.h"
11 #include "ash/root_window_controller.h" 11 #include "ash/root_window_controller.h"
12 #include "ash/screen_util.h" 12 #include "ash/screen_util.h"
13 #include "ash/session/session_controller.h" 13 #include "ash/session/session_controller.h"
14 #include "ash/shelf/wm_shelf.h" 14 #include "ash/shelf/wm_shelf.h"
15 #include "ash/shell.h" 15 #include "ash/shell.h"
16 #include "ash/wm/always_on_top_controller.h" 16 #include "ash/wm/always_on_top_controller.h"
17 #include "ash/wm/fullscreen_window_finder.h" 17 #include "ash/wm/fullscreen_window_finder.h"
18 #include "ash/wm/screen_pinning_controller.h" 18 #include "ash/wm/screen_pinning_controller.h"
19 #include "ash/wm/window_positioner.h" 19 #include "ash/wm/window_positioner.h"
20 #include "ash/wm/window_properties.h" 20 #include "ash/wm/window_properties.h"
21 #include "ash/wm/window_state.h" 21 #include "ash/wm/window_state.h"
22 #include "ash/wm/window_state_aura.h" 22 #include "ash/wm/window_state_aura.h"
23 #include "ash/wm/window_util.h" 23 #include "ash/wm/window_util.h"
24 #include "ash/wm/wm_event.h" 24 #include "ash/wm/wm_event.h"
25 #include "ash/wm/workspace/backdrop_controller.h" 25 #include "ash/wm/workspace/workspace_layout_manager_backdrop_delegate.h"
26 #include "ash/wm/workspace/backdrop_delegate.h"
27 #include "ash/wm_window.h" 26 #include "ash/wm_window.h"
28 #include "base/command_line.h" 27 #include "base/command_line.h"
29 #include "ui/aura/client/aura_constants.h" 28 #include "ui/aura/client/aura_constants.h"
30 #include "ui/base/ui_base_switches.h" 29 #include "ui/base/ui_base_switches.h"
31 #include "ui/compositor/layer.h" 30 #include "ui/compositor/layer.h"
32 #include "ui/display/display.h" 31 #include "ui/display/display.h"
33 #include "ui/display/screen.h" 32 #include "ui/display/screen.h"
34 #include "ui/keyboard/keyboard_controller.h" 33 #include "ui/keyboard/keyboard_controller.h"
35 #include "ui/keyboard/keyboard_controller_observer.h" 34 #include "ui/keyboard/keyboard_controller_observer.h"
36 #include "ui/wm/core/coordinate_conversion.h" 35 #include "ui/wm/core/coordinate_conversion.h"
37 #include "ui/wm/public/activation_client.h" 36 #include "ui/wm/public/activation_client.h"
38 37
39 namespace ash { 38 namespace ash {
40 39
41 WorkspaceLayoutManager::WorkspaceLayoutManager(aura::Window* window) 40 WorkspaceLayoutManager::WorkspaceLayoutManager(aura::Window* window)
42 : window_(window), 41 : window_(window),
43 root_window_(window->GetRootWindow()), 42 root_window_(window->GetRootWindow()),
44 root_window_controller_(RootWindowController::ForWindow(root_window_)), 43 root_window_controller_(RootWindowController::ForWindow(root_window_)),
45 work_area_in_parent_( 44 work_area_in_parent_(
46 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_)), 45 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_)),
47 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr), 46 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr),
48 keyboard_observer_(this) { 47 keyboard_observer_(this) {
49 Shell::Get()->AddShellObserver(this); 48 Shell::Get()->AddShellObserver(this);
50 Shell::Get()->activation_client()->AddObserver(this); 49 Shell::Get()->activation_client()->AddObserver(this);
51 root_window_->AddObserver(this); 50 root_window_->AddObserver(this);
52 display::Screen::GetScreen()->AddObserver(this); 51 display::Screen::GetScreen()->AddObserver(this);
53 DCHECK(window->GetProperty(kSnapChildrenToPixelBoundary)); 52 DCHECK(window->GetProperty(kSnapChildrenToPixelBoundary));
54 backdrop_controller_ = base::MakeUnique<BackdropController>(window_);
55 } 53 }
56 54
57 WorkspaceLayoutManager::~WorkspaceLayoutManager() { 55 WorkspaceLayoutManager::~WorkspaceLayoutManager() {
58 if (root_window_) 56 if (root_window_)
59 root_window_->RemoveObserver(this); 57 root_window_->RemoveObserver(this);
60 for (aura::Window* window : windows_) { 58 for (aura::Window* window : windows_) {
61 wm::WindowState* window_state = wm::GetWindowState(window); 59 wm::WindowState* window_state = wm::GetWindowState(window);
62 window_state->RemoveObserver(this); 60 window_state->RemoveObserver(this);
63 window->RemoveObserver(this); 61 window->RemoveObserver(this);
64 } 62 }
65 display::Screen::GetScreen()->RemoveObserver(this); 63 display::Screen::GetScreen()->RemoveObserver(this);
66 Shell::Get()->activation_client()->RemoveObserver(this); 64 Shell::Get()->activation_client()->RemoveObserver(this);
67 Shell::Get()->RemoveShellObserver(this); 65 Shell::Get()->RemoveShellObserver(this);
68 } 66 }
69 67
70 void WorkspaceLayoutManager::SetBackdropDelegate( 68 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate(
71 std::unique_ptr<BackdropDelegate> delegate) { 69 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) {
72 backdrop_controller_->SetBackdropDelegate(std::move(delegate)); 70 backdrop_delegate_ = std::move(delegate);
73 } 71 }
74 72
75 ////////////////////////////////////////////////////////////////////////////// 73 //////////////////////////////////////////////////////////////////////////////
76 // WorkspaceLayoutManager, aura::LayoutManager implementation: 74 // WorkspaceLayoutManager, aura::LayoutManager implementation:
77 75
78 void WorkspaceLayoutManager::OnWindowResized() {} 76 void WorkspaceLayoutManager::OnWindowResized() {}
79 77
80 void WorkspaceLayoutManager::OnWindowAddedToLayout(aura::Window* child) { 78 void WorkspaceLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
81 wm::WindowState* window_state = wm::GetWindowState(child); 79 wm::WindowState* window_state = wm::GetWindowState(child);
82 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); 80 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE);
83 window_state->OnWMEvent(&event); 81 window_state->OnWMEvent(&event);
84 windows_.insert(child); 82 windows_.insert(child);
85 child->AddObserver(this); 83 child->AddObserver(this);
86 window_state->AddObserver(this); 84 window_state->AddObserver(this);
87 UpdateShelfVisibility(); 85 UpdateShelfVisibility();
88 UpdateFullscreenState(); 86 UpdateFullscreenState();
89 87 if (backdrop_delegate_)
90 backdrop_controller_->OnWindowAddedToLayout(child); 88 backdrop_delegate_->OnWindowAddedToLayout(WmWindow::Get(child));
91 WindowPositioner::RearrangeVisibleWindowOnShow(WmWindow::Get(child)); 89 WindowPositioner::RearrangeVisibleWindowOnShow(WmWindow::Get(child));
92 if (Shell::Get()->screen_pinning_controller()->IsPinned()) 90 if (Shell::Get()->screen_pinning_controller()->IsPinned())
93 wm::GetWindowState(child)->DisableAlwaysOnTop(nullptr); 91 wm::GetWindowState(child)->DisableAlwaysOnTop(nullptr);
94 } 92 }
95 93
96 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { 94 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) {
97 windows_.erase(child); 95 windows_.erase(child);
98 child->RemoveObserver(this); 96 child->RemoveObserver(this);
99 wm::GetWindowState(child)->RemoveObserver(this); 97 wm::GetWindowState(child)->RemoveObserver(this);
100 98
101 if (child->layer()->GetTargetVisibility()) 99 if (child->layer()->GetTargetVisibility())
102 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove( 100 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(
103 WmWindow::Get(child)); 101 WmWindow::Get(child));
104 } 102 }
105 103
106 void WorkspaceLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { 104 void WorkspaceLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) {
107 UpdateShelfVisibility(); 105 UpdateShelfVisibility();
108 UpdateFullscreenState(); 106 UpdateFullscreenState();
109 backdrop_controller_->OnWindowRemovedFromLayout(child); 107 if (backdrop_delegate_)
108 backdrop_delegate_->OnWindowRemovedFromLayout(WmWindow::Get(child));
110 } 109 }
111 110
112 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, 111 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child,
113 bool visible) { 112 bool visible) {
114 wm::WindowState* window_state = wm::GetWindowState(child); 113 wm::WindowState* window_state = wm::GetWindowState(child);
115 // Attempting to show a minimized window. Unminimize it. 114 // Attempting to show a minimized window. Unminimize it.
116 if (visible && window_state->IsMinimized()) 115 if (visible && window_state->IsMinimized())
117 window_state->Unminimize(); 116 window_state->Unminimize();
118 117
119 if (child->layer()->GetTargetVisibility()) 118 if (child->layer()->GetTargetVisibility())
120 WindowPositioner::RearrangeVisibleWindowOnShow(WmWindow::Get(child)); 119 WindowPositioner::RearrangeVisibleWindowOnShow(WmWindow::Get(child));
121 else 120 else
122 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove( 121 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(
123 WmWindow::Get(child)); 122 WmWindow::Get(child));
124 UpdateFullscreenState(); 123 UpdateFullscreenState();
125 UpdateShelfVisibility(); 124 UpdateShelfVisibility();
126 backdrop_controller_->OnChildWindowVisibilityChanged(child, visible); 125 if (backdrop_delegate_) {
126 backdrop_delegate_->OnChildWindowVisibilityChanged(WmWindow::Get(child),
127 visible);
128 }
127 } 129 }
128 130
129 void WorkspaceLayoutManager::SetChildBounds(aura::Window* child, 131 void WorkspaceLayoutManager::SetChildBounds(aura::Window* child,
130 const gfx::Rect& requested_bounds) { 132 const gfx::Rect& requested_bounds) {
131 wm::SetBoundsEvent event(wm::WM_EVENT_SET_BOUNDS, requested_bounds); 133 wm::SetBoundsEvent event(wm::WM_EVENT_SET_BOUNDS, requested_bounds);
132 wm::GetWindowState(child)->OnWMEvent(&event); 134 wm::GetWindowState(child)->OnWMEvent(&event);
133 UpdateShelfVisibility(); 135 UpdateShelfVisibility();
134 } 136 }
135 137
136 ////////////////////////////////////////////////////////////////////////////// 138 //////////////////////////////////////////////////////////////////////////////
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 // the fullscreen state accordingly. 209 // the fullscreen state accordingly.
208 if (params.new_parent && params.new_parent->GetRootWindow() == root_window_) { 210 if (params.new_parent && params.new_parent->GetRootWindow() == root_window_) {
209 UpdateFullscreenState(); 211 UpdateFullscreenState();
210 UpdateShelfVisibility(); 212 UpdateShelfVisibility();
211 } 213 }
212 } 214 }
213 215
214 void WorkspaceLayoutManager::OnWindowPropertyChanged(aura::Window* window, 216 void WorkspaceLayoutManager::OnWindowPropertyChanged(aura::Window* window,
215 const void* key, 217 const void* key,
216 intptr_t old) { 218 intptr_t old) {
217 if (key == aura::client::kAlwaysOnTopKey) { 219 if (key == aura::client::kAlwaysOnTopKey &&
218 if (window->GetProperty(aura::client::kAlwaysOnTopKey)) { 220 window->GetProperty(aura::client::kAlwaysOnTopKey)) {
219 aura::Window* container = 221 aura::Window* container =
220 root_window_controller_->always_on_top_controller() 222 root_window_controller_->always_on_top_controller()
221 ->GetContainer(WmWindow::Get(window)) 223 ->GetContainer(WmWindow::Get(window))
222 ->aura_window(); 224 ->aura_window();
223 if (window->parent() != container) 225 if (window->parent() != container)
224 container->AddChild(window); 226 container->AddChild(window);
225 }
226 } else if (key == aura::client::kHasBackdrop) {
227 backdrop_controller_->UpdateBackdrop();
228 } 227 }
229 } 228 }
230 229
231 void WorkspaceLayoutManager::OnWindowStackingChanged(aura::Window* window) { 230 void WorkspaceLayoutManager::OnWindowStackingChanged(aura::Window* window) {
232 UpdateShelfVisibility(); 231 UpdateShelfVisibility();
233 UpdateFullscreenState(); 232 UpdateFullscreenState();
234 backdrop_controller_->OnWindowStackingChanged(window); 233 if (backdrop_delegate_)
234 backdrop_delegate_->OnWindowStackingChanged(WmWindow::Get(window));
235 } 235 }
236 236
237 void WorkspaceLayoutManager::OnWindowDestroying(aura::Window* window) { 237 void WorkspaceLayoutManager::OnWindowDestroying(aura::Window* window) {
238 if (root_window_ == window) { 238 if (root_window_ == window) {
239 root_window_->RemoveObserver(this); 239 root_window_->RemoveObserver(this);
240 root_window_ = nullptr; 240 root_window_ = nullptr;
241 } 241 }
242 } 242 }
243 243
244 void WorkspaceLayoutManager::OnWindowBoundsChanged( 244 void WorkspaceLayoutManager::OnWindowBoundsChanged(
(...skipping 30 matching lines...) Expand all
275 void WorkspaceLayoutManager::OnPostWindowStateTypeChange( 275 void WorkspaceLayoutManager::OnPostWindowStateTypeChange(
276 wm::WindowState* window_state, 276 wm::WindowState* window_state,
277 wm::WindowStateType old_type) { 277 wm::WindowStateType old_type) {
278 // Notify observers that fullscreen state may be changing. 278 // Notify observers that fullscreen state may be changing.
279 if (window_state->IsFullscreen() || 279 if (window_state->IsFullscreen() ||
280 old_type == wm::WINDOW_STATE_TYPE_FULLSCREEN) { 280 old_type == wm::WINDOW_STATE_TYPE_FULLSCREEN) {
281 UpdateFullscreenState(); 281 UpdateFullscreenState();
282 } 282 }
283 283
284 UpdateShelfVisibility(); 284 UpdateShelfVisibility();
285 backdrop_controller_->OnPostWindowStateTypeChange(window_state, old_type); 285 if (backdrop_delegate_)
286 backdrop_delegate_->OnPostWindowStateTypeChange(window_state, old_type);
286 } 287 }
287 288
288 ////////////////////////////////////////////////////////////////////////////// 289 //////////////////////////////////////////////////////////////////////////////
289 // WorkspaceLayoutManager, display::DisplayObserver implementation: 290 // WorkspaceLayoutManager, display::DisplayObserver implementation:
290 291
291 void WorkspaceLayoutManager::OnDisplayMetricsChanged( 292 void WorkspaceLayoutManager::OnDisplayMetricsChanged(
292 const display::Display& display, 293 const display::Display& display,
293 uint32_t changed_metrics) { 294 uint32_t changed_metrics) {
294 if (display::Screen::GetScreen()->GetDisplayNearestWindow(window_).id() != 295 if (display::Screen::GetScreen()->GetDisplayNearestWindow(window_).id() !=
295 display.id()) { 296 display.id()) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 for (aura::Window* window : windows) { 403 for (aura::Window* window : windows) {
403 wm::WindowState* window_state = wm::GetWindowState(window); 404 wm::WindowState* window_state = wm::GetWindowState(window);
404 if (window_on_top) 405 if (window_on_top)
405 window_state->DisableAlwaysOnTop(WmWindow::Get(window_on_top)); 406 window_state->DisableAlwaysOnTop(WmWindow::Get(window_on_top));
406 else 407 else
407 window_state->RestoreAlwaysOnTop(); 408 window_state->RestoreAlwaysOnTop();
408 } 409 }
409 } 410 }
410 411
411 } // namespace ash 412 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_layout_manager.h ('k') | ash/wm/workspace/workspace_layout_manager_backdrop_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698