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

Side by Side Diff: ash/wm/default_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
« no previous file with comments | « ash/wm/common/wm_window_property.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" 7 #include "ash/display/window_tree_host_manager.h"
8 #include "ash/root_window_controller.h" 8 #include "ash/root_window_controller.h"
9 #include "ash/screen_util.h" 9 #include "ash/screen_util.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 if (!window_state->HasRestoreBounds()) 47 if (!window_state->HasRestoreBounds())
48 return; 48 return;
49 const gfx::Rect& restore_bounds = window_state->GetRestoreBoundsInScreen(); 49 const gfx::Rect& restore_bounds = window_state->GetRestoreBoundsInScreen();
50 50
51 // Move only if the restore bounds is outside of 51 // Move only if the restore bounds is outside of
52 // the display. There is no information about in which 52 // the display. There is no information about in which
53 // display it should be restored, so this is best guess. 53 // display it should be restored, so this is best guess.
54 // TODO(oshima): Restore information should contain the 54 // TODO(oshima): Restore information should contain the
55 // work area information like WindowResizer does for the 55 // work area information like WindowResizer does for the
56 // last window location. 56 // last window location.
57 gfx::Rect display_area = gfx::Screen::GetScreen() 57 gfx::Rect display_area =
58 ->GetDisplayNearestWindow(window_state->window()) 58 gfx::Screen::GetScreen()
59 .bounds(); 59 ->GetDisplayNearestWindow(window_state->aura_window())
60 .bounds();
60 61
61 if (!display_area.Intersects(restore_bounds)) { 62 if (!display_area.Intersects(restore_bounds)) {
62 const gfx::Display& display = 63 const gfx::Display& display =
63 gfx::Screen::GetScreen()->GetDisplayMatching(restore_bounds); 64 gfx::Screen::GetScreen()->GetDisplayMatching(restore_bounds);
64 WindowTreeHostManager* window_tree_host_manager = 65 WindowTreeHostManager* window_tree_host_manager =
65 Shell::GetInstance()->window_tree_host_manager(); 66 Shell::GetInstance()->window_tree_host_manager();
66 aura::Window* new_root = 67 aura::Window* new_root =
67 window_tree_host_manager->GetRootWindowForDisplayId(display.id()); 68 window_tree_host_manager->GetRootWindowForDisplayId(display.id());
68 if (new_root != window_state->window()->GetRootWindow()) { 69 if (new_root != window_state->aura_window()->GetRootWindow()) {
69 aura::Window* new_container = 70 aura::Window* new_container = Shell::GetContainer(
70 Shell::GetContainer(new_root, window_state->window()->parent()->id()); 71 new_root, window_state->aura_window()->parent()->id());
71 new_container->AddChild(window_state->window()); 72 new_container->AddChild(window_state->aura_window());
72 } 73 }
73 } 74 }
74 } 75 }
75 76
76 DockedWindowLayoutManager* GetDockedWindowLayoutManager() { 77 DockedWindowLayoutManager* GetDockedWindowLayoutManager() {
77 aura::Window* active_window = ash::wm::GetActiveWindow(); 78 aura::Window* active_window = ash::wm::GetActiveWindow();
78 if (active_window) { 79 if (active_window) {
79 aura::Window* dock_container = Shell::GetContainer( 80 aura::Window* dock_container = Shell::GetContainer(
80 active_window->GetRootWindow(), kShellWindowId_DockedContainer); 81 active_window->GetRootWindow(), kShellWindowId_DockedContainer);
81 DockedWindowLayoutManager* dock_layout = 82 DockedWindowLayoutManager* dock_layout =
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 WM_EVENT_CYCLE_SNAP_DOCK_LEFT ? 132 WM_EVENT_CYCLE_SNAP_DOCK_LEFT ?
132 DOCKED_ALIGNMENT_LEFT : DOCKED_ALIGNMENT_RIGHT; 133 DOCKED_ALIGNMENT_LEFT : DOCKED_ALIGNMENT_RIGHT;
133 DockedAlignment current_dock_alignment = dock_layout ? 134 DockedAlignment current_dock_alignment = dock_layout ?
134 dock_layout->CalculateAlignment() : DOCKED_ALIGNMENT_NONE; 135 dock_layout->CalculateAlignment() : DOCKED_ALIGNMENT_NONE;
135 136
136 if (!window_state->IsDocked() || 137 if (!window_state->IsDocked() ||
137 (current_dock_alignment != DOCKED_ALIGNMENT_NONE && 138 (current_dock_alignment != DOCKED_ALIGNMENT_NONE &&
138 current_dock_alignment != desired_dock_alignment)) { 139 current_dock_alignment != desired_dock_alignment)) {
139 if (window_state->CanSnap() && 140 if (window_state->CanSnap() &&
140 window_state->GetStateType() != desired_snap_state && 141 window_state->GetStateType() != desired_snap_state &&
141 window_state->window()->type() != ui::wm::WINDOW_TYPE_PANEL) { 142 window_state->aura_window()->type() != ui::wm::WINDOW_TYPE_PANEL) {
142 const wm::WMEvent event(desired_snap_state == 143 const wm::WMEvent event(desired_snap_state ==
143 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED ? 144 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED ?
144 wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT); 145 wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT);
145 window_state->OnWMEvent(&event); 146 window_state->OnWMEvent(&event);
146 return; 147 return;
147 } 148 }
148 149
149 if (dock_layout && 150 if (dock_layout &&
150 dock_layout->CanDockWindow(window_state->window(), 151 dock_layout->CanDockWindow(window_state->aura_window(),
151 desired_dock_alignment)) { 152 desired_dock_alignment)) {
152 if (window_state->IsDocked()) { 153 if (window_state->IsDocked()) {
153 dock_layout->MaybeSetDesiredDockedAlignment(desired_dock_alignment); 154 dock_layout->MaybeSetDesiredDockedAlignment(desired_dock_alignment);
154 return; 155 return;
155 } 156 }
156 157
157 ScopedDockedLayoutEventSourceResetter event_source_resetter(dock_layout); 158 ScopedDockedLayoutEventSourceResetter event_source_resetter(dock_layout);
158 ScopedPreferredAlignmentResetter alignmentResetter(desired_dock_alignment, 159 ScopedPreferredAlignmentResetter alignmentResetter(desired_dock_alignment,
159 dock_layout); 160 dock_layout);
160 const wm::WMEvent event(wm::WM_EVENT_DOCK); 161 const wm::WMEvent event(wm::WM_EVENT_DOCK);
161 window_state->OnWMEvent(&event); 162 window_state->OnWMEvent(&event);
162 return; 163 return;
163 } 164 }
164 } 165 }
165 166
166 if (window_state->IsDocked() || window_state->IsSnapped()) { 167 if (window_state->IsDocked() || window_state->IsSnapped()) {
167 ScopedDockedLayoutEventSourceResetter event_source_resetter(dock_layout); 168 ScopedDockedLayoutEventSourceResetter event_source_resetter(dock_layout);
168 window_state->Restore(); 169 window_state->Restore();
169 return; 170 return;
170 } 171 }
171 ::wm::AnimateWindow(window_state->window(), 172 ::wm::AnimateWindow(window_state->aura_window(),
172 ::wm::WINDOW_ANIMATION_TYPE_BOUNCE); 173 ::wm::WINDOW_ANIMATION_TYPE_BOUNCE);
173 } 174 }
174 175
175 } // namespace 176 } // namespace
176 177
177 DefaultState::DefaultState(WindowStateType initial_state_type) 178 DefaultState::DefaultState(WindowStateType initial_state_type)
178 : state_type_(initial_state_type), stored_window_state_(nullptr) {} 179 : state_type_(initial_state_type), stored_window_state_(nullptr) {}
179 DefaultState::~DefaultState() {} 180 DefaultState::~DefaultState() {}
180 181
181 void DefaultState::OnWMEvent(WindowState* window_state, 182 void DefaultState::OnWMEvent(WindowState* window_state,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 void DefaultState::AttachState( 256 void DefaultState::AttachState(
256 WindowState* window_state, 257 WindowState* window_state,
257 WindowState::State* state_in_previous_mode) { 258 WindowState::State* state_in_previous_mode) {
258 DCHECK_EQ(stored_window_state_, window_state); 259 DCHECK_EQ(stored_window_state_, window_state);
259 260
260 ReenterToCurrentState(window_state, state_in_previous_mode); 261 ReenterToCurrentState(window_state, state_in_previous_mode);
261 262
262 // If the display has changed while in the another mode, 263 // If the display has changed while in the another mode,
263 // we need to let windows know the change. 264 // we need to let windows know the change.
264 gfx::Display current_display = 265 gfx::Display current_display =
265 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window_state->window()); 266 gfx::Screen::GetScreen()->GetDisplayNearestWindow(
267 window_state->aura_window());
266 if (stored_display_state_.bounds() != current_display.bounds()) { 268 if (stored_display_state_.bounds() != current_display.bounds()) {
267 const WMEvent event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED); 269 const WMEvent event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED);
268 window_state->OnWMEvent(&event); 270 window_state->OnWMEvent(&event);
269 } else if (stored_display_state_.work_area() != current_display.work_area()) { 271 } else if (stored_display_state_.work_area() != current_display.work_area()) {
270 const WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); 272 const WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED);
271 window_state->OnWMEvent(&event); 273 window_state->OnWMEvent(&event);
272 } 274 }
273 } 275 }
274 276
275 void DefaultState::DetachState(WindowState* window_state) { 277 void DefaultState::DetachState(WindowState* window_state) {
276 stored_window_state_ = window_state; 278 stored_window_state_ = window_state;
277 aura::Window* window = window_state->window(); 279 aura::Window* window = window_state->aura_window();
278 stored_bounds_ = window->bounds(); 280 stored_bounds_ = window->bounds();
279 stored_restore_bounds_ = window_state->HasRestoreBounds() ? 281 stored_restore_bounds_ = window_state->HasRestoreBounds() ?
280 window_state->GetRestoreBoundsInParent() : gfx::Rect(); 282 window_state->GetRestoreBoundsInParent() : gfx::Rect();
281 // Remember the display state so that in case of the display change 283 // Remember the display state so that in case of the display change
282 // while in the other mode, we can perform necessary action to 284 // while in the other mode, we can perform necessary action to
283 // restore the window state to the proper state for the current 285 // restore the window state to the proper state for the current
284 // display. 286 // display.
285 stored_display_state_ = 287 stored_display_state_ = gfx::Screen::GetScreen()->GetDisplayNearestWindow(
286 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window_state->window()); 288 window_state->aura_window());
287 } 289 }
288 290
289 // static 291 // static
290 bool DefaultState::ProcessCompoundEvents(WindowState* window_state, 292 bool DefaultState::ProcessCompoundEvents(WindowState* window_state,
291 const WMEvent* event) { 293 const WMEvent* event) {
292 aura::Window* window = window_state->window(); 294 aura::Window* window = window_state->aura_window();
293 295
294 switch (event->type()) { 296 switch (event->type()) {
295 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: 297 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION:
296 if (window_state->IsFullscreen()) { 298 if (window_state->IsFullscreen()) {
297 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); 299 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
298 window_state->OnWMEvent(&event); 300 window_state->OnWMEvent(&event);
299 } else if (window_state->IsMaximized()) { 301 } else if (window_state->IsMaximized()) {
300 window_state->Restore(); 302 window_state->Restore();
301 } else if (window_state->IsNormalOrSnapped()) { 303 } else if (window_state->IsNormalOrSnapped()) {
302 if (window_state->CanMaximize()) 304 if (window_state->CanMaximize())
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 // When a window is dragged and dropped onto a different 413 // When a window is dragged and dropped onto a different
412 // root window, the bounds will be updated after they are added 414 // root window, the bounds will be updated after they are added
413 // to the root window. 415 // to the root window.
414 // If a window is opened as maximized or fullscreen, its bounds may be 416 // If a window is opened as maximized or fullscreen, its bounds may be
415 // empty, so update the bounds now before checking empty. 417 // empty, so update the bounds now before checking empty.
416 if (window_state->is_dragged() || 418 if (window_state->is_dragged() ||
417 SetMaximizedOrFullscreenBounds(window_state)) { 419 SetMaximizedOrFullscreenBounds(window_state)) {
418 return true; 420 return true;
419 } 421 }
420 422
421 aura::Window* window = window_state->window(); 423 aura::Window* window = window_state->aura_window();
422 gfx::Rect bounds = window->bounds(); 424 gfx::Rect bounds = window->bounds();
423 425
424 // Don't adjust window bounds if the bounds are empty as this 426 // Don't adjust window bounds if the bounds are empty as this
425 // happens when a new views::Widget is created. 427 // happens when a new views::Widget is created.
426 if (bounds.IsEmpty()) 428 if (bounds.IsEmpty())
427 return true; 429 return true;
428 430
429 // Only windows of type WINDOW_TYPE_NORMAL or WINDOW_TYPE_PANEL need to be 431 // Only windows of type WINDOW_TYPE_NORMAL or WINDOW_TYPE_PANEL need to be
430 // adjusted to have minimum visibility, because they are positioned by the 432 // adjusted to have minimum visibility, because they are positioned by the
431 // user and user should always be able to interact with them. Other 433 // user and user should always be able to interact with them. Other
(...skipping 14 matching lines...) Expand all
446 if (window->bounds() != bounds) 448 if (window->bounds() != bounds)
447 window_state->SetBoundsConstrained(bounds); 449 window_state->SetBoundsConstrained(bounds);
448 return true; 450 return true;
449 } 451 }
450 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: { 452 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: {
451 if (window_state->is_dragged() || 453 if (window_state->is_dragged() ||
452 SetMaximizedOrFullscreenBounds(window_state)) { 454 SetMaximizedOrFullscreenBounds(window_state)) {
453 return true; 455 return true;
454 } 456 }
455 gfx::Rect work_area_in_parent = 457 gfx::Rect work_area_in_parent =
456 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_state->window()); 458 ScreenUtil::GetDisplayWorkAreaBoundsInParent(
457 gfx::Rect bounds = window_state->window()->bounds(); 459 window_state->aura_window());
460 gfx::Rect bounds = window_state->aura_window()->bounds();
458 // When display bounds has changed, make sure the entire window is fully 461 // When display bounds has changed, make sure the entire window is fully
459 // visible. 462 // visible.
460 bounds.AdjustToFit(work_area_in_parent); 463 bounds.AdjustToFit(work_area_in_parent);
461 window_state->AdjustSnappedBounds(&bounds); 464 window_state->AdjustSnappedBounds(&bounds);
462 if (window_state->window()->bounds() != bounds) 465 if (window_state->aura_window()->bounds() != bounds)
463 window_state->SetBoundsDirectAnimated(bounds); 466 window_state->SetBoundsDirectAnimated(bounds);
464 return true; 467 return true;
465 } 468 }
466 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: { 469 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: {
467 // Don't resize the maximized window when the desktop is covered 470 // Don't resize the maximized window when the desktop is covered
468 // by fullscreen window. crbug.com/504299. 471 // by fullscreen window. crbug.com/504299.
469 bool in_fullscreen = 472 bool in_fullscreen =
470 RootWindowController::ForWindow(window_state->window()) 473 RootWindowController::ForWindow(window_state->aura_window())
471 ->workspace_controller() 474 ->workspace_controller()
472 ->GetWindowState() == WORKSPACE_WINDOW_STATE_FULL_SCREEN; 475 ->GetWindowState() == WORKSPACE_WINDOW_STATE_FULL_SCREEN;
473 if (in_fullscreen && window_state->IsMaximized()) 476 if (in_fullscreen && window_state->IsMaximized())
474 return true; 477 return true;
475 478
476 if (window_state->is_dragged() || 479 if (window_state->is_dragged() ||
477 SetMaximizedOrFullscreenBounds(window_state)) { 480 SetMaximizedOrFullscreenBounds(window_state)) {
478 return true; 481 return true;
479 } 482 }
480 gfx::Rect work_area_in_parent = 483 gfx::Rect work_area_in_parent =
481 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_state->window()); 484 ScreenUtil::GetDisplayWorkAreaBoundsInParent(
482 gfx::Rect bounds = window_state->window()->bounds(); 485 window_state->aura_window());
486 gfx::Rect bounds = window_state->aura_window()->bounds();
483 AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent, &bounds); 487 AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent, &bounds);
484 window_state->AdjustSnappedBounds(&bounds); 488 window_state->AdjustSnappedBounds(&bounds);
485 if (window_state->window()->bounds() != bounds) 489 if (window_state->aura_window()->bounds() != bounds)
486 window_state->SetBoundsDirectAnimated(bounds); 490 window_state->SetBoundsDirectAnimated(bounds);
487 return true; 491 return true;
488 } 492 }
489 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: 493 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION:
490 case WM_EVENT_TOGGLE_MAXIMIZE: 494 case WM_EVENT_TOGGLE_MAXIMIZE:
491 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: 495 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE:
492 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: 496 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE:
493 case WM_EVENT_TOGGLE_FULLSCREEN: 497 case WM_EVENT_TOGGLE_FULLSCREEN:
494 case WM_EVENT_CYCLE_SNAP_DOCK_LEFT: 498 case WM_EVENT_CYCLE_SNAP_DOCK_LEFT:
495 case WM_EVENT_CYCLE_SNAP_DOCK_RIGHT: 499 case WM_EVENT_CYCLE_SNAP_DOCK_RIGHT:
496 case WM_EVENT_CENTER: 500 case WM_EVENT_CENTER:
497 case WM_EVENT_NORMAL: 501 case WM_EVENT_NORMAL:
498 case WM_EVENT_MAXIMIZE: 502 case WM_EVENT_MAXIMIZE:
499 case WM_EVENT_MINIMIZE: 503 case WM_EVENT_MINIMIZE:
500 case WM_EVENT_FULLSCREEN: 504 case WM_EVENT_FULLSCREEN:
501 case WM_EVENT_SNAP_LEFT: 505 case WM_EVENT_SNAP_LEFT:
502 case WM_EVENT_SNAP_RIGHT: 506 case WM_EVENT_SNAP_RIGHT:
503 case WM_EVENT_SET_BOUNDS: 507 case WM_EVENT_SET_BOUNDS:
504 case WM_EVENT_SHOW_INACTIVE: 508 case WM_EVENT_SHOW_INACTIVE:
505 case WM_EVENT_DOCK: 509 case WM_EVENT_DOCK:
506 break; 510 break;
507 } 511 }
508 return false; 512 return false;
509 } 513 }
510 514
511 // static 515 // static
512 bool DefaultState::SetMaximizedOrFullscreenBounds(WindowState* window_state) { 516 bool DefaultState::SetMaximizedOrFullscreenBounds(WindowState* window_state) {
513 DCHECK(!window_state->is_dragged()); 517 DCHECK(!window_state->is_dragged());
514 if (window_state->IsMaximized()) { 518 if (window_state->IsMaximized()) {
515 window_state->SetBoundsDirect( 519 window_state->SetBoundsDirect(ScreenUtil::GetMaximizedWindowBoundsInParent(
516 ScreenUtil::GetMaximizedWindowBoundsInParent(window_state->window())); 520 window_state->aura_window()));
517 return true; 521 return true;
518 } 522 }
519 if (window_state->IsFullscreen()) { 523 if (window_state->IsFullscreen()) {
520 window_state->SetBoundsDirect( 524 window_state->SetBoundsDirect(
521 ScreenUtil::GetDisplayBoundsInParent(window_state->window())); 525 ScreenUtil::GetDisplayBoundsInParent(window_state->aura_window()));
522 return true; 526 return true;
523 } 527 }
524 return false; 528 return false;
525 } 529 }
526 530
527 // static 531 // static
528 void DefaultState::SetBounds(WindowState* window_state, 532 void DefaultState::SetBounds(WindowState* window_state,
529 const SetBoundsEvent* event) { 533 const SetBoundsEvent* event) {
530 if (window_state->is_dragged()) { 534 if (window_state->is_dragged()) {
531 // TODO(oshima|varkha): This may be no longer needed, as the dragging 535 // TODO(oshima|varkha): This may be no longer needed, as the dragging
532 // happens in docked window container. crbug.com/485612. 536 // happens in docked window container. crbug.com/485612.
533 window_state->SetBoundsDirect(event->requested_bounds()); 537 window_state->SetBoundsDirect(event->requested_bounds());
534 } else if (window_state->IsSnapped()) { 538 } else if (window_state->IsSnapped()) {
535 gfx::Rect work_area_in_parent = 539 gfx::Rect work_area_in_parent =
536 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_state->window()); 540 ScreenUtil::GetDisplayWorkAreaBoundsInParent(
541 window_state->aura_window());
537 gfx::Rect child_bounds(event->requested_bounds()); 542 gfx::Rect child_bounds(event->requested_bounds());
538 AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds); 543 AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds);
539 window_state->AdjustSnappedBounds(&child_bounds); 544 window_state->AdjustSnappedBounds(&child_bounds);
540 window_state->SetBoundsDirect(child_bounds); 545 window_state->SetBoundsDirect(child_bounds);
541 } else if (!SetMaximizedOrFullscreenBounds(window_state)) { 546 } else if (!SetMaximizedOrFullscreenBounds(window_state)) {
542 window_state->SetBoundsConstrained(event->requested_bounds()); 547 window_state->SetBoundsConstrained(event->requested_bounds());
543 } 548 }
544 } 549 }
545 550
546 void DefaultState::EnterToNextState(WindowState* window_state, 551 void DefaultState::EnterToNextState(WindowState* window_state,
547 WindowStateType next_state_type) { 552 WindowStateType next_state_type) {
548 // Do nothing if we're already in the same state. 553 // Do nothing if we're already in the same state.
549 if (state_type_ == next_state_type) 554 if (state_type_ == next_state_type)
550 return; 555 return;
551 556
552 WindowStateType previous_state_type = state_type_; 557 WindowStateType previous_state_type = state_type_;
553 state_type_ = next_state_type; 558 state_type_ = next_state_type;
554 559
555 window_state->UpdateWindowShowStateFromStateType(); 560 window_state->UpdateWindowShowStateFromStateType();
556 window_state->NotifyPreStateTypeChange(previous_state_type); 561 window_state->NotifyPreStateTypeChange(previous_state_type);
557 562
558 if (window_state->window()->parent()) { 563 if (window_state->aura_window()->parent()) {
559 if (!window_state->HasRestoreBounds() && 564 if (!window_state->HasRestoreBounds() &&
560 (previous_state_type == WINDOW_STATE_TYPE_DEFAULT || 565 (previous_state_type == WINDOW_STATE_TYPE_DEFAULT ||
561 previous_state_type == WINDOW_STATE_TYPE_NORMAL) && 566 previous_state_type == WINDOW_STATE_TYPE_NORMAL) &&
562 !window_state->IsMinimized() && 567 !window_state->IsMinimized() &&
563 !window_state->IsNormalStateType()) { 568 !window_state->IsNormalStateType()) {
564 window_state->SaveCurrentBoundsForRestore(); 569 window_state->SaveCurrentBoundsForRestore();
565 } 570 }
566 571
567 // When restoring from a minimized state, we want to restore to the 572 // When restoring from a minimized state, we want to restore to the
568 // previous bounds. However, we want to maintain the restore bounds. 573 // previous bounds. However, we want to maintain the restore bounds.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 if (!stored_restore_bounds_.IsEmpty()) 627 if (!stored_restore_bounds_.IsEmpty())
623 window_state->SetRestoreBoundsInParent(stored_restore_bounds_); 628 window_state->SetRestoreBoundsInParent(stored_restore_bounds_);
624 else 629 else
625 window_state->ClearRestoreBounds(); 630 window_state->ClearRestoreBounds();
626 631
627 window_state->NotifyPostStateTypeChange(previous_state_type); 632 window_state->NotifyPostStateTypeChange(previous_state_type);
628 } 633 }
629 634
630 void DefaultState::UpdateBoundsFromState(WindowState* window_state, 635 void DefaultState::UpdateBoundsFromState(WindowState* window_state,
631 WindowStateType previous_state_type) { 636 WindowStateType previous_state_type) {
632 aura::Window* window = window_state->window(); 637 aura::Window* window = window_state->aura_window();
633 gfx::Rect bounds_in_parent; 638 gfx::Rect bounds_in_parent;
634 switch (state_type_) { 639 switch (state_type_) {
635 case WINDOW_STATE_TYPE_LEFT_SNAPPED: 640 case WINDOW_STATE_TYPE_LEFT_SNAPPED:
636 case WINDOW_STATE_TYPE_RIGHT_SNAPPED: 641 case WINDOW_STATE_TYPE_RIGHT_SNAPPED:
637 bounds_in_parent = state_type_ == WINDOW_STATE_TYPE_LEFT_SNAPPED ? 642 bounds_in_parent = state_type_ == WINDOW_STATE_TYPE_LEFT_SNAPPED ?
638 GetDefaultLeftSnappedWindowBoundsInParent(window_state->window()) : 643 GetDefaultLeftSnappedWindowBoundsInParent(window_state->window()) :
639 GetDefaultRightSnappedWindowBoundsInParent(window_state->window()); 644 GetDefaultRightSnappedWindowBoundsInParent(window_state->window());
640 break; 645 break;
641 case WINDOW_STATE_TYPE_DOCKED: { 646 case WINDOW_STATE_TYPE_DOCKED: {
642 if (window->parent()->id() != kShellWindowId_DockedContainer) { 647 if (window->parent()->id() != kShellWindowId_DockedContainer) {
643 aura::Window* docked_container = Shell::GetContainer( 648 aura::Window* docked_container = Shell::GetContainer(
644 window->GetRootWindow(), 649 window->GetRootWindow(),
645 kShellWindowId_DockedContainer); 650 kShellWindowId_DockedContainer);
646 wm::ReparentChildWithTransientChildren(window, 651 wm::ReparentChildWithTransientChildren(window,
647 window->parent(), 652 window->parent(),
648 docked_container); 653 docked_container);
649 } 654 }
650 // Return early because we don't want to update the bounds of the 655 // Return early because we don't want to update the bounds of the
651 // window below; as the bounds are managed by the dock layout. 656 // window below; as the bounds are managed by the dock layout.
652 return; 657 return;
653 } 658 }
654 case WINDOW_STATE_TYPE_DEFAULT: 659 case WINDOW_STATE_TYPE_DEFAULT:
655 case WINDOW_STATE_TYPE_NORMAL: { 660 case WINDOW_STATE_TYPE_NORMAL: {
656 gfx::Rect work_area_in_parent = 661 gfx::Rect work_area_in_parent =
657 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_state->window()); 662 ScreenUtil::GetDisplayWorkAreaBoundsInParent(
663 window_state->aura_window());
658 if (window_state->HasRestoreBounds()) { 664 if (window_state->HasRestoreBounds()) {
659 bounds_in_parent = window_state->GetRestoreBoundsInParent(); 665 bounds_in_parent = window_state->GetRestoreBoundsInParent();
660 // Check if the |window|'s restored size is bigger than the working area 666 // Check if the |window|'s restored size is bigger than the working area
661 // This may happen if a window was resized to maximized bounds or if the 667 // This may happen if a window was resized to maximized bounds or if the
662 // display resolution changed while the window was maximized. 668 // display resolution changed while the window was maximized.
663 if (previous_state_type == WINDOW_STATE_TYPE_MAXIMIZED && 669 if (previous_state_type == WINDOW_STATE_TYPE_MAXIMIZED &&
664 bounds_in_parent.width() >= work_area_in_parent.width() && 670 bounds_in_parent.width() >= work_area_in_parent.width() &&
665 bounds_in_parent.height() >= work_area_in_parent.height()) { 671 bounds_in_parent.height() >= work_area_in_parent.height()) {
666 bounds_in_parent = work_area_in_parent; 672 bounds_in_parent = work_area_in_parent;
667 bounds_in_parent.Inset(kMaximizedWindowInset, kMaximizedWindowInset, 673 bounds_in_parent.Inset(kMaximizedWindowInset, kMaximizedWindowInset,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 // SetBoundsDirectAnimated does not work when the window gets reparented. 709 // SetBoundsDirectAnimated does not work when the window gets reparented.
704 // TODO(oshima): Consider fixing it and reenable the animation. 710 // TODO(oshima): Consider fixing it and reenable the animation.
705 window_state->SetBoundsDirect(bounds_in_parent); 711 window_state->SetBoundsDirect(bounds_in_parent);
706 } else { 712 } else {
707 window_state->SetBoundsDirectAnimated(bounds_in_parent); 713 window_state->SetBoundsDirectAnimated(bounds_in_parent);
708 } 714 }
709 } 715 }
710 716
711 if (window_state->IsMinimized()) { 717 if (window_state->IsMinimized()) {
712 // Save the previous show state so that we can correctly restore it. 718 // Save the previous show state so that we can correctly restore it.
713 window_state->window()->SetProperty(aura::client::kRestoreShowStateKey, 719 window_state->aura_window()->SetProperty(
714 ToWindowShowState(previous_state_type)); 720 aura::client::kRestoreShowStateKey,
721 ToWindowShowState(previous_state_type));
715 ::wm::SetWindowVisibilityAnimationType( 722 ::wm::SetWindowVisibilityAnimationType(
716 window_state->window(), WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); 723 window_state->aura_window(), WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
717 724
718 // Hide the window. 725 // Hide the window.
719 window_state->window()->Hide(); 726 window_state->window()->Hide();
720 // Activate another window. 727 // Activate another window.
721 if (window_state->IsActive()) 728 if (window_state->IsActive())
722 window_state->Deactivate(); 729 window_state->Deactivate();
723 } else if ((window_state->window()->TargetVisibility() || 730 } else if ((window_state->window()->GetTargetVisibility() ||
724 IsMinimizedWindowState(previous_state_type)) && 731 IsMinimizedWindowState(previous_state_type)) &&
725 !window_state->window()->layer()->visible()) { 732 !window_state->aura_window()->layer()->visible()) {
726 // The layer may be hidden if the window was previously minimized. Make 733 // The layer may be hidden if the window was previously minimized. Make
727 // sure it's visible. 734 // sure it's visible.
728 window_state->window()->Show(); 735 window_state->window()->Show();
729 if (IsMinimizedWindowState(previous_state_type) && 736 if (IsMinimizedWindowState(previous_state_type) &&
730 !window_state->IsMaximizedOrFullscreen()) { 737 !window_state->IsMaximizedOrFullscreen()) {
731 window_state->set_unminimize_to_restore_bounds(false); 738 window_state->set_unminimize_to_restore_bounds(false);
732 } 739 }
733 } 740 }
734 } 741 }
735 742
736 // static 743 // static
737 void DefaultState::CenterWindow(WindowState* window_state) { 744 void DefaultState::CenterWindow(WindowState* window_state) {
738 if (!window_state->IsNormalOrSnapped()) 745 if (!window_state->IsNormalOrSnapped())
739 return; 746 return;
740 aura::Window* window = window_state->window(); 747 aura::Window* window = window_state->aura_window();
741 if (window_state->IsSnapped()) { 748 if (window_state->IsSnapped()) {
742 gfx::Rect center_in_screen = 749 gfx::Rect center_in_screen =
743 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window).work_area(); 750 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window).work_area();
744 gfx::Size size = window_state->HasRestoreBounds() ? 751 gfx::Size size = window_state->HasRestoreBounds() ?
745 window_state->GetRestoreBoundsInScreen().size() : 752 window_state->GetRestoreBoundsInScreen().size() :
746 window->bounds().size(); 753 window->bounds().size();
747 center_in_screen.ClampToCenteredSize(size); 754 center_in_screen.ClampToCenteredSize(size);
748 window_state->SetRestoreBoundsInScreen(center_in_screen); 755 window_state->SetRestoreBoundsInScreen(center_in_screen);
749 window_state->Restore(); 756 window_state->Restore();
750 } else { 757 } else {
751 gfx::Rect center_in_parent = 758 gfx::Rect center_in_parent =
752 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window); 759 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window);
753 center_in_parent.ClampToCenteredSize(window->bounds().size()); 760 center_in_parent.ClampToCenteredSize(window->bounds().size());
754 window_state->SetBoundsDirectAnimated(center_in_parent); 761 window_state->SetBoundsDirectAnimated(center_in_parent);
755 } 762 }
756 // Centering window is treated as if a user moved and resized the window. 763 // Centering window is treated as if a user moved and resized the window.
757 window_state->set_bounds_changed_by_user(true); 764 window_state->set_bounds_changed_by_user(true);
758 } 765 }
759 766
760 } // namespace wm 767 } // namespace wm
761 } // namespace ash 768 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/common/wm_window_property.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