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(); |
| 91 UpdateFullscreenState(); |
89 WindowPositioner::RearrangeVisibleWindowOnShow(child); | 92 WindowPositioner::RearrangeVisibleWindowOnShow(child); |
90 } | 93 } |
91 | 94 |
92 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(Window* child) { | 95 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(Window* child) { |
93 BaseLayoutManager::OnWillRemoveWindowFromLayout(child); | 96 BaseLayoutManager::OnWillRemoveWindowFromLayout(child); |
94 if (child->TargetVisibility()) | 97 if (child->TargetVisibility()) |
95 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(child); | 98 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(child); |
96 } | 99 } |
97 | 100 |
98 void WorkspaceLayoutManager::OnWindowRemovedFromLayout(Window* child) { | 101 void WorkspaceLayoutManager::OnWindowRemovedFromLayout(Window* child) { |
99 BaseLayoutManager::OnWindowRemovedFromLayout(child); | 102 BaseLayoutManager::OnWindowRemovedFromLayout(child); |
100 UpdateDesktopVisibility(); | 103 UpdateShelfVisibility(); |
| 104 UpdateFullscreenState(); |
101 } | 105 } |
102 | 106 |
103 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged(Window* child, | 107 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged(Window* child, |
104 bool visible) { | 108 bool visible) { |
105 BaseLayoutManager::OnChildWindowVisibilityChanged(child, visible); | 109 BaseLayoutManager::OnChildWindowVisibilityChanged(child, visible); |
106 if (child->TargetVisibility()) { | 110 if (child->TargetVisibility()) { |
107 WindowPositioner::RearrangeVisibleWindowOnShow(child); | 111 WindowPositioner::RearrangeVisibleWindowOnShow(child); |
108 } else { | 112 } else { |
109 if (wm::GetWindowState(child)->IsFullscreen()) { | 113 if (wm::GetWindowState(child)->IsFullscreen()) |
110 ash::Shell::GetInstance()->NotifyFullscreenStateChange( | 114 UpdateFullscreenState(); |
111 false, child->GetRootWindow()); | |
112 } | |
113 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(child); | 115 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(child); |
114 } | 116 } |
115 UpdateDesktopVisibility(); | 117 UpdateShelfVisibility(); |
116 } | 118 } |
117 | 119 |
118 void WorkspaceLayoutManager::SetChildBounds( | 120 void WorkspaceLayoutManager::SetChildBounds( |
119 Window* child, | 121 Window* child, |
120 const gfx::Rect& requested_bounds) { | 122 const gfx::Rect& requested_bounds) { |
121 wm::WindowState* window_state = wm::GetWindowState(child); | 123 wm::WindowState* window_state = wm::GetWindowState(child); |
122 if (window_state->is_dragged()) { | 124 if (window_state->is_dragged()) { |
123 SetChildBoundsDirect(child, requested_bounds); | 125 SetChildBoundsDirect(child, requested_bounds); |
124 } else if (!SetMaximizedOrFullscreenBounds(window_state)) { | 126 } else if (!SetMaximizedOrFullscreenBounds(window_state)) { |
125 // Some windows rely on this to set their initial bounds. | 127 // Some windows rely on this to set their initial bounds. |
126 // Non-maximized/full-screen windows have their size constrained to the | 128 // Non-maximized/full-screen windows have their size constrained to the |
127 // work-area. | 129 // work-area. |
128 gfx::Rect child_bounds(requested_bounds); | 130 gfx::Rect child_bounds(requested_bounds); |
129 child_bounds.set_width(std::min(work_area_in_parent_.width(), | 131 child_bounds.set_width(std::min(work_area_in_parent_.width(), |
130 child_bounds.width())); | 132 child_bounds.width())); |
131 child_bounds.set_height(std::min(work_area_in_parent_.height(), | 133 child_bounds.set_height(std::min(work_area_in_parent_.height(), |
132 child_bounds.height())); | 134 child_bounds.height())); |
133 AdjustSnappedBounds(window_state, &child_bounds); | 135 AdjustSnappedBounds(window_state, &child_bounds); |
134 SetChildBoundsDirect(child, child_bounds); | 136 SetChildBoundsDirect(child, child_bounds); |
135 } | 137 } |
136 UpdateDesktopVisibility(); | 138 UpdateShelfVisibility(); |
137 } | 139 } |
138 | 140 |
139 void WorkspaceLayoutManager::OnDisplayWorkAreaInsetsChanged() { | 141 void WorkspaceLayoutManager::OnDisplayWorkAreaInsetsChanged() { |
140 const gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( | 142 const gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( |
141 window_->parent())); | 143 window_->parent())); |
142 if (work_area != work_area_in_parent_) { | 144 if (work_area != work_area_in_parent_) { |
143 AdjustAllWindowsBoundsForWorkAreaChange( | 145 AdjustAllWindowsBoundsForWorkAreaChange( |
144 ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED); | 146 ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED); |
145 } | 147 } |
146 } | 148 } |
147 | 149 |
148 void WorkspaceLayoutManager::OnWindowPropertyChanged(Window* window, | 150 void WorkspaceLayoutManager::OnWindowPropertyChanged(Window* window, |
149 const void* key, | 151 const void* key, |
150 intptr_t old) { | 152 intptr_t old) { |
151 if (key == aura::client::kAlwaysOnTopKey && | 153 if (key == aura::client::kAlwaysOnTopKey && |
152 window->GetProperty(aura::client::kAlwaysOnTopKey)) { | 154 window->GetProperty(aura::client::kAlwaysOnTopKey)) { |
153 GetRootWindowController(window->GetRootWindow())-> | 155 GetRootWindowController(window->GetRootWindow())-> |
154 always_on_top_controller()->GetContainer(window)->AddChild(window); | 156 always_on_top_controller()->GetContainer(window)->AddChild(window); |
155 } | 157 } |
156 } | 158 } |
157 | 159 |
| 160 void WorkspaceLayoutManager::OnWindowStackingChanged(aura::Window* window) { |
| 161 BaseLayoutManager::OnWindowStackingChanged(window); |
| 162 UpdateShelfVisibility(); |
| 163 UpdateFullscreenState(); |
| 164 } |
| 165 |
158 void WorkspaceLayoutManager::OnWindowShowTypeChanged( | 166 void WorkspaceLayoutManager::OnWindowShowTypeChanged( |
159 wm::WindowState* window_state, | 167 wm::WindowState* window_state, |
160 wm::WindowShowType old_type) { | 168 wm::WindowShowType old_type) { |
161 ui::WindowShowState old_state = ToWindowShowState(old_type); | 169 ui::WindowShowState old_state = ToWindowShowState(old_type); |
162 ui::WindowShowState new_state = window_state->GetShowState(); | 170 ui::WindowShowState new_state = window_state->GetShowState(); |
163 if (old_state != ui::SHOW_STATE_MINIMIZED && | 171 if (old_state != ui::SHOW_STATE_MINIMIZED && |
164 !window_state->HasRestoreBounds() && | 172 !window_state->HasRestoreBounds() && |
165 window_state->IsMaximizedOrFullscreen() && | 173 window_state->IsMaximizedOrFullscreen() && |
166 !wm::WindowState::IsMaximizedOrFullscreenState(old_state)) { | 174 !wm::WindowState::IsMaximizedOrFullscreenState(old_state)) { |
167 window_state->SaveCurrentBoundsForRestore(); | 175 window_state->SaveCurrentBoundsForRestore(); |
168 } | 176 } |
169 // When restoring from a minimized state, we want to restore to the | 177 // When restoring from a minimized state, we want to restore to the |
170 // previous (maybe L/R maximized) state. Since we do also want to keep the | 178 // previous (maybe L/R maximized) state. Since we do also want to keep the |
171 // restore rectangle, we set the restore rectangle to the rectangle we want | 179 // restore rectangle, we set the restore rectangle to the rectangle we want |
172 // to restore to and restore it after we switched so that it is preserved. | 180 // to restore to and restore it after we switched so that it is preserved. |
173 gfx::Rect restore; | 181 gfx::Rect restore; |
174 if (old_state == ui::SHOW_STATE_MINIMIZED && | 182 if (old_state == ui::SHOW_STATE_MINIMIZED && |
175 (new_state == ui::SHOW_STATE_NORMAL || | 183 (new_state == ui::SHOW_STATE_NORMAL || |
176 new_state == ui::SHOW_STATE_DEFAULT) && | 184 new_state == ui::SHOW_STATE_DEFAULT) && |
177 window_state->HasRestoreBounds() && | 185 window_state->HasRestoreBounds() && |
178 !window_state->always_restores_to_restore_bounds()) { | 186 !window_state->always_restores_to_restore_bounds()) { |
179 restore = window_state->GetRestoreBoundsInScreen(); | 187 restore = window_state->GetRestoreBoundsInScreen(); |
180 window_state->SaveCurrentBoundsForRestore(); | 188 window_state->SaveCurrentBoundsForRestore(); |
181 } | 189 } |
182 // Notify observers that fullscreen state may be changing. | 190 // Notify observers that fullscreen state may be changing. |
183 if (old_state != new_state && | 191 if (old_state != new_state && |
184 (new_state == ui::SHOW_STATE_FULLSCREEN || | 192 (new_state == ui::SHOW_STATE_FULLSCREEN || |
185 old_state == ui::SHOW_STATE_FULLSCREEN)) { | 193 old_state == ui::SHOW_STATE_FULLSCREEN)) { |
186 ash::Shell::GetInstance()->NotifyFullscreenStateChange( | 194 UpdateFullscreenState(); |
187 new_state == ui::SHOW_STATE_FULLSCREEN, | |
188 window_state->window()->GetRootWindow()); | |
189 } | 195 } |
190 | 196 |
191 UpdateBoundsFromShowState(window_state, old_state); | 197 UpdateBoundsFromShowState(window_state, old_state); |
192 ShowStateChanged(window_state, old_state); | 198 ShowStateChanged(window_state, old_state); |
193 | 199 |
194 // Set the restore rectangle to the previously set restore rectangle. | 200 // Set the restore rectangle to the previously set restore rectangle. |
195 if (!restore.IsEmpty()) | 201 if (!restore.IsEmpty()) |
196 window_state->SetRestoreBoundsInScreen(restore); | 202 window_state->SetRestoreBoundsInScreen(restore); |
197 } | 203 } |
198 | 204 |
199 void WorkspaceLayoutManager::ShowStateChanged( | 205 void WorkspaceLayoutManager::ShowStateChanged( |
200 wm::WindowState* state, | 206 wm::WindowState* state, |
201 ui::WindowShowState last_show_state) { | 207 ui::WindowShowState last_show_state) { |
202 BaseLayoutManager::ShowStateChanged(state, last_show_state); | 208 BaseLayoutManager::ShowStateChanged(state, last_show_state); |
203 UpdateDesktopVisibility(); | 209 UpdateShelfVisibility(); |
204 } | 210 } |
205 | 211 |
206 void WorkspaceLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange( | 212 void WorkspaceLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange( |
207 AdjustWindowReason reason) { | 213 AdjustWindowReason reason) { |
208 work_area_in_parent_ = | 214 work_area_in_parent_ = |
209 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_->parent()); | 215 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_->parent()); |
210 BaseLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange(reason); | 216 BaseLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange(reason); |
211 } | 217 } |
212 | 218 |
213 void WorkspaceLayoutManager::AdjustWindowBoundsForWorkAreaChange( | 219 void WorkspaceLayoutManager::AdjustWindowBoundsForWorkAreaChange( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 // moved. | 280 // moved. |
275 gfx::Rect display_area = ScreenAsh::GetDisplayBoundsInParent(window); | 281 gfx::Rect display_area = ScreenAsh::GetDisplayBoundsInParent(window); |
276 | 282 |
277 ash::wm::AdjustBoundsToEnsureWindowVisibility( | 283 ash::wm::AdjustBoundsToEnsureWindowVisibility( |
278 display_area, min_width, min_height, &bounds); | 284 display_area, min_width, min_height, &bounds); |
279 AdjustSnappedBounds(window_state, &bounds); | 285 AdjustSnappedBounds(window_state, &bounds); |
280 if (window->bounds() != bounds) | 286 if (window->bounds() != bounds) |
281 window->SetBounds(bounds); | 287 window->SetBounds(bounds); |
282 } | 288 } |
283 | 289 |
284 void WorkspaceLayoutManager::UpdateDesktopVisibility() { | 290 void WorkspaceLayoutManager::UpdateShelfVisibility() { |
285 if (shelf_) | 291 if (shelf_) |
286 shelf_->UpdateVisibilityState(); | 292 shelf_->UpdateVisibilityState(); |
287 } | 293 } |
288 | 294 |
| 295 void WorkspaceLayoutManager::UpdateFullscreenState() { |
| 296 bool is_fullscreen = GetRootWindowController( |
| 297 window_->GetRootWindow())->GetWindowForFullscreenMode() != NULL; |
| 298 if (is_fullscreen != is_fullscreen_) { |
| 299 ash::Shell::GetInstance()->NotifyFullscreenStateChange( |
| 300 is_fullscreen, window_->GetRootWindow()); |
| 301 is_fullscreen_ = is_fullscreen; |
| 302 } |
| 303 } |
| 304 |
289 void WorkspaceLayoutManager::UpdateBoundsFromShowState( | 305 void WorkspaceLayoutManager::UpdateBoundsFromShowState( |
290 wm::WindowState* window_state, | 306 wm::WindowState* window_state, |
291 ui::WindowShowState last_show_state) { | 307 ui::WindowShowState last_show_state) { |
292 aura::Window* window = window_state->window(); | 308 aura::Window* window = window_state->window(); |
293 // See comment in SetMaximizedOrFullscreenBounds() as to why we use parent in | 309 // See comment in SetMaximizedOrFullscreenBounds() as to why we use parent in |
294 // these calculation. | 310 // these calculation. |
295 // TODO(varkha): Change the switch statement below to use wm::WindowShowType. | 311 // TODO(varkha): Change the switch statement below to use wm::WindowShowType. |
296 switch (window_state->GetShowState()) { | 312 switch (window_state->GetShowState()) { |
297 case ui::SHOW_STATE_DEFAULT: | 313 case ui::SHOW_STATE_DEFAULT: |
298 case ui::SHOW_STATE_NORMAL: { | 314 case ui::SHOW_STATE_NORMAL: { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 ui::ScopedLayerAnimationSettings slide_settings(layer->GetAnimator()); | 427 ui::ScopedLayerAnimationSettings slide_settings(layer->GetAnimator()); |
412 slide_settings.SetPreemptionStrategy( | 428 slide_settings.SetPreemptionStrategy( |
413 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 429 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
414 slide_settings.SetTransitionDuration( | 430 slide_settings.SetTransitionDuration( |
415 base::TimeDelta::FromMilliseconds(kBoundsChangeSlideDurationMs)); | 431 base::TimeDelta::FromMilliseconds(kBoundsChangeSlideDurationMs)); |
416 SetChildBoundsDirect(child, bounds); | 432 SetChildBoundsDirect(child, bounds); |
417 } | 433 } |
418 | 434 |
419 } // namespace internal | 435 } // namespace internal |
420 } // namespace ash | 436 } // namespace ash |
OLD | NEW |