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" | |
13 #include "ash/display/display_util.h" | |
14 #include "ash/shell.h" | |
15 #include "ash/wm/screen_pinning_controller.h" | |
16 #include "ash/wm/window_state_aura.h" | |
17 #include "ash/wm/window_util.h" | |
18 #include "base/metrics/user_metrics.h" | 12 #include "base/metrics/user_metrics.h" |
19 | 13 |
20 namespace ash { | 14 namespace ash { |
21 namespace accelerators { | 15 namespace accelerators { |
22 | 16 |
23 bool ToggleMinimized() { | 17 bool ToggleMinimized() { |
24 aura::Window* window = wm::GetActiveWindow(); | 18 WmWindow* window = WmShell::Get()->GetActiveWindow(); |
25 // Attempt to restore the window that would be cycled through next from | 19 // Attempt to restore the window that would be cycled through next from |
26 // the launcher when there is no active window. | 20 // the launcher when there is no active window. |
27 if (!window) { | 21 if (!window) { |
28 MruWindowTracker::WindowList mru_windows( | 22 MruWindowTracker::WindowList mru_windows( |
29 WmShell::Get()->mru_window_tracker()->BuildMruWindowList()); | 23 WmShell::Get()->mru_window_tracker()->BuildMruWindowList()); |
30 if (!mru_windows.empty()) | 24 if (!mru_windows.empty()) |
31 mru_windows.front()->GetWindowState()->Activate(); | 25 mru_windows.front()->GetWindowState()->Activate(); |
32 return true; | 26 return true; |
33 } | 27 } |
34 wm::WindowState* window_state = wm::GetWindowState(window); | 28 wm::WindowState* window_state = window->GetWindowState(); |
35 if (!window_state->CanMinimize()) | 29 if (!window_state->CanMinimize()) |
36 return false; | 30 return false; |
37 window_state->Minimize(); | 31 window_state->Minimize(); |
38 return true; | 32 return true; |
39 } | 33 } |
40 | 34 |
41 void ToggleMaximized() { | 35 void ToggleMaximized() { |
42 wm::WindowState* window_state = wm::GetActiveWindowState(); | 36 WmWindow* active_window = WmShell::Get()->GetActiveWindow(); |
43 if (!window_state) | 37 if (!active_window) |
44 return; | 38 return; |
45 base::RecordAction(base::UserMetricsAction("Accel_Toggle_Maximized")); | 39 base::RecordAction(base::UserMetricsAction("Accel_Toggle_Maximized")); |
46 wm::WMEvent event(wm::WM_EVENT_TOGGLE_MAXIMIZE); | 40 wm::WMEvent event(wm::WM_EVENT_TOGGLE_MAXIMIZE); |
47 window_state->OnWMEvent(&event); | 41 active_window->GetWindowState()->OnWMEvent(&event); |
48 } | 42 } |
49 | 43 |
50 void ToggleFullscreen() { | 44 void ToggleFullscreen() { |
51 wm::WindowState* window_state = wm::GetActiveWindowState(); | 45 WmWindow* active_window = WmShell::Get()->GetActiveWindow(); |
52 if (window_state) { | 46 if (!active_window) |
53 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | 47 return; |
54 window_state->OnWMEvent(&event); | 48 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); |
55 } | 49 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 } | 50 } |
117 | 51 |
118 } // namespace accelerators | 52 } // namespace accelerators |
119 } // namespace ash | 53 } // namespace ash |
OLD | NEW |