Chromium Code Reviews| Index: ash/accelerators/accelerator_controller.cc |
| diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc |
| index 0dc7bbceb54024459f4b597211446c52843e6036..4ad844069f897381b4445b79f49407032aa6389a 100644 |
| --- a/ash/accelerators/accelerator_controller.cc |
| +++ b/ash/accelerators/accelerator_controller.cc |
| @@ -44,11 +44,13 @@ |
| #include "ash/system/web_notification/web_notification_tray.h" |
| #include "ash/touch/touch_hud_debug.h" |
| #include "ash/volume_control_delegate.h" |
| +#include "ash/wm/dock/docked_window_layout_manager.h" |
| #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
| #include "ash/wm/mru_window_tracker.h" |
| #include "ash/wm/overview/window_selector_controller.h" |
| #include "ash/wm/partial_screenshot_view.h" |
| #include "ash/wm/power_button_controller.h" |
| +#include "ash/wm/window_animations.h" |
| #include "ash/wm/window_cycle_controller.h" |
| #include "ash/wm/window_state.h" |
| #include "ash/wm/window_util.h" |
| @@ -502,26 +504,130 @@ bool HandleToggleRootWindowFullScreen() { |
| return true; |
| } |
| -bool HandleWindowSnap(int action) { |
| +DockedWindowLayoutManager* GetDockedWindowLayoutManager() |
| +{ |
| + aura::Window* active_window = ash::wm::GetActiveWindow(); |
| + if (active_window) { |
| + aura::Window* dock_container = Shell::GetContainer( |
| + active_window->GetRootWindow(), kShellWindowId_DockedContainer); |
| + DockedWindowLayoutManager* dock_layout = |
| + static_cast<DockedWindowLayoutManager*>( |
| + dock_container->layout_manager()); |
| + return dock_layout; |
| + } |
| + return NULL; |
| +} |
| + |
| +class ScopedPreferredAlignmentResetter { |
| + public: |
| + ScopedPreferredAlignmentResetter(DockedAlignment dock_alignment) |
| + : docked_window_layout_manager_(GetDockedWindowLayoutManager()) { |
| + docked_window_layout_manager_->SetPreferredAlignment(dock_alignment); |
| + } |
| + ~ScopedPreferredAlignmentResetter() { |
| + docked_window_layout_manager_->SetPreferredAlignment(DOCKED_ALIGNMENT_NONE); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(ScopedPreferredAlignmentResetter); |
| + DockedWindowLayoutManager* docked_window_layout_manager_; |
| +}; |
| + |
| +void RestoreWindow() { |
| + wm::WindowState* window_state = wm::GetActiveWindowState(); |
| + if (!window_state) |
| + return; |
| + |
| + base::RecordAction(UserMetricsAction("Accel_Window_Restore")); |
| + const wm::WMEvent event(wm::WM_EVENT_NORMAL); |
| + window_state->OnWMEvent(&event); |
| +} |
| + |
| +void DockWindow(DockedAlignment dock_alignment) { |
| + wm::WindowState* window_state = wm::GetActiveWindowState(); |
| + if (!window_state) |
| + return; |
| + |
| + if (window_state->IsDocked()) { |
| + GetDockedWindowLayoutManager()->SetDockedAlignment(dock_alignment); |
| + return; |
| + } |
| + |
| + ScopedPreferredAlignmentResetter alignmentResetter(dock_alignment); |
| + base::RecordAction(UserMetricsAction(dock_alignment == DOCKED_ALIGNMENT_LEFT ? |
| + "Accel_Window_Dock_Left" : "Accel_Window_Dock_Right")); |
| + const wm::WMEvent event(wm::WM_EVENT_DOCK); |
| + window_state->OnWMEvent(&event); |
| +} |
| + |
| +void SnapWindow(wm::WMEventType event_type) { |
| + wm::WindowState* window_state = wm::GetActiveWindowState(); |
| + if (!window_state) |
| + return; |
| + base::RecordAction(UserMetricsAction(event_type == wm::WM_EVENT_SNAP_LEFT ? |
| + "Accel_Window_Snap_Left" : |
| + "Accel_Window_Snap_Right")); |
| + const wm::WMEvent event(event_type); |
| + window_state->OnWMEvent(&event); |
| +} |
| + |
| +bool CanDock(DockedAlignment desired_alignment) { |
| + aura::Window* active_window = ash::wm::GetActiveWindow(); |
| + DockedWindowLayoutManager* dock_layout = GetDockedWindowLayoutManager(); |
| + if (dock_layout) |
| + return dock_layout->CanDockWindow(active_window, desired_alignment); |
| + return false; |
| +} |
| + |
| +DockedAlignment CurrentDockAlignment() { |
| + DockedWindowLayoutManager* dock_layout = GetDockedWindowLayoutManager(); |
| + if (dock_layout) |
| + return dock_layout->CalculateAlignment(); |
| + return DOCKED_ALIGNMENT_NONE; |
| +} |
| + |
| +bool HandleWindowSnapOrDock(int action) { |
|
varkha
2014/09/29 21:04:34
I am not sure it this should be AcceleratorAction
dtapuska
2014/09/30 14:40:49
It appears they wanted to speed up compilation by
varkha
2014/09/30 20:31:03
Acknowledged.
|
| wm::WindowState* window_state = wm::GetActiveWindowState(); |
| // Disable window snapping shortcut key for full screen window due to |
| // http://crbug.com/135487. |
| if (!window_state || |
| - window_state->window()->type() != ui::wm::WINDOW_TYPE_NORMAL || |
| - window_state->IsFullscreen() || |
| - !window_state->CanSnap()) { |
| + (window_state->window()->type() != ui::wm::WINDOW_TYPE_NORMAL && |
| + window_state->window()->type() != ui::wm::WINDOW_TYPE_PANEL) || |
| + window_state->IsFullscreen()) { |
| return false; |
| } |
| - if (action == WINDOW_SNAP_LEFT) { |
| - base::RecordAction(UserMetricsAction("Accel_Window_Snap_Left")); |
| + wm::WindowStateType desired_snap_state = action == WINDOW_SNAP_OR_DOCK_LEFT ? |
| + wm::WINDOW_STATE_TYPE_LEFT_SNAPPED : wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED; |
| + DockedAlignment desired_dock_alignment = action == WINDOW_SNAP_OR_DOCK_LEFT ? |
| + DOCKED_ALIGNMENT_LEFT : DOCKED_ALIGNMENT_RIGHT; |
|
varkha
2014/09/29 21:04:34
nit: alignment +4
dtapuska
2014/09/30 14:40:49
Done.
|
| + DockedAlignment current_dock_alignment = CurrentDockAlignment(); |
| + |
| + if (!window_state->IsDocked() || |
| + (current_dock_alignment != DOCKED_ALIGNMENT_NONE && |
| + current_dock_alignment != desired_dock_alignment)) { |
| + if (window_state->CanSnap() && |
| + window_state->GetStateType() != desired_snap_state && |
| + window_state->window()->type() != ui::wm::WINDOW_TYPE_PANEL) { |
| + SnapWindow(desired_snap_state == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED ? |
| + wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT); |
| + return true; |
| + } |
| + |
| + if (CanDock(desired_dock_alignment)) { |
| + DockWindow(desired_dock_alignment); |
| + return true; |
| + } |
| + } |
| + |
| + if (window_state->IsDocked() || window_state->IsSnapped()) { |
| + RestoreWindow(); |
| + return true; |
| } else { |
|
varkha
2014/09/29 21:04:34
nit: No need for else after return (mentioned in h
dtapuska
2014/09/30 14:40:48
Done.
|
| - base::RecordAction(UserMetricsAction("Accel_Window_Snap_Right")); |
| + ::wm::AnimateWindow(window_state->window(), |
| + ::wm::WINDOW_ANIMATION_TYPE_BOUNCE); |
| + return false; |
| } |
| - const wm::WMEvent event(action == WINDOW_SNAP_LEFT ? |
| - wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT); |
| - window_state->OnWMEvent(&event); |
| - return true; |
| } |
| bool HandleWindowMinimize() { |
| @@ -1051,9 +1157,9 @@ bool AcceleratorController::PerformAction(int action, |
| return HandleLaunchAppN(7); |
| case LAUNCH_LAST_APP: |
| return HandleLaunchLastApp(); |
| - case WINDOW_SNAP_LEFT: |
| - case WINDOW_SNAP_RIGHT: |
| - return HandleWindowSnap(action); |
| + case WINDOW_SNAP_OR_DOCK_LEFT: |
| + case WINDOW_SNAP_OR_DOCK_RIGHT: |
| + return HandleWindowSnapOrDock(action); |
| case WINDOW_MINIMIZE: |
| return HandleWindowMinimize(); |
| case TOGGLE_FULLSCREEN: |