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/public/cpp/shell_window_ids.h" | 9 #include "ash/public/cpp/shell_window_ids.h" |
10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.h" |
11 #include "ash/shell.h" | 11 #include "ash/shell.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/screen_pinning_controller.h" | 13 #include "ash/wm/screen_pinning_controller.h" |
14 #include "ash/wm/splitview/split_view_controller.h" | |
14 #include "ash/wm/window_animation_types.h" | 15 #include "ash/wm/window_animation_types.h" |
15 #include "ash/wm/window_properties.h" | 16 #include "ash/wm/window_properties.h" |
16 #include "ash/wm/window_state_util.h" | 17 #include "ash/wm/window_state_util.h" |
17 #include "ash/wm/wm_event.h" | 18 #include "ash/wm/wm_event.h" |
18 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
19 #include "ui/aura/window_delegate.h" | 20 #include "ui/aura/window_delegate.h" |
20 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
21 #include "ui/gfx/geometry/rect.h" | 22 #include "ui/gfx/geometry/rect.h" |
22 | 23 |
23 namespace ash { | 24 namespace ash { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 ScreenUtil::GetDisplayWorkAreaBoundsInParent(state_object->window()); | 66 ScreenUtil::GetDisplayWorkAreaBoundsInParent(state_object->window()); |
66 work_area_in_parent.ClampToCenteredSize(bounds_in_parent.size()); | 67 work_area_in_parent.ClampToCenteredSize(bounds_in_parent.size()); |
67 return work_area_in_parent; | 68 return work_area_in_parent; |
68 } | 69 } |
69 | 70 |
70 // Returns the maximized/full screen and/or centered bounds of a window. | 71 // Returns the maximized/full screen and/or centered bounds of a window. |
71 gfx::Rect GetBoundsInMaximizedMode(wm::WindowState* state_object) { | 72 gfx::Rect GetBoundsInMaximizedMode(wm::WindowState* state_object) { |
72 if (state_object->IsFullscreen() || state_object->IsPinned()) | 73 if (state_object->IsFullscreen() || state_object->IsPinned()) |
73 return ScreenUtil::GetDisplayBoundsInParent(state_object->window()); | 74 return ScreenUtil::GetDisplayBoundsInParent(state_object->window()); |
74 | 75 |
76 if (state_object->CanSnap() && SplitViewController::ShouldAllowSplitView() && | |
oshima
2017/06/14 00:19:26
do you need CanSnap check? I believe it shouldn't
xdai1
2017/06/15 22:11:41
Yes. Theoretically the state type won't be wm::WIN
oshima
2017/06/16 01:20:56
Please use DCHECK if that condition shouldn't happ
xdai1
2017/06/16 18:49:52
Moved the CanSnap() to DCHECK.
| |
77 state_object->GetStateType() == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED) { | |
78 return Shell::Get()->split_view_controller()->GetLeftWindowBoundsInParent( | |
oshima
2017/06/14 00:19:26
You may want to call it first, second as you most
xdai1
2017/06/15 22:11:41
Do you mean put the two if-clause at top of this f
oshima
2017/06/16 01:20:56
I was going to remove this comment, sorry. You may
xdai1
2017/06/16 18:49:52
Put it back here.
| |
79 state_object->window()); | |
80 } | |
81 | |
82 if (state_object->CanSnap() && SplitViewController::ShouldAllowSplitView() && | |
83 state_object->GetStateType() == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED) { | |
84 return Shell::Get()->split_view_controller()->GetRightWindowBoundsInParent( | |
85 state_object->window()); | |
86 } | |
87 | |
75 gfx::Rect bounds_in_parent; | 88 gfx::Rect bounds_in_parent; |
76 // Make the window as big as possible. | 89 // Make the window as big as possible. |
77 if (state_object->CanMaximize() || state_object->CanResize()) { | 90 if (state_object->CanMaximize() || state_object->CanResize()) { |
78 bounds_in_parent.set_size(GetMaximumSizeOfWindow(state_object)); | 91 bounds_in_parent.set_size(GetMaximumSizeOfWindow(state_object)); |
79 } else { | 92 } else { |
80 // We prefer the user given window dimensions over the current windows | 93 // We prefer the user given window dimensions over the current windows |
81 // dimensions since they are likely to be the result from some other state | 94 // dimensions since they are likely to be the result from some other state |
82 // object logic. | 95 // object logic. |
83 if (state_object->HasRestoreBounds()) | 96 if (state_object->HasRestoreBounds()) |
84 bounds_in_parent = state_object->GetRestoreBoundsInParent(); | 97 bounds_in_parent = state_object->GetRestoreBoundsInParent(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 if (!Shell::Get()->screen_pinning_controller()->IsPinned()) | 175 if (!Shell::Get()->screen_pinning_controller()->IsPinned()) |
163 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_TRUSTED_PINNED, true); | 176 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_TRUSTED_PINNED, true); |
164 break; | 177 break; |
165 case wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: | 178 case wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: |
166 case wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: | 179 case wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: |
167 case wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: | 180 case wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: |
168 case wm::WM_EVENT_TOGGLE_MAXIMIZE: | 181 case wm::WM_EVENT_TOGGLE_MAXIMIZE: |
169 case wm::WM_EVENT_CYCLE_SNAP_LEFT: | 182 case wm::WM_EVENT_CYCLE_SNAP_LEFT: |
170 case wm::WM_EVENT_CYCLE_SNAP_RIGHT: | 183 case wm::WM_EVENT_CYCLE_SNAP_RIGHT: |
171 case wm::WM_EVENT_CENTER: | 184 case wm::WM_EVENT_CENTER: |
172 case wm::WM_EVENT_SNAP_LEFT: | |
173 case wm::WM_EVENT_SNAP_RIGHT: | |
174 case wm::WM_EVENT_NORMAL: | 185 case wm::WM_EVENT_NORMAL: |
175 case wm::WM_EVENT_MAXIMIZE: | 186 case wm::WM_EVENT_MAXIMIZE: |
176 UpdateWindow(window_state, GetMaximizedOrCenteredWindowType(window_state), | 187 UpdateWindow(window_state, GetMaximizedOrCenteredWindowType(window_state), |
177 true); | 188 true); |
178 return; | 189 return; |
190 case wm::WM_EVENT_SNAP_LEFT: | |
191 if (SplitViewController::ShouldAllowSplitView()) { | |
192 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, true); | |
193 } else { | |
194 UpdateWindow(window_state, | |
195 GetMaximizedOrCenteredWindowType(window_state), true); | |
196 } | |
197 return; | |
198 case wm::WM_EVENT_SNAP_RIGHT: | |
199 if (SplitViewController::ShouldAllowSplitView()) { | |
200 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED, true); | |
201 } else { | |
202 UpdateWindow(window_state, | |
203 GetMaximizedOrCenteredWindowType(window_state), true); | |
204 } | |
205 return; | |
179 case wm::WM_EVENT_MINIMIZE: | 206 case wm::WM_EVENT_MINIMIZE: |
180 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_MINIMIZED, true); | 207 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_MINIMIZED, true); |
181 return; | 208 return; |
182 case wm::WM_EVENT_SHOW_INACTIVE: | 209 case wm::WM_EVENT_SHOW_INACTIVE: |
183 return; | 210 return; |
184 case wm::WM_EVENT_SET_BOUNDS: | 211 case wm::WM_EVENT_SET_BOUNDS: |
185 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MAXIMIZED) { | 212 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MAXIMIZED) { |
186 // Having a maximized window, it could have been created with an empty | 213 // Having a maximized window, it could have been created with an empty |
187 // size and the caller should get his size upon leaving the maximized | 214 // size and the caller should get his size upon leaving the maximized |
188 // mode. As such we set the restore bounds to the requested bounds. | 215 // mode. As such we set the restore bounds to the requested bounds. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 | 294 |
268 void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state, | 295 void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state, |
269 wm::WindowStateType target_state, | 296 wm::WindowStateType target_state, |
270 bool animated) { | 297 bool animated) { |
271 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED || | 298 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED || |
272 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED || | 299 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED || |
273 target_state == wm::WINDOW_STATE_TYPE_PINNED || | 300 target_state == wm::WINDOW_STATE_TYPE_PINNED || |
274 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED || | 301 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED || |
275 (target_state == wm::WINDOW_STATE_TYPE_NORMAL && | 302 (target_state == wm::WINDOW_STATE_TYPE_NORMAL && |
276 !window_state->CanMaximize()) || | 303 !window_state->CanMaximize()) || |
277 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN); | 304 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN || |
305 target_state == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED || | |
306 target_state == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED); | |
278 | 307 |
279 if (current_state_type_ == target_state) { | 308 if (current_state_type_ == target_state) { |
280 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) | 309 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) |
281 return; | 310 return; |
282 // If the state type did not change, update it accordingly. | 311 // If the state type did not change, update it accordingly. |
283 UpdateBounds(window_state, animated); | 312 UpdateBounds(window_state, animated); |
284 return; | 313 return; |
285 } | 314 } |
286 | 315 |
287 const wm::WindowStateType old_state_type = current_state_type_; | 316 const wm::WindowStateType old_state_type = current_state_type_; |
288 current_state_type_ = target_state; | 317 current_state_type_ = target_state; |
289 window_state->UpdateWindowPropertiesFromStateType(); | 318 window_state->UpdateWindowPropertiesFromStateType(); |
290 window_state->NotifyPreStateTypeChange(old_state_type); | 319 window_state->NotifyPreStateTypeChange(old_state_type); |
291 | 320 |
292 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) { | 321 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) { |
293 ::wm::SetWindowVisibilityAnimationType( | 322 ::wm::SetWindowVisibilityAnimationType( |
294 window_state->window(), wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); | 323 window_state->window(), wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); |
295 window_state->window()->Hide(); | 324 window_state->window()->Hide(); |
296 if (window_state->IsActive()) | 325 if (window_state->IsActive()) |
297 window_state->Deactivate(); | 326 window_state->Deactivate(); |
327 } else if (target_state == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED || | |
328 target_state == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED) { | |
329 gfx::Rect bounds = | |
330 (target_state == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED) | |
oshima
2017/06/14 00:19:26
it's probably simple to have two ifs. (just a gues
xdai1
2017/06/15 22:11:41
Done.
| |
331 ? Shell::Get() | |
332 ->split_view_controller() | |
333 ->GetLeftWindowBoundsInParent(window_state->window()) | |
334 : Shell::Get() | |
335 ->split_view_controller() | |
336 ->GetRightWindowBoundsInParent(window_state->window()); | |
337 window_state->SetBoundsDirectAnimated(bounds); | |
298 } else { | 338 } else { |
299 UpdateBounds(window_state, animated); | 339 UpdateBounds(window_state, animated); |
300 } | 340 } |
301 | 341 |
302 window_state->NotifyPostStateTypeChange(old_state_type); | 342 window_state->NotifyPostStateTypeChange(old_state_type); |
303 | 343 |
304 if (old_state_type == wm::WINDOW_STATE_TYPE_PINNED || | 344 if (old_state_type == wm::WINDOW_STATE_TYPE_PINNED || |
305 target_state == wm::WINDOW_STATE_TYPE_PINNED || | 345 target_state == wm::WINDOW_STATE_TYPE_PINNED || |
306 old_state_type == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED || | 346 old_state_type == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED || |
307 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED) { | 347 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 // avoid flashing. | 381 // avoid flashing. |
342 if (window_state->IsMaximized()) | 382 if (window_state->IsMaximized()) |
343 window_state->SetBoundsDirectCrossFade(bounds_in_parent); | 383 window_state->SetBoundsDirectCrossFade(bounds_in_parent); |
344 else | 384 else |
345 window_state->SetBoundsDirectAnimated(bounds_in_parent); | 385 window_state->SetBoundsDirectAnimated(bounds_in_parent); |
346 } | 386 } |
347 } | 387 } |
348 } | 388 } |
349 | 389 |
350 } // namespace ash | 390 } // namespace ash |
OLD | NEW |