Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: ash/common/accelerators/debug_commands.cc

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "ash/common/accelerators/debug_commands.h"
6
7 #include "ash/common/accelerators/accelerator_commands.h"
8 #include "ash/common/ash_switches.h"
9 #include "ash/common/shell_delegate.h"
10 #include "ash/common/system/toast/toast_data.h"
11 #include "ash/common/system/toast/toast_manager.h"
12 #include "ash/common/wallpaper/wallpaper_controller.h"
13 #include "ash/common/wallpaper/wallpaper_delegate.h"
14 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
15 #include "ash/common/wm_shell.h"
16 #include "ash/common/wm_window.h"
17 #include "ash/root_window_controller.h"
18 #include "ash/wm/window_properties.h"
19 #include "base/command_line.h"
20 #include "base/metrics/user_metrics.h"
21 #include "base/metrics/user_metrics_action.h"
22 #include "base/strings/utf_string_conversions.h"
23 #include "ui/compositor/debug_utils.h"
24 #include "ui/compositor/layer.h"
25 #include "ui/gfx/canvas.h"
26 #include "ui/gfx/image/image_skia.h"
27 #include "ui/views/debug_utils.h"
28 #include "ui/views/widget/widget.h"
29
30 namespace ash {
31 namespace debug {
32 namespace {
33
34 void HandlePrintLayerHierarchy() {
35 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) {
36 ui::Layer* layer = root->GetLayer();
37 if (layer)
38 ui::PrintLayerHierarchy(
39 layer, root->GetRootWindowController()->GetLastMouseLocationInRoot());
40 }
41 }
42
43 void HandlePrintViewHierarchy() {
44 WmWindow* active_window = WmShell::Get()->GetActiveWindow();
45 if (!active_window)
46 return;
47 views::Widget* widget = active_window->GetInternalWidget();
48 if (!widget)
49 return;
50 views::PrintViewHierarchy(widget->GetRootView());
51 }
52
53 void PrintWindowHierarchy(const WmWindow* active_window,
54 WmWindow* window,
55 int indent,
56 std::ostringstream* out) {
57 std::string indent_str(indent, ' ');
58 std::string name(window->GetName());
59 if (name.empty())
60 name = "\"\"";
61 *out << indent_str << name << " (" << window << ")"
62 << " type=" << window->GetType()
63 << ((window == active_window) ? " [active] " : " ")
64 << (window->IsVisible() ? " visible " : " ")
65 << window->GetBounds().ToString()
66 << (window->aura_window()->GetProperty(kSnapChildrenToPixelBoundary)
67 ? " [snapped] "
68 : "")
69 << ", subpixel offset="
70 << window->GetLayer()->subpixel_position_offset().ToString() << '\n';
71
72 for (WmWindow* child : window->GetChildren())
73 PrintWindowHierarchy(active_window, child, indent + 3, out);
74 }
75
76 void HandlePrintWindowHierarchy() {
77 WmWindow* active_window = WmShell::Get()->GetActiveWindow();
78 WmWindow::Windows roots = WmShell::Get()->GetAllRootWindows();
79 for (size_t i = 0; i < roots.size(); ++i) {
80 std::ostringstream out;
81 out << "RootWindow " << i << ":\n";
82 PrintWindowHierarchy(active_window, roots[i], 0, &out);
83 // Error so logs can be collected from end-users.
84 LOG(ERROR) << out.str();
85 }
86 }
87
88 gfx::ImageSkia CreateWallpaperImage(SkColor fill, SkColor rect) {
89 // TODO(oshima): Consider adding a command line option to control wallpaper
90 // images for testing. The size is randomly picked.
91 gfx::Size image_size(1366, 768);
92 gfx::Canvas canvas(image_size, 1.0f, true);
93 canvas.DrawColor(fill);
94 cc::PaintFlags flags;
95 flags.setColor(rect);
96 flags.setStrokeWidth(10);
97 flags.setStyle(cc::PaintFlags::kStroke_Style);
98 flags.setBlendMode(SkBlendMode::kSrcOver);
99 canvas.DrawRoundRect(gfx::Rect(image_size), 100, flags);
100 return gfx::ImageSkia(canvas.ExtractImageRep());
101 }
102
103 void HandleToggleWallpaperMode() {
104 static int index = 0;
105 WallpaperController* wallpaper_controller =
106 WmShell::Get()->wallpaper_controller();
107 switch (++index % 4) {
108 case 0:
109 ash::WmShell::Get()->wallpaper_delegate()->InitializeWallpaper();
110 break;
111 case 1:
112 wallpaper_controller->SetWallpaperImage(
113 CreateWallpaperImage(SK_ColorRED, SK_ColorBLUE),
114 wallpaper::WALLPAPER_LAYOUT_STRETCH);
115 break;
116 case 2:
117 wallpaper_controller->SetWallpaperImage(
118 CreateWallpaperImage(SK_ColorBLUE, SK_ColorGREEN),
119 wallpaper::WALLPAPER_LAYOUT_CENTER);
120 break;
121 case 3:
122 wallpaper_controller->SetWallpaperImage(
123 CreateWallpaperImage(SK_ColorGREEN, SK_ColorRED),
124 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED);
125 break;
126 }
127 }
128
129 void HandleToggleTouchpad() {
130 base::RecordAction(base::UserMetricsAction("Accel_Toggle_Touchpad"));
131 ash::WmShell::Get()->delegate()->ToggleTouchpad();
132 }
133
134 void HandleToggleTouchscreen() {
135 base::RecordAction(base::UserMetricsAction("Accel_Toggle_Touchscreen"));
136 ShellDelegate* delegate = WmShell::Get()->delegate();
137 delegate->SetTouchscreenEnabledInPrefs(
138 !delegate->IsTouchscreenEnabledInPrefs(false /* use_local_state */),
139 false /* use_local_state */);
140 delegate->UpdateTouchscreenStatusFromPrefs();
141 }
142
143 void HandleToggleTouchView() {
144 MaximizeModeController* controller =
145 WmShell::Get()->maximize_mode_controller();
146 controller->EnableMaximizeModeWindowManager(
147 !controller->IsMaximizeModeWindowManagerEnabled());
148 }
149
150 void HandleTriggerCrash() {
151 CHECK(false) << "Intentional crash via debug accelerator.";
152 }
153
154 } // namespace
155
156 void PrintUIHierarchies() {
157 // This is a separate command so the user only has to hit one key to generate
158 // all the logs. Developers use the individual dumps repeatedly, so keep
159 // those as separate commands to avoid spamming their logs.
160 HandlePrintLayerHierarchy();
161 HandlePrintWindowHierarchy();
162 HandlePrintViewHierarchy();
163 }
164
165 bool DebugAcceleratorsEnabled() {
166 return base::CommandLine::ForCurrentProcess()->HasSwitch(
167 switches::kAshDebugShortcuts);
168 }
169
170 bool DeveloperAcceleratorsEnabled() {
171 return base::CommandLine::ForCurrentProcess()->HasSwitch(
172 switches::kAshDeveloperShortcuts);
173 }
174
175 void PerformDebugActionIfEnabled(AcceleratorAction action) {
176 if (!DebugAcceleratorsEnabled())
177 return;
178
179 switch (action) {
180 case DEBUG_PRINT_LAYER_HIERARCHY:
181 HandlePrintLayerHierarchy();
182 break;
183 case DEBUG_PRINT_VIEW_HIERARCHY:
184 HandlePrintViewHierarchy();
185 break;
186 case DEBUG_PRINT_WINDOW_HIERARCHY:
187 HandlePrintWindowHierarchy();
188 break;
189 case DEBUG_SHOW_TOAST:
190 WmShell::Get()->toast_manager()->Show(
191 ToastData("id", base::ASCIIToUTF16("Toast"), 5000 /* duration_ms */,
192 base::ASCIIToUTF16("Dismiss")));
193 break;
194 case DEBUG_TOGGLE_TOUCH_PAD:
195 HandleToggleTouchpad();
196 break;
197 case DEBUG_TOGGLE_TOUCH_SCREEN:
198 HandleToggleTouchscreen();
199 break;
200 case DEBUG_TOGGLE_TOUCH_VIEW:
201 HandleToggleTouchView();
202 break;
203 case DEBUG_TOGGLE_WALLPAPER_MODE:
204 HandleToggleWallpaperMode();
205 break;
206 case DEBUG_TRIGGER_CRASH:
207 HandleTriggerCrash();
208 break;
209 default:
210 break;
211 }
212 }
213
214 } // namespace debug
215 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/accelerators/debug_commands.h ('k') | ash/common/accelerators/exit_warning_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698