| 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 "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
| 8 #include "ash/screen_util.h" | 8 #include "ash/screen_util.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
| 11 #include "ash/wm/coordinate_conversion.h" | 11 #include "ash/wm/coordinate_conversion.h" |
| 12 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" | 12 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" |
| 13 #include "ash/wm/window_animations.h" | 13 #include "ash/wm/window_animations.h" |
| 14 #include "ash/wm/window_state.h" | 14 #include "ash/wm/window_state.h" |
| 15 #include "ash/wm/window_state_delegate.h" | 15 #include "ash/wm/window_state_delegate.h" |
| 16 #include "ash/wm/window_state_util.h" |
| 16 #include "ash/wm/window_util.h" | 17 #include "ash/wm/window_util.h" |
| 17 #include "ash/wm/wm_event.h" | 18 #include "ash/wm/wm_event.h" |
| 18 #include "ash/wm/workspace/workspace_window_resizer.h" | 19 #include "ash/wm/workspace/workspace_window_resizer.h" |
| 19 #include "ui/aura/client/aura_constants.h" | 20 #include "ui/aura/client/aura_constants.h" |
| 20 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 21 #include "ui/aura/window_delegate.h" | 22 #include "ui/aura/window_delegate.h" |
| 22 #include "ui/gfx/display.h" | 23 #include "ui/gfx/display.h" |
| 23 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
| 24 | 25 |
| 25 namespace ash { | 26 namespace ash { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 47 | 48 |
| 48 // Returns the centered bounds of the given bounds in the work area. | 49 // Returns the centered bounds of the given bounds in the work area. |
| 49 gfx::Rect GetCenteredBounds(const gfx::Rect& bounds_in_parent, | 50 gfx::Rect GetCenteredBounds(const gfx::Rect& bounds_in_parent, |
| 50 wm::WindowState* state_object) { | 51 wm::WindowState* state_object) { |
| 51 gfx::Rect work_area_in_parent = | 52 gfx::Rect work_area_in_parent = |
| 52 ScreenUtil::GetDisplayWorkAreaBoundsInParent(state_object->window()); | 53 ScreenUtil::GetDisplayWorkAreaBoundsInParent(state_object->window()); |
| 53 work_area_in_parent.ClampToCenteredSize(bounds_in_parent.size()); | 54 work_area_in_parent.ClampToCenteredSize(bounds_in_parent.size()); |
| 54 return work_area_in_parent; | 55 return work_area_in_parent; |
| 55 } | 56 } |
| 56 | 57 |
| 57 // Returns the maximized and centered bounds of a window. | 58 // Returns the maximized/full screen and/or centered bounds of a window. |
| 58 gfx::Rect GetMaximizedAndCenteredBounds(wm::WindowState* state_object) { | 59 gfx::Rect GetBoundsInMaximizedMode(wm::WindowState* state_object) { |
| 60 if (state_object->IsFullscreen()) |
| 61 return ScreenUtil::GetDisplayBoundsInParent(state_object->window()); |
| 62 |
| 59 gfx::Rect bounds_in_parent; | 63 gfx::Rect bounds_in_parent; |
| 60 // Make the window as big as possible. | 64 // Make the window as big as possible. |
| 61 if (state_object->CanMaximize() || state_object->CanResize()) { | 65 if (state_object->CanMaximize() || state_object->CanResize()) { |
| 62 bounds_in_parent.set_size(GetMaximumSizeOfWindow(state_object)); | 66 bounds_in_parent.set_size(GetMaximumSizeOfWindow(state_object)); |
| 63 } else { | 67 } else { |
| 64 // We prefer the user given window dimensions over the current windows | 68 // We prefer the user given window dimensions over the current windows |
| 65 // dimensions since they are likely to be the result from some other state | 69 // dimensions since they are likely to be the result from some other state |
| 66 // object logic. | 70 // object logic. |
| 67 if (state_object->HasRestoreBounds()) | 71 if (state_object->HasRestoreBounds()) |
| 68 bounds_in_parent = state_object->GetRestoreBoundsInParent(); | 72 bounds_in_parent = state_object->GetRestoreBoundsInParent(); |
| 69 else | 73 else |
| 70 bounds_in_parent = state_object->window()->bounds(); | 74 bounds_in_parent = state_object->window()->bounds(); |
| 71 } | 75 } |
| 72 return GetCenteredBounds(bounds_in_parent, state_object); | 76 return GetCenteredBounds(bounds_in_parent, state_object); |
| 73 } | 77 } |
| 74 | 78 |
| 75 } // namespace | 79 } // namespace |
| 76 | 80 |
| 77 // static | 81 // static |
| 78 void MaximizeModeWindowState::UpdateWindowPosition( | 82 void MaximizeModeWindowState::UpdateWindowPosition( |
| 79 wm::WindowState* window_state, bool animated) { | 83 wm::WindowState* window_state, bool animated) { |
| 80 gfx::Rect bounds_in_parent = GetMaximizedAndCenteredBounds(window_state); | 84 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); |
| 81 | 85 |
| 82 if (bounds_in_parent == window_state->window()->bounds()) | 86 if (bounds_in_parent == window_state->window()->bounds()) |
| 83 return; | 87 return; |
| 84 | 88 |
| 85 if (animated) | 89 if (animated) |
| 86 window_state->SetBoundsDirect(bounds_in_parent); | 90 window_state->SetBoundsDirect(bounds_in_parent); |
| 87 else | 91 else |
| 88 window_state->SetBoundsDirectAnimated(bounds_in_parent); | 92 window_state->SetBoundsDirectAnimated(bounds_in_parent); |
| 89 } | 93 } |
| 90 | 94 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 104 | 108 |
| 105 void MaximizeModeWindowState::LeaveMaximizeMode(wm::WindowState* window_state) { | 109 void MaximizeModeWindowState::LeaveMaximizeMode(wm::WindowState* window_state) { |
| 106 // Note: When we return we will destroy ourselves with the |our_reference|. | 110 // Note: When we return we will destroy ourselves with the |our_reference|. |
| 107 scoped_ptr<wm::WindowState::State> our_reference = | 111 scoped_ptr<wm::WindowState::State> our_reference = |
| 108 window_state->SetStateObject(old_state_.Pass()); | 112 window_state->SetStateObject(old_state_.Pass()); |
| 109 } | 113 } |
| 110 | 114 |
| 111 void MaximizeModeWindowState::OnWMEvent(wm::WindowState* window_state, | 115 void MaximizeModeWindowState::OnWMEvent(wm::WindowState* window_state, |
| 112 const wm::WMEvent* event) { | 116 const wm::WMEvent* event) { |
| 113 switch (event->type()) { | 117 switch (event->type()) { |
| 118 case wm::WM_EVENT_TOGGLE_FULLSCREEN: |
| 119 ToggleFullScreen(window_state, window_state->delegate()); |
| 120 break; |
| 121 case wm::WM_EVENT_FULLSCREEN: |
| 122 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_FULLSCREEN, true); |
| 123 break; |
| 114 case wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: | 124 case wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: |
| 115 case wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: | 125 case wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: |
| 116 case wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: | 126 case wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: |
| 117 case wm::WM_EVENT_TOGGLE_FULLSCREEN: | |
| 118 case wm::WM_EVENT_TOGGLE_MAXIMIZE: | 127 case wm::WM_EVENT_TOGGLE_MAXIMIZE: |
| 119 case wm::WM_EVENT_CENTER: | 128 case wm::WM_EVENT_CENTER: |
| 120 case wm::WM_EVENT_FULLSCREEN: | |
| 121 case wm::WM_EVENT_SNAP_LEFT: | 129 case wm::WM_EVENT_SNAP_LEFT: |
| 122 case wm::WM_EVENT_SNAP_RIGHT: | 130 case wm::WM_EVENT_SNAP_RIGHT: |
| 123 case wm::WM_EVENT_NORMAL: | 131 case wm::WM_EVENT_NORMAL: |
| 124 case wm::WM_EVENT_MAXIMIZE: | 132 case wm::WM_EVENT_MAXIMIZE: |
| 125 MaximizeOrCenterWindow(window_state, true); | 133 UpdateWindow(window_state, |
| 134 GetMaximizedOrCenteredWindowType(window_state), |
| 135 true); |
| 126 return; | 136 return; |
| 127 case wm::WM_EVENT_MINIMIZE: | 137 case wm::WM_EVENT_MINIMIZE: |
| 128 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED) { | 138 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_MINIMIZED, true); |
| 129 current_state_type_ = wm::WINDOW_STATE_TYPE_MINIMIZED; | |
| 130 Minimize(window_state); | |
| 131 } | |
| 132 return; | 139 return; |
| 133 case wm::WM_EVENT_SHOW_INACTIVE: | 140 case wm::WM_EVENT_SHOW_INACTIVE: |
| 134 return; | 141 return; |
| 135 case wm::WM_EVENT_SET_BOUNDS: | 142 case wm::WM_EVENT_SET_BOUNDS: |
| 136 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MAXIMIZED || | 143 if (window_state->CanResize()) { |
| 137 window_state->CanResize()) { | |
| 138 // In case the window is resizable and / or maximized we ignore the | 144 // In case the window is resizable and / or maximized we ignore the |
| 139 // requested bounds change and resize to the biggest possible size. | 145 // requested bounds change and resize to the biggest possible size. |
| 140 MaximizeOrCenterWindow(window_state, true); | 146 UpdateBounds(window_state, true); |
| 141 } else if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED) { | 147 } else |
| 148 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && |
| 149 current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED) { |
| 142 // In all other cases (except for minimized windows) we respect the | 150 // In all other cases (except for minimized windows) we respect the |
| 143 // requested bounds and center it to a fully visible area on the screen. | 151 // requested bounds and center it to a fully visible area on the screen. |
| 144 gfx::Rect bounds_in_parent = | 152 gfx::Rect bounds_in_parent = |
| 145 (static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds(); | 153 (static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds(); |
| 146 bounds_in_parent = GetCenteredBounds(bounds_in_parent, window_state); | 154 bounds_in_parent = GetCenteredBounds(bounds_in_parent, window_state); |
| 147 if (bounds_in_parent != window_state->window()->bounds()) { | 155 if (bounds_in_parent != window_state->window()->bounds()) { |
| 148 if (window_state->window()->IsVisible()) | 156 if (window_state->window()->IsVisible()) |
| 149 window_state->SetBoundsDirectAnimated(bounds_in_parent); | 157 window_state->SetBoundsDirectAnimated(bounds_in_parent); |
| 150 else | 158 else |
| 151 window_state->SetBoundsDirect(bounds_in_parent); | 159 window_state->SetBoundsDirect(bounds_in_parent); |
| 152 } | 160 } |
| 153 } | 161 } |
| 154 break; | 162 break; |
| 155 case wm::WM_EVENT_ADDED_TO_WORKSPACE: | 163 case wm::WM_EVENT_ADDED_TO_WORKSPACE: |
| 156 MaximizeOrCenterWindow(window_state, true); | 164 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && |
| 165 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && |
| 166 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED) { |
| 167 wm::WindowStateType new_state = |
| 168 GetMaximizedOrCenteredWindowType(window_state); |
| 169 UpdateWindow(window_state, new_state, true); |
| 170 } |
| 157 break; | 171 break; |
| 158 case wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED: | 172 case wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED: |
| 159 case wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED: | 173 case wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED: |
| 160 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED) | 174 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED) |
| 161 MaximizeOrCenterWindow(window_state, false); | 175 UpdateBounds(window_state, true); |
| 162 break; | 176 break; |
| 163 } | 177 } |
| 164 } | 178 } |
| 165 | 179 |
| 166 wm::WindowStateType MaximizeModeWindowState::GetType() const { | 180 wm::WindowStateType MaximizeModeWindowState::GetType() const { |
| 167 return current_state_type_; | 181 return current_state_type_; |
| 168 } | 182 } |
| 169 | 183 |
| 170 void MaximizeModeWindowState::AttachState( | 184 void MaximizeModeWindowState::AttachState( |
| 171 wm::WindowState* window_state, | 185 wm::WindowState* window_state, |
| 172 wm::WindowState::State* previous_state) { | 186 wm::WindowState::State* previous_state) { |
| 173 current_state_type_ = previous_state->GetType(); | 187 current_state_type_ = previous_state->GetType(); |
| 174 | 188 |
| 175 // Initialize the state to a good preset. | 189 // Initialize the state to a good preset. |
| 176 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && | 190 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && |
| 177 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED) { | 191 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && |
| 178 MaximizeOrCenterWindow(window_state, true); | 192 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) { |
| 193 UpdateWindow(window_state, |
| 194 GetMaximizedOrCenteredWindowType(window_state), |
| 195 true); |
| 179 } | 196 } |
| 180 | 197 |
| 181 window_state->set_can_be_dragged(false); | 198 window_state->set_can_be_dragged(false); |
| 182 } | 199 } |
| 183 | 200 |
| 184 void MaximizeModeWindowState::DetachState(wm::WindowState* window_state) { | 201 void MaximizeModeWindowState::DetachState(wm::WindowState* window_state) { |
| 185 window_state->set_can_be_dragged(true); | 202 window_state->set_can_be_dragged(true); |
| 186 } | 203 } |
| 187 | 204 |
| 188 void MaximizeModeWindowState::MaximizeOrCenterWindow( | 205 void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state, |
| 189 wm::WindowState* window_state, | 206 wm::WindowStateType target_state, |
| 190 bool animated) { | 207 bool animated) { |
| 191 const wm::WindowStateType target_state = | 208 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED || |
| 192 window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED : | 209 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED || |
| 193 wm::WINDOW_STATE_TYPE_NORMAL; | 210 (target_state == wm::WINDOW_STATE_TYPE_NORMAL && |
| 211 !window_state->CanMaximize()) || |
| 212 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN); |
| 213 |
| 214 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) { |
| 215 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED) |
| 216 return; |
| 217 |
| 218 current_state_type_ = target_state; |
| 219 ::wm::SetWindowVisibilityAnimationType( |
| 220 window_state->window(), WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); |
| 221 window_state->window()->Hide(); |
| 222 if (window_state->IsActive()) |
| 223 window_state->Deactivate(); |
| 224 return; |
| 225 } |
| 226 |
| 227 if (current_state_type_ == target_state) { |
| 228 // If the state type did not change, update it accordingly. |
| 229 UpdateBounds(window_state, animated); |
| 230 return; |
| 231 } |
| 232 |
| 194 const wm::WindowStateType old_state_type = current_state_type_; | 233 const wm::WindowStateType old_state_type = current_state_type_; |
| 195 gfx::Rect bounds_in_parent = GetMaximizedAndCenteredBounds(window_state); | 234 current_state_type_ = target_state; |
| 196 | 235 window_state->UpdateWindowShowStateFromStateType(); |
| 197 if (current_state_type_ != target_state) { | 236 window_state->NotifyPreStateTypeChange(old_state_type); |
| 198 current_state_type_ = target_state; | 237 UpdateBounds(window_state, animated); |
| 199 window_state->UpdateWindowShowStateFromStateType(); | 238 window_state->NotifyPostStateTypeChange(old_state_type); |
| 200 window_state->NotifyPreStateTypeChange(old_state_type); | |
| 201 // If we have a target bounds rectangle, we center it and set it | |
| 202 // accordingly. | |
| 203 if (!bounds_in_parent.IsEmpty()) { | |
| 204 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED || !animated) | |
| 205 window_state->SetBoundsDirect(bounds_in_parent); | |
| 206 else | |
| 207 window_state->SetBoundsDirectAnimated(bounds_in_parent); | |
| 208 } | |
| 209 window_state->NotifyPostStateTypeChange(old_state_type); | |
| 210 } else if (!bounds_in_parent.IsEmpty() && | |
| 211 bounds_in_parent != window_state->window()->bounds()) { | |
| 212 // Coming here, we were most probably called through a display change. | |
| 213 // Do not animate. | |
| 214 if (animated) | |
| 215 window_state->SetBoundsDirectAnimated(bounds_in_parent); | |
| 216 else | |
| 217 window_state->SetBoundsDirect(bounds_in_parent); | |
| 218 } | |
| 219 | 239 |
| 220 if ((window_state->window()->TargetVisibility() || | 240 if ((window_state->window()->TargetVisibility() || |
| 221 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) && | 241 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) && |
| 222 !window_state->window()->layer()->visible()) { | 242 !window_state->window()->layer()->visible()) { |
| 223 // The layer may be hidden if the window was previously minimized. Make | 243 // The layer may be hidden if the window was previously minimized. Make |
| 224 // sure it's visible. | 244 // sure it's visible. |
| 225 window_state->window()->Show(); | 245 window_state->window()->Show(); |
| 226 } | 246 } |
| 227 } | 247 } |
| 228 | 248 |
| 229 void MaximizeModeWindowState::Minimize(wm::WindowState* window_state) { | 249 wm::WindowStateType MaximizeModeWindowState::GetMaximizedOrCenteredWindowType( |
| 230 ::wm::SetWindowVisibilityAnimationType( | 250 wm::WindowState* window_state) { |
| 231 window_state->window(), WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); | 251 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED : |
| 252 wm::WINDOW_STATE_TYPE_NORMAL; |
| 253 } |
| 232 | 254 |
| 233 // Hide the window. | 255 void MaximizeModeWindowState::UpdateBounds(wm::WindowState* window_state, |
| 234 window_state->window()->Hide(); | 256 bool animated) { |
| 235 // Activate another window. | 257 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); |
| 236 if (window_state->IsActive()) | 258 // If we have a target bounds rectangle, we center it and set it |
| 237 window_state->Deactivate(); | 259 // accordingly. |
| 260 if (!bounds_in_parent.IsEmpty() && |
| 261 bounds_in_parent != window_state->window()->bounds()) { |
| 262 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED || |
| 263 !window_state->window()->IsVisible() || |
| 264 !animated) { |
| 265 window_state->SetBoundsDirect(bounds_in_parent); |
| 266 } else { |
| 267 window_state->SetBoundsDirectAnimated(bounds_in_parent); |
| 268 } |
| 269 } |
| 238 } | 270 } |
| 239 | 271 |
| 240 } // namespace ash | 272 } // namespace ash |
| OLD | NEW |