| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/common/wm/default_state.h" | 5 #include "ash/common/wm/default_state.h" |
| 6 | 6 |
| 7 #include "ash/common/ash_switches.h" |
| 7 #include "ash/common/wm/dock/docked_window_layout_manager.h" | 8 #include "ash/common/wm/dock/docked_window_layout_manager.h" |
| 8 #include "ash/common/wm/window_animation_types.h" | 9 #include "ash/common/wm/window_animation_types.h" |
| 9 #include "ash/common/wm/window_parenting_utils.h" | 10 #include "ash/common/wm/window_parenting_utils.h" |
| 10 #include "ash/common/wm/window_positioning_utils.h" | 11 #include "ash/common/wm/window_positioning_utils.h" |
| 11 #include "ash/common/wm/window_state.h" | 12 #include "ash/common/wm/window_state.h" |
| 12 #include "ash/common/wm/window_state_delegate.h" | 13 #include "ash/common/wm/window_state_delegate.h" |
| 13 #include "ash/common/wm/window_state_util.h" | 14 #include "ash/common/wm/window_state_util.h" |
| 14 #include "ash/common/wm/wm_event.h" | 15 #include "ash/common/wm/wm_event.h" |
| 15 #include "ash/common/wm/wm_screen_util.h" | 16 #include "ash/common/wm/wm_screen_util.h" |
| 16 #include "ash/common/wm_root_window_controller.h" | 17 #include "ash/common/wm_root_window_controller.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 docked_window_layout_manager_->set_event_source( | 99 docked_window_layout_manager_->set_event_source( |
| 99 DOCKED_ACTION_SOURCE_UNKNOWN); | 100 DOCKED_ACTION_SOURCE_UNKNOWN); |
| 100 } | 101 } |
| 101 | 102 |
| 102 private: | 103 private: |
| 103 DockedWindowLayoutManager* docked_window_layout_manager_; | 104 DockedWindowLayoutManager* docked_window_layout_manager_; |
| 104 | 105 |
| 105 DISALLOW_COPY_AND_ASSIGN(ScopedDockedLayoutEventSourceResetter); | 106 DISALLOW_COPY_AND_ASSIGN(ScopedDockedLayoutEventSourceResetter); |
| 106 }; | 107 }; |
| 107 | 108 |
| 109 void CycleSnap(WindowState* window_state, WMEventType event) { |
| 110 DCHECK(!ash::switches::DockedWindowsEnabled()); |
| 111 |
| 112 wm::WindowStateType desired_snap_state = |
| 113 event == WM_EVENT_CYCLE_SNAP_DOCK_LEFT |
| 114 ? wm::WINDOW_STATE_TYPE_LEFT_SNAPPED |
| 115 : wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED; |
| 116 |
| 117 if (window_state->CanSnap() && |
| 118 window_state->GetStateType() != desired_snap_state && |
| 119 window_state->window()->GetType() != ui::wm::WINDOW_TYPE_PANEL) { |
| 120 const wm::WMEvent event(desired_snap_state == |
| 121 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED |
| 122 ? wm::WM_EVENT_SNAP_LEFT |
| 123 : wm::WM_EVENT_SNAP_RIGHT); |
| 124 window_state->OnWMEvent(&event); |
| 125 return; |
| 126 } |
| 127 |
| 128 if (window_state->IsSnapped()) { |
| 129 window_state->Restore(); |
| 130 return; |
| 131 } |
| 132 window_state->window()->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE); |
| 133 } |
| 134 |
| 108 void CycleSnapDock(WindowState* window_state, WMEventType event) { | 135 void CycleSnapDock(WindowState* window_state, WMEventType event) { |
| 136 DCHECK(ash::switches::DockedWindowsEnabled()); |
| 137 |
| 109 DockedWindowLayoutManager* dock_layout = | 138 DockedWindowLayoutManager* dock_layout = |
| 110 GetDockedWindowLayoutManager(window_state->window()->GetShell()); | 139 GetDockedWindowLayoutManager(window_state->window()->GetShell()); |
| 111 wm::WindowStateType desired_snap_state = | 140 wm::WindowStateType desired_snap_state = |
| 112 event == WM_EVENT_CYCLE_SNAP_DOCK_LEFT | 141 event == WM_EVENT_CYCLE_SNAP_DOCK_LEFT |
| 113 ? wm::WINDOW_STATE_TYPE_LEFT_SNAPPED | 142 ? wm::WINDOW_STATE_TYPE_LEFT_SNAPPED |
| 114 : wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED; | 143 : wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED; |
| 115 DockedAlignment desired_dock_alignment = | 144 DockedAlignment desired_dock_alignment = |
| 116 event == WM_EVENT_CYCLE_SNAP_DOCK_LEFT ? DOCKED_ALIGNMENT_LEFT | 145 event == WM_EVENT_CYCLE_SNAP_DOCK_LEFT ? DOCKED_ALIGNMENT_LEFT |
| 117 : DOCKED_ALIGNMENT_RIGHT; | 146 : DOCKED_ALIGNMENT_RIGHT; |
| 118 DockedAlignment current_dock_alignment = | 147 DockedAlignment current_dock_alignment = |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 window_state->SetRestoreBoundsInParent(restore_bounds); | 401 window_state->SetRestoreBoundsInParent(restore_bounds); |
| 373 window->SetBounds(new_bounds); | 402 window->SetBounds(new_bounds); |
| 374 } | 403 } |
| 375 return true; | 404 return true; |
| 376 } | 405 } |
| 377 case WM_EVENT_TOGGLE_FULLSCREEN: | 406 case WM_EVENT_TOGGLE_FULLSCREEN: |
| 378 ToggleFullScreen(window_state, window_state->delegate()); | 407 ToggleFullScreen(window_state, window_state->delegate()); |
| 379 return true; | 408 return true; |
| 380 case WM_EVENT_CYCLE_SNAP_DOCK_LEFT: | 409 case WM_EVENT_CYCLE_SNAP_DOCK_LEFT: |
| 381 case WM_EVENT_CYCLE_SNAP_DOCK_RIGHT: | 410 case WM_EVENT_CYCLE_SNAP_DOCK_RIGHT: |
| 382 CycleSnapDock(window_state, event->type()); | 411 if (ash::switches::DockedWindowsEnabled()) |
| 412 CycleSnapDock(window_state, event->type()); |
| 413 else |
| 414 CycleSnap(window_state, event->type()); |
| 383 return true; | 415 return true; |
| 384 case WM_EVENT_CENTER: | 416 case WM_EVENT_CENTER: |
| 385 CenterWindow(window_state); | 417 CenterWindow(window_state); |
| 386 return true; | 418 return true; |
| 387 case WM_EVENT_NORMAL: | 419 case WM_EVENT_NORMAL: |
| 388 case WM_EVENT_MAXIMIZE: | 420 case WM_EVENT_MAXIMIZE: |
| 389 case WM_EVENT_MINIMIZE: | 421 case WM_EVENT_MINIMIZE: |
| 390 case WM_EVENT_FULLSCREEN: | 422 case WM_EVENT_FULLSCREEN: |
| 391 case WM_EVENT_PIN: | 423 case WM_EVENT_PIN: |
| 392 case WM_EVENT_TRUSTED_PIN: | 424 case WM_EVENT_TRUSTED_PIN: |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 gfx::Rect bounds_in_parent; | 682 gfx::Rect bounds_in_parent; |
| 651 switch (state_type_) { | 683 switch (state_type_) { |
| 652 case WINDOW_STATE_TYPE_LEFT_SNAPPED: | 684 case WINDOW_STATE_TYPE_LEFT_SNAPPED: |
| 653 case WINDOW_STATE_TYPE_RIGHT_SNAPPED: | 685 case WINDOW_STATE_TYPE_RIGHT_SNAPPED: |
| 654 bounds_in_parent = | 686 bounds_in_parent = |
| 655 state_type_ == WINDOW_STATE_TYPE_LEFT_SNAPPED | 687 state_type_ == WINDOW_STATE_TYPE_LEFT_SNAPPED |
| 656 ? GetDefaultLeftSnappedWindowBoundsInParent(window) | 688 ? GetDefaultLeftSnappedWindowBoundsInParent(window) |
| 657 : GetDefaultRightSnappedWindowBoundsInParent(window); | 689 : GetDefaultRightSnappedWindowBoundsInParent(window); |
| 658 break; | 690 break; |
| 659 case WINDOW_STATE_TYPE_DOCKED: { | 691 case WINDOW_STATE_TYPE_DOCKED: { |
| 692 // TODO(afakhry): Remove in M58. |
| 693 DCHECK(ash::switches::DockedWindowsEnabled()); |
| 660 if (window->GetParent()->GetShellWindowId() != | 694 if (window->GetParent()->GetShellWindowId() != |
| 661 kShellWindowId_DockedContainer) { | 695 kShellWindowId_DockedContainer) { |
| 662 WmWindow* docked_container = | 696 WmWindow* docked_container = |
| 663 window->GetRootWindow()->GetChildByShellWindowId( | 697 window->GetRootWindow()->GetChildByShellWindowId( |
| 664 kShellWindowId_DockedContainer); | 698 kShellWindowId_DockedContainer); |
| 665 ReparentChildWithTransientChildren(window, window->GetParent(), | 699 ReparentChildWithTransientChildren(window, window->GetParent(), |
| 666 docked_container); | 700 docked_container); |
| 667 } | 701 } |
| 668 // Return early because we don't want to update the bounds of the | 702 // Return early because we don't want to update the bounds of the |
| 669 // window below; as the bounds are managed by the dock layout. | 703 // window below; as the bounds are managed by the dock layout. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 gfx::Rect center_in_parent = GetDisplayWorkAreaBoundsInParent(window); | 808 gfx::Rect center_in_parent = GetDisplayWorkAreaBoundsInParent(window); |
| 775 center_in_parent.ClampToCenteredSize(window->GetBounds().size()); | 809 center_in_parent.ClampToCenteredSize(window->GetBounds().size()); |
| 776 window_state->SetBoundsDirectAnimated(center_in_parent); | 810 window_state->SetBoundsDirectAnimated(center_in_parent); |
| 777 } | 811 } |
| 778 // Centering window is treated as if a user moved and resized the window. | 812 // Centering window is treated as if a user moved and resized the window. |
| 779 window_state->set_bounds_changed_by_user(true); | 813 window_state->set_bounds_changed_by_user(true); |
| 780 } | 814 } |
| 781 | 815 |
| 782 } // namespace wm | 816 } // namespace wm |
| 783 } // namespace ash | 817 } // namespace ash |
| OLD | NEW |