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 "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
9 #include "ash/screen_ash.h" | 9 #include "ash/screen_ash.h" |
10 #include "ash/shelf/shelf_layout_manager.h" | 10 #include "ash/shelf/shelf_layout_manager.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 } // namespace | 68 } // namespace |
69 | 69 |
70 WorkspaceLayoutManager::WorkspaceLayoutManager(aura::Window* window) | 70 WorkspaceLayoutManager::WorkspaceLayoutManager(aura::Window* window) |
71 : BaseLayoutManager(window->GetRootWindow()), | 71 : BaseLayoutManager(window->GetRootWindow()), |
72 shelf_(NULL), | 72 shelf_(NULL), |
73 window_(window), | 73 window_(window), |
74 work_area_in_parent_(ScreenAsh::GetDisplayWorkAreaBoundsInParent( | 74 work_area_in_parent_(ScreenAsh::GetDisplayWorkAreaBoundsInParent( |
75 window->parent())) { | 75 window->parent())), |
| 76 is_fullscreen_(GetRootWindowController( |
| 77 window->GetRootWindow())->GetWindowForFullscreenMode() != NULL) { |
76 } | 78 } |
77 | 79 |
78 WorkspaceLayoutManager::~WorkspaceLayoutManager() { | 80 WorkspaceLayoutManager::~WorkspaceLayoutManager() { |
79 } | 81 } |
80 | 82 |
81 void WorkspaceLayoutManager::SetShelf(internal::ShelfLayoutManager* shelf) { | 83 void WorkspaceLayoutManager::SetShelf(internal::ShelfLayoutManager* shelf) { |
82 shelf_ = shelf; | 84 shelf_ = shelf; |
83 } | 85 } |
84 | 86 |
85 void WorkspaceLayoutManager::OnWindowAddedToLayout(Window* child) { | 87 void WorkspaceLayoutManager::OnWindowAddedToLayout(Window* child) { |
86 AdjustWindowBoundsWhenAdded(wm::GetWindowState(child)); | 88 AdjustWindowBoundsWhenAdded(wm::GetWindowState(child)); |
87 BaseLayoutManager::OnWindowAddedToLayout(child); | 89 BaseLayoutManager::OnWindowAddedToLayout(child); |
88 UpdateDesktopVisibility(); | 90 UpdateShelfVisibility(); |
89 WindowPositioner::RearrangeVisibleWindowOnShow(child); | 91 WindowPositioner::RearrangeVisibleWindowOnShow(child); |
90 } | 92 } |
91 | 93 |
92 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(Window* child) { | 94 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(Window* child) { |
93 BaseLayoutManager::OnWillRemoveWindowFromLayout(child); | 95 BaseLayoutManager::OnWillRemoveWindowFromLayout(child); |
94 if (child->TargetVisibility()) | 96 if (child->TargetVisibility()) |
95 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(child); | 97 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(child); |
96 } | 98 } |
97 | 99 |
98 void WorkspaceLayoutManager::OnWindowRemovedFromLayout(Window* child) { | 100 void WorkspaceLayoutManager::OnWindowRemovedFromLayout(Window* child) { |
99 BaseLayoutManager::OnWindowRemovedFromLayout(child); | 101 BaseLayoutManager::OnWindowRemovedFromLayout(child); |
100 UpdateDesktopVisibility(); | 102 UpdateShelfVisibility(); |
101 } | 103 } |
102 | 104 |
103 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged(Window* child, | 105 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged(Window* child, |
104 bool visible) { | 106 bool visible) { |
105 BaseLayoutManager::OnChildWindowVisibilityChanged(child, visible); | 107 BaseLayoutManager::OnChildWindowVisibilityChanged(child, visible); |
106 if (child->TargetVisibility()) { | 108 if (child->TargetVisibility()) { |
107 WindowPositioner::RearrangeVisibleWindowOnShow(child); | 109 WindowPositioner::RearrangeVisibleWindowOnShow(child); |
108 } else { | 110 } else { |
109 if (wm::GetWindowState(child)->IsFullscreen()) { | 111 if (wm::GetWindowState(child)->IsFullscreen()) |
110 ash::Shell::GetInstance()->NotifyFullscreenStateChange( | 112 UpdateFullscreenState(); |
111 false, child->GetRootWindow()); | |
112 } | |
113 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(child); | 113 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(child); |
114 } | 114 } |
115 UpdateDesktopVisibility(); | 115 UpdateShelfVisibility(); |
116 } | 116 } |
117 | 117 |
118 void WorkspaceLayoutManager::SetChildBounds( | 118 void WorkspaceLayoutManager::SetChildBounds( |
119 Window* child, | 119 Window* child, |
120 const gfx::Rect& requested_bounds) { | 120 const gfx::Rect& requested_bounds) { |
121 wm::WindowState* window_state = wm::GetWindowState(child); | 121 wm::WindowState* window_state = wm::GetWindowState(child); |
122 if (!window_state->tracked_by_workspace()) { | 122 if (!window_state->tracked_by_workspace()) { |
123 SetChildBoundsDirect(child, requested_bounds); | 123 SetChildBoundsDirect(child, requested_bounds); |
124 return; | 124 return; |
125 } | 125 } |
126 gfx::Rect child_bounds(requested_bounds); | 126 gfx::Rect child_bounds(requested_bounds); |
127 // Some windows rely on this to set their initial bounds. | 127 // Some windows rely on this to set their initial bounds. |
128 if (!SetMaximizedOrFullscreenBounds(window_state)) { | 128 if (!SetMaximizedOrFullscreenBounds(window_state)) { |
129 // Non-maximized/full-screen windows have their size constrained to the | 129 // Non-maximized/full-screen windows have their size constrained to the |
130 // work-area. | 130 // work-area. |
131 child_bounds.set_width(std::min(work_area_in_parent_.width(), | 131 child_bounds.set_width(std::min(work_area_in_parent_.width(), |
132 child_bounds.width())); | 132 child_bounds.width())); |
133 child_bounds.set_height(std::min(work_area_in_parent_.height(), | 133 child_bounds.set_height(std::min(work_area_in_parent_.height(), |
134 child_bounds.height())); | 134 child_bounds.height())); |
135 AdjustSnappedBounds(window_state, &child_bounds); | 135 AdjustSnappedBounds(window_state, &child_bounds); |
136 SetChildBoundsDirect(child, child_bounds); | 136 SetChildBoundsDirect(child, child_bounds); |
137 } | 137 } |
138 UpdateDesktopVisibility(); | 138 UpdateShelfVisibility(); |
139 } | 139 } |
140 | 140 |
141 void WorkspaceLayoutManager::OnDisplayWorkAreaInsetsChanged() { | 141 void WorkspaceLayoutManager::OnDisplayWorkAreaInsetsChanged() { |
142 const gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( | 142 const gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( |
143 window_->parent())); | 143 window_->parent())); |
144 if (work_area != work_area_in_parent_) { | 144 if (work_area != work_area_in_parent_) { |
145 AdjustAllWindowsBoundsForWorkAreaChange( | 145 AdjustAllWindowsBoundsForWorkAreaChange( |
146 ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED); | 146 ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED); |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 void WorkspaceLayoutManager::OnWindowPropertyChanged(Window* window, | 150 void WorkspaceLayoutManager::OnWindowPropertyChanged(Window* window, |
151 const void* key, | 151 const void* key, |
152 intptr_t old) { | 152 intptr_t old) { |
153 if (key == aura::client::kAlwaysOnTopKey && | 153 if (key == aura::client::kAlwaysOnTopKey && |
154 window->GetProperty(aura::client::kAlwaysOnTopKey)) { | 154 window->GetProperty(aura::client::kAlwaysOnTopKey)) { |
155 GetRootWindowController(window->GetRootWindow())-> | 155 GetRootWindowController(window->GetRootWindow())-> |
156 always_on_top_controller()->GetContainer(window)->AddChild(window); | 156 always_on_top_controller()->GetContainer(window)->AddChild(window); |
157 } | 157 } |
158 } | 158 } |
159 | 159 |
| 160 void WorkspaceLayoutManager::OnWindowStackingChanged(aura::Window* window) { |
| 161 BaseLayoutManager::OnWindowStackingChanged(window); |
| 162 UpdateShelfVisibility(); |
| 163 UpdateFullscreenState(); |
| 164 } |
| 165 |
160 void WorkspaceLayoutManager::OnTrackedByWorkspaceChanged( | 166 void WorkspaceLayoutManager::OnTrackedByWorkspaceChanged( |
161 wm::WindowState* window_state, | 167 wm::WindowState* window_state, |
162 bool old){ | 168 bool old){ |
163 if (window_state->tracked_by_workspace()) { | 169 if (window_state->tracked_by_workspace()) { |
164 if (!SetMaximizedOrFullscreenBounds(window_state)) { | 170 if (!SetMaximizedOrFullscreenBounds(window_state)) { |
165 gfx::Rect bounds = window_state->window()->bounds(); | 171 gfx::Rect bounds = window_state->window()->bounds(); |
166 AdjustSnappedBounds(window_state, &bounds); | 172 AdjustSnappedBounds(window_state, &bounds); |
167 if (window_state->window()->bounds() != bounds) | 173 if (window_state->window()->bounds() != bounds) |
168 SetChildBoundsDirect(window_state->window(), bounds); | 174 SetChildBoundsDirect(window_state->window(), bounds); |
169 } | 175 } |
(...skipping 21 matching lines...) Expand all Loading... |
191 new_state == ui::SHOW_STATE_DEFAULT) && | 197 new_state == ui::SHOW_STATE_DEFAULT) && |
192 window_state->HasRestoreBounds() && | 198 window_state->HasRestoreBounds() && |
193 !window_state->always_restores_to_restore_bounds()) { | 199 !window_state->always_restores_to_restore_bounds()) { |
194 restore = window_state->GetRestoreBoundsInScreen(); | 200 restore = window_state->GetRestoreBoundsInScreen(); |
195 window_state->SaveCurrentBoundsForRestore(); | 201 window_state->SaveCurrentBoundsForRestore(); |
196 } | 202 } |
197 // Notify observers that fullscreen state may be changing. | 203 // Notify observers that fullscreen state may be changing. |
198 if (old_state != new_state && | 204 if (old_state != new_state && |
199 (new_state == ui::SHOW_STATE_FULLSCREEN || | 205 (new_state == ui::SHOW_STATE_FULLSCREEN || |
200 old_state == ui::SHOW_STATE_FULLSCREEN)) { | 206 old_state == ui::SHOW_STATE_FULLSCREEN)) { |
201 ash::Shell::GetInstance()->NotifyFullscreenStateChange( | 207 UpdateFullscreenState(); |
202 new_state == ui::SHOW_STATE_FULLSCREEN, | |
203 window_state->window()->GetRootWindow()); | |
204 } | 208 } |
205 | 209 |
206 UpdateBoundsFromShowState(window_state, old_state); | 210 UpdateBoundsFromShowState(window_state, old_state); |
207 ShowStateChanged(window_state, old_state); | 211 ShowStateChanged(window_state, old_state); |
208 | 212 |
209 // Set the restore rectangle to the previously set restore rectangle. | 213 // Set the restore rectangle to the previously set restore rectangle. |
210 if (!restore.IsEmpty()) | 214 if (!restore.IsEmpty()) |
211 window_state->SetRestoreBoundsInScreen(restore); | 215 window_state->SetRestoreBoundsInScreen(restore); |
212 } | 216 } |
213 | 217 |
214 void WorkspaceLayoutManager::ShowStateChanged( | 218 void WorkspaceLayoutManager::ShowStateChanged( |
215 wm::WindowState* state, | 219 wm::WindowState* state, |
216 ui::WindowShowState last_show_state) { | 220 ui::WindowShowState last_show_state) { |
217 BaseLayoutManager::ShowStateChanged(state, last_show_state); | 221 BaseLayoutManager::ShowStateChanged(state, last_show_state); |
218 UpdateDesktopVisibility(); | 222 UpdateShelfVisibility(); |
219 } | 223 } |
220 | 224 |
221 void WorkspaceLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange( | 225 void WorkspaceLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange( |
222 AdjustWindowReason reason) { | 226 AdjustWindowReason reason) { |
223 work_area_in_parent_ = | 227 work_area_in_parent_ = |
224 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_->parent()); | 228 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_->parent()); |
225 BaseLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange(reason); | 229 BaseLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange(reason); |
226 } | 230 } |
227 | 231 |
228 void WorkspaceLayoutManager::AdjustWindowBoundsForWorkAreaChange( | 232 void WorkspaceLayoutManager::AdjustWindowBoundsForWorkAreaChange( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 // moved. | 293 // moved. |
290 gfx::Rect display_area = ScreenAsh::GetDisplayBoundsInParent(window); | 294 gfx::Rect display_area = ScreenAsh::GetDisplayBoundsInParent(window); |
291 | 295 |
292 ash::wm::AdjustBoundsToEnsureWindowVisibility( | 296 ash::wm::AdjustBoundsToEnsureWindowVisibility( |
293 display_area, min_width, min_height, &bounds); | 297 display_area, min_width, min_height, &bounds); |
294 AdjustSnappedBounds(window_state, &bounds); | 298 AdjustSnappedBounds(window_state, &bounds); |
295 if (window->bounds() != bounds) | 299 if (window->bounds() != bounds) |
296 window->SetBounds(bounds); | 300 window->SetBounds(bounds); |
297 } | 301 } |
298 | 302 |
299 void WorkspaceLayoutManager::UpdateDesktopVisibility() { | 303 void WorkspaceLayoutManager::UpdateShelfVisibility() { |
300 if (shelf_) | 304 if (shelf_) |
301 shelf_->UpdateVisibilityState(); | 305 shelf_->UpdateVisibilityState(); |
302 } | 306 } |
303 | 307 |
| 308 void WorkspaceLayoutManager::UpdateFullscreenState() { |
| 309 bool is_fullscreen = GetRootWindowController( |
| 310 window_->GetRootWindow())->GetWindowForFullscreenMode() != NULL; |
| 311 if (is_fullscreen != is_fullscreen_) { |
| 312 ash::Shell::GetInstance()->NotifyFullscreenStateChange( |
| 313 is_fullscreen, window_->GetRootWindow()); |
| 314 is_fullscreen_ = is_fullscreen; |
| 315 } |
| 316 } |
| 317 |
304 void WorkspaceLayoutManager::UpdateBoundsFromShowState( | 318 void WorkspaceLayoutManager::UpdateBoundsFromShowState( |
305 wm::WindowState* window_state, | 319 wm::WindowState* window_state, |
306 ui::WindowShowState last_show_state) { | 320 ui::WindowShowState last_show_state) { |
307 aura::Window* window = window_state->window(); | 321 aura::Window* window = window_state->window(); |
308 // See comment in SetMaximizedOrFullscreenBounds() as to why we use parent in | 322 // See comment in SetMaximizedOrFullscreenBounds() as to why we use parent in |
309 // these calculation. | 323 // these calculation. |
310 // TODO(varkha): Change the switch statement below to use wm::WindowShowType. | 324 // TODO(varkha): Change the switch statement below to use wm::WindowShowType. |
311 switch (window_state->GetShowState()) { | 325 switch (window_state->GetShowState()) { |
312 case ui::SHOW_STATE_DEFAULT: | 326 case ui::SHOW_STATE_DEFAULT: |
313 case ui::SHOW_STATE_NORMAL: { | 327 case ui::SHOW_STATE_NORMAL: { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 ui::ScopedLayerAnimationSettings slide_settings(layer->GetAnimator()); | 447 ui::ScopedLayerAnimationSettings slide_settings(layer->GetAnimator()); |
434 slide_settings.SetPreemptionStrategy( | 448 slide_settings.SetPreemptionStrategy( |
435 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 449 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
436 slide_settings.SetTransitionDuration( | 450 slide_settings.SetTransitionDuration( |
437 base::TimeDelta::FromMilliseconds(kBoundsChangeSlideDurationMs)); | 451 base::TimeDelta::FromMilliseconds(kBoundsChangeSlideDurationMs)); |
438 SetChildBoundsDirect(child, bounds); | 452 SetChildBoundsDirect(child, bounds); |
439 } | 453 } |
440 | 454 |
441 } // namespace internal | 455 } // namespace internal |
442 } // namespace ash | 456 } // namespace ash |
OLD | NEW |