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

Side by Side Diff: ash/wm/default_state.cc

Issue 1901773002: Removes most of aura dependencies from DefaultState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wm_window_positioner
Patch Set: nit and merge 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
« no previous file with comments | « ash/wm/common/workspace/workspace_types.h ('k') | ash/wm/dock/docked_window_layout_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/default_state.h" 5 #include "ash/wm/default_state.h"
6 6
7 #include "ash/display/window_tree_host_manager.h"
8 #include "ash/root_window_controller.h"
9 #include "ash/screen_util.h"
10 #include "ash/shell.h"
11 #include "ash/shell_window_ids.h" 7 #include "ash/shell_window_ids.h"
8 #include "ash/wm/aura/wm_window_aura.h"
9 #include "ash/wm/common/window_animation_types.h"
10 #include "ash/wm/common/window_parenting_utils.h"
12 #include "ash/wm/common/window_positioning_utils.h" 11 #include "ash/wm/common/window_positioning_utils.h"
12 #include "ash/wm/common/window_state_util.h"
13 #include "ash/wm/common/wm_event.h" 13 #include "ash/wm/common/wm_event.h"
14 #include "ash/wm/coordinate_conversion.h" 14 #include "ash/wm/common/wm_globals.h"
15 #include "ash/wm/common/wm_root_window_controller.h"
16 #include "ash/wm/common/wm_screen_util.h"
15 #include "ash/wm/dock/docked_window_layout_manager.h" 17 #include "ash/wm/dock/docked_window_layout_manager.h"
16 #include "ash/wm/window_animations.h"
17 #include "ash/wm/window_state.h" 18 #include "ash/wm/window_state.h"
18 #include "ash/wm/window_state_delegate.h" 19 #include "ash/wm/window_state_delegate.h"
19 #include "ash/wm/window_state_util.h"
20 #include "ash/wm/window_util.h"
21 #include "ash/wm/workspace/workspace_window_resizer.h"
22 #include "ash/wm/workspace_controller.h"
23 #include "ui/aura/client/aura_constants.h"
24 #include "ui/aura/window.h" 20 #include "ui/aura/window.h"
25 #include "ui/aura/window_delegate.h"
26 #include "ui/gfx/display.h" 21 #include "ui/gfx/display.h"
27 #include "ui/gfx/geometry/rect.h" 22 #include "ui/gfx/geometry/rect.h"
23 #include "ui/gfx/screen.h"
28 24
29 namespace ash { 25 namespace ash {
30 namespace wm { 26 namespace wm {
31 namespace { 27 namespace {
32 28
33 // This specifies how much percent (30%) of a window rect 29 // This specifies how much percent (30%) of a window rect
34 // must be visible when the window is added to the workspace. 30 // must be visible when the window is added to the workspace.
35 const float kMinimumPercentOnScreenArea = 0.3f; 31 const float kMinimumPercentOnScreenArea = 0.3f;
36 32
37 // When a window that has restore bounds at least as large as a work area is 33 // When a window that has restore bounds at least as large as a work area is
(...skipping 11 matching lines...) Expand all
49 return; 45 return;
50 const gfx::Rect& restore_bounds = window_state->GetRestoreBoundsInScreen(); 46 const gfx::Rect& restore_bounds = window_state->GetRestoreBoundsInScreen();
51 47
52 // Move only if the restore bounds is outside of 48 // Move only if the restore bounds is outside of
53 // the display. There is no information about in which 49 // the display. There is no information about in which
54 // display it should be restored, so this is best guess. 50 // display it should be restored, so this is best guess.
55 // TODO(oshima): Restore information should contain the 51 // TODO(oshima): Restore information should contain the
56 // work area information like WindowResizer does for the 52 // work area information like WindowResizer does for the
57 // last window location. 53 // last window location.
58 gfx::Rect display_area = 54 gfx::Rect display_area =
59 gfx::Screen::GetScreen() 55 window_state->window()->GetDisplayNearestWindow().bounds();
60 ->GetDisplayNearestWindow(window_state->aura_window())
61 .bounds();
62 56
63 if (!display_area.Intersects(restore_bounds)) { 57 if (!display_area.Intersects(restore_bounds)) {
64 const gfx::Display& display = 58 const gfx::Display& display =
65 gfx::Screen::GetScreen()->GetDisplayMatching(restore_bounds); 59 gfx::Screen::GetScreen()->GetDisplayMatching(restore_bounds);
66 WindowTreeHostManager* window_tree_host_manager = 60 WmGlobals* globals = window_state->window()->GetGlobals();
67 Shell::GetInstance()->window_tree_host_manager(); 61 WmWindow* new_root = globals->GetRootWindowForDisplayId(display.id());
68 aura::Window* new_root = 62 if (new_root != window_state->window()->GetRootWindow()) {
69 window_tree_host_manager->GetRootWindowForDisplayId(display.id()); 63 WmWindow* new_container = new_root->GetChildByShellWindowId(
70 if (new_root != window_state->aura_window()->GetRootWindow()) { 64 window_state->window()->GetParent()->GetShellWindowId());
71 aura::Window* new_container = Shell::GetContainer( 65 new_container->AddChild(window_state->window());
72 new_root, window_state->aura_window()->parent()->id());
73 new_container->AddChild(window_state->aura_window());
74 } 66 }
75 } 67 }
76 } 68 }
77 69
78 DockedWindowLayoutManager* GetDockedWindowLayoutManager() { 70 DockedWindowLayoutManager* GetDockedWindowLayoutManager(WmGlobals* globals) {
79 aura::Window* active_window = ash::wm::GetActiveWindow(); 71 WmWindow* active_window = globals->GetActiveWindow();
80 if (active_window) { 72 if (!active_window)
81 aura::Window* dock_container = Shell::GetContainer( 73 return nullptr;
82 active_window->GetRootWindow(), kShellWindowId_DockedContainer); 74
83 DockedWindowLayoutManager* dock_layout = 75 WmWindow* dock_container =
76 active_window->GetRootWindow()->GetChildByShellWindowId(
77 kShellWindowId_DockedContainer);
78 DockedWindowLayoutManager* dock_layout =
84 static_cast<DockedWindowLayoutManager*>( 79 static_cast<DockedWindowLayoutManager*>(
85 dock_container->layout_manager()); 80 WmWindowAura::GetAuraWindow(dock_container)->layout_manager());
86 return dock_layout; 81 return dock_layout;
87 }
88 return NULL;
89 } 82 }
90 83
91 class ScopedPreferredAlignmentResetter { 84 class ScopedPreferredAlignmentResetter {
92 public: 85 public:
93 ScopedPreferredAlignmentResetter(DockedAlignment dock_alignment, 86 ScopedPreferredAlignmentResetter(DockedAlignment dock_alignment,
94 DockedWindowLayoutManager* dock_layout) 87 DockedWindowLayoutManager* dock_layout)
95 : docked_window_layout_manager_(dock_layout) { 88 : docked_window_layout_manager_(dock_layout) {
96 docked_window_layout_manager_->set_preferred_alignment(dock_alignment); 89 docked_window_layout_manager_->set_preferred_alignment(dock_alignment);
97 } 90 }
98 ~ScopedPreferredAlignmentResetter() { 91 ~ScopedPreferredAlignmentResetter() {
(...skipping 19 matching lines...) Expand all
118 DOCKED_ACTION_SOURCE_UNKNOWN); 111 DOCKED_ACTION_SOURCE_UNKNOWN);
119 } 112 }
120 113
121 private: 114 private:
122 DockedWindowLayoutManager* docked_window_layout_manager_; 115 DockedWindowLayoutManager* docked_window_layout_manager_;
123 116
124 DISALLOW_COPY_AND_ASSIGN(ScopedDockedLayoutEventSourceResetter); 117 DISALLOW_COPY_AND_ASSIGN(ScopedDockedLayoutEventSourceResetter);
125 }; 118 };
126 119
127 void CycleSnapDock(WindowState* window_state, WMEventType event) { 120 void CycleSnapDock(WindowState* window_state, WMEventType event) {
128 DockedWindowLayoutManager* dock_layout = GetDockedWindowLayoutManager(); 121 DockedWindowLayoutManager* dock_layout =
122 GetDockedWindowLayoutManager(window_state->window()->GetGlobals());
129 wm::WindowStateType desired_snap_state = event == 123 wm::WindowStateType desired_snap_state = event ==
130 WM_EVENT_CYCLE_SNAP_DOCK_LEFT ? wm::WINDOW_STATE_TYPE_LEFT_SNAPPED : 124 WM_EVENT_CYCLE_SNAP_DOCK_LEFT ? wm::WINDOW_STATE_TYPE_LEFT_SNAPPED :
131 wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED; 125 wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED;
132 DockedAlignment desired_dock_alignment = event == 126 DockedAlignment desired_dock_alignment = event ==
133 WM_EVENT_CYCLE_SNAP_DOCK_LEFT ? 127 WM_EVENT_CYCLE_SNAP_DOCK_LEFT ?
134 DOCKED_ALIGNMENT_LEFT : DOCKED_ALIGNMENT_RIGHT; 128 DOCKED_ALIGNMENT_LEFT : DOCKED_ALIGNMENT_RIGHT;
135 DockedAlignment current_dock_alignment = dock_layout ? 129 DockedAlignment current_dock_alignment = dock_layout ?
136 dock_layout->CalculateAlignment() : DOCKED_ALIGNMENT_NONE; 130 dock_layout->CalculateAlignment() : DOCKED_ALIGNMENT_NONE;
137 131
138 if (!window_state->IsDocked() || 132 if (!window_state->IsDocked() ||
139 (current_dock_alignment != DOCKED_ALIGNMENT_NONE && 133 (current_dock_alignment != DOCKED_ALIGNMENT_NONE &&
140 current_dock_alignment != desired_dock_alignment)) { 134 current_dock_alignment != desired_dock_alignment)) {
141 if (window_state->CanSnap() && 135 if (window_state->CanSnap() &&
142 window_state->GetStateType() != desired_snap_state && 136 window_state->GetStateType() != desired_snap_state &&
143 window_state->aura_window()->type() != ui::wm::WINDOW_TYPE_PANEL) { 137 window_state->window()->GetType() != ui::wm::WINDOW_TYPE_PANEL) {
144 const wm::WMEvent event(desired_snap_state == 138 const wm::WMEvent event(desired_snap_state ==
145 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED ? 139 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED ?
146 wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT); 140 wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT);
147 window_state->OnWMEvent(&event); 141 window_state->OnWMEvent(&event);
148 return; 142 return;
149 } 143 }
150 144
151 if (dock_layout && 145 if (dock_layout &&
152 dock_layout->CanDockWindow(window_state->aura_window(), 146 dock_layout->CanDockWindow(window_state->aura_window(),
153 desired_dock_alignment)) { 147 desired_dock_alignment)) {
154 if (window_state->IsDocked()) { 148 if (window_state->IsDocked()) {
155 dock_layout->MaybeSetDesiredDockedAlignment(desired_dock_alignment); 149 dock_layout->MaybeSetDesiredDockedAlignment(desired_dock_alignment);
156 return; 150 return;
157 } 151 }
158 152
159 ScopedDockedLayoutEventSourceResetter event_source_resetter(dock_layout); 153 ScopedDockedLayoutEventSourceResetter event_source_resetter(dock_layout);
160 ScopedPreferredAlignmentResetter alignmentResetter(desired_dock_alignment, 154 ScopedPreferredAlignmentResetter alignmentResetter(desired_dock_alignment,
161 dock_layout); 155 dock_layout);
162 const wm::WMEvent event(wm::WM_EVENT_DOCK); 156 const wm::WMEvent event(wm::WM_EVENT_DOCK);
163 window_state->OnWMEvent(&event); 157 window_state->OnWMEvent(&event);
164 return; 158 return;
165 } 159 }
166 } 160 }
167 161
168 if (window_state->IsDocked() || window_state->IsSnapped()) { 162 if (window_state->IsDocked() || window_state->IsSnapped()) {
169 ScopedDockedLayoutEventSourceResetter event_source_resetter(dock_layout); 163 ScopedDockedLayoutEventSourceResetter event_source_resetter(dock_layout);
170 window_state->Restore(); 164 window_state->Restore();
171 return; 165 return;
172 } 166 }
173 ::wm::AnimateWindow(window_state->aura_window(), 167 window_state->window()->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE);
174 ::wm::WINDOW_ANIMATION_TYPE_BOUNCE);
175 } 168 }
176 169
177 } // namespace 170 } // namespace
178 171
179 DefaultState::DefaultState(WindowStateType initial_state_type) 172 DefaultState::DefaultState(WindowStateType initial_state_type)
180 : state_type_(initial_state_type), stored_window_state_(nullptr) {} 173 : state_type_(initial_state_type), stored_window_state_(nullptr) {}
181 DefaultState::~DefaultState() {} 174 DefaultState::~DefaultState() {}
182 175
183 void DefaultState::OnWMEvent(WindowState* window_state, 176 void DefaultState::OnWMEvent(WindowState* window_state,
184 const WMEvent* event) { 177 const WMEvent* event) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 void DefaultState::AttachState( 250 void DefaultState::AttachState(
258 WindowState* window_state, 251 WindowState* window_state,
259 WindowState::State* state_in_previous_mode) { 252 WindowState::State* state_in_previous_mode) {
260 DCHECK_EQ(stored_window_state_, window_state); 253 DCHECK_EQ(stored_window_state_, window_state);
261 254
262 ReenterToCurrentState(window_state, state_in_previous_mode); 255 ReenterToCurrentState(window_state, state_in_previous_mode);
263 256
264 // If the display has changed while in the another mode, 257 // If the display has changed while in the another mode,
265 // we need to let windows know the change. 258 // we need to let windows know the change.
266 gfx::Display current_display = 259 gfx::Display current_display =
267 gfx::Screen::GetScreen()->GetDisplayNearestWindow( 260 window_state->window()->GetDisplayNearestWindow();
268 window_state->aura_window());
269 if (stored_display_state_.bounds() != current_display.bounds()) { 261 if (stored_display_state_.bounds() != current_display.bounds()) {
270 const WMEvent event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED); 262 const WMEvent event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED);
271 window_state->OnWMEvent(&event); 263 window_state->OnWMEvent(&event);
272 } else if (stored_display_state_.work_area() != current_display.work_area()) { 264 } else if (stored_display_state_.work_area() != current_display.work_area()) {
273 const WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); 265 const WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED);
274 window_state->OnWMEvent(&event); 266 window_state->OnWMEvent(&event);
275 } 267 }
276 } 268 }
277 269
278 void DefaultState::DetachState(WindowState* window_state) { 270 void DefaultState::DetachState(WindowState* window_state) {
279 stored_window_state_ = window_state; 271 stored_window_state_ = window_state;
280 aura::Window* window = window_state->aura_window(); 272 stored_bounds_ = window_state->window()->GetBounds();
281 stored_bounds_ = window->bounds();
282 stored_restore_bounds_ = window_state->HasRestoreBounds() ? 273 stored_restore_bounds_ = window_state->HasRestoreBounds() ?
283 window_state->GetRestoreBoundsInParent() : gfx::Rect(); 274 window_state->GetRestoreBoundsInParent() : gfx::Rect();
284 // Remember the display state so that in case of the display change 275 // Remember the display state so that in case of the display change
285 // while in the other mode, we can perform necessary action to 276 // while in the other mode, we can perform necessary action to
286 // restore the window state to the proper state for the current 277 // restore the window state to the proper state for the current
287 // display. 278 // display.
288 stored_display_state_ = gfx::Screen::GetScreen()->GetDisplayNearestWindow( 279 stored_display_state_ = window_state->window()->GetDisplayNearestWindow();
289 window_state->aura_window());
290 } 280 }
291 281
292 // static 282 // static
293 bool DefaultState::ProcessCompoundEvents(WindowState* window_state, 283 bool DefaultState::ProcessCompoundEvents(WindowState* window_state,
294 const WMEvent* event) { 284 const WMEvent* event) {
295 aura::Window* window = window_state->aura_window(); 285 WmWindow* window = window_state->window();
296 286
297 switch (event->type()) { 287 switch (event->type()) {
298 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: 288 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION:
299 if (window_state->IsFullscreen()) { 289 if (window_state->IsFullscreen()) {
300 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); 290 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
301 window_state->OnWMEvent(&event); 291 window_state->OnWMEvent(&event);
302 } else if (window_state->IsMaximized()) { 292 } else if (window_state->IsMaximized()) {
303 window_state->Restore(); 293 window_state->Restore();
304 } else if (window_state->IsNormalOrSnapped()) { 294 } else if (window_state->IsNormalOrSnapped()) {
305 if (window_state->CanMaximize()) 295 if (window_state->CanMaximize())
306 window_state->Maximize(); 296 window_state->Maximize();
307 } 297 }
308 return true; 298 return true;
309 case WM_EVENT_TOGGLE_MAXIMIZE: 299 case WM_EVENT_TOGGLE_MAXIMIZE:
310 if (window_state->IsFullscreen()) { 300 if (window_state->IsFullscreen()) {
311 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); 301 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
312 window_state->OnWMEvent(&event); 302 window_state->OnWMEvent(&event);
313 } else if (window_state->IsMaximized()) { 303 } else if (window_state->IsMaximized()) {
314 window_state->Restore(); 304 window_state->Restore();
315 } else if (window_state->CanMaximize()) { 305 } else if (window_state->CanMaximize()) {
316 window_state->Maximize(); 306 window_state->Maximize();
317 } 307 }
318 return true; 308 return true;
319 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: { 309 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: {
320 gfx::Rect work_area = 310 gfx::Rect work_area = GetDisplayWorkAreaBoundsInParent(window);
321 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window);
322 311
323 // Maximize vertically if: 312 // Maximize vertically if:
324 // - The window does not have a max height defined. 313 // - The window does not have a max height defined.
325 // - The window has the normal state type. Snapped windows are excluded 314 // - The window has the normal state type. Snapped windows are excluded
326 // because they are already maximized vertically and reverting to the 315 // because they are already maximized vertically and reverting to the
327 // restored bounds looks weird. 316 // restored bounds looks weird.
328 if (window->delegate()->GetMaximumSize().height() != 0 || 317 if (window->GetMaximumSize().height() != 0 ||
329 !window_state->IsNormalStateType()) { 318 !window_state->IsNormalStateType()) {
330 return true; 319 return true;
331 } 320 }
332 if (window_state->HasRestoreBounds() && 321 if (window_state->HasRestoreBounds() &&
333 (window->bounds().height() == work_area.height() && 322 (window->GetBounds().height() == work_area.height() &&
334 window->bounds().y() == work_area.y())) { 323 window->GetBounds().y() == work_area.y())) {
335 window_state->SetAndClearRestoreBounds(); 324 window_state->SetAndClearRestoreBounds();
336 } else { 325 } else {
337 window_state->SaveCurrentBoundsForRestore(); 326 window_state->SaveCurrentBoundsForRestore();
338 window->SetBounds(gfx::Rect(window->bounds().x(), 327 window->SetBounds(gfx::Rect(window->GetBounds().x(), work_area.y(),
339 work_area.y(), 328 window->GetBounds().width(),
340 window->bounds().width(),
341 work_area.height())); 329 work_area.height()));
342 } 330 }
343 return true; 331 return true;
344 } 332 }
345 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: { 333 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: {
346 // Maximize horizontally if: 334 // Maximize horizontally if:
347 // - The window does not have a max width defined. 335 // - The window does not have a max width defined.
348 // - The window is snapped or has the normal state type. 336 // - The window is snapped or has the normal state type.
349 if (window->delegate()->GetMaximumSize().width() != 0) 337 if (window->GetMaximumSize().width() != 0)
350 return true; 338 return true;
351 if (!window_state->IsNormalOrSnapped()) 339 if (!window_state->IsNormalOrSnapped())
352 return true; 340 return true;
353 gfx::Rect work_area = 341 gfx::Rect work_area = GetDisplayWorkAreaBoundsInParent(window);
354 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window);
355 if (window_state->IsNormalStateType() && 342 if (window_state->IsNormalStateType() &&
356 window_state->HasRestoreBounds() && 343 window_state->HasRestoreBounds() &&
357 (window->bounds().width() == work_area.width() && 344 (window->GetBounds().width() == work_area.width() &&
358 window->bounds().x() == work_area.x())) { 345 window->GetBounds().x() == work_area.x())) {
359 window_state->SetAndClearRestoreBounds(); 346 window_state->SetAndClearRestoreBounds();
360 } else { 347 } else {
361 gfx::Rect new_bounds(work_area.x(), 348 gfx::Rect new_bounds(work_area.x(), window->GetBounds().y(),
362 window->bounds().y(), 349 work_area.width(), window->GetBounds().height());
363 work_area.width(),
364 window->bounds().height());
365 350
366 gfx::Rect restore_bounds = window->bounds(); 351 gfx::Rect restore_bounds = window->GetBounds();
367 if (window_state->IsSnapped()) { 352 if (window_state->IsSnapped()) {
368 window_state->SetRestoreBoundsInParent(new_bounds); 353 window_state->SetRestoreBoundsInParent(new_bounds);
369 window_state->Restore(); 354 window_state->Restore();
370 355
371 // The restore logic prevents a window from being restored to bounds 356 // The restore logic prevents a window from being restored to bounds
372 // which match the workspace bounds exactly so it is necessary to set 357 // which match the workspace bounds exactly so it is necessary to set
373 // the bounds again below. 358 // the bounds again below.
374 } 359 }
375 360
376 window_state->SetRestoreBoundsInParent(restore_bounds); 361 window_state->SetRestoreBoundsInParent(restore_bounds);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 // When a window is dragged and dropped onto a different 399 // When a window is dragged and dropped onto a different
415 // root window, the bounds will be updated after they are added 400 // root window, the bounds will be updated after they are added
416 // to the root window. 401 // to the root window.
417 // If a window is opened as maximized or fullscreen, its bounds may be 402 // If a window is opened as maximized or fullscreen, its bounds may be
418 // empty, so update the bounds now before checking empty. 403 // empty, so update the bounds now before checking empty.
419 if (window_state->is_dragged() || 404 if (window_state->is_dragged() ||
420 SetMaximizedOrFullscreenBounds(window_state)) { 405 SetMaximizedOrFullscreenBounds(window_state)) {
421 return true; 406 return true;
422 } 407 }
423 408
424 aura::Window* window = window_state->aura_window(); 409 WmWindow* window = window_state->window();
425 gfx::Rect bounds = window->bounds(); 410 gfx::Rect bounds = window->GetBounds();
426 411
427 // Don't adjust window bounds if the bounds are empty as this 412 // Don't adjust window bounds if the bounds are empty as this
428 // happens when a new views::Widget is created. 413 // happens when a new views::Widget is created.
429 if (bounds.IsEmpty()) 414 if (bounds.IsEmpty())
430 return true; 415 return true;
431 416
432 // Only windows of type WINDOW_TYPE_NORMAL or WINDOW_TYPE_PANEL need to be 417 // Only windows of type WINDOW_TYPE_NORMAL or WINDOW_TYPE_PANEL need to be
433 // adjusted to have minimum visibility, because they are positioned by the 418 // adjusted to have minimum visibility, because they are positioned by the
434 // user and user should always be able to interact with them. Other 419 // user and user should always be able to interact with them. Other
435 // windows are positioned programmatically. 420 // windows are positioned programmatically.
436 if (!window_state->IsUserPositionable()) 421 if (!window_state->IsUserPositionable())
437 return true; 422 return true;
438 423
439 // Use entire display instead of workarea because the workarea can 424 // Use entire display instead of workarea because the workarea can
440 // be further shrunk by the docked area. The logic ensures 30% 425 // be further shrunk by the docked area. The logic ensures 30%
441 // visibility which should be enough to see where the window gets 426 // visibility which should be enough to see where the window gets
442 // moved. 427 // moved.
443 gfx::Rect display_area = ScreenUtil::GetDisplayBoundsInParent(window); 428 gfx::Rect display_area = GetDisplayBoundsInParent(window);
444 int min_width = bounds.width() * wm::kMinimumPercentOnScreenArea; 429 int min_width = bounds.width() * wm::kMinimumPercentOnScreenArea;
445 int min_height = bounds.height() * wm::kMinimumPercentOnScreenArea; 430 int min_height = bounds.height() * wm::kMinimumPercentOnScreenArea;
446 wm::AdjustBoundsToEnsureWindowVisibility(display_area, min_width, 431 wm::AdjustBoundsToEnsureWindowVisibility(display_area, min_width,
447 min_height, &bounds); 432 min_height, &bounds);
448 window_state->AdjustSnappedBounds(&bounds); 433 window_state->AdjustSnappedBounds(&bounds);
449 if (window->bounds() != bounds) 434 if (window->GetBounds() != bounds)
450 window_state->SetBoundsConstrained(bounds); 435 window_state->SetBoundsConstrained(bounds);
451 return true; 436 return true;
452 } 437 }
453 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: { 438 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: {
454 if (window_state->is_dragged() || 439 if (window_state->is_dragged() ||
455 SetMaximizedOrFullscreenBounds(window_state)) { 440 SetMaximizedOrFullscreenBounds(window_state)) {
456 return true; 441 return true;
457 } 442 }
458 gfx::Rect work_area_in_parent = 443 gfx::Rect work_area_in_parent =
459 ScreenUtil::GetDisplayWorkAreaBoundsInParent( 444 GetDisplayWorkAreaBoundsInParent(window_state->window());
460 window_state->aura_window()); 445 gfx::Rect bounds = window_state->window()->GetBounds();
461 gfx::Rect bounds = window_state->aura_window()->bounds();
462 // When display bounds has changed, make sure the entire window is fully 446 // When display bounds has changed, make sure the entire window is fully
463 // visible. 447 // visible.
464 bounds.AdjustToFit(work_area_in_parent); 448 bounds.AdjustToFit(work_area_in_parent);
465 window_state->AdjustSnappedBounds(&bounds); 449 window_state->AdjustSnappedBounds(&bounds);
466 if (window_state->aura_window()->bounds() != bounds) 450 if (window_state->window()->GetBounds() != bounds)
467 window_state->SetBoundsDirectAnimated(bounds); 451 window_state->SetBoundsDirectAnimated(bounds);
468 return true; 452 return true;
469 } 453 }
470 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: { 454 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: {
471 // Don't resize the maximized window when the desktop is covered 455 // Don't resize the maximized window when the desktop is covered
472 // by fullscreen window. crbug.com/504299. 456 // by fullscreen window. crbug.com/504299.
473 bool in_fullscreen = 457 bool in_fullscreen =
474 RootWindowController::ForWindow(window_state->aura_window()) 458 window_state->window()
475 ->workspace_controller() 459 ->GetRootWindowController()
476 ->GetWindowState() == WORKSPACE_WINDOW_STATE_FULL_SCREEN; 460 ->GetWorkspaceWindowState() == WORKSPACE_WINDOW_STATE_FULL_SCREEN;
477 if (in_fullscreen && window_state->IsMaximized()) 461 if (in_fullscreen && window_state->IsMaximized())
478 return true; 462 return true;
479 463
480 if (window_state->is_dragged() || 464 if (window_state->is_dragged() ||
481 SetMaximizedOrFullscreenBounds(window_state)) { 465 SetMaximizedOrFullscreenBounds(window_state)) {
482 return true; 466 return true;
483 } 467 }
484 gfx::Rect work_area_in_parent = 468 gfx::Rect work_area_in_parent =
485 ScreenUtil::GetDisplayWorkAreaBoundsInParent( 469 GetDisplayWorkAreaBoundsInParent(window_state->window());
486 window_state->aura_window()); 470 gfx::Rect bounds = window_state->window()->GetBounds();
487 gfx::Rect bounds = window_state->aura_window()->bounds();
488 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent, 471 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent,
489 &bounds); 472 &bounds);
490 window_state->AdjustSnappedBounds(&bounds); 473 window_state->AdjustSnappedBounds(&bounds);
491 if (window_state->aura_window()->bounds() != bounds) 474 if (window_state->window()->GetBounds() != bounds)
492 window_state->SetBoundsDirectAnimated(bounds); 475 window_state->SetBoundsDirectAnimated(bounds);
493 return true; 476 return true;
494 } 477 }
495 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: 478 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION:
496 case WM_EVENT_TOGGLE_MAXIMIZE: 479 case WM_EVENT_TOGGLE_MAXIMIZE:
497 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: 480 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE:
498 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: 481 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE:
499 case WM_EVENT_TOGGLE_FULLSCREEN: 482 case WM_EVENT_TOGGLE_FULLSCREEN:
500 case WM_EVENT_CYCLE_SNAP_DOCK_LEFT: 483 case WM_EVENT_CYCLE_SNAP_DOCK_LEFT:
501 case WM_EVENT_CYCLE_SNAP_DOCK_RIGHT: 484 case WM_EVENT_CYCLE_SNAP_DOCK_RIGHT:
502 case WM_EVENT_CENTER: 485 case WM_EVENT_CENTER:
503 case WM_EVENT_NORMAL: 486 case WM_EVENT_NORMAL:
504 case WM_EVENT_MAXIMIZE: 487 case WM_EVENT_MAXIMIZE:
505 case WM_EVENT_MINIMIZE: 488 case WM_EVENT_MINIMIZE:
506 case WM_EVENT_FULLSCREEN: 489 case WM_EVENT_FULLSCREEN:
507 case WM_EVENT_SNAP_LEFT: 490 case WM_EVENT_SNAP_LEFT:
508 case WM_EVENT_SNAP_RIGHT: 491 case WM_EVENT_SNAP_RIGHT:
509 case WM_EVENT_SET_BOUNDS: 492 case WM_EVENT_SET_BOUNDS:
510 case WM_EVENT_SHOW_INACTIVE: 493 case WM_EVENT_SHOW_INACTIVE:
511 case WM_EVENT_DOCK: 494 case WM_EVENT_DOCK:
512 break; 495 break;
513 } 496 }
514 return false; 497 return false;
515 } 498 }
516 499
517 // static 500 // static
518 bool DefaultState::SetMaximizedOrFullscreenBounds(WindowState* window_state) { 501 bool DefaultState::SetMaximizedOrFullscreenBounds(WindowState* window_state) {
519 DCHECK(!window_state->is_dragged()); 502 DCHECK(!window_state->is_dragged());
520 if (window_state->IsMaximized()) { 503 if (window_state->IsMaximized()) {
521 window_state->SetBoundsDirect(ScreenUtil::GetMaximizedWindowBoundsInParent( 504 window_state->SetBoundsDirect(
522 window_state->aura_window())); 505 GetMaximizedWindowBoundsInParent(window_state->window()));
523 return true; 506 return true;
524 } 507 }
525 if (window_state->IsFullscreen()) { 508 if (window_state->IsFullscreen()) {
526 window_state->SetBoundsDirect( 509 window_state->SetBoundsDirect(
527 ScreenUtil::GetDisplayBoundsInParent(window_state->aura_window())); 510 GetDisplayBoundsInParent(window_state->window()));
528 return true; 511 return true;
529 } 512 }
530 return false; 513 return false;
531 } 514 }
532 515
533 // static 516 // static
534 void DefaultState::SetBounds(WindowState* window_state, 517 void DefaultState::SetBounds(WindowState* window_state,
535 const SetBoundsEvent* event) { 518 const SetBoundsEvent* event) {
536 if (window_state->is_dragged()) { 519 if (window_state->is_dragged()) {
537 // TODO(oshima|varkha): This may be no longer needed, as the dragging 520 // TODO(oshima|varkha): This may be no longer needed, as the dragging
538 // happens in docked window container. crbug.com/485612. 521 // happens in docked window container. crbug.com/485612.
539 window_state->SetBoundsDirect(event->requested_bounds()); 522 window_state->SetBoundsDirect(event->requested_bounds());
540 } else if (window_state->IsSnapped()) { 523 } else if (window_state->IsSnapped()) {
541 gfx::Rect work_area_in_parent = 524 gfx::Rect work_area_in_parent =
542 ScreenUtil::GetDisplayWorkAreaBoundsInParent( 525 GetDisplayWorkAreaBoundsInParent(window_state->window());
543 window_state->aura_window());
544 gfx::Rect child_bounds(event->requested_bounds()); 526 gfx::Rect child_bounds(event->requested_bounds());
545 wm::AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds); 527 wm::AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds);
546 window_state->AdjustSnappedBounds(&child_bounds); 528 window_state->AdjustSnappedBounds(&child_bounds);
547 window_state->SetBoundsDirect(child_bounds); 529 window_state->SetBoundsDirect(child_bounds);
548 } else if (!SetMaximizedOrFullscreenBounds(window_state)) { 530 } else if (!SetMaximizedOrFullscreenBounds(window_state)) {
549 window_state->SetBoundsConstrained(event->requested_bounds()); 531 window_state->SetBoundsConstrained(event->requested_bounds());
550 } 532 }
551 } 533 }
552 534
553 void DefaultState::EnterToNextState(WindowState* window_state, 535 void DefaultState::EnterToNextState(WindowState* window_state,
554 WindowStateType next_state_type) { 536 WindowStateType next_state_type) {
555 // Do nothing if we're already in the same state. 537 // Do nothing if we're already in the same state.
556 if (state_type_ == next_state_type) 538 if (state_type_ == next_state_type)
557 return; 539 return;
558 540
559 WindowStateType previous_state_type = state_type_; 541 WindowStateType previous_state_type = state_type_;
560 state_type_ = next_state_type; 542 state_type_ = next_state_type;
561 543
562 window_state->UpdateWindowShowStateFromStateType(); 544 window_state->UpdateWindowShowStateFromStateType();
563 window_state->NotifyPreStateTypeChange(previous_state_type); 545 window_state->NotifyPreStateTypeChange(previous_state_type);
564 546
565 if (window_state->aura_window()->parent()) { 547 if (window_state->window()->GetParent()) {
566 if (!window_state->HasRestoreBounds() && 548 if (!window_state->HasRestoreBounds() &&
567 (previous_state_type == WINDOW_STATE_TYPE_DEFAULT || 549 (previous_state_type == WINDOW_STATE_TYPE_DEFAULT ||
568 previous_state_type == WINDOW_STATE_TYPE_NORMAL) && 550 previous_state_type == WINDOW_STATE_TYPE_NORMAL) &&
569 !window_state->IsMinimized() && 551 !window_state->IsMinimized() &&
570 !window_state->IsNormalStateType()) { 552 !window_state->IsNormalStateType()) {
571 window_state->SaveCurrentBoundsForRestore(); 553 window_state->SaveCurrentBoundsForRestore();
572 } 554 }
573 555
574 // When restoring from a minimized state, we want to restore to the 556 // When restoring from a minimized state, we want to restore to the
575 // previous bounds. However, we want to maintain the restore bounds. 557 // previous bounds. However, we want to maintain the restore bounds.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 if (!stored_restore_bounds_.IsEmpty()) 611 if (!stored_restore_bounds_.IsEmpty())
630 window_state->SetRestoreBoundsInParent(stored_restore_bounds_); 612 window_state->SetRestoreBoundsInParent(stored_restore_bounds_);
631 else 613 else
632 window_state->ClearRestoreBounds(); 614 window_state->ClearRestoreBounds();
633 615
634 window_state->NotifyPostStateTypeChange(previous_state_type); 616 window_state->NotifyPostStateTypeChange(previous_state_type);
635 } 617 }
636 618
637 void DefaultState::UpdateBoundsFromState(WindowState* window_state, 619 void DefaultState::UpdateBoundsFromState(WindowState* window_state,
638 WindowStateType previous_state_type) { 620 WindowStateType previous_state_type) {
639 aura::Window* window = window_state->aura_window(); 621 WmWindow* window = window_state->window();
640 gfx::Rect bounds_in_parent; 622 gfx::Rect bounds_in_parent;
641 switch (state_type_) { 623 switch (state_type_) {
642 case WINDOW_STATE_TYPE_LEFT_SNAPPED: 624 case WINDOW_STATE_TYPE_LEFT_SNAPPED:
643 case WINDOW_STATE_TYPE_RIGHT_SNAPPED: 625 case WINDOW_STATE_TYPE_RIGHT_SNAPPED:
644 bounds_in_parent = state_type_ == WINDOW_STATE_TYPE_LEFT_SNAPPED ? 626 bounds_in_parent =
645 GetDefaultLeftSnappedWindowBoundsInParent(window_state->window()) : 627 state_type_ == WINDOW_STATE_TYPE_LEFT_SNAPPED
646 GetDefaultRightSnappedWindowBoundsInParent(window_state->window()); 628 ? GetDefaultLeftSnappedWindowBoundsInParent(window)
629 : GetDefaultRightSnappedWindowBoundsInParent(window);
647 break; 630 break;
648 case WINDOW_STATE_TYPE_DOCKED: { 631 case WINDOW_STATE_TYPE_DOCKED: {
649 if (window->parent()->id() != kShellWindowId_DockedContainer) { 632 if (window->GetParent()->GetShellWindowId() !=
650 aura::Window* docked_container = Shell::GetContainer( 633 kShellWindowId_DockedContainer) {
651 window->GetRootWindow(), 634 WmWindow* docked_container =
652 kShellWindowId_DockedContainer); 635 window->GetRootWindow()->GetChildByShellWindowId(
653 wm::ReparentChildWithTransientChildren(window, 636 kShellWindowId_DockedContainer);
654 window->parent(), 637 ReparentChildWithTransientChildren(window, window->GetParent(),
655 docked_container); 638 docked_container);
656 } 639 }
657 // Return early because we don't want to update the bounds of the 640 // Return early because we don't want to update the bounds of the
658 // window below; as the bounds are managed by the dock layout. 641 // window below; as the bounds are managed by the dock layout.
659 return; 642 return;
660 } 643 }
661 case WINDOW_STATE_TYPE_DEFAULT: 644 case WINDOW_STATE_TYPE_DEFAULT:
662 case WINDOW_STATE_TYPE_NORMAL: { 645 case WINDOW_STATE_TYPE_NORMAL: {
663 gfx::Rect work_area_in_parent = 646 gfx::Rect work_area_in_parent = GetDisplayWorkAreaBoundsInParent(window);
664 ScreenUtil::GetDisplayWorkAreaBoundsInParent(
665 window_state->aura_window());
666 if (window_state->HasRestoreBounds()) { 647 if (window_state->HasRestoreBounds()) {
667 bounds_in_parent = window_state->GetRestoreBoundsInParent(); 648 bounds_in_parent = window_state->GetRestoreBoundsInParent();
668 // Check if the |window|'s restored size is bigger than the working area 649 // Check if the |window|'s restored size is bigger than the working area
669 // This may happen if a window was resized to maximized bounds or if the 650 // This may happen if a window was resized to maximized bounds or if the
670 // display resolution changed while the window was maximized. 651 // display resolution changed while the window was maximized.
671 if (previous_state_type == WINDOW_STATE_TYPE_MAXIMIZED && 652 if (previous_state_type == WINDOW_STATE_TYPE_MAXIMIZED &&
672 bounds_in_parent.width() >= work_area_in_parent.width() && 653 bounds_in_parent.width() >= work_area_in_parent.width() &&
673 bounds_in_parent.height() >= work_area_in_parent.height()) { 654 bounds_in_parent.height() >= work_area_in_parent.height()) {
674 bounds_in_parent = work_area_in_parent; 655 bounds_in_parent = work_area_in_parent;
675 bounds_in_parent.Inset(kMaximizedWindowInset, kMaximizedWindowInset, 656 bounds_in_parent.Inset(kMaximizedWindowInset, kMaximizedWindowInset,
676 kMaximizedWindowInset, kMaximizedWindowInset); 657 kMaximizedWindowInset, kMaximizedWindowInset);
677 } 658 }
678 } else { 659 } else {
679 bounds_in_parent = window->bounds(); 660 bounds_in_parent = window->GetBounds();
680 } 661 }
681 // Make sure that part of the window is always visible. 662 // Make sure that part of the window is always visible.
682 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent, 663 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent,
683 &bounds_in_parent); 664 &bounds_in_parent);
684 break; 665 break;
685 } 666 }
686 case WINDOW_STATE_TYPE_MAXIMIZED: 667 case WINDOW_STATE_TYPE_MAXIMIZED:
687 bounds_in_parent = ScreenUtil::GetMaximizedWindowBoundsInParent(window); 668 bounds_in_parent = GetMaximizedWindowBoundsInParent(window);
688 break; 669 break;
689 670
690 case WINDOW_STATE_TYPE_FULLSCREEN: 671 case WINDOW_STATE_TYPE_FULLSCREEN:
691 bounds_in_parent = ScreenUtil::GetDisplayBoundsInParent(window); 672 bounds_in_parent = GetDisplayBoundsInParent(window);
692 break; 673 break;
693 674
694 case WINDOW_STATE_TYPE_DOCKED_MINIMIZED: 675 case WINDOW_STATE_TYPE_DOCKED_MINIMIZED:
695 case WINDOW_STATE_TYPE_MINIMIZED: 676 case WINDOW_STATE_TYPE_MINIMIZED:
696 break; 677 break;
697 case WINDOW_STATE_TYPE_INACTIVE: 678 case WINDOW_STATE_TYPE_INACTIVE:
698 case WINDOW_STATE_TYPE_END: 679 case WINDOW_STATE_TYPE_END:
699 case WINDOW_STATE_TYPE_AUTO_POSITIONED: 680 case WINDOW_STATE_TYPE_AUTO_POSITIONED:
700 return; 681 return;
701 } 682 }
702 683
703 if (!window_state->IsMinimized()) { 684 if (!window_state->IsMinimized()) {
704 if (IsMinimizedWindowState(previous_state_type) || 685 if (IsMinimizedWindowState(previous_state_type) ||
705 window_state->IsFullscreen()) { 686 window_state->IsFullscreen()) {
706 window_state->SetBoundsDirect(bounds_in_parent); 687 window_state->SetBoundsDirect(bounds_in_parent);
707 } else if (window_state->IsMaximized() || 688 } else if (window_state->IsMaximized() ||
708 IsMaximizedOrFullscreenWindowStateType(previous_state_type)) { 689 IsMaximizedOrFullscreenWindowStateType(previous_state_type)) {
709 window_state->SetBoundsDirectCrossFade(bounds_in_parent); 690 window_state->SetBoundsDirectCrossFade(bounds_in_parent);
710 } else if (window_state->is_dragged()) { 691 } else if (window_state->is_dragged()) {
711 // SetBoundsDirectAnimated does not work when the window gets reparented. 692 // SetBoundsDirectAnimated does not work when the window gets reparented.
712 // TODO(oshima): Consider fixing it and reenable the animation. 693 // TODO(oshima): Consider fixing it and reenable the animation.
713 window_state->SetBoundsDirect(bounds_in_parent); 694 window_state->SetBoundsDirect(bounds_in_parent);
714 } else { 695 } else {
715 window_state->SetBoundsDirectAnimated(bounds_in_parent); 696 window_state->SetBoundsDirectAnimated(bounds_in_parent);
716 } 697 }
717 } 698 }
718 699
719 if (window_state->IsMinimized()) { 700 if (window_state->IsMinimized()) {
720 // Save the previous show state so that we can correctly restore it. 701 // Save the previous show state so that we can correctly restore it.
721 window_state->aura_window()->SetProperty( 702 window->SetRestoreShowState(ToWindowShowState(previous_state_type));
722 aura::client::kRestoreShowStateKey, 703 window->SetVisibilityAnimationType(
723 ToWindowShowState(previous_state_type)); 704 WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
724 ::wm::SetWindowVisibilityAnimationType(
725 window_state->aura_window(), WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
726 705
727 // Hide the window. 706 // Hide the window.
728 window_state->window()->Hide(); 707 window->Hide();
729 // Activate another window. 708 // Activate another window.
730 if (window_state->IsActive()) 709 if (window_state->IsActive())
731 window_state->Deactivate(); 710 window_state->Deactivate();
732 } else if ((window_state->window()->GetTargetVisibility() || 711 } else if ((window->GetTargetVisibility() ||
733 IsMinimizedWindowState(previous_state_type)) && 712 IsMinimizedWindowState(previous_state_type)) &&
734 !window_state->aura_window()->layer()->visible()) { 713 !window->GetLayer()->visible()) {
735 // The layer may be hidden if the window was previously minimized. Make 714 // The layer may be hidden if the window was previously minimized. Make
736 // sure it's visible. 715 // sure it's visible.
737 window_state->window()->Show(); 716 window->Show();
738 if (IsMinimizedWindowState(previous_state_type) && 717 if (IsMinimizedWindowState(previous_state_type) &&
739 !window_state->IsMaximizedOrFullscreen()) { 718 !window_state->IsMaximizedOrFullscreen()) {
740 window_state->set_unminimize_to_restore_bounds(false); 719 window_state->set_unminimize_to_restore_bounds(false);
741 } 720 }
742 } 721 }
743 } 722 }
744 723
745 // static 724 // static
746 void DefaultState::CenterWindow(WindowState* window_state) { 725 void DefaultState::CenterWindow(WindowState* window_state) {
747 if (!window_state->IsNormalOrSnapped()) 726 if (!window_state->IsNormalOrSnapped())
748 return; 727 return;
749 aura::Window* window = window_state->aura_window(); 728 WmWindow* window = window_state->window();
750 if (window_state->IsSnapped()) { 729 if (window_state->IsSnapped()) {
751 gfx::Rect center_in_screen = 730 gfx::Rect center_in_screen = window->GetDisplayNearestWindow().work_area();
752 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window).work_area(); 731 gfx::Size size = window_state->HasRestoreBounds()
753 gfx::Size size = window_state->HasRestoreBounds() ? 732 ? window_state->GetRestoreBoundsInScreen().size()
754 window_state->GetRestoreBoundsInScreen().size() : 733 : window->GetBounds().size();
755 window->bounds().size();
756 center_in_screen.ClampToCenteredSize(size); 734 center_in_screen.ClampToCenteredSize(size);
757 window_state->SetRestoreBoundsInScreen(center_in_screen); 735 window_state->SetRestoreBoundsInScreen(center_in_screen);
758 window_state->Restore(); 736 window_state->Restore();
759 } else { 737 } else {
760 gfx::Rect center_in_parent = 738 gfx::Rect center_in_parent = GetDisplayWorkAreaBoundsInParent(window);
761 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window); 739 center_in_parent.ClampToCenteredSize(window->GetBounds().size());
762 center_in_parent.ClampToCenteredSize(window->bounds().size());
763 window_state->SetBoundsDirectAnimated(center_in_parent); 740 window_state->SetBoundsDirectAnimated(center_in_parent);
764 } 741 }
765 // Centering window is treated as if a user moved and resized the window. 742 // Centering window is treated as if a user moved and resized the window.
766 window_state->set_bounds_changed_by_user(true); 743 window_state->set_bounds_changed_by_user(true);
767 } 744 }
768 745
769 } // namespace wm 746 } // namespace wm
770 } // namespace ash 747 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/common/workspace/workspace_types.h ('k') | ash/wm/dock/docked_window_layout_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698