OLD | NEW |
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/root_window_controller.h" | |
10 #include "ash/screen_util.h" | |
11 #include "ash/session/session_state_delegate.h" | |
12 #include "ash/shell.h" | |
13 #include "ash/wm/always_on_top_controller.h" | 9 #include "ash/wm/always_on_top_controller.h" |
14 #include "ash/wm/aura/wm_window_aura.h" | 10 #include "ash/wm/common/fullscreen_window_finder.h" |
15 #include "ash/wm/common/window_state.h" | 11 #include "ash/wm/common/window_state.h" |
16 #include "ash/wm/common/wm_event.h" | 12 #include "ash/wm/common/wm_event.h" |
| 13 #include "ash/wm/common/wm_globals.h" |
| 14 #include "ash/wm/common/wm_root_window_controller.h" |
| 15 #include "ash/wm/common/wm_screen_util.h" |
| 16 #include "ash/wm/common/wm_window.h" |
| 17 #include "ash/wm/common/wm_window_property.h" |
17 #include "ash/wm/common/workspace/workspace_layout_manager_delegate.h" | 18 #include "ash/wm/common/workspace/workspace_layout_manager_delegate.h" |
18 #include "ash/wm/window_animations.h" | |
19 #include "ash/wm/window_positioner.h" | 19 #include "ash/wm/window_positioner.h" |
20 #include "ash/wm/window_properties.h" | |
21 #include "ash/wm/window_state_aura.h" | |
22 #include "ash/wm/window_util.h" | |
23 #include "ash/wm/workspace/workspace_layout_manager_backdrop_delegate.h" | 20 #include "ash/wm/workspace/workspace_layout_manager_backdrop_delegate.h" |
24 #include "ui/aura/client/aura_constants.h" | |
25 #include "ui/aura/window.h" | |
26 #include "ui/aura/window_observer.h" | |
27 #include "ui/base/ui_base_types.h" | |
28 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
29 #include "ui/display/screen.h" | |
30 #include "ui/events/event.h" | |
31 #include "ui/keyboard/keyboard_controller_observer.h" | 22 #include "ui/keyboard/keyboard_controller_observer.h" |
32 #include "ui/wm/core/window_util.h" | |
33 #include "ui/wm/public/activation_client.h" | |
34 | |
35 using aura::Window; | |
36 | 23 |
37 namespace ash { | 24 namespace ash { |
38 | 25 |
39 WorkspaceLayoutManager::WorkspaceLayoutManager( | 26 WorkspaceLayoutManager::WorkspaceLayoutManager( |
40 aura::Window* window, | 27 wm::WmWindow* window, |
41 std::unique_ptr<wm::WorkspaceLayoutManagerDelegate> delegate) | 28 std::unique_ptr<wm::WorkspaceLayoutManagerDelegate> delegate) |
42 : window_(window), | 29 : window_(window), |
43 root_window_(window->GetRootWindow()), | 30 root_window_(window->GetRootWindow()), |
| 31 root_window_controller_(root_window_->GetRootWindowController()), |
| 32 globals_(window_->GetGlobals()), |
44 delegate_(std::move(delegate)), | 33 delegate_(std::move(delegate)), |
45 work_area_in_parent_(ScreenUtil::ConvertRectFromScreen( | 34 work_area_in_parent_(wm::GetDisplayWorkAreaBounds(window_)), |
46 window_, | 35 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr) { |
47 display::Screen::GetScreen() | 36 globals_->AddActivationObserver(this); |
48 ->GetDisplayNearestWindow(window_) | |
49 .work_area())), | |
50 is_fullscreen_(GetRootWindowController(window->GetRootWindow()) | |
51 ->GetWindowForFullscreenMode() != NULL) { | |
52 Shell::GetInstance()->activation_client()->AddObserver(this); | |
53 Shell::GetInstance()->AddShellObserver(this); | |
54 root_window_->AddObserver(this); | 37 root_window_->AddObserver(this); |
55 DCHECK(window->GetProperty(kSnapChildrenToPixelBoundary)); | 38 root_window_controller_->AddObserver(this); |
| 39 DCHECK(window->GetBoolProperty( |
| 40 wm::WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUDARY)); |
56 } | 41 } |
57 | 42 |
58 WorkspaceLayoutManager::~WorkspaceLayoutManager() { | 43 WorkspaceLayoutManager::~WorkspaceLayoutManager() { |
59 if (root_window_) | 44 if (root_window_) |
60 root_window_->RemoveObserver(this); | 45 root_window_->RemoveObserver(this); |
61 for (WindowSet::const_iterator i = windows_.begin(); i != windows_.end(); ++i) | 46 for (wm::WmWindow* window : windows_) |
62 (*i)->RemoveObserver(this); | 47 window->RemoveObserver(this); |
63 Shell::GetInstance()->RemoveShellObserver(this); | 48 root_window_->GetRootWindowController()->RemoveObserver(this); |
64 Shell::GetInstance()->activation_client()->RemoveObserver(this); | 49 globals_->RemoveActivationObserver(this); |
65 } | 50 } |
66 | 51 |
67 void WorkspaceLayoutManager::DeleteDelegate() { | 52 void WorkspaceLayoutManager::DeleteDelegate() { |
68 delegate_.reset(); | 53 delegate_.reset(); |
69 } | 54 } |
70 | 55 |
71 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate( | 56 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate( |
72 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { | 57 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { |
73 backdrop_delegate_.reset(delegate.release()); | 58 backdrop_delegate_.reset(delegate.release()); |
74 } | 59 } |
75 | 60 |
76 ////////////////////////////////////////////////////////////////////////////// | 61 ////////////////////////////////////////////////////////////////////////////// |
77 // WorkspaceLayoutManager, aura::LayoutManager implementation: | 62 // WorkspaceLayoutManager, aura::LayoutManager implementation: |
78 | 63 |
79 void WorkspaceLayoutManager::OnWindowAddedToLayout(Window* child) { | 64 void WorkspaceLayoutManager::OnWindowResized() {} |
80 wm::WindowState* window_state = wm::GetWindowState(child); | 65 |
| 66 void WorkspaceLayoutManager::OnWindowAddedToLayout(wm::WmWindow* child) { |
| 67 wm::WindowState* window_state = child->GetWindowState(); |
81 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); | 68 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); |
82 window_state->OnWMEvent(&event); | 69 window_state->OnWMEvent(&event); |
83 windows_.insert(child); | 70 windows_.insert(child); |
84 child->AddObserver(this); | 71 child->AddObserver(this); |
85 window_state->AddObserver(this); | 72 window_state->AddObserver(this); |
86 UpdateShelfVisibility(); | 73 UpdateShelfVisibility(); |
87 UpdateFullscreenState(); | 74 UpdateFullscreenState(); |
88 if (backdrop_delegate_) | 75 if (backdrop_delegate_) |
89 backdrop_delegate_->OnWindowAddedToLayout(child); | 76 backdrop_delegate_->OnWindowAddedToLayout(child); |
90 WindowPositioner::RearrangeVisibleWindowOnShow(wm::WmWindowAura::Get(child)); | 77 WindowPositioner::RearrangeVisibleWindowOnShow(child); |
91 } | 78 } |
92 | 79 |
93 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(Window* child) { | 80 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(wm::WmWindow* child) { |
94 windows_.erase(child); | 81 windows_.erase(child); |
95 child->RemoveObserver(this); | 82 child->RemoveObserver(this); |
96 wm::GetWindowState(child)->RemoveObserver(this); | 83 child->GetWindowState()->RemoveObserver(this); |
97 | 84 |
98 if (child->TargetVisibility()) { | 85 if (child->GetTargetVisibility()) |
99 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove( | 86 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(child); |
100 wm::WmWindowAura::Get(child)); | |
101 } | |
102 } | 87 } |
103 | 88 |
104 void WorkspaceLayoutManager::OnWindowRemovedFromLayout(Window* child) { | 89 void WorkspaceLayoutManager::OnWindowRemovedFromLayout(wm::WmWindow* child) { |
105 UpdateShelfVisibility(); | 90 UpdateShelfVisibility(); |
106 UpdateFullscreenState(); | 91 UpdateFullscreenState(); |
107 if (backdrop_delegate_) | 92 if (backdrop_delegate_) |
108 backdrop_delegate_->OnWindowRemovedFromLayout(child); | 93 backdrop_delegate_->OnWindowRemovedFromLayout(child); |
109 } | 94 } |
110 | 95 |
111 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged(Window* child, | 96 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged(wm::WmWindow* child, |
112 bool visible) { | 97 bool visible) { |
113 wm::WindowState* window_state = wm::GetWindowState(child); | 98 wm::WindowState* window_state = child->GetWindowState(); |
114 // Attempting to show a minimized window. Unminimize it. | 99 // Attempting to show a minimized window. Unminimize it. |
115 if (visible && window_state->IsMinimized()) | 100 if (visible && window_state->IsMinimized()) |
116 window_state->Unminimize(); | 101 window_state->Unminimize(); |
117 | 102 |
118 if (child->TargetVisibility()) { | 103 if (child->GetTargetVisibility()) |
119 WindowPositioner::RearrangeVisibleWindowOnShow( | 104 WindowPositioner::RearrangeVisibleWindowOnShow(child); |
120 wm::WmWindowAura::Get(child)); | 105 else |
121 } else { | 106 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(child); |
122 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove( | |
123 wm::WmWindowAura::Get(child)); | |
124 } | |
125 UpdateFullscreenState(); | 107 UpdateFullscreenState(); |
126 UpdateShelfVisibility(); | 108 UpdateShelfVisibility(); |
127 if (backdrop_delegate_) | 109 if (backdrop_delegate_) |
128 backdrop_delegate_->OnChildWindowVisibilityChanged(child, visible); | 110 backdrop_delegate_->OnChildWindowVisibilityChanged(child, visible); |
129 } | 111 } |
130 | 112 |
131 void WorkspaceLayoutManager::SetChildBounds( | 113 void WorkspaceLayoutManager::SetChildBounds(wm::WmWindow* child, |
132 Window* child, | 114 const gfx::Rect& requested_bounds) { |
133 const gfx::Rect& requested_bounds) { | |
134 wm::WindowState* window_state = wm::GetWindowState(child); | |
135 wm::SetBoundsEvent event(wm::WM_EVENT_SET_BOUNDS, requested_bounds); | 115 wm::SetBoundsEvent event(wm::WM_EVENT_SET_BOUNDS, requested_bounds); |
136 window_state->OnWMEvent(&event); | 116 child->GetWindowState()->OnWMEvent(&event); |
137 UpdateShelfVisibility(); | 117 UpdateShelfVisibility(); |
138 } | 118 } |
139 | 119 |
140 ////////////////////////////////////////////////////////////////////////////// | 120 ////////////////////////////////////////////////////////////////////////////// |
141 // WorkspaceLayoutManager, keyboard::KeyboardControllerObserver implementation: | 121 // WorkspaceLayoutManager, keyboard::KeyboardControllerObserver implementation: |
142 | 122 |
143 void WorkspaceLayoutManager::OnKeyboardBoundsChanging( | 123 void WorkspaceLayoutManager::OnKeyboardBoundsChanging( |
144 const gfx::Rect& new_bounds) { | 124 const gfx::Rect& new_bounds) { |
145 aura::Window* window = wm::GetActiveWindow()->GetToplevelWindow(); | 125 wm::WmWindow* window = globals_->GetActiveWindow(); |
146 if (!window || !window_->Contains(window)) | 126 if (!window) |
147 return; | 127 return; |
148 wm::WindowState* window_state = wm::GetWindowState(window); | 128 |
| 129 window = window->GetToplevelWindow(); |
| 130 if (!window_->Contains(window)) |
| 131 return; |
| 132 wm::WindowState* window_state = window->GetWindowState(); |
149 if (!new_bounds.IsEmpty()) { | 133 if (!new_bounds.IsEmpty()) { |
150 // Store existing bounds to be restored before resizing for keyboard if it | 134 // Store existing bounds to be restored before resizing for keyboard if it |
151 // is not already stored. | 135 // is not already stored. |
152 if (!window_state->HasRestoreBounds()) | 136 if (!window_state->HasRestoreBounds()) |
153 window_state->SaveCurrentBoundsForRestore(); | 137 window_state->SaveCurrentBoundsForRestore(); |
154 | 138 |
155 gfx::Rect window_bounds = ScreenUtil::ConvertRectToScreen( | 139 gfx::Rect window_bounds = |
156 window_, | 140 window_->ConvertRectToScreen(window->GetTargetBounds()); |
157 window->GetTargetBounds()); | |
158 int vertical_displacement = | 141 int vertical_displacement = |
159 std::max(0, window_bounds.bottom() - new_bounds.y()); | 142 std::max(0, window_bounds.bottom() - new_bounds.y()); |
160 int shift = std::min(vertical_displacement, | 143 int shift = std::min(vertical_displacement, |
161 window_bounds.y() - work_area_in_parent_.y()); | 144 window_bounds.y() - work_area_in_parent_.y()); |
162 if (shift > 0) { | 145 if (shift > 0) { |
163 gfx::Point origin(window_bounds.x(), window_bounds.y() - shift); | 146 gfx::Point origin(window_bounds.x(), window_bounds.y() - shift); |
164 SetChildBounds(window, gfx::Rect(origin, window_bounds.size())); | 147 SetChildBounds(window, gfx::Rect(origin, window_bounds.size())); |
165 } | 148 } |
166 } else if (window_state->HasRestoreBounds()) { | 149 } else if (window_state->HasRestoreBounds()) { |
167 // Keyboard hidden, restore original bounds if they exist. If the user has | 150 // Keyboard hidden, restore original bounds if they exist. If the user has |
168 // resized or dragged the window in the meantime, WorkspaceWindowResizer | 151 // resized or dragged the window in the meantime, WorkspaceWindowResizer |
169 // will have cleared the restore bounds and this code will not accidentally | 152 // will have cleared the restore bounds and this code will not accidentally |
170 // override user intent. | 153 // override user intent. |
171 window_state->SetAndClearRestoreBounds(); | 154 window_state->SetAndClearRestoreBounds(); |
172 } | 155 } |
173 } | 156 } |
174 | 157 |
175 ////////////////////////////////////////////////////////////////////////////// | 158 ////////////////////////////////////////////////////////////////////////////// |
176 // WorkspaceLayoutManager, ash::ShellObserver implementation: | 159 // WorkspaceLayoutManager, wm::WmRootWindowControllerObserver implementation: |
177 | 160 |
178 void WorkspaceLayoutManager::OnDisplayWorkAreaInsetsChanged() { | 161 void WorkspaceLayoutManager::OnWorkAreaChanged() { |
179 const gfx::Rect work_area(ScreenUtil::ConvertRectFromScreen( | 162 const gfx::Rect work_area(wm::GetDisplayWorkAreaBounds(window_)); |
180 window_, display::Screen::GetScreen() | |
181 ->GetDisplayNearestWindow(window_) | |
182 .work_area())); | |
183 if (work_area != work_area_in_parent_) { | 163 if (work_area != work_area_in_parent_) { |
184 const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); | 164 const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); |
185 AdjustAllWindowsBoundsForWorkAreaChange(&event); | 165 AdjustAllWindowsBoundsForWorkAreaChange(&event); |
186 } | 166 } |
187 if (backdrop_delegate_) | 167 if (backdrop_delegate_) |
188 backdrop_delegate_->OnDisplayWorkAreaInsetsChanged(); | 168 backdrop_delegate_->OnDisplayWorkAreaInsetsChanged(); |
189 } | 169 } |
190 | 170 |
191 void WorkspaceLayoutManager::OnFullscreenStateChanged( | 171 void WorkspaceLayoutManager::OnFullscreenStateChanged(bool is_fullscreen) { |
192 bool is_fullscreen, | 172 if (is_fullscreen_ == is_fullscreen) |
193 aura::Window* root_window) { | |
194 if (window_->GetRootWindow() != root_window || | |
195 is_fullscreen_ == is_fullscreen) { | |
196 return; | 173 return; |
197 } | 174 |
198 is_fullscreen_ = is_fullscreen; | 175 is_fullscreen_ = is_fullscreen; |
199 Window* fullscreen_window = | 176 wm::WmWindow* fullscreen_window = |
200 is_fullscreen | 177 is_fullscreen ? GetWindowForFullscreenMode(window_) : nullptr; |
201 ? GetRootWindowController(window_->GetRootWindow()) | |
202 ->GetWindowForFullscreenMode() | |
203 : NULL; | |
204 // Changing always on top state may change window's parent. Iterate on a copy | 178 // Changing always on top state may change window's parent. Iterate on a copy |
205 // of |windows_| to avoid invalidating an iterator. Since both workspace and | 179 // of |windows_| to avoid invalidating an iterator. Since both workspace and |
206 // always_on_top containers' layouts are managed by this class all the | 180 // always_on_top containers' layouts are managed by this class all the |
207 // appropriate windows will be included in the iteration. | 181 // appropriate windows will be included in the iteration. |
208 WindowSet windows(windows_); | 182 WindowSet windows(windows_); |
209 for (auto window : windows) { | 183 for (auto window : windows) { |
210 wm::WindowState* window_state = wm::GetWindowState(window); | 184 wm::WindowState* window_state = window->GetWindowState(); |
211 if (is_fullscreen) { | 185 if (is_fullscreen) |
212 window_state->DisableAlwaysOnTop( | 186 window_state->DisableAlwaysOnTop(fullscreen_window); |
213 wm::WmWindowAura::Get(fullscreen_window)); | 187 else |
214 } else { | |
215 window_state->RestoreAlwaysOnTop(); | 188 window_state->RestoreAlwaysOnTop(); |
216 } | |
217 } | 189 } |
218 } | 190 } |
219 | 191 |
220 ////////////////////////////////////////////////////////////////////////////// | 192 ////////////////////////////////////////////////////////////////////////////// |
221 // WorkspaceLayoutManager, aura::WindowObserver implementation: | 193 // WorkspaceLayoutManager, aura::WindowObserver implementation: |
222 | 194 |
223 void WorkspaceLayoutManager::OnWindowHierarchyChanged( | 195 void WorkspaceLayoutManager::OnWindowTreeChanged( |
224 const WindowObserver::HierarchyChangeParams& params) { | 196 wm::WmWindow* window, |
225 if (!wm::GetWindowState(params.target)->IsActive()) | 197 const wm::WmWindowObserver::TreeChangeParams& params) { |
| 198 if (!params.target->GetWindowState()->IsActive()) |
226 return; | 199 return; |
227 // If the window is already tracked by the workspace this update would be | 200 // If the window is already tracked by the workspace this update would be |
228 // redundant as the fullscreen and shelf state would have been handled in | 201 // redundant as the fullscreen and shelf state would have been handled in |
229 // OnWindowAddedToLayout. | 202 // OnWindowAddedToLayout. |
230 if (windows_.find(params.target) != windows_.end()) | 203 if (windows_.find(params.target) != windows_.end()) |
231 return; | 204 return; |
232 | 205 |
233 // If the active window has moved to this root window then update the | 206 // If the active window has moved to this root window then update the |
234 // fullscreen state. | 207 // fullscreen state. |
235 // TODO(flackr): Track the active window leaving this root window and update | 208 // TODO(flackr): Track the active window leaving this root window and update |
236 // the fullscreen state accordingly. | 209 // the fullscreen state accordingly. |
237 if (params.new_parent && params.new_parent->GetRootWindow() == root_window_) { | 210 if (params.new_parent && params.new_parent->GetRootWindow() == root_window_) { |
238 UpdateFullscreenState(); | 211 UpdateFullscreenState(); |
239 UpdateShelfVisibility(); | 212 UpdateShelfVisibility(); |
240 } | 213 } |
241 } | 214 } |
242 | 215 |
243 void WorkspaceLayoutManager::OnWindowPropertyChanged(Window* window, | 216 void WorkspaceLayoutManager::OnWindowPropertyChanged( |
244 const void* key, | 217 wm::WmWindow* window, |
245 intptr_t old) { | 218 wm::WmWindowProperty property, |
246 if (key == aura::client::kAlwaysOnTopKey && | 219 intptr_t old) { |
247 window->GetProperty(aura::client::kAlwaysOnTopKey)) { | 220 if (property == wm::WmWindowProperty::ALWAYS_ON_TOP && |
248 GetRootWindowController(window->GetRootWindow())-> | 221 window->GetBoolProperty(wm::WmWindowProperty::ALWAYS_ON_TOP)) { |
249 always_on_top_controller()->GetContainer(window)->AddChild(window); | 222 root_window_controller_->GetAlwaysOnTopController() |
| 223 ->GetContainer(window) |
| 224 ->AddChild(window); |
250 } | 225 } |
251 } | 226 } |
252 | 227 |
253 void WorkspaceLayoutManager::OnWindowStackingChanged(aura::Window* window) { | 228 void WorkspaceLayoutManager::OnWindowStackingChanged(wm::WmWindow* window) { |
254 UpdateShelfVisibility(); | 229 UpdateShelfVisibility(); |
255 UpdateFullscreenState(); | 230 UpdateFullscreenState(); |
256 if (backdrop_delegate_) | 231 if (backdrop_delegate_) |
257 backdrop_delegate_->OnWindowStackingChanged(window); | 232 backdrop_delegate_->OnWindowStackingChanged(window); |
258 } | 233 } |
259 | 234 |
260 void WorkspaceLayoutManager::OnWindowDestroying(aura::Window* window) { | 235 void WorkspaceLayoutManager::OnWindowDestroying(wm::WmWindow* window) { |
261 if (root_window_ == window) { | 236 if (root_window_ == window) { |
262 root_window_->RemoveObserver(this); | 237 root_window_->RemoveObserver(this); |
263 root_window_ = NULL; | 238 root_window_ = nullptr; |
264 } | 239 } |
265 } | 240 } |
266 | 241 |
267 void WorkspaceLayoutManager::OnWindowBoundsChanged(aura::Window* window, | 242 void WorkspaceLayoutManager::OnWindowBoundsChanged( |
268 const gfx::Rect& old_bounds, | 243 wm::WmWindow* window, |
269 const gfx::Rect& new_bounds) { | 244 const gfx::Rect& old_bounds, |
| 245 const gfx::Rect& new_bounds) { |
270 if (root_window_ == window) { | 246 if (root_window_ == window) { |
271 const wm::WMEvent wm_event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED); | 247 const wm::WMEvent wm_event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED); |
272 AdjustAllWindowsBoundsForWorkAreaChange(&wm_event); | 248 AdjustAllWindowsBoundsForWorkAreaChange(&wm_event); |
273 } | 249 } |
274 } | 250 } |
275 | 251 |
276 ////////////////////////////////////////////////////////////////////////////// | 252 ////////////////////////////////////////////////////////////////////////////// |
277 // WorkspaceLayoutManager, | 253 // WorkspaceLayoutManager, |
278 // aura::client::ActivationChangeObserver implementation: | 254 // aura::client::ActivationChangeObserver implementation: |
279 | 255 |
280 void WorkspaceLayoutManager::OnWindowActivated( | 256 void WorkspaceLayoutManager::OnWindowActivated(wm::WmWindow* gained_active, |
281 aura::client::ActivationChangeObserver::ActivationReason reason, | 257 wm::WmWindow* lost_active) { |
282 aura::Window* gained_active, | 258 wm::WindowState* window_state = |
283 aura::Window* lost_active) { | 259 gained_active ? gained_active->GetWindowState() : nullptr; |
284 wm::WindowState* window_state = wm::GetWindowState(gained_active); | |
285 if (window_state && window_state->IsMinimized() && | 260 if (window_state && window_state->IsMinimized() && |
286 !gained_active->IsVisible()) { | 261 !gained_active->IsVisible()) { |
287 window_state->Unminimize(); | 262 window_state->Unminimize(); |
288 DCHECK(!window_state->IsMinimized()); | 263 DCHECK(!window_state->IsMinimized()); |
289 } | 264 } |
290 UpdateFullscreenState(); | 265 UpdateFullscreenState(); |
291 UpdateShelfVisibility(); | 266 UpdateShelfVisibility(); |
292 } | 267 } |
293 | 268 |
294 ////////////////////////////////////////////////////////////////////////////// | 269 ////////////////////////////////////////////////////////////////////////////// |
295 // WorkspaceLayoutManager, wm::WindowStateObserver implementation: | 270 // WorkspaceLayoutManager, wm::WindowStateObserver implementation: |
296 | 271 |
297 void WorkspaceLayoutManager::OnPostWindowStateTypeChange( | 272 void WorkspaceLayoutManager::OnPostWindowStateTypeChange( |
298 wm::WindowState* window_state, | 273 wm::WindowState* window_state, |
299 wm::WindowStateType old_type) { | 274 wm::WindowStateType old_type) { |
300 | |
301 // Notify observers that fullscreen state may be changing. | 275 // Notify observers that fullscreen state may be changing. |
302 if (window_state->IsFullscreen() || | 276 if (window_state->IsFullscreen() || |
303 old_type == wm::WINDOW_STATE_TYPE_FULLSCREEN) { | 277 old_type == wm::WINDOW_STATE_TYPE_FULLSCREEN) { |
304 UpdateFullscreenState(); | 278 UpdateFullscreenState(); |
305 } | 279 } |
306 | 280 |
307 UpdateShelfVisibility(); | 281 UpdateShelfVisibility(); |
308 if (backdrop_delegate_) | 282 if (backdrop_delegate_) |
309 backdrop_delegate_->OnPostWindowStateTypeChange(window_state, old_type); | 283 backdrop_delegate_->OnPostWindowStateTypeChange(window_state, old_type); |
310 } | 284 } |
311 | 285 |
312 ////////////////////////////////////////////////////////////////////////////// | 286 ////////////////////////////////////////////////////////////////////////////// |
313 // WorkspaceLayoutManager, private: | 287 // WorkspaceLayoutManager, private: |
314 | 288 |
315 void WorkspaceLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange( | 289 void WorkspaceLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange( |
316 const wm::WMEvent* event) { | 290 const wm::WMEvent* event) { |
317 DCHECK(event->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED || | 291 DCHECK(event->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED || |
318 event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); | 292 event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); |
319 | 293 |
320 work_area_in_parent_ = ScreenUtil::ConvertRectFromScreen( | 294 work_area_in_parent_ = wm::GetDisplayWorkAreaBounds(window_); |
321 window_, display::Screen::GetScreen() | |
322 ->GetDisplayNearestWindow(window_) | |
323 .work_area()); | |
324 | 295 |
325 // Don't do any adjustments of the insets while we are in screen locked mode. | 296 // Don't do any adjustments of the insets while we are in screen locked mode. |
326 // This would happen if the launcher was auto hidden before the login screen | 297 // This would happen if the launcher was auto hidden before the login screen |
327 // was shown and then gets shown when the login screen gets presented. | 298 // was shown and then gets shown when the login screen gets presented. |
328 if (event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED && | 299 if (event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED && |
329 Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) | 300 globals_->IsScreenLocked()) |
330 return; | 301 return; |
331 | 302 |
332 // If a user plugs an external display into a laptop running Aura the | 303 // If a user plugs an external display into a laptop running Aura the |
333 // display size will change. Maximized windows need to resize to match. | 304 // display size will change. Maximized windows need to resize to match. |
334 // We also do this when developers running Aura on a desktop manually resize | 305 // We also do this when developers running Aura on a desktop manually resize |
335 // the host window. | 306 // the host window. |
336 // We also need to do this when the work area insets changes. | 307 // We also need to do this when the work area insets changes. |
337 for (WindowSet::const_iterator it = windows_.begin(); | 308 for (wm::WmWindow* window : windows_) |
338 it != windows_.end(); | 309 window->GetWindowState()->OnWMEvent(event); |
339 ++it) { | |
340 wm::GetWindowState(*it)->OnWMEvent(event); | |
341 } | |
342 } | 310 } |
343 | 311 |
344 void WorkspaceLayoutManager::UpdateShelfVisibility() { | 312 void WorkspaceLayoutManager::UpdateShelfVisibility() { |
345 if (delegate_) | 313 if (delegate_) |
346 delegate_->UpdateShelfVisibility(); | 314 delegate_->UpdateShelfVisibility(); |
347 } | 315 } |
348 | 316 |
349 void WorkspaceLayoutManager::UpdateFullscreenState() { | 317 void WorkspaceLayoutManager::UpdateFullscreenState() { |
350 // TODO(flackr): The fullscreen state is currently tracked per workspace | 318 // TODO(flackr): The fullscreen state is currently tracked per workspace |
351 // but the shell notification implies a per root window state. Currently | 319 // but the shell notification implies a per root window state. Currently |
352 // only windows in the default workspace container will go fullscreen but | 320 // only windows in the default workspace container will go fullscreen but |
353 // this should really be tracked by the RootWindowController since | 321 // this should really be tracked by the RootWindowController since |
354 // technically any container could get a fullscreen window. | 322 // technically any container could get a fullscreen window. |
355 if (!delegate_) | 323 if (!delegate_) |
356 return; | 324 return; |
357 bool is_fullscreen = GetRootWindowController( | 325 bool is_fullscreen = GetWindowForFullscreenMode(window_) != nullptr; |
358 window_->GetRootWindow())->GetWindowForFullscreenMode() != NULL; | |
359 if (is_fullscreen != is_fullscreen_) { | 326 if (is_fullscreen != is_fullscreen_) { |
360 delegate_->OnFullscreenStateChanged(is_fullscreen); | 327 delegate_->OnFullscreenStateChanged(is_fullscreen); |
361 is_fullscreen_ = is_fullscreen; | 328 is_fullscreen_ = is_fullscreen; |
362 } | 329 } |
363 } | 330 } |
364 | 331 |
365 } // namespace ash | 332 } // namespace ash |
OLD | NEW |