Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/accelerators/accelerator_commands.h" | 5 #include "ash/accelerators/accelerator_commands.h" |
| 6 | 6 |
| 7 #include "ash/common/wm/mru_window_tracker.h" | 7 #include "ash/common/wm/mru_window_tracker.h" |
| 8 #include "ash/common/wm/window_state.h" | 8 #include "ash/common/wm/window_state.h" |
| 9 #include "ash/common/wm/wm_event.h" | 9 #include "ash/common/wm/wm_event.h" |
| 10 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
| 11 #include "ash/common/wm_window.h" | 11 #include "ash/common/wm_window.h" |
| 12 #include "ash/display/display_manager.h" | 12 #include "ash/display/display_manager.h" |
|
James Cook
2016/07/20 16:08:04
not needed (and most of the ones below)
sky
2016/07/20 16:42:49
Done.
| |
| 13 #include "ash/display/display_util.h" | 13 #include "ash/display/display_util.h" |
| 14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 15 #include "ash/wm/screen_pinning_controller.h" | 15 #include "ash/wm/screen_pinning_controller.h" |
| 16 #include "ash/wm/window_state_aura.h" | 16 #include "ash/wm/window_state_aura.h" |
| 17 #include "ash/wm/window_util.h" | 17 #include "ash/wm/window_util.h" |
| 18 #include "base/metrics/user_metrics.h" | 18 #include "base/metrics/user_metrics.h" |
| 19 | 19 |
| 20 namespace ash { | 20 namespace ash { |
| 21 namespace accelerators { | 21 namespace accelerators { |
| 22 | 22 |
| 23 bool ToggleMinimized() { | 23 bool ToggleMinimized() { |
| 24 aura::Window* window = wm::GetActiveWindow(); | 24 WmWindow* window = WmShell::Get()->GetActiveWindow(); |
| 25 // Attempt to restore the window that would be cycled through next from | 25 // Attempt to restore the window that would be cycled through next from |
| 26 // the launcher when there is no active window. | 26 // the launcher when there is no active window. |
| 27 if (!window) { | 27 if (!window) { |
| 28 MruWindowTracker::WindowList mru_windows( | 28 MruWindowTracker::WindowList mru_windows( |
| 29 WmShell::Get()->mru_window_tracker()->BuildMruWindowList()); | 29 WmShell::Get()->mru_window_tracker()->BuildMruWindowList()); |
| 30 if (!mru_windows.empty()) | 30 if (!mru_windows.empty()) |
| 31 mru_windows.front()->GetWindowState()->Activate(); | 31 mru_windows.front()->GetWindowState()->Activate(); |
| 32 return true; | 32 return true; |
| 33 } | 33 } |
| 34 wm::WindowState* window_state = wm::GetWindowState(window); | 34 wm::WindowState* window_state = window->GetWindowState(); |
| 35 if (!window_state->CanMinimize()) | 35 if (!window_state->CanMinimize()) |
| 36 return false; | 36 return false; |
| 37 window_state->Minimize(); | 37 window_state->Minimize(); |
| 38 return true; | 38 return true; |
| 39 } | 39 } |
| 40 | 40 |
| 41 void ToggleMaximized() { | 41 void ToggleMaximized() { |
| 42 wm::WindowState* window_state = wm::GetActiveWindowState(); | 42 WmWindow* active_window = WmShell::Get()->GetActiveWindow(); |
| 43 if (!window_state) | 43 if (!active_window) |
| 44 return; | 44 return; |
| 45 base::RecordAction(base::UserMetricsAction("Accel_Toggle_Maximized")); | 45 base::RecordAction(base::UserMetricsAction("Accel_Toggle_Maximized")); |
| 46 wm::WMEvent event(wm::WM_EVENT_TOGGLE_MAXIMIZE); | 46 wm::WMEvent event(wm::WM_EVENT_TOGGLE_MAXIMIZE); |
| 47 window_state->OnWMEvent(&event); | 47 active_window->GetWindowState()->OnWMEvent(&event); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void ToggleFullscreen() { | 50 void ToggleFullscreen() { |
| 51 wm::WindowState* window_state = wm::GetActiveWindowState(); | 51 WmWindow* active_window = WmShell::Get()->GetActiveWindow(); |
| 52 if (window_state) { | 52 if (!active_window) |
| 53 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | 53 return; |
| 54 window_state->OnWMEvent(&event); | 54 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); |
| 55 } | 55 active_window->GetWindowState()->OnWMEvent(&event); |
| 56 } | |
| 57 | |
| 58 void ToggleTouchHudProjection() { | |
| 59 base::RecordAction(base::UserMetricsAction("Accel_Touch_Hud_Clear")); | |
| 60 bool enabled = Shell::GetInstance()->is_touch_hud_projection_enabled(); | |
| 61 Shell::GetInstance()->SetTouchHudProjectionEnabled(!enabled); | |
| 62 } | |
| 63 | |
| 64 bool IsInternalDisplayZoomEnabled() { | |
| 65 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 66 return display_manager->IsDisplayUIScalingEnabled() || | |
| 67 display_manager->IsInUnifiedMode(); | |
| 68 } | |
| 69 | |
| 70 bool ZoomInternalDisplay(bool up) { | |
| 71 if (up) | |
| 72 base::RecordAction(base::UserMetricsAction("Accel_Scale_Ui_Up")); | |
| 73 else | |
| 74 base::RecordAction(base::UserMetricsAction("Accel_Scale_Ui_Down")); | |
| 75 | |
| 76 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 77 | |
| 78 int64_t display_id = display_manager->IsInUnifiedMode() | |
| 79 ? DisplayManager::kUnifiedDisplayId | |
| 80 : display_manager->GetDisplayIdForUIScaling(); | |
| 81 const DisplayInfo& display_info = display_manager->GetDisplayInfo(display_id); | |
| 82 DisplayMode mode; | |
| 83 | |
| 84 if (display_manager->IsInUnifiedMode()) { | |
| 85 if (!GetDisplayModeForNextResolution(display_info, up, &mode)) | |
| 86 return false; | |
| 87 } else { | |
| 88 if (!GetDisplayModeForNextUIScale(display_info, up, &mode)) | |
| 89 return false; | |
| 90 } | |
| 91 return display_manager->SetDisplayMode(display_id, mode); | |
| 92 } | |
| 93 | |
| 94 void ResetInternalDisplayZoom() { | |
| 95 base::RecordAction(base::UserMetricsAction("Accel_Scale_Ui_Reset")); | |
| 96 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 97 | |
| 98 if (display_manager->IsInUnifiedMode()) { | |
| 99 const DisplayInfo& display_info = | |
| 100 display_manager->GetDisplayInfo(DisplayManager::kUnifiedDisplayId); | |
| 101 const std::vector<DisplayMode>& modes = display_info.display_modes(); | |
| 102 auto iter = | |
| 103 std::find_if(modes.begin(), modes.end(), | |
| 104 [](const DisplayMode& mode) { return mode.native; }); | |
| 105 display_manager->SetDisplayMode(DisplayManager::kUnifiedDisplayId, *iter); | |
| 106 } else { | |
| 107 SetDisplayUIScale(display_manager->GetDisplayIdForUIScaling(), 1.0f); | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 void Unpin() { | |
| 112 WmWindow* pinned_window = | |
| 113 Shell::GetInstance()->screen_pinning_controller()->pinned_window(); | |
| 114 if (pinned_window) | |
| 115 pinned_window->GetWindowState()->Restore(); | |
| 116 } | 56 } |
| 117 | 57 |
| 118 } // namespace accelerators | 58 } // namespace accelerators |
| 119 } // namespace ash | 59 } // namespace ash |
| OLD | NEW |