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

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

Issue 597683003: Add window states docked; and docked minimized. Add wm window event to set docked and undocked. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dock
Patch Set: Add docked window states Created 6 years, 2 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/default_state.h" 5 #include "ash/wm/default_state.h"
6 6
7 #include "ash/display/display_controller.h" 7 #include "ash/display/display_controller.h"
8 #include "ash/screen_util.h" 8 #include "ash/screen_util.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/shell_window_ids.h" 10 #include "ash/shell_window_ids.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 DefaultState::~DefaultState() {} 71 DefaultState::~DefaultState() {}
72 72
73 void DefaultState::OnWMEvent(WindowState* window_state, 73 void DefaultState::OnWMEvent(WindowState* window_state,
74 const WMEvent* event) { 74 const WMEvent* event) {
75 if (ProcessWorkspaceEvents(window_state, event)) 75 if (ProcessWorkspaceEvents(window_state, event))
76 return; 76 return;
77 77
78 if (ProcessCompoundEvents(window_state, event)) 78 if (ProcessCompoundEvents(window_state, event))
79 return; 79 return;
80 80
81 WindowStateType current_state_type = window_state->GetStateType();
81 WindowStateType next_state_type = WINDOW_STATE_TYPE_NORMAL; 82 WindowStateType next_state_type = WINDOW_STATE_TYPE_NORMAL;
82 switch (event->type()) { 83 switch (event->type()) {
83 case WM_EVENT_NORMAL: 84 case WM_EVENT_NORMAL:
84 next_state_type = WINDOW_STATE_TYPE_NORMAL; 85 if (current_state_type == WINDOW_STATE_TYPE_DOCKED_MINIMIZED) {
varkha 2014/09/25 22:09:28 nit: there are still some nits from the first batc
dtapuska 2014/09/26 14:17:07 Sorry I thought I covered them all; but I should A
86 next_state_type = WINDOW_STATE_TYPE_DOCKED;
87 } else {
88 next_state_type = WINDOW_STATE_TYPE_NORMAL;
89 }
85 break; 90 break;
86 case WM_EVENT_MAXIMIZE: 91 case WM_EVENT_MAXIMIZE:
87 next_state_type = WINDOW_STATE_TYPE_MAXIMIZED; 92 next_state_type = WINDOW_STATE_TYPE_MAXIMIZED;
88 break; 93 break;
89 case WM_EVENT_MINIMIZE: 94 case WM_EVENT_MINIMIZE:
90 next_state_type = WINDOW_STATE_TYPE_MINIMIZED; 95 if (current_state_type == WINDOW_STATE_TYPE_DOCKED) {
96 next_state_type = WINDOW_STATE_TYPE_DOCKED_MINIMIZED;
97 } else {
98 next_state_type = WINDOW_STATE_TYPE_MINIMIZED;
99 }
91 break; 100 break;
92 case WM_EVENT_FULLSCREEN: 101 case WM_EVENT_FULLSCREEN:
93 next_state_type = WINDOW_STATE_TYPE_FULLSCREEN; 102 next_state_type = WINDOW_STATE_TYPE_FULLSCREEN;
94 break; 103 break;
95 case WM_EVENT_SNAP_LEFT: 104 case WM_EVENT_SNAP_LEFT:
96 next_state_type = WINDOW_STATE_TYPE_LEFT_SNAPPED; 105 next_state_type = WINDOW_STATE_TYPE_LEFT_SNAPPED;
97 break; 106 break;
98 case WM_EVENT_SNAP_RIGHT: 107 case WM_EVENT_SNAP_RIGHT:
99 next_state_type = WINDOW_STATE_TYPE_RIGHT_SNAPPED; 108 next_state_type = WINDOW_STATE_TYPE_RIGHT_SNAPPED;
100 break; 109 break;
110 case WM_EVENT_DOCK:
111 next_state_type = WINDOW_STATE_TYPE_DOCKED;
112 break;
101 case WM_EVENT_SET_BOUNDS: 113 case WM_EVENT_SET_BOUNDS:
102 SetBounds(window_state, static_cast<const SetBoundsEvent*>(event)); 114 SetBounds(window_state, static_cast<const SetBoundsEvent*>(event));
103 return; 115 return;
104 case WM_EVENT_SHOW_INACTIVE: 116 case WM_EVENT_SHOW_INACTIVE:
105 next_state_type = WINDOW_STATE_TYPE_INACTIVE; 117 next_state_type = WINDOW_STATE_TYPE_INACTIVE;
106 break; 118 break;
107 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: 119 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION:
108 case WM_EVENT_TOGGLE_MAXIMIZE: 120 case WM_EVENT_TOGGLE_MAXIMIZE:
109 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: 121 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE:
110 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: 122 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE:
111 case WM_EVENT_TOGGLE_FULLSCREEN: 123 case WM_EVENT_TOGGLE_FULLSCREEN:
112 case WM_EVENT_CENTER: 124 case WM_EVENT_CENTER:
113 NOTREACHED() << "Compound event should not reach here:" << event; 125 NOTREACHED() << "Compound event should not reach here:" << event;
114 return; 126 return;
115 case WM_EVENT_ADDED_TO_WORKSPACE: 127 case WM_EVENT_ADDED_TO_WORKSPACE:
116 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: 128 case WM_EVENT_WORKAREA_BOUNDS_CHANGED:
117 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: 129 case WM_EVENT_DISPLAY_BOUNDS_CHANGED:
118 NOTREACHED() << "Workspace event should not reach here:" << event; 130 NOTREACHED() << "Workspace event should not reach here:" << event;
119 return; 131 return;
120 } 132 }
121 133
122 WindowStateType current = window_state->GetStateType(); 134 if (next_state_type == current_state_type && window_state->IsSnapped()) {
123
124 if (next_state_type == current && window_state->IsSnapped()) {
125 gfx::Rect snapped_bounds = event->type() == WM_EVENT_SNAP_LEFT ? 135 gfx::Rect snapped_bounds = event->type() == WM_EVENT_SNAP_LEFT ?
126 GetDefaultLeftSnappedWindowBoundsInParent(window_state->window()) : 136 GetDefaultLeftSnappedWindowBoundsInParent(window_state->window()) :
127 GetDefaultRightSnappedWindowBoundsInParent(window_state->window()); 137 GetDefaultRightSnappedWindowBoundsInParent(window_state->window());
128 window_state->SetBoundsDirectAnimated(snapped_bounds); 138 window_state->SetBoundsDirectAnimated(snapped_bounds);
129 return; 139 return;
130 } 140 }
131 141
132 EnterToNextState(window_state, next_state_type); 142 EnterToNextState(window_state, next_state_type);
133 } 143 }
134 144
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 CenterWindow(window_state); 276 CenterWindow(window_state);
267 return true; 277 return true;
268 case WM_EVENT_NORMAL: 278 case WM_EVENT_NORMAL:
269 case WM_EVENT_MAXIMIZE: 279 case WM_EVENT_MAXIMIZE:
270 case WM_EVENT_MINIMIZE: 280 case WM_EVENT_MINIMIZE:
271 case WM_EVENT_FULLSCREEN: 281 case WM_EVENT_FULLSCREEN:
272 case WM_EVENT_SNAP_LEFT: 282 case WM_EVENT_SNAP_LEFT:
273 case WM_EVENT_SNAP_RIGHT: 283 case WM_EVENT_SNAP_RIGHT:
274 case WM_EVENT_SET_BOUNDS: 284 case WM_EVENT_SET_BOUNDS:
275 case WM_EVENT_SHOW_INACTIVE: 285 case WM_EVENT_SHOW_INACTIVE:
286 case WM_EVENT_DOCK:
276 break; 287 break;
277 case WM_EVENT_ADDED_TO_WORKSPACE: 288 case WM_EVENT_ADDED_TO_WORKSPACE:
278 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: 289 case WM_EVENT_WORKAREA_BOUNDS_CHANGED:
279 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: 290 case WM_EVENT_DISPLAY_BOUNDS_CHANGED:
280 NOTREACHED() << "Workspace event should not reach here:" << event; 291 NOTREACHED() << "Workspace event should not reach here:" << event;
281 break; 292 break;
282 } 293 }
283 return false; 294 return false;
284 } 295 }
285 296
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 case WM_EVENT_TOGGLE_FULLSCREEN: 376 case WM_EVENT_TOGGLE_FULLSCREEN:
366 case WM_EVENT_CENTER: 377 case WM_EVENT_CENTER:
367 case WM_EVENT_NORMAL: 378 case WM_EVENT_NORMAL:
368 case WM_EVENT_MAXIMIZE: 379 case WM_EVENT_MAXIMIZE:
369 case WM_EVENT_MINIMIZE: 380 case WM_EVENT_MINIMIZE:
370 case WM_EVENT_FULLSCREEN: 381 case WM_EVENT_FULLSCREEN:
371 case WM_EVENT_SNAP_LEFT: 382 case WM_EVENT_SNAP_LEFT:
372 case WM_EVENT_SNAP_RIGHT: 383 case WM_EVENT_SNAP_RIGHT:
373 case WM_EVENT_SET_BOUNDS: 384 case WM_EVENT_SET_BOUNDS:
374 case WM_EVENT_SHOW_INACTIVE: 385 case WM_EVENT_SHOW_INACTIVE:
386 case WM_EVENT_DOCK:
375 break; 387 break;
376 } 388 }
377 return false; 389 return false;
378 } 390 }
379 391
380 // static 392 // static
381 bool DefaultState::SetMaximizedOrFullscreenBounds(WindowState* window_state) { 393 bool DefaultState::SetMaximizedOrFullscreenBounds(WindowState* window_state) {
382 DCHECK(!window_state->is_dragged()); 394 DCHECK(!window_state->is_dragged());
383 if (window_state->IsMaximized()) { 395 if (window_state->IsMaximized()) {
384 window_state->SetBoundsDirect( 396 window_state->SetBoundsDirect(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 return; 429 return;
418 430
419 WindowStateType previous_state_type = state_type_; 431 WindowStateType previous_state_type = state_type_;
420 state_type_ = next_state_type; 432 state_type_ = next_state_type;
421 433
422 window_state->UpdateWindowShowStateFromStateType(); 434 window_state->UpdateWindowShowStateFromStateType();
423 window_state->NotifyPreStateTypeChange(previous_state_type); 435 window_state->NotifyPreStateTypeChange(previous_state_type);
424 436
425 // This Docked/Snapped hack is due to the issue that IsDocked returns 437 // This Docked/Snapped hack is due to the issue that IsDocked returns
426 // true for dragging window. TODO(oshima): Make docked window a state 438 // true for dragging window. TODO(oshima): Make docked window a state
427 // and remove this hack. 439 // and remove this hack.
varkha 2014/09/25 22:09:28 This comment can now be moved to above line 449.
dtapuska 2014/09/26 14:17:07 Done.
428 if (window_state->window()->parent() && 440 if (window_state->window()->parent()) {
429 (window_state->IsSnapped() ||
430 (!window_state->IsDocked() && !IsPanel(window_state->window())))) {
431 if (!window_state->HasRestoreBounds() && 441 if (!window_state->HasRestoreBounds() &&
432 (previous_state_type == WINDOW_STATE_TYPE_DEFAULT || 442 (previous_state_type == WINDOW_STATE_TYPE_DEFAULT ||
433 previous_state_type == WINDOW_STATE_TYPE_NORMAL) && 443 previous_state_type == WINDOW_STATE_TYPE_NORMAL) &&
434 !window_state->IsMinimized() && 444 !window_state->IsMinimized() &&
435 !window_state->IsNormalStateType()) { 445 !window_state->IsNormalStateType()) {
436 window_state->SaveCurrentBoundsForRestore(); 446 window_state->SaveCurrentBoundsForRestore();
437 } 447 }
438 448
439 // When restoring from a minimized state, we want to restore to the previous 449 if (window_state->IsSnapped() ||
440 // bounds. However, we want to maintain the restore bounds. (The restore 450 (!window_state->IsDocked() && !IsPanel(window_state->window()))) {
441 // bounds are set if a user maximized the window in one axis by double
442 // clicking the window border for example).
443 gfx::Rect restore_bounds_in_screen;
444 if (previous_state_type == WINDOW_STATE_TYPE_MINIMIZED &&
445 window_state->IsNormalStateType() &&
446 window_state->HasRestoreBounds() &&
447 !window_state->unminimize_to_restore_bounds()) {
448 restore_bounds_in_screen = window_state->GetRestoreBoundsInScreen();
449 window_state->SaveCurrentBoundsForRestore();
450 }
451 451
varkha 2014/09/25 22:09:28 nit: no need for empty line.
dtapuska 2014/09/26 14:17:07 Done.
452 if (window_state->IsMaximizedOrFullscreen()) 452 // When restoring from a minimized state, we want to restore to the
453 MoveToDisplayForRestore(window_state); 453 // previousbounds. However, we want to maintain the restore bounds.
varkha 2014/09/25 22:09:28 nit: space after 'previous'.
dtapuska 2014/09/26 14:17:07 Done.
454 // (The restore bounds are set if a user maximized the window in one
455 // axis by double clicking the window border for example).
456 gfx::Rect restore_bounds_in_screen;
457 if (previous_state_type == WINDOW_STATE_TYPE_MINIMIZED &&
458 window_state->IsNormalStateType() &&
459 window_state->HasRestoreBounds() &&
460 !window_state->unminimize_to_restore_bounds()) {
461 restore_bounds_in_screen = window_state->GetRestoreBoundsInScreen();
462 window_state->SaveCurrentBoundsForRestore();
463 }
454 464
455 UpdateBoundsFromState(window_state, previous_state_type); 465 if (window_state->IsMaximizedOrFullscreen())
466 MoveToDisplayForRestore(window_state);
456 467
457 // Normal state should have no restore bounds unless it's 468 UpdateBoundsFromState(window_state, previous_state_type);
458 // unminimzied. 469
459 if (!restore_bounds_in_screen.IsEmpty()) 470 // Normal state should have no restore bounds unless it's
460 window_state->SetRestoreBoundsInScreen(restore_bounds_in_screen); 471 // unminimized.
461 else if (window_state->IsNormalStateType()) 472 if (!restore_bounds_in_screen.IsEmpty())
462 window_state->ClearRestoreBounds(); 473 window_state->SetRestoreBoundsInScreen(restore_bounds_in_screen);
474 else if (window_state->IsNormalStateType())
475 window_state->ClearRestoreBounds();
476 }
463 } 477 }
464 window_state->NotifyPostStateTypeChange(previous_state_type); 478 window_state->NotifyPostStateTypeChange(previous_state_type);
465 } 479 }
466 480
467 void DefaultState::ReenterToCurrentState( 481 void DefaultState::ReenterToCurrentState(
468 WindowState* window_state, 482 WindowState* window_state,
469 WindowState::State* state_in_previous_mode) { 483 WindowState::State* state_in_previous_mode) {
470 WindowStateType previous_state_type = state_in_previous_mode->GetType(); 484 WindowStateType previous_state_type = state_in_previous_mode->GetType();
471 if (previous_state_type == wm::WINDOW_STATE_TYPE_FULLSCREEN) { 485 if (previous_state_type == wm::WINDOW_STATE_TYPE_FULLSCREEN) {
472 // A state change should not move a window out of full screen since full 486 // A state change should not move a window out of full screen since full
(...skipping 27 matching lines...) Expand all
500 WindowStateType previous_state_type) { 514 WindowStateType previous_state_type) {
501 aura::Window* window = window_state->window(); 515 aura::Window* window = window_state->window();
502 gfx::Rect bounds_in_parent; 516 gfx::Rect bounds_in_parent;
503 switch (state_type_) { 517 switch (state_type_) {
504 case WINDOW_STATE_TYPE_LEFT_SNAPPED: 518 case WINDOW_STATE_TYPE_LEFT_SNAPPED:
505 case WINDOW_STATE_TYPE_RIGHT_SNAPPED: 519 case WINDOW_STATE_TYPE_RIGHT_SNAPPED:
506 bounds_in_parent = state_type_ == WINDOW_STATE_TYPE_LEFT_SNAPPED ? 520 bounds_in_parent = state_type_ == WINDOW_STATE_TYPE_LEFT_SNAPPED ?
507 GetDefaultLeftSnappedWindowBoundsInParent(window_state->window()) : 521 GetDefaultLeftSnappedWindowBoundsInParent(window_state->window()) :
508 GetDefaultRightSnappedWindowBoundsInParent(window_state->window()); 522 GetDefaultRightSnappedWindowBoundsInParent(window_state->window());
509 break; 523 break;
524 case WINDOW_STATE_TYPE_DOCKED:
525 case WINDOW_STATE_TYPE_DOCKED_MINIMIZED:
526 break;
varkha 2014/09/25 22:09:28 nit: I suggest merging this with case WINDOW_STATE
dtapuska 2014/09/26 14:17:07 Slightly modified; but adjusted.
510 case WINDOW_STATE_TYPE_DEFAULT: 527 case WINDOW_STATE_TYPE_DEFAULT:
511 case WINDOW_STATE_TYPE_NORMAL: { 528 case WINDOW_STATE_TYPE_NORMAL: {
512 gfx::Rect work_area_in_parent = 529 gfx::Rect work_area_in_parent =
513 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_state->window()); 530 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_state->window());
514 if (window_state->HasRestoreBounds()) { 531 if (window_state->HasRestoreBounds()) {
515 bounds_in_parent = window_state->GetRestoreBoundsInParent(); 532 bounds_in_parent = window_state->GetRestoreBoundsInParent();
516 // Check if the |window|'s restored size is bigger than the working area 533 // Check if the |window|'s restored size is bigger than the working area
517 // This may happen if a window was resized to maximized bounds or if the 534 // This may happen if a window was resized to maximized bounds or if the
518 // display resolution changed while the window was maximized. 535 // display resolution changed while the window was maximized.
519 if (previous_state_type == WINDOW_STATE_TYPE_MAXIMIZED && 536 if (previous_state_type == WINDOW_STATE_TYPE_MAXIMIZED &&
(...skipping 21 matching lines...) Expand all
541 break; 558 break;
542 559
543 case WINDOW_STATE_TYPE_MINIMIZED: 560 case WINDOW_STATE_TYPE_MINIMIZED:
544 break; 561 break;
545 case WINDOW_STATE_TYPE_INACTIVE: 562 case WINDOW_STATE_TYPE_INACTIVE:
546 case WINDOW_STATE_TYPE_END: 563 case WINDOW_STATE_TYPE_END:
547 case WINDOW_STATE_TYPE_AUTO_POSITIONED: 564 case WINDOW_STATE_TYPE_AUTO_POSITIONED:
548 return; 565 return;
549 } 566 }
550 567
551 if (state_type_ != WINDOW_STATE_TYPE_MINIMIZED) { 568 if (state_type_ != WINDOW_STATE_TYPE_MINIMIZED) {
varkha 2014/09/25 22:09:28 Should this account for the new WINDOW_STATE_DOCKE
dtapuska 2014/09/26 14:17:07 Done.
552 if (previous_state_type == WINDOW_STATE_TYPE_MINIMIZED || 569 if (previous_state_type == WINDOW_STATE_TYPE_MINIMIZED ||
553 window_state->IsFullscreen()) { 570 window_state->IsFullscreen()) {
554 window_state->SetBoundsDirect(bounds_in_parent); 571 window_state->SetBoundsDirect(bounds_in_parent);
555 } else if (window_state->IsMaximized() || 572 } else if (window_state->IsMaximized() ||
556 IsMaximizedOrFullscreenWindowStateType(previous_state_type)) { 573 IsMaximizedOrFullscreenWindowStateType(previous_state_type)) {
557 window_state->SetBoundsDirectCrossFade(bounds_in_parent); 574 window_state->SetBoundsDirectCrossFade(bounds_in_parent);
558 } else if (window_state->is_dragged()) { 575 } else if (window_state->is_dragged()) {
559 // SetBoundsDirectAnimated does not work when the window gets reparented. 576 // SetBoundsDirectAnimated does not work when the window gets reparented.
560 // TODO(oshima): Consider fixing it and reenable the animation. 577 // TODO(oshima): Consider fixing it and reenable the animation.
561 window_state->SetBoundsDirect(bounds_in_parent); 578 window_state->SetBoundsDirect(bounds_in_parent);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window); 625 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window);
609 center_in_parent.ClampToCenteredSize(window->bounds().size()); 626 center_in_parent.ClampToCenteredSize(window->bounds().size());
610 window_state->SetBoundsDirectAnimated(center_in_parent); 627 window_state->SetBoundsDirectAnimated(center_in_parent);
611 } 628 }
612 // Centering window is treated as if a user moved and resized the window. 629 // Centering window is treated as if a user moved and resized the window.
613 window_state->set_bounds_changed_by_user(true); 630 window_state->set_bounds_changed_by_user(true);
614 } 631 }
615 632
616 } // namespace wm 633 } // namespace wm
617 } // namespace ash 634 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698