| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/maximize_mode/maximize_mode_window_state.h" | 5 #include "ash/wm/maximize_mode/maximize_mode_window_state.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/aura/wm_window_aura.h" | 9 #include "ash/aura/wm_window_aura.h" |
| 10 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 // static | 105 // static |
| 106 void MaximizeModeWindowState::UpdateWindowPosition( | 106 void MaximizeModeWindowState::UpdateWindowPosition( |
| 107 wm::WindowState* window_state) { | 107 wm::WindowState* window_state) { |
| 108 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); | 108 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); |
| 109 if (bounds_in_parent == window_state->window()->GetBounds()) | 109 if (bounds_in_parent == window_state->window()->GetBounds()) |
| 110 return; | 110 return; |
| 111 window_state->SetBoundsDirect(bounds_in_parent); | 111 window_state->SetBoundsDirect(bounds_in_parent); |
| 112 } | 112 } |
| 113 | 113 |
| 114 MaximizeModeWindowState::MaximizeModeWindowState( | 114 MaximizeModeWindowState::MaximizeModeWindowState( |
| 115 aura::Window* window, MaximizeModeWindowManager* creator) | 115 aura::Window* window, |
| 116 MaximizeModeWindowManager* creator) |
| 116 : window_(window), | 117 : window_(window), |
| 117 creator_(creator), | 118 creator_(creator), |
| 118 current_state_type_(wm::GetWindowState(window)->GetStateType()), | 119 current_state_type_(wm::GetWindowState(window)->GetStateType()), |
| 119 defer_bounds_updates_(false) { | 120 defer_bounds_updates_(false) { |
| 120 old_state_.reset(wm::GetWindowState(window) | 121 old_state_.reset(wm::GetWindowState(window) |
| 121 ->SetStateObject(std::unique_ptr<State>(this)) | 122 ->SetStateObject(std::unique_ptr<State>(this)) |
| 122 .release()); | 123 .release()); |
| 123 } | 124 } |
| 124 | 125 |
| 125 MaximizeModeWindowState::~MaximizeModeWindowState() { | 126 MaximizeModeWindowState::~MaximizeModeWindowState() { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 case wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: | 160 case wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: |
| 160 case wm::WM_EVENT_TOGGLE_MAXIMIZE: | 161 case wm::WM_EVENT_TOGGLE_MAXIMIZE: |
| 161 case wm::WM_EVENT_CYCLE_SNAP_DOCK_LEFT: | 162 case wm::WM_EVENT_CYCLE_SNAP_DOCK_LEFT: |
| 162 case wm::WM_EVENT_CYCLE_SNAP_DOCK_RIGHT: | 163 case wm::WM_EVENT_CYCLE_SNAP_DOCK_RIGHT: |
| 163 case wm::WM_EVENT_CENTER: | 164 case wm::WM_EVENT_CENTER: |
| 164 case wm::WM_EVENT_SNAP_LEFT: | 165 case wm::WM_EVENT_SNAP_LEFT: |
| 165 case wm::WM_EVENT_SNAP_RIGHT: | 166 case wm::WM_EVENT_SNAP_RIGHT: |
| 166 case wm::WM_EVENT_NORMAL: | 167 case wm::WM_EVENT_NORMAL: |
| 167 case wm::WM_EVENT_MAXIMIZE: | 168 case wm::WM_EVENT_MAXIMIZE: |
| 168 case wm::WM_EVENT_DOCK: | 169 case wm::WM_EVENT_DOCK: |
| 169 UpdateWindow(window_state, | 170 UpdateWindow(window_state, GetMaximizedOrCenteredWindowType(window_state), |
| 170 GetMaximizedOrCenteredWindowType(window_state), | |
| 171 true); | 171 true); |
| 172 return; | 172 return; |
| 173 case wm::WM_EVENT_MINIMIZE: | 173 case wm::WM_EVENT_MINIMIZE: |
| 174 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_MINIMIZED, true); | 174 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_MINIMIZED, true); |
| 175 return; | 175 return; |
| 176 case wm::WM_EVENT_SHOW_INACTIVE: | 176 case wm::WM_EVENT_SHOW_INACTIVE: |
| 177 return; | 177 return; |
| 178 case wm::WM_EVENT_SET_BOUNDS: | 178 case wm::WM_EVENT_SET_BOUNDS: |
| 179 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MAXIMIZED) { | 179 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MAXIMIZED) { |
| 180 // Having a maximized window, it could have been created with an empty | 180 // Having a maximized window, it could have been created with an empty |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 window_state->GetShowState()); | 240 window_state->GetShowState()); |
| 241 window->SetProperty(ash::kRestoreBoundsOverrideKey, | 241 window->SetProperty(ash::kRestoreBoundsOverrideKey, |
| 242 new gfx::Rect(restore_bounds)); | 242 new gfx::Rect(restore_bounds)); |
| 243 } | 243 } |
| 244 | 244 |
| 245 // Initialize the state to a good preset. | 245 // Initialize the state to a good preset. |
| 246 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && | 246 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && |
| 247 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && | 247 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && |
| 248 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && | 248 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && |
| 249 current_state_type_ != wm::WINDOW_STATE_TYPE_PINNED) { | 249 current_state_type_ != wm::WINDOW_STATE_TYPE_PINNED) { |
| 250 UpdateWindow(window_state, | 250 UpdateWindow(window_state, GetMaximizedOrCenteredWindowType(window_state), |
| 251 GetMaximizedOrCenteredWindowType(window_state), | |
| 252 true); | 251 true); |
| 253 } | 252 } |
| 254 | 253 |
| 255 window_state->set_can_be_dragged(false); | 254 window_state->set_can_be_dragged(false); |
| 256 } | 255 } |
| 257 | 256 |
| 258 void MaximizeModeWindowState::DetachState(wm::WindowState* window_state) { | 257 void MaximizeModeWindowState::DetachState(wm::WindowState* window_state) { |
| 259 // From now on, we can use the default session restore mechanism again. | 258 // From now on, we can use the default session restore mechanism again. |
| 260 ash::WmWindowAura::GetAuraWindow(window_state->window()) | 259 ash::WmWindowAura::GetAuraWindow(window_state->window()) |
| 261 ->ClearProperty(ash::kRestoreBoundsOverrideKey); | 260 ->ClearProperty(ash::kRestoreBoundsOverrideKey); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 if ((window_state->window()->GetTargetVisibility() || | 305 if ((window_state->window()->GetTargetVisibility() || |
| 307 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) && | 306 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) && |
| 308 !window_state->window()->GetLayer()->visible()) { | 307 !window_state->window()->GetLayer()->visible()) { |
| 309 // The layer may be hidden if the window was previously minimized. Make | 308 // The layer may be hidden if the window was previously minimized. Make |
| 310 // sure it's visible. | 309 // sure it's visible. |
| 311 window_state->window()->Show(); | 310 window_state->window()->Show(); |
| 312 } | 311 } |
| 313 } | 312 } |
| 314 | 313 |
| 315 wm::WindowStateType MaximizeModeWindowState::GetMaximizedOrCenteredWindowType( | 314 wm::WindowStateType MaximizeModeWindowState::GetMaximizedOrCenteredWindowType( |
| 316 wm::WindowState* window_state) { | 315 wm::WindowState* window_state) { |
| 317 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED : | 316 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED |
| 318 wm::WINDOW_STATE_TYPE_NORMAL; | 317 : wm::WINDOW_STATE_TYPE_NORMAL; |
| 319 } | 318 } |
| 320 | 319 |
| 321 void MaximizeModeWindowState::UpdateBounds(wm::WindowState* window_state, | 320 void MaximizeModeWindowState::UpdateBounds(wm::WindowState* window_state, |
| 322 bool animated) { | 321 bool animated) { |
| 323 if (defer_bounds_updates_) | 322 if (defer_bounds_updates_) |
| 324 return; | 323 return; |
| 325 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); | 324 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); |
| 326 // If we have a target bounds rectangle, we center it and set it | 325 // If we have a target bounds rectangle, we center it and set it |
| 327 // accordingly. | 326 // accordingly. |
| 328 if (!bounds_in_parent.IsEmpty() && | 327 if (!bounds_in_parent.IsEmpty() && |
| 329 bounds_in_parent != window_state->window()->GetBounds()) { | 328 bounds_in_parent != window_state->window()->GetBounds()) { |
| 330 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED || | 329 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED || |
| 331 !window_state->window()->IsVisible() || | 330 !window_state->window()->IsVisible() || !animated) { |
| 332 !animated) { | |
| 333 window_state->SetBoundsDirect(bounds_in_parent); | 331 window_state->SetBoundsDirect(bounds_in_parent); |
| 334 } else { | 332 } else { |
| 335 // If we animate (to) maximized mode, we want to use the cross fade to | 333 // If we animate (to) maximized mode, we want to use the cross fade to |
| 336 // avoid flashing. | 334 // avoid flashing. |
| 337 if (window_state->IsMaximized()) | 335 if (window_state->IsMaximized()) |
| 338 window_state->SetBoundsDirectCrossFade(bounds_in_parent); | 336 window_state->SetBoundsDirectCrossFade(bounds_in_parent); |
| 339 else | 337 else |
| 340 window_state->SetBoundsDirectAnimated(bounds_in_parent); | 338 window_state->SetBoundsDirectAnimated(bounds_in_parent); |
| 341 } | 339 } |
| 342 } | 340 } |
| 343 } | 341 } |
| 344 | 342 |
| 345 } // namespace ash | 343 } // namespace ash |
| OLD | NEW |