Chromium Code Reviews| 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" | |
| 10 #include "ash/common/shell_window_ids.h" | 9 #include "ash/common/shell_window_ids.h" |
| 11 #include "ash/common/wm/window_animation_types.h" | 10 #include "ash/common/wm/window_animation_types.h" |
| 12 #include "ash/common/wm/window_state_delegate.h" | |
| 13 #include "ash/common/wm/window_state_util.h" | 11 #include "ash/common/wm/window_state_util.h" |
| 14 #include "ash/common/wm/wm_event.h" | 12 #include "ash/common/wm/wm_event.h" |
| 15 #include "ash/common/wm/wm_screen_util.h" | 13 #include "ash/common/wm/wm_screen_util.h" |
| 16 #include "ash/common/wm/workspace/workspace_window_resizer.h" | |
| 17 #include "ash/common/wm_shell.h" | 14 #include "ash/common/wm_shell.h" |
| 18 #include "ash/screen_util.h" | 15 #include "ash/common/wm_window.h" |
| 19 #include "ash/shell.h" | |
| 20 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" | 16 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" |
| 21 #include "ash/wm/window_animations.h" | |
| 22 #include "ash/wm/window_properties.h" | |
| 23 #include "ash/wm/window_state_aura.h" | |
| 24 #include "ash/wm/window_util.h" | |
| 25 #include "ui/aura/client/aura_constants.h" | |
| 26 #include "ui/aura/window.h" | |
| 27 #include "ui/aura/window_delegate.h" | |
| 28 #include "ui/compositor/layer.h" | 17 #include "ui/compositor/layer.h" |
| 29 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 30 #include "ui/views/view_constants_aura.h" | |
| 31 #include "ui/views/widget/widget.h" | |
| 32 | 19 |
| 33 namespace ash { | 20 namespace ash { |
| 34 namespace { | 21 namespace { |
| 35 | 22 |
| 36 // Returns the biggest possible size for a window which is about to be | 23 // Returns the biggest possible size for a window which is about to be |
| 37 // maximized. | 24 // maximized. |
| 38 gfx::Size GetMaximumSizeOfWindow(wm::WindowState* window_state) { | 25 gfx::Size GetMaximumSizeOfWindow(wm::WindowState* window_state) { |
| 39 DCHECK(window_state->CanMaximize() || window_state->CanResize()); | 26 DCHECK(window_state->CanMaximize() || window_state->CanResize()); |
| 40 | 27 |
| 41 gfx::Size workspace_size = | 28 gfx::Size workspace_size = |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 // static | 92 // static |
| 106 void MaximizeModeWindowState::UpdateWindowPosition( | 93 void MaximizeModeWindowState::UpdateWindowPosition( |
| 107 wm::WindowState* window_state) { | 94 wm::WindowState* window_state) { |
| 108 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); | 95 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); |
| 109 if (bounds_in_parent == window_state->window()->GetBounds()) | 96 if (bounds_in_parent == window_state->window()->GetBounds()) |
| 110 return; | 97 return; |
| 111 window_state->SetBoundsDirect(bounds_in_parent); | 98 window_state->SetBoundsDirect(bounds_in_parent); |
| 112 } | 99 } |
| 113 | 100 |
| 114 MaximizeModeWindowState::MaximizeModeWindowState( | 101 MaximizeModeWindowState::MaximizeModeWindowState( |
| 115 aura::Window* window, MaximizeModeWindowManager* creator) | 102 WmWindow* window, |
| 103 MaximizeModeWindowManager* creator) | |
| 116 : window_(window), | 104 : window_(window), |
| 117 creator_(creator), | 105 creator_(creator), |
| 118 current_state_type_(wm::GetWindowState(window)->GetStateType()), | 106 current_state_type_(window->GetWindowState()->GetStateType()), |
| 119 defer_bounds_updates_(false) { | 107 defer_bounds_updates_(false) { |
| 120 old_state_.reset(wm::GetWindowState(window) | 108 old_state_.reset(window_->GetWindowState() |
| 121 ->SetStateObject(std::unique_ptr<State>(this)) | 109 ->SetStateObject(std::unique_ptr<State>(this)) |
| 122 .release()); | 110 .release()); |
| 123 } | 111 } |
| 124 | 112 |
| 125 MaximizeModeWindowState::~MaximizeModeWindowState() { | 113 MaximizeModeWindowState::~MaximizeModeWindowState() { |
| 126 creator_->WindowStateDestroyed(window_); | 114 creator_->WindowStateDestroyed(window_); |
| 127 } | 115 } |
| 128 | 116 |
| 129 void MaximizeModeWindowState::LeaveMaximizeMode(wm::WindowState* window_state) { | 117 void MaximizeModeWindowState::LeaveMaximizeMode(wm::WindowState* window_state) { |
| 130 // Note: When we return we will destroy ourselves with the |our_reference|. | 118 // Note: When we return we will destroy ourselves with the |our_reference|. |
| 131 std::unique_ptr<wm::WindowState::State> our_reference = | 119 std::unique_ptr<wm::WindowState::State> our_reference = |
| 132 window_state->SetStateObject(std::move(old_state_)); | 120 window_state->SetStateObject(std::move(old_state_)); |
| 133 } | 121 } |
| 134 | 122 |
| 135 void MaximizeModeWindowState::SetDeferBoundsUpdates(bool defer_bounds_updates) { | 123 void MaximizeModeWindowState::SetDeferBoundsUpdates(bool defer_bounds_updates) { |
| 136 if (defer_bounds_updates_ == defer_bounds_updates) | 124 if (defer_bounds_updates_ == defer_bounds_updates) |
| 137 return; | 125 return; |
| 138 | 126 |
| 139 defer_bounds_updates_ = defer_bounds_updates; | 127 defer_bounds_updates_ = defer_bounds_updates; |
| 140 if (!defer_bounds_updates_) | 128 if (!defer_bounds_updates_) |
| 141 UpdateBounds(wm::GetWindowState(window_), true); | 129 UpdateBounds(window_->GetWindowState(), true); |
| 142 } | 130 } |
| 143 | 131 |
| 144 void MaximizeModeWindowState::OnWMEvent(wm::WindowState* window_state, | 132 void MaximizeModeWindowState::OnWMEvent(wm::WindowState* window_state, |
| 145 const wm::WMEvent* event) { | 133 const wm::WMEvent* event) { |
| 146 switch (event->type()) { | 134 switch (event->type()) { |
| 147 case wm::WM_EVENT_TOGGLE_FULLSCREEN: | 135 case wm::WM_EVENT_TOGGLE_FULLSCREEN: |
| 148 ToggleFullScreen(window_state, window_state->delegate()); | 136 ToggleFullScreen(window_state, window_state->delegate()); |
| 149 break; | 137 break; |
| 150 case wm::WM_EVENT_FULLSCREEN: | 138 case wm::WM_EVENT_FULLSCREEN: |
| 151 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_FULLSCREEN, true); | 139 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_FULLSCREEN, true); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 | 211 |
| 224 wm::WindowStateType MaximizeModeWindowState::GetType() const { | 212 wm::WindowStateType MaximizeModeWindowState::GetType() const { |
| 225 return current_state_type_; | 213 return current_state_type_; |
| 226 } | 214 } |
| 227 | 215 |
| 228 void MaximizeModeWindowState::AttachState( | 216 void MaximizeModeWindowState::AttachState( |
| 229 wm::WindowState* window_state, | 217 wm::WindowState* window_state, |
| 230 wm::WindowState::State* previous_state) { | 218 wm::WindowState::State* previous_state) { |
| 231 current_state_type_ = previous_state->GetType(); | 219 current_state_type_ = previous_state->GetType(); |
| 232 | 220 |
| 233 aura::Window* window = | |
| 234 ash::WmWindowAura::GetAuraWindow(window_state->window()); | |
| 235 gfx::Rect restore_bounds = GetRestoreBounds(window_state); | 221 gfx::Rect restore_bounds = GetRestoreBounds(window_state); |
| 236 if (!restore_bounds.IsEmpty()) { | 222 if (!restore_bounds.IsEmpty()) { |
| 237 // We do not want to do a session restore to our window states. Therefore | 223 // We do not want to do a session restore to our window states. Therefore |
| 238 // we tell the window to use the current default states instead. | 224 // we tell the window to use the current default states instead. |
| 239 window->SetProperty(ash::kRestoreShowStateOverrideKey, | 225 window_state->window()->SetRestoreOverrides(restore_bounds, |
| 240 window_state->GetShowState()); | 226 window_state->GetShowState()); |
| 241 window->SetProperty(ash::kRestoreBoundsOverrideKey, | |
| 242 new gfx::Rect(restore_bounds)); | |
| 243 } | 227 } |
| 244 | 228 |
| 245 // Initialize the state to a good preset. | 229 // Initialize the state to a good preset. |
| 246 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && | 230 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && |
| 247 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && | 231 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && |
| 248 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && | 232 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && |
| 249 current_state_type_ != wm::WINDOW_STATE_TYPE_PINNED) { | 233 current_state_type_ != wm::WINDOW_STATE_TYPE_PINNED) { |
| 250 UpdateWindow(window_state, | 234 UpdateWindow(window_state, |
| 251 GetMaximizedOrCenteredWindowType(window_state), | 235 GetMaximizedOrCenteredWindowType(window_state), |
| 252 true); | 236 true); |
| 253 } | 237 } |
| 254 | 238 |
| 255 window_state->set_can_be_dragged(false); | 239 window_state->set_can_be_dragged(false); |
| 256 } | 240 } |
| 257 | 241 |
| 258 void MaximizeModeWindowState::DetachState(wm::WindowState* window_state) { | 242 void MaximizeModeWindowState::DetachState(wm::WindowState* window_state) { |
| 259 // From now on, we can use the default session restore mechanism again. | 243 // From now on, we can use the default session restore mechanism again. |
| 260 ash::WmWindowAura::GetAuraWindow(window_state->window()) | 244 window_state->window()->SetRestoreOverrides(gfx::Rect(), |
|
James Cook
2016/06/27 00:19:21
I like that you combined these into a single set/c
| |
| 261 ->ClearProperty(ash::kRestoreBoundsOverrideKey); | 245 ui::SHOW_STATE_NORMAL); |
| 262 window_state->set_can_be_dragged(true); | 246 window_state->set_can_be_dragged(true); |
| 263 } | 247 } |
| 264 | 248 |
| 265 void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state, | 249 void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state, |
| 266 wm::WindowStateType target_state, | 250 wm::WindowStateType target_state, |
| 267 bool animated) { | 251 bool animated) { |
| 268 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED || | 252 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED || |
| 269 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED || | 253 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED || |
| 270 target_state == wm::WINDOW_STATE_TYPE_PINNED || | 254 target_state == wm::WINDOW_STATE_TYPE_PINNED || |
| 271 (target_state == wm::WINDOW_STATE_TYPE_NORMAL && | 255 (target_state == wm::WINDOW_STATE_TYPE_NORMAL && |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 // avoid flashing. | 320 // avoid flashing. |
| 337 if (window_state->IsMaximized()) | 321 if (window_state->IsMaximized()) |
| 338 window_state->SetBoundsDirectCrossFade(bounds_in_parent); | 322 window_state->SetBoundsDirectCrossFade(bounds_in_parent); |
| 339 else | 323 else |
| 340 window_state->SetBoundsDirectAnimated(bounds_in_parent); | 324 window_state->SetBoundsDirectAnimated(bounds_in_parent); |
| 341 } | 325 } |
| 342 } | 326 } |
| 343 } | 327 } |
| 344 | 328 |
| 345 } // namespace ash | 329 } // namespace ash |
| OLD | NEW |