Chromium Code Reviews| 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/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" |
| 11 #include "ash/wm/coordinate_conversion.h" | 11 #include "ash/wm/coordinate_conversion.h" |
| 12 #include "ash/wm/dock/docked_window_layout_manager.h" | |
| 12 #include "ash/wm/window_animations.h" | 13 #include "ash/wm/window_animations.h" |
| 13 #include "ash/wm/window_state.h" | 14 #include "ash/wm/window_state.h" |
| 14 #include "ash/wm/window_state_delegate.h" | 15 #include "ash/wm/window_state_delegate.h" |
| 15 #include "ash/wm/window_state_util.h" | 16 #include "ash/wm/window_state_util.h" |
| 16 #include "ash/wm/window_util.h" | 17 #include "ash/wm/window_util.h" |
| 17 #include "ash/wm/wm_event.h" | 18 #include "ash/wm/wm_event.h" |
| 18 #include "ash/wm/workspace/workspace_window_resizer.h" | 19 #include "ash/wm/workspace/workspace_window_resizer.h" |
| 19 #include "ui/aura/client/aura_constants.h" | 20 #include "ui/aura/client/aura_constants.h" |
| 20 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 21 #include "ui/aura/window_delegate.h" | 22 #include "ui/aura/window_delegate.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 aura::Window* new_root = | 58 aura::Window* new_root = |
| 58 display_controller->GetRootWindowForDisplayId(display.id()); | 59 display_controller->GetRootWindowForDisplayId(display.id()); |
| 59 if (new_root != window_state->window()->GetRootWindow()) { | 60 if (new_root != window_state->window()->GetRootWindow()) { |
| 60 aura::Window* new_container = | 61 aura::Window* new_container = |
| 61 Shell::GetContainer(new_root, window_state->window()->parent()->id()); | 62 Shell::GetContainer(new_root, window_state->window()->parent()->id()); |
| 62 new_container->AddChild(window_state->window()); | 63 new_container->AddChild(window_state->window()); |
| 63 } | 64 } |
| 64 } | 65 } |
| 65 } | 66 } |
| 66 | 67 |
| 68 DockedWindowLayoutManager* GetDockedWindowLayoutManager() | |
| 69 { | |
|
oshima
2014/10/02 21:58:41
nit: move { to previous line (see style guide)
dtapuska
2014/10/03 15:44:59
Done.
| |
| 70 aura::Window* active_window = ash::wm::GetActiveWindow(); | |
| 71 if (active_window) { | |
| 72 aura::Window* dock_container = Shell::GetContainer( | |
| 73 active_window->GetRootWindow(), kShellWindowId_DockedContainer); | |
| 74 DockedWindowLayoutManager* dock_layout = | |
| 75 static_cast<DockedWindowLayoutManager*>( | |
| 76 dock_container->layout_manager()); | |
| 77 return dock_layout; | |
| 78 } | |
| 79 return NULL; | |
| 80 } | |
| 81 | |
| 82 class ScopedPreferredAlignmentResetter { | |
| 83 public: | |
| 84 ScopedPreferredAlignmentResetter(DockedAlignment dock_alignment, | |
| 85 DockedWindowLayoutManager* dock_layout) | |
| 86 : docked_window_layout_manager_(dock_layout) { | |
| 87 docked_window_layout_manager_->set_preferred_alignment(dock_alignment); | |
| 88 } | |
| 89 ~ScopedPreferredAlignmentResetter() { | |
| 90 docked_window_layout_manager_->set_preferred_alignment( | |
| 91 DOCKED_ALIGNMENT_NONE); | |
| 92 } | |
| 93 | |
| 94 private: | |
| 95 DISALLOW_COPY_AND_ASSIGN(ScopedPreferredAlignmentResetter); | |
|
oshima
2014/10/02 21:58:41
nit: move DISALLOW... to the last, with one new li
dtapuska
2014/10/03 15:44:59
Done.
| |
| 96 DockedWindowLayoutManager* docked_window_layout_manager_; | |
| 97 }; | |
| 98 | |
| 99 void ToggleSnapDock(WindowState* window_state, WMEventType event) { | |
| 100 DockedWindowLayoutManager* dock_layout = GetDockedWindowLayoutManager(); | |
| 101 wm::WindowStateType desired_snap_state = event == | |
| 102 WM_EVENT_TOGGLE_SNAP_DOCK_LEFT ? wm::WINDOW_STATE_TYPE_LEFT_SNAPPED : | |
| 103 wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED; | |
| 104 DockedAlignment desired_dock_alignment = event == | |
| 105 WM_EVENT_TOGGLE_SNAP_DOCK_LEFT ? | |
| 106 DOCKED_ALIGNMENT_LEFT : DOCKED_ALIGNMENT_RIGHT; | |
| 107 DockedAlignment current_dock_alignment = dock_layout ? | |
| 108 dock_layout->CalculateAlignment() : DOCKED_ALIGNMENT_NONE; | |
| 109 | |
| 110 if (!window_state->IsDocked() || | |
| 111 (current_dock_alignment != DOCKED_ALIGNMENT_NONE && | |
| 112 current_dock_alignment != desired_dock_alignment)) { | |
| 113 if (window_state->CanSnap() && | |
| 114 window_state->GetStateType() != desired_snap_state && | |
| 115 window_state->window()->type() != ui::wm::WINDOW_TYPE_PANEL) { | |
| 116 const wm::WMEvent event(desired_snap_state == | |
| 117 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED ? | |
| 118 wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT); | |
| 119 window_state->OnWMEvent(&event); | |
|
varkha
2014/10/02 22:17:59
May need to RecordUmaAction DOCKED_ACTION_MAXIMIZE
dtapuska
2014/10/03 15:44:59
Done.
| |
| 120 return; | |
| 121 } | |
| 122 | |
| 123 if (dock_layout && | |
| 124 dock_layout->CanDockWindow(window_state->window(), | |
| 125 desired_dock_alignment)) { | |
| 126 | |
| 127 if (window_state->IsDocked()) { | |
| 128 dock_layout->MaybeSetDesiredDockedAlignment(desired_dock_alignment); | |
| 129 return; | |
| 130 } | |
| 131 | |
| 132 ScopedPreferredAlignmentResetter alignmentResetter(desired_dock_alignment, | |
| 133 dock_layout); | |
| 134 const wm::WMEvent event(wm::WM_EVENT_DOCK); | |
|
oshima
2014/10/02 21:58:41
This is ok for now. Alternative way is to pass the
dtapuska
2014/10/03 15:44:59
Acknowledged.
| |
| 135 window_state->OnWMEvent(&event); | |
|
varkha
2014/10/02 22:17:59
Need to RecordUmaAction DOCKED_ACTION_DOCK.
dtapuska
2014/10/03 15:44:59
Applied in the docked_window_layout_manager when a
| |
| 136 return; | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 if (window_state->IsDocked() || window_state->IsSnapped()) { | |
| 141 window_state->Restore(); | |
|
varkha
2014/10/02 22:17:59
May need to RecordUmaAction DOCKED_ACTION_UNDOCK.
dtapuska
2014/10/03 15:44:59
Applied in the docked_window_layout_manager.cc
| |
| 142 return; | |
| 143 } | |
| 144 ::wm::AnimateWindow(window_state->window(), | |
| 145 ::wm::WINDOW_ANIMATION_TYPE_BOUNCE); | |
| 146 } | |
| 147 | |
| 67 } // namespace; | 148 } // namespace; |
| 68 | 149 |
| 69 DefaultState::DefaultState(WindowStateType initial_state_type) | 150 DefaultState::DefaultState(WindowStateType initial_state_type) |
| 70 : state_type_(initial_state_type) {} | 151 : state_type_(initial_state_type) {} |
| 71 DefaultState::~DefaultState() {} | 152 DefaultState::~DefaultState() {} |
| 72 | 153 |
| 73 void DefaultState::OnWMEvent(WindowState* window_state, | 154 void DefaultState::OnWMEvent(WindowState* window_state, |
| 74 const WMEvent* event) { | 155 const WMEvent* event) { |
| 75 if (ProcessWorkspaceEvents(window_state, event)) | 156 if (ProcessWorkspaceEvents(window_state, event)) |
| 76 return; | 157 return; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 SetBounds(window_state, static_cast<const SetBoundsEvent*>(event)); | 191 SetBounds(window_state, static_cast<const SetBoundsEvent*>(event)); |
| 111 return; | 192 return; |
| 112 case WM_EVENT_SHOW_INACTIVE: | 193 case WM_EVENT_SHOW_INACTIVE: |
| 113 next_state_type = WINDOW_STATE_TYPE_INACTIVE; | 194 next_state_type = WINDOW_STATE_TYPE_INACTIVE; |
| 114 break; | 195 break; |
| 115 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: | 196 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: |
| 116 case WM_EVENT_TOGGLE_MAXIMIZE: | 197 case WM_EVENT_TOGGLE_MAXIMIZE: |
| 117 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: | 198 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: |
| 118 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: | 199 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: |
| 119 case WM_EVENT_TOGGLE_FULLSCREEN: | 200 case WM_EVENT_TOGGLE_FULLSCREEN: |
| 201 case WM_EVENT_TOGGLE_SNAP_DOCK_LEFT: | |
| 202 case WM_EVENT_TOGGLE_SNAP_DOCK_RIGHT: | |
| 120 case WM_EVENT_CENTER: | 203 case WM_EVENT_CENTER: |
| 121 NOTREACHED() << "Compound event should not reach here:" << event; | 204 NOTREACHED() << "Compound event should not reach here:" << event; |
| 122 return; | 205 return; |
| 123 case WM_EVENT_ADDED_TO_WORKSPACE: | 206 case WM_EVENT_ADDED_TO_WORKSPACE: |
| 124 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: | 207 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: |
| 125 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: | 208 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: |
| 126 NOTREACHED() << "Workspace event should not reach here:" << event; | 209 NOTREACHED() << "Workspace event should not reach here:" << event; |
| 127 return; | 210 return; |
| 128 } | 211 } |
| 129 | 212 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 } | 344 } |
| 262 | 345 |
| 263 window_state->SetRestoreBoundsInParent(restore_bounds); | 346 window_state->SetRestoreBoundsInParent(restore_bounds); |
| 264 window->SetBounds(new_bounds); | 347 window->SetBounds(new_bounds); |
| 265 } | 348 } |
| 266 return true; | 349 return true; |
| 267 } | 350 } |
| 268 case WM_EVENT_TOGGLE_FULLSCREEN: | 351 case WM_EVENT_TOGGLE_FULLSCREEN: |
| 269 ToggleFullScreen(window_state, window_state->delegate()); | 352 ToggleFullScreen(window_state, window_state->delegate()); |
| 270 return true; | 353 return true; |
| 354 case WM_EVENT_TOGGLE_SNAP_DOCK_LEFT: | |
| 355 case WM_EVENT_TOGGLE_SNAP_DOCK_RIGHT: | |
| 356 ToggleSnapDock(window_state, event->type()); | |
| 357 return true; | |
| 271 case WM_EVENT_CENTER: | 358 case WM_EVENT_CENTER: |
| 272 CenterWindow(window_state); | 359 CenterWindow(window_state); |
| 273 return true; | 360 return true; |
| 274 case WM_EVENT_NORMAL: | 361 case WM_EVENT_NORMAL: |
| 275 case WM_EVENT_MAXIMIZE: | 362 case WM_EVENT_MAXIMIZE: |
| 276 case WM_EVENT_MINIMIZE: | 363 case WM_EVENT_MINIMIZE: |
| 277 case WM_EVENT_FULLSCREEN: | 364 case WM_EVENT_FULLSCREEN: |
| 278 case WM_EVENT_SNAP_LEFT: | 365 case WM_EVENT_SNAP_LEFT: |
| 279 case WM_EVENT_SNAP_RIGHT: | 366 case WM_EVENT_SNAP_RIGHT: |
| 280 case WM_EVENT_SET_BOUNDS: | 367 case WM_EVENT_SET_BOUNDS: |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 window_state->AdjustSnappedBounds(&bounds); | 450 window_state->AdjustSnappedBounds(&bounds); |
| 364 if (window_state->window()->bounds() != bounds) | 451 if (window_state->window()->bounds() != bounds) |
| 365 window_state->SetBoundsDirectAnimated(bounds); | 452 window_state->SetBoundsDirectAnimated(bounds); |
| 366 return true; | 453 return true; |
| 367 } | 454 } |
| 368 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: | 455 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: |
| 369 case WM_EVENT_TOGGLE_MAXIMIZE: | 456 case WM_EVENT_TOGGLE_MAXIMIZE: |
| 370 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: | 457 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: |
| 371 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: | 458 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: |
| 372 case WM_EVENT_TOGGLE_FULLSCREEN: | 459 case WM_EVENT_TOGGLE_FULLSCREEN: |
| 460 case WM_EVENT_TOGGLE_SNAP_DOCK_LEFT: | |
| 461 case WM_EVENT_TOGGLE_SNAP_DOCK_RIGHT: | |
| 373 case WM_EVENT_CENTER: | 462 case WM_EVENT_CENTER: |
| 374 case WM_EVENT_NORMAL: | 463 case WM_EVENT_NORMAL: |
| 375 case WM_EVENT_MAXIMIZE: | 464 case WM_EVENT_MAXIMIZE: |
| 376 case WM_EVENT_MINIMIZE: | 465 case WM_EVENT_MINIMIZE: |
| 377 case WM_EVENT_FULLSCREEN: | 466 case WM_EVENT_FULLSCREEN: |
| 378 case WM_EVENT_SNAP_LEFT: | 467 case WM_EVENT_SNAP_LEFT: |
| 379 case WM_EVENT_SNAP_RIGHT: | 468 case WM_EVENT_SNAP_RIGHT: |
| 380 case WM_EVENT_SET_BOUNDS: | 469 case WM_EVENT_SET_BOUNDS: |
| 381 case WM_EVENT_SHOW_INACTIVE: | 470 case WM_EVENT_SHOW_INACTIVE: |
| 382 case WM_EVENT_DOCK: | 471 case WM_EVENT_DOCK: |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window); | 712 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window); |
| 624 center_in_parent.ClampToCenteredSize(window->bounds().size()); | 713 center_in_parent.ClampToCenteredSize(window->bounds().size()); |
| 625 window_state->SetBoundsDirectAnimated(center_in_parent); | 714 window_state->SetBoundsDirectAnimated(center_in_parent); |
| 626 } | 715 } |
| 627 // Centering window is treated as if a user moved and resized the window. | 716 // Centering window is treated as if a user moved and resized the window. |
| 628 window_state->set_bounds_changed_by_user(true); | 717 window_state->set_bounds_changed_by_user(true); |
| 629 } | 718 } |
| 630 | 719 |
| 631 } // namespace wm | 720 } // namespace wm |
| 632 } // namespace ash | 721 } // namespace ash |
| OLD | NEW |