forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccelerator_commands.cc
110 lines (95 loc) · 3.74 KB
/
accelerator_commands.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/accelerators/accelerator_commands.h"
#include "ash/display/display_manager.h"
#include "ash/display/display_util.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/wm/common/window_state.h"
#include "ash/wm/common/wm_event.h"
#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/window_state_aura.h"
#include "ash/wm/window_util.h"
#include "base/metrics/user_metrics.h"
namespace ash {
namespace accelerators {
bool ToggleMinimized() {
aura::Window* window = wm::GetActiveWindow();
// Attempt to restore the window that would be cycled through next from
// the launcher when there is no active window.
if (!window) {
MruWindowTracker::WindowList mru_windows(
Shell::GetInstance()->mru_window_tracker()->BuildMruWindowList());
if (!mru_windows.empty())
wm::GetWindowState(mru_windows.front())->Activate();
return true;
}
wm::WindowState* window_state = wm::GetWindowState(window);
if (!window_state->CanMinimize())
return false;
window_state->Minimize();
return true;
}
void ToggleMaximized() {
wm::WindowState* window_state = wm::GetActiveWindowState();
if (!window_state)
return;
base::RecordAction(base::UserMetricsAction("Accel_Toggle_Maximized"));
wm::WMEvent event(wm::WM_EVENT_TOGGLE_MAXIMIZE);
window_state->OnWMEvent(&event);
}
void ToggleFullscreen() {
wm::WindowState* window_state = wm::GetActiveWindowState();
if (window_state) {
const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
window_state->OnWMEvent(&event);
}
}
void ToggleTouchHudProjection() {
base::RecordAction(base::UserMetricsAction("Accel_Touch_Hud_Clear"));
bool enabled = Shell::GetInstance()->is_touch_hud_projection_enabled();
Shell::GetInstance()->SetTouchHudProjectionEnabled(!enabled);
}
bool IsInternalDisplayZoomEnabled() {
DisplayManager* display_manager = Shell::GetInstance()->display_manager();
return display_manager->IsDisplayUIScalingEnabled() ||
display_manager->IsInUnifiedMode();
}
bool ZoomInternalDisplay(bool up) {
if (up)
base::RecordAction(base::UserMetricsAction("Accel_Scale_Ui_Up"));
else
base::RecordAction(base::UserMetricsAction("Accel_Scale_Ui_Down"));
DisplayManager* display_manager = Shell::GetInstance()->display_manager();
int64_t display_id = display_manager->IsInUnifiedMode()
? DisplayManager::kUnifiedDisplayId
: display_manager->GetDisplayIdForUIScaling();
const DisplayInfo& display_info = display_manager->GetDisplayInfo(display_id);
DisplayMode mode;
if (display_manager->IsInUnifiedMode()) {
if (!GetDisplayModeForNextResolution(display_info, up, &mode))
return false;
} else {
if (!GetDisplayModeForNextUIScale(display_info, up, &mode))
return false;
}
return display_manager->SetDisplayMode(display_id, mode);
}
void ResetInternalDisplayZoom() {
base::RecordAction(base::UserMetricsAction("Accel_Scale_Ui_Reset"));
DisplayManager* display_manager = Shell::GetInstance()->display_manager();
if (display_manager->IsInUnifiedMode()) {
const DisplayInfo& display_info =
display_manager->GetDisplayInfo(DisplayManager::kUnifiedDisplayId);
const std::vector<DisplayMode>& modes = display_info.display_modes();
auto iter =
std::find_if(modes.begin(), modes.end(),
[](const DisplayMode& mode) { return mode.native; });
display_manager->SetDisplayMode(DisplayManager::kUnifiedDisplayId, *iter);
} else {
SetDisplayUIScale(display_manager->GetDisplayIdForUIScaling(), 1.0f);
}
}
} // namespace accelerators
} // namespace ash