forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug_commands.cc
193 lines (172 loc) · 5.9 KB
/
debug_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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// 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/debug_commands.h"
#include <string>
#include <utility>
#include "ash/accelerators/accelerator_commands.h"
#include "ash/hud_display/hud_display.h"
#include "ash/public/cpp/ash_switches.h"
#include "ash/public/cpp/debug_utils.h"
#include "ash/public/cpp/toast_data.h"
#include "ash/shell.h"
#include "ash/system/toast/toast_manager_impl.h"
#include "ash/touch/touch_devices_controller.h"
#include "ash/wallpaper/wallpaper_controller_impl.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/command_line.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/accessibility/ax_tree_id.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/display/manager/display_manager.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_rep.h"
#include "ui/views/widget/widget.h"
namespace ash {
namespace debug {
namespace {
gfx::ImageSkia CreateWallpaperImage(SkColor fill, SkColor rect) {
// TODO(oshima): Consider adding a command line option to control wallpaper
// images for testing. The size is randomly picked.
gfx::Size image_size(1366, 768);
SkBitmap bitmap;
bitmap.allocN32Pixels(image_size.width(), image_size.height(), true);
SkCanvas canvas(bitmap);
canvas.drawColor(fill);
SkPaint paint;
paint.setColor(rect);
paint.setStrokeWidth(10);
paint.setStyle(SkPaint::kStroke_Style);
paint.setBlendMode(SkBlendMode::kSrcOver);
canvas.drawRoundRect(gfx::RectToSkRect(gfx::Rect(image_size)), 100.f, 100.f,
paint);
return gfx::ImageSkia::CreateFromBitmap(std::move(bitmap), 1.f);
}
void HandleToggleWallpaperMode() {
static int index = 0;
auto* wallpaper_controller = Shell::Get()->wallpaper_controller();
WallpaperInfo info("", WALLPAPER_LAYOUT_STRETCH, DEFAULT,
base::Time::Now().LocalMidnight());
switch (++index % 4) {
case 0:
wallpaper_controller->ShowDefaultWallpaperForTesting();
break;
case 1:
wallpaper_controller->ShowWallpaperImage(
CreateWallpaperImage(SK_ColorRED, SK_ColorBLUE), info,
/*preview_mode=*/false, /*always_on_top=*/false);
break;
case 2:
info.layout = WALLPAPER_LAYOUT_CENTER;
wallpaper_controller->ShowWallpaperImage(
CreateWallpaperImage(SK_ColorBLUE, SK_ColorGREEN), info,
/*preview_mode=*/false, /*always_on_top=*/false);
break;
case 3:
info.layout = WALLPAPER_LAYOUT_CENTER_CROPPED;
wallpaper_controller->ShowWallpaperImage(
CreateWallpaperImage(SK_ColorGREEN, SK_ColorRED), info,
/*preview_mode=*/false, /*always_on_top=*/false);
break;
}
}
void HandleToggleTouchpad() {
base::RecordAction(base::UserMetricsAction("Accel_Toggle_Touchpad"));
Shell::Get()->touch_devices_controller()->ToggleTouchpad();
}
void HandleToggleTouchscreen() {
base::RecordAction(base::UserMetricsAction("Accel_Toggle_Touchscreen"));
TouchDevicesController* controller = Shell::Get()->touch_devices_controller();
controller->SetTouchscreenEnabled(
!controller->GetTouchscreenEnabled(TouchDeviceEnabledSource::USER_PREF),
TouchDeviceEnabledSource::USER_PREF);
}
void HandleToggleTabletMode() {
TabletModeController* controller = Shell::Get()->tablet_mode_controller();
controller->SetEnabledForDev(!controller->InTabletMode());
}
void HandleTriggerCrash() {
LOG(FATAL) << "Intentional crash via debug accelerator.";
}
void HandleTriggerHUDDisplay() {
hud_display::HUDDisplayView::Toggle();
}
} // namespace
void HandlePrintLayerHierarchy() {
std::ostringstream out;
PrintLayerHierarchy(&out);
LOG(ERROR) << out.str();
}
void HandlePrintViewHierarchy() {
std::ostringstream out;
PrintViewHierarchy(&out);
LOG(ERROR) << out.str();
}
void HandlePrintWindowHierarchy() {
std::ostringstream out;
PrintWindowHierarchy(&out, /*scrub_data=*/false);
LOG(ERROR) << out.str();
}
void PrintUIHierarchies() {
// This is a separate command so the user only has to hit one key to generate
// all the logs. Developers use the individual dumps repeatedly, so keep
// those as separate commands to avoid spamming their logs.
HandlePrintLayerHierarchy();
HandlePrintWindowHierarchy();
HandlePrintViewHierarchy();
}
bool DebugAcceleratorsEnabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAshDebugShortcuts);
}
bool DeveloperAcceleratorsEnabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAshDeveloperShortcuts);
}
void PerformDebugActionIfEnabled(AcceleratorAction action) {
if (!DebugAcceleratorsEnabled())
return;
switch (action) {
case DEBUG_PRINT_LAYER_HIERARCHY:
HandlePrintLayerHierarchy();
break;
case DEBUG_PRINT_VIEW_HIERARCHY:
HandlePrintViewHierarchy();
break;
case DEBUG_PRINT_WINDOW_HIERARCHY:
HandlePrintWindowHierarchy();
break;
case DEBUG_SHOW_TOAST:
Shell::Get()->toast_manager()->Show(
ToastData("id", u"Toast", 5000 /* duration_ms */, u"Dismiss"));
break;
case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR:
Shell::Get()->display_manager()->ToggleDisplayScaleFactor();
break;
case DEBUG_TOGGLE_TOUCH_PAD:
HandleToggleTouchpad();
break;
case DEBUG_TOGGLE_TOUCH_SCREEN:
HandleToggleTouchscreen();
break;
case DEBUG_TOGGLE_TABLET_MODE:
HandleToggleTabletMode();
break;
case DEBUG_TOGGLE_WALLPAPER_MODE:
HandleToggleWallpaperMode();
break;
case DEBUG_TRIGGER_CRASH:
HandleTriggerCrash();
break;
case DEBUG_TOGGLE_HUD_DISPLAY:
HandleTriggerHUDDisplay();
break;
default:
break;
}
}
} // namespace debug
} // namespace ash