Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(820)

Side by Side Diff: ash/wm/maximize_mode/maximize_mode_window_state.cc

Issue 1890713002: Adds WmWindow and converts WindowState to use it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge again Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/screen_util.h" 9 #include "ash/screen_util.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/shell_window_ids.h" 11 #include "ash/shell_window_ids.h"
12 #include "ash/wm/common/wm_event.h" 12 #include "ash/wm/common/wm_event.h"
13 #include "ash/wm/coordinate_conversion.h" 13 #include "ash/wm/coordinate_conversion.h"
14 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" 14 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h"
15 #include "ash/wm/window_animations.h" 15 #include "ash/wm/window_animations.h"
16 #include "ash/wm/window_properties.h" 16 #include "ash/wm/window_properties.h"
17 #include "ash/wm/window_state_aura.h"
17 #include "ash/wm/window_state_delegate.h" 18 #include "ash/wm/window_state_delegate.h"
18 #include "ash/wm/window_state_util.h" 19 #include "ash/wm/window_state_util.h"
19 #include "ash/wm/window_util.h" 20 #include "ash/wm/window_util.h"
20 #include "ash/wm/workspace/workspace_window_resizer.h" 21 #include "ash/wm/workspace/workspace_window_resizer.h"
21 #include "ui/aura/client/aura_constants.h" 22 #include "ui/aura/client/aura_constants.h"
22 #include "ui/aura/window.h" 23 #include "ui/aura/window.h"
23 #include "ui/aura/window_delegate.h" 24 #include "ui/aura/window_delegate.h"
24 #include "ui/compositor/layer.h" 25 #include "ui/compositor/layer.h"
25 #include "ui/gfx/display.h" 26 #include "ui/gfx/display.h"
26 #include "ui/gfx/geometry/rect.h" 27 #include "ui/gfx/geometry/rect.h"
27 #include "ui/views/view_constants_aura.h" 28 #include "ui/views/view_constants_aura.h"
28 #include "ui/views/widget/widget.h" 29 #include "ui/views/widget/widget.h"
29 30
30 namespace ash { 31 namespace ash {
31 namespace { 32 namespace {
32 33
33 // Returns the biggest possible size for a window which is about to be 34 // Returns the biggest possible size for a window which is about to be
34 // maximized. 35 // maximized.
35 gfx::Size GetMaximumSizeOfWindow(wm::WindowState* window_state) { 36 gfx::Size GetMaximumSizeOfWindow(wm::WindowState* window_state) {
36 DCHECK(window_state->CanMaximize() || window_state->CanResize()); 37 DCHECK(window_state->CanMaximize() || window_state->CanResize());
37 38
38 gfx::Size workspace_size = ScreenUtil::GetMaximizedWindowBoundsInParent( 39 gfx::Size workspace_size =
39 window_state->window()).size(); 40 ScreenUtil::GetMaximizedWindowBoundsInParent(window_state->aura_window())
41 .size();
40 42
41 aura::WindowDelegate* delegate = window_state->window()->delegate(); 43 aura::WindowDelegate* delegate = window_state->aura_window()->delegate();
42 if (!delegate) 44 if (!delegate)
43 return workspace_size; 45 return workspace_size;
44 46
45 gfx::Size size = delegate->GetMaximumSize(); 47 gfx::Size size = delegate->GetMaximumSize();
46 if (size.IsEmpty()) 48 if (size.IsEmpty())
47 return workspace_size; 49 return workspace_size;
48 50
49 size.SetToMin(workspace_size); 51 size.SetToMin(workspace_size);
50 return size; 52 return size;
51 } 53 }
52 54
53 // Returns the centered bounds of the given bounds in the work area. 55 // Returns the centered bounds of the given bounds in the work area.
54 gfx::Rect GetCenteredBounds(const gfx::Rect& bounds_in_parent, 56 gfx::Rect GetCenteredBounds(const gfx::Rect& bounds_in_parent,
55 wm::WindowState* state_object) { 57 wm::WindowState* state_object) {
56 gfx::Rect work_area_in_parent = 58 gfx::Rect work_area_in_parent =
57 ScreenUtil::GetDisplayWorkAreaBoundsInParent(state_object->window()); 59 ScreenUtil::GetDisplayWorkAreaBoundsInParent(state_object->aura_window());
58 work_area_in_parent.ClampToCenteredSize(bounds_in_parent.size()); 60 work_area_in_parent.ClampToCenteredSize(bounds_in_parent.size());
59 return work_area_in_parent; 61 return work_area_in_parent;
60 } 62 }
61 63
62 // Returns the maximized/full screen and/or centered bounds of a window. 64 // Returns the maximized/full screen and/or centered bounds of a window.
63 gfx::Rect GetBoundsInMaximizedMode(wm::WindowState* state_object) { 65 gfx::Rect GetBoundsInMaximizedMode(wm::WindowState* state_object) {
64 if (state_object->IsFullscreen()) 66 if (state_object->IsFullscreen())
65 return ScreenUtil::GetDisplayBoundsInParent(state_object->window()); 67 return ScreenUtil::GetDisplayBoundsInParent(state_object->aura_window());
66 68
67 gfx::Rect bounds_in_parent; 69 gfx::Rect bounds_in_parent;
68 // Make the window as big as possible. 70 // Make the window as big as possible.
69 if (state_object->CanMaximize() || state_object->CanResize()) { 71 if (state_object->CanMaximize() || state_object->CanResize()) {
70 bounds_in_parent.set_size(GetMaximumSizeOfWindow(state_object)); 72 bounds_in_parent.set_size(GetMaximumSizeOfWindow(state_object));
71 } else { 73 } else {
72 // We prefer the user given window dimensions over the current windows 74 // We prefer the user given window dimensions over the current windows
73 // dimensions since they are likely to be the result from some other state 75 // dimensions since they are likely to be the result from some other state
74 // object logic. 76 // object logic.
75 if (state_object->HasRestoreBounds()) 77 if (state_object->HasRestoreBounds())
76 bounds_in_parent = state_object->GetRestoreBoundsInParent(); 78 bounds_in_parent = state_object->GetRestoreBoundsInParent();
77 else 79 else
78 bounds_in_parent = state_object->window()->bounds(); 80 bounds_in_parent = state_object->aura_window()->bounds();
79 } 81 }
80 return GetCenteredBounds(bounds_in_parent, state_object); 82 return GetCenteredBounds(bounds_in_parent, state_object);
81 } 83 }
82 84
83 } // namespace 85 } // namespace
84 86
85 // static 87 // static
86 void MaximizeModeWindowState::UpdateWindowPosition( 88 void MaximizeModeWindowState::UpdateWindowPosition(
87 wm::WindowState* window_state) { 89 wm::WindowState* window_state) {
88 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); 90 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state);
89 if (bounds_in_parent == window_state->window()->bounds()) 91 if (bounds_in_parent == window_state->aura_window()->bounds())
90 return; 92 return;
91 window_state->SetBoundsDirect(bounds_in_parent); 93 window_state->SetBoundsDirect(bounds_in_parent);
92 } 94 }
93 95
94 MaximizeModeWindowState::MaximizeModeWindowState( 96 MaximizeModeWindowState::MaximizeModeWindowState(
95 aura::Window* window, MaximizeModeWindowManager* creator) 97 aura::Window* window, MaximizeModeWindowManager* creator)
96 : window_(window), 98 : window_(window),
97 creator_(creator), 99 creator_(creator),
98 current_state_type_(wm::GetWindowState(window)->GetStateType()), 100 current_state_type_(wm::GetWindowState(window)->GetStateType()),
99 defer_bounds_updates_(false) { 101 defer_bounds_updates_(false) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 if (!bounds_in_parent.IsEmpty()) 163 if (!bounds_in_parent.IsEmpty())
162 window_state->SetRestoreBoundsInParent(bounds_in_parent); 164 window_state->SetRestoreBoundsInParent(bounds_in_parent);
163 } else if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && 165 } else if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED &&
164 current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && 166 current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED &&
165 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) { 167 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) {
166 // In all other cases (except for minimized windows) we respect the 168 // In all other cases (except for minimized windows) we respect the
167 // requested bounds and center it to a fully visible area on the screen. 169 // requested bounds and center it to a fully visible area on the screen.
168 gfx::Rect bounds_in_parent = 170 gfx::Rect bounds_in_parent =
169 (static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds(); 171 (static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds();
170 bounds_in_parent = GetCenteredBounds(bounds_in_parent, window_state); 172 bounds_in_parent = GetCenteredBounds(bounds_in_parent, window_state);
171 if (bounds_in_parent != window_state->window()->bounds()) { 173 if (bounds_in_parent != window_state->aura_window()->bounds()) {
172 if (window_state->window()->IsVisible()) 174 if (window_state->window()->IsVisible())
173 window_state->SetBoundsDirectAnimated(bounds_in_parent); 175 window_state->SetBoundsDirectAnimated(bounds_in_parent);
174 else 176 else
175 window_state->SetBoundsDirect(bounds_in_parent); 177 window_state->SetBoundsDirect(bounds_in_parent);
176 } 178 }
177 } 179 }
178 break; 180 break;
179 case wm::WM_EVENT_ADDED_TO_WORKSPACE: 181 case wm::WM_EVENT_ADDED_TO_WORKSPACE:
180 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && 182 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED &&
181 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && 183 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN &&
(...skipping 18 matching lines...) Expand all
200 wm::WindowStateType MaximizeModeWindowState::GetType() const { 202 wm::WindowStateType MaximizeModeWindowState::GetType() const {
201 return current_state_type_; 203 return current_state_type_;
202 } 204 }
203 205
204 void MaximizeModeWindowState::AttachState( 206 void MaximizeModeWindowState::AttachState(
205 wm::WindowState* window_state, 207 wm::WindowState* window_state,
206 wm::WindowState::State* previous_state) { 208 wm::WindowState::State* previous_state) {
207 current_state_type_ = previous_state->GetType(); 209 current_state_type_ = previous_state->GetType();
208 210
209 views::Widget* widget = 211 views::Widget* widget =
210 views::Widget::GetWidgetForNativeWindow(window_state->window()); 212 views::Widget::GetWidgetForNativeWindow(window_state->aura_window());
211 if (widget) { 213 if (widget) {
212 gfx::Rect bounds = widget->GetRestoredBounds(); 214 gfx::Rect bounds = widget->GetRestoredBounds();
213 if (!bounds.IsEmpty()) { 215 if (!bounds.IsEmpty()) {
214 // We do not want to do a session restore to our window states. Therefore 216 // We do not want to do a session restore to our window states. Therefore
215 // we tell the window to use the current default states instead. 217 // we tell the window to use the current default states instead.
216 window_state->window()->SetProperty(ash::kRestoreShowStateOverrideKey, 218 window_state->aura_window()->SetProperty(
217 window_state->GetShowState()); 219 ash::kRestoreShowStateOverrideKey, window_state->GetShowState());
218 window_state->window()->SetProperty(ash::kRestoreBoundsOverrideKey, 220 window_state->aura_window()->SetProperty(
221 ash::kRestoreBoundsOverrideKey,
219 new gfx::Rect(widget->GetRestoredBounds())); 222 new gfx::Rect(widget->GetRestoredBounds()));
220 } 223 }
221 } 224 }
222 225
223 // Initialize the state to a good preset. 226 // Initialize the state to a good preset.
224 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && 227 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED &&
225 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && 228 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED &&
226 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) { 229 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) {
227 UpdateWindow(window_state, 230 UpdateWindow(window_state,
228 GetMaximizedOrCenteredWindowType(window_state), 231 GetMaximizedOrCenteredWindowType(window_state),
229 true); 232 true);
230 } 233 }
231 234
232 window_state->set_can_be_dragged(false); 235 window_state->set_can_be_dragged(false);
233 } 236 }
234 237
235 void MaximizeModeWindowState::DetachState(wm::WindowState* window_state) { 238 void MaximizeModeWindowState::DetachState(wm::WindowState* window_state) {
236 // From now on, we can use the default session restore mechanism again. 239 // From now on, we can use the default session restore mechanism again.
237 window_state->window()->ClearProperty(ash::kRestoreBoundsOverrideKey); 240 window_state->aura_window()->ClearProperty(ash::kRestoreBoundsOverrideKey);
238 window_state->set_can_be_dragged(true); 241 window_state->set_can_be_dragged(true);
239 } 242 }
240 243
241 void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state, 244 void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state,
242 wm::WindowStateType target_state, 245 wm::WindowStateType target_state,
243 bool animated) { 246 bool animated) {
244 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED || 247 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED ||
245 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED || 248 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED ||
246 (target_state == wm::WINDOW_STATE_TYPE_NORMAL && 249 (target_state == wm::WINDOW_STATE_TYPE_NORMAL &&
247 !window_state->CanMaximize()) || 250 !window_state->CanMaximize()) ||
248 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN); 251 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN);
249 252
250 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) { 253 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) {
251 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED) 254 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED)
252 return; 255 return;
253 256
254 current_state_type_ = target_state; 257 current_state_type_ = target_state;
255 ::wm::SetWindowVisibilityAnimationType( 258 ::wm::SetWindowVisibilityAnimationType(
256 window_state->window(), WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); 259 window_state->aura_window(), WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
257 window_state->window()->Hide(); 260 window_state->window()->Hide();
258 if (window_state->IsActive()) 261 if (window_state->IsActive())
259 window_state->Deactivate(); 262 window_state->Deactivate();
260 return; 263 return;
261 } 264 }
262 265
263 if (current_state_type_ == target_state) { 266 if (current_state_type_ == target_state) {
264 // If the state type did not change, update it accordingly. 267 // If the state type did not change, update it accordingly.
265 UpdateBounds(window_state, animated); 268 UpdateBounds(window_state, animated);
266 return; 269 return;
267 } 270 }
268 271
269 const wm::WindowStateType old_state_type = current_state_type_; 272 const wm::WindowStateType old_state_type = current_state_type_;
270 current_state_type_ = target_state; 273 current_state_type_ = target_state;
271 window_state->UpdateWindowShowStateFromStateType(); 274 window_state->UpdateWindowShowStateFromStateType();
272 window_state->NotifyPreStateTypeChange(old_state_type); 275 window_state->NotifyPreStateTypeChange(old_state_type);
273 UpdateBounds(window_state, animated); 276 UpdateBounds(window_state, animated);
274 window_state->NotifyPostStateTypeChange(old_state_type); 277 window_state->NotifyPostStateTypeChange(old_state_type);
275 278
276 if ((window_state->window()->TargetVisibility() || 279 if ((window_state->aura_window()->TargetVisibility() ||
277 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) && 280 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) &&
278 !window_state->window()->layer()->visible()) { 281 !window_state->aura_window()->layer()->visible()) {
279 // The layer may be hidden if the window was previously minimized. Make 282 // The layer may be hidden if the window was previously minimized. Make
280 // sure it's visible. 283 // sure it's visible.
281 window_state->window()->Show(); 284 window_state->window()->Show();
282 } 285 }
283 } 286 }
284 287
285 wm::WindowStateType MaximizeModeWindowState::GetMaximizedOrCenteredWindowType( 288 wm::WindowStateType MaximizeModeWindowState::GetMaximizedOrCenteredWindowType(
286 wm::WindowState* window_state) { 289 wm::WindowState* window_state) {
287 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED : 290 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED :
288 wm::WINDOW_STATE_TYPE_NORMAL; 291 wm::WINDOW_STATE_TYPE_NORMAL;
289 } 292 }
290 293
291 void MaximizeModeWindowState::UpdateBounds(wm::WindowState* window_state, 294 void MaximizeModeWindowState::UpdateBounds(wm::WindowState* window_state,
292 bool animated) { 295 bool animated) {
293 if (defer_bounds_updates_) 296 if (defer_bounds_updates_)
294 return; 297 return;
295 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); 298 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state);
296 // If we have a target bounds rectangle, we center it and set it 299 // If we have a target bounds rectangle, we center it and set it
297 // accordingly. 300 // accordingly.
298 if (!bounds_in_parent.IsEmpty() && 301 if (!bounds_in_parent.IsEmpty() &&
299 bounds_in_parent != window_state->window()->bounds()) { 302 bounds_in_parent != window_state->aura_window()->bounds()) {
300 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED || 303 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED ||
301 !window_state->window()->IsVisible() || 304 !window_state->window()->IsVisible() ||
302 !animated) { 305 !animated) {
303 window_state->SetBoundsDirect(bounds_in_parent); 306 window_state->SetBoundsDirect(bounds_in_parent);
304 } else { 307 } else {
305 // If we animate (to) maximized mode, we want to use the cross fade to 308 // If we animate (to) maximized mode, we want to use the cross fade to
306 // avoid flashing. 309 // avoid flashing.
307 if (window_state->IsMaximized()) 310 if (window_state->IsMaximized())
308 window_state->SetBoundsDirectCrossFade(bounds_in_parent); 311 window_state->SetBoundsDirectCrossFade(bounds_in_parent);
309 else 312 else
310 window_state->SetBoundsDirectAnimated(bounds_in_parent); 313 window_state->SetBoundsDirectAnimated(bounds_in_parent);
311 } 314 }
312 } 315 }
313 } 316 }
314 317
315 } // namespace ash 318 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_window_manager_unittest.cc ('k') | ash/wm/mru_window_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698