Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / ash / accelerators / accelerator_commands.cc
blob83e5d26da67e54cc64b71153a6a45342691c6b42
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
3 // found in the LICENSE file.
5 #include "ash/accelerators/accelerator_commands.h"
7 #include "ash/display/display_manager.h"
8 #include "ash/display/display_util.h"
9 #include "ash/shell.h"
10 #include "ash/shell_delegate.h"
11 #include "ash/wm/mru_window_tracker.h"
12 #include "ash/wm/window_state.h"
13 #include "ash/wm/window_util.h"
14 #include "ash/wm/wm_event.h"
15 #include "base/metrics/user_metrics.h"
17 namespace ash {
18 namespace accelerators {
20 bool ToggleMinimized() {
21 aura::Window* window = wm::GetActiveWindow();
22 // Attempt to restore the window that would be cycled through next from
23 // the launcher when there is no active window.
24 if (!window) {
25 MruWindowTracker::WindowList mru_windows(
26 Shell::GetInstance()->mru_window_tracker()->BuildMruWindowList());
27 if (!mru_windows.empty())
28 wm::GetWindowState(mru_windows.front())->Activate();
29 return true;
31 wm::WindowState* window_state = wm::GetWindowState(window);
32 if (!window_state->CanMinimize())
33 return false;
34 window_state->Minimize();
35 return true;
38 void ToggleMaximized() {
39 wm::WindowState* window_state = wm::GetActiveWindowState();
40 if (!window_state)
41 return;
42 base::RecordAction(base::UserMetricsAction("Accel_Toggle_Maximized"));
43 wm::WMEvent event(wm::WM_EVENT_TOGGLE_MAXIMIZE);
44 window_state->OnWMEvent(&event);
47 void ToggleFullscreen() {
48 wm::WindowState* window_state = wm::GetActiveWindowState();
49 if (window_state) {
50 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
51 window_state->OnWMEvent(&event);
55 void ToggleTouchHudProjection() {
56 base::RecordAction(base::UserMetricsAction("Accel_Touch_Hud_Clear"));
57 bool enabled = Shell::GetInstance()->is_touch_hud_projection_enabled();
58 Shell::GetInstance()->SetTouchHudProjectionEnabled(!enabled);
61 bool IsInternalDisplayZoomEnabled() {
62 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
63 return display_manager->IsDisplayUIScalingEnabled() ||
64 display_manager->IsInUnifiedMode();
67 bool ZoomInternalDisplay(bool up) {
68 if (up)
69 base::RecordAction(base::UserMetricsAction("Accel_Scale_Ui_Up"));
70 else
71 base::RecordAction(base::UserMetricsAction("Accel_Scale_Ui_Down"));
73 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
75 int64 display_id = display_manager->IsInUnifiedMode()
76 ? DisplayManager::kUnifiedDisplayId
77 : display_manager->GetDisplayIdForUIScaling();
78 const DisplayInfo& display_info = display_manager->GetDisplayInfo(display_id);
79 DisplayMode mode;
81 if (display_manager->IsInUnifiedMode()) {
82 if (!GetDisplayModeForNextResolution(display_info, up, &mode))
83 return false;
84 } else {
85 if (!GetDisplayModeForNextUIScale(display_info, up, &mode))
86 return false;
88 return display_manager->SetDisplayMode(display_id, mode);
91 void ResetInternalDisplayZoom() {
92 base::RecordAction(base::UserMetricsAction("Accel_Scale_Ui_Reset"));
93 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
95 if (display_manager->IsInUnifiedMode()) {
96 const DisplayInfo& display_info =
97 display_manager->GetDisplayInfo(DisplayManager::kUnifiedDisplayId);
98 const std::vector<DisplayMode>& modes = display_info.display_modes();
99 auto iter =
100 std::find_if(modes.begin(), modes.end(),
101 [](const DisplayMode& mode) { return mode.native; });
102 display_manager->SetDisplayMode(DisplayManager::kUnifiedDisplayId, *iter);
103 } else {
104 SetDisplayUIScale(display_manager->GetDisplayIdForUIScaling(), 1.0f);
108 } // namespace accelerators
109 } // namespace ash