Add ICU message format support
[chromium-blink-merge.git] / ash / accelerators / debug_commands.cc
blobfe4589d89d9e5ba03d97e7a82ca0c21ffb27ce38
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/debug_commands.h"
7 #include "ash/accelerators/accelerator_commands.h"
8 #include "ash/ash_switches.h"
9 #include "ash/debug.h"
10 #include "ash/desktop_background/desktop_background_controller.h"
11 #include "ash/desktop_background/user_wallpaper_delegate.h"
12 #include "ash/display/display_manager.h"
13 #include "ash/host/ash_window_tree_host.h"
14 #include "ash/root_window_controller.h"
15 #include "ash/shell.h"
16 #include "ash/wm/window_util.h"
17 #include "base/command_line.h"
18 #include "third_party/skia/include/core/SkColor.h"
19 #include "third_party/skia/include/core/SkPaint.h"
20 #include "ui/aura/window.h"
21 #include "ui/aura/window_event_dispatcher.h"
22 #include "ui/compositor/debug_utils.h"
23 #include "ui/compositor/layer.h"
24 #include "ui/gfx/canvas.h"
25 #include "ui/gfx/image/image_skia.h"
26 #include "ui/views/debug_utils.h"
27 #include "ui/views/widget/widget.h"
29 namespace ash {
30 namespace debug {
31 namespace {
33 void HandlePrintLayerHierarchy() {
34 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
35 for (size_t i = 0; i < root_windows.size(); ++i) {
36 ui::PrintLayerHierarchy(
37 root_windows[i]->layer(),
38 root_windows[i]->GetHost()->dispatcher()->GetLastMouseLocationInRoot());
42 void HandlePrintViewHierarchy() {
43 aura::Window* active_window = ash::wm::GetActiveWindow();
44 if (!active_window)
45 return;
46 views::Widget* browser_widget =
47 views::Widget::GetWidgetForNativeWindow(active_window);
48 if (!browser_widget)
49 return;
50 views::PrintViewHierarchy(browser_widget->GetRootView());
53 void PrintWindowHierarchy(aura::Window* window,
54 int indent,
55 std::ostringstream* out) {
56 std::string indent_str(indent, ' ');
57 std::string name(window->name());
58 if (name.empty())
59 name = "\"\"";
60 *out << indent_str << name << " (" << window << ")"
61 << " type=" << window->type()
62 << (wm::IsActiveWindow(window) ? " [active] " : " ")
63 << (window->IsVisible() ? " visible " : " ")
64 << window->bounds().ToString()
65 << '\n';
67 for (size_t i = 0; i < window->children().size(); ++i)
68 PrintWindowHierarchy(window->children()[i], indent + 3, out);
71 void HandlePrintWindowHierarchy() {
72 Shell::RootWindowControllerList controllers =
73 Shell::GetAllRootWindowControllers();
74 for (size_t i = 0; i < controllers.size(); ++i) {
75 std::ostringstream out;
76 out << "RootWindow " << i << ":\n";
77 PrintWindowHierarchy(controllers[i]->GetRootWindow(), 0, &out);
78 // Error so logs can be collected from end-users.
79 LOG(ERROR) << out.str();
83 gfx::ImageSkia CreateWallpaperImage(SkColor fill, SkColor rect) {
84 // TODO(oshima): Consider adding a command line option to control
85 // wallpaper images for testing.
86 // The size is randomly picked.
87 gfx::Size image_size(1366, 768);
88 gfx::Canvas canvas(image_size, 1.0f, true);
89 canvas.DrawColor(fill);
90 SkPaint paint;
91 paint.setColor(rect);
92 paint.setStrokeWidth(10);
93 paint.setStyle(SkPaint::kStroke_Style);
94 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
95 canvas.DrawRoundRect(gfx::Rect(image_size), 100, paint);
96 return gfx::ImageSkia(canvas.ExtractImageRep());
99 void HandleToggleDesktopBackgroundMode() {
100 static int index = 0;
101 DesktopBackgroundController* desktop_background_controller =
102 Shell::GetInstance()->desktop_background_controller();
103 switch (++index % 4) {
104 case 0:
105 ash::Shell::GetInstance()->user_wallpaper_delegate()->
106 InitializeWallpaper();
107 break;
108 case 1:
109 desktop_background_controller->SetWallpaperImage(
110 CreateWallpaperImage(SK_ColorRED, SK_ColorBLUE),
111 wallpaper::WALLPAPER_LAYOUT_STRETCH);
112 break;
113 case 2:
114 desktop_background_controller->SetWallpaperImage(
115 CreateWallpaperImage(SK_ColorBLUE, SK_ColorGREEN),
116 wallpaper::WALLPAPER_LAYOUT_CENTER);
117 break;
118 case 3:
119 desktop_background_controller->SetWallpaperImage(
120 CreateWallpaperImage(SK_ColorGREEN, SK_ColorRED),
121 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED);
122 break;
126 } // namespace
128 void PrintUIHierarchies() {
129 // This is a separate command so the user only has to hit one key to generate
130 // all the logs. Developers use the individual dumps repeatedly, so keep
131 // those as separate commands to avoid spamming their logs.
132 HandlePrintLayerHierarchy();
133 HandlePrintWindowHierarchy();
134 HandlePrintViewHierarchy();
137 bool DebugAcceleratorsEnabled() {
138 return base::CommandLine::ForCurrentProcess()->HasSwitch(
139 switches::kAshDebugShortcuts);
142 void PerformDebugActionIfEnabled(AcceleratorAction action) {
143 if (!DebugAcceleratorsEnabled())
144 return;
146 switch (action) {
147 #if defined(OS_CHROMEOS)
148 case DEBUG_ADD_REMOVE_DISPLAY:
149 Shell::GetInstance()->display_manager()->AddRemoveDisplay();
150 break;
151 case DEBUG_TOGGLE_UNIFIED_DESKTOP:
152 Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled(
153 !Shell::GetInstance()->display_manager()->unified_desktop_enabled());
154 break;
155 #endif
156 case DEBUG_PRINT_LAYER_HIERARCHY:
157 HandlePrintLayerHierarchy();
158 break;
159 case DEBUG_PRINT_VIEW_HIERARCHY:
160 HandlePrintViewHierarchy();
161 break;
162 case DEBUG_PRINT_WINDOW_HIERARCHY:
163 HandlePrintWindowHierarchy();
164 break;
165 case DEBUG_TOGGLE_DESKTOP_BACKGROUND_MODE:
166 HandleToggleDesktopBackgroundMode();
167 break;
168 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR:
169 Shell::GetInstance()->display_manager()->ToggleDisplayScaleFactor();
170 break;
171 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN:
172 Shell::GetPrimaryRootWindowController()->ash_host()->ToggleFullScreen();
173 break;
174 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS:
175 ToggleShowDebugBorders();
176 break;
177 case DEBUG_TOGGLE_SHOW_FPS_COUNTER:
178 ToggleShowFpsCounter();
179 break;
180 case DEBUG_TOGGLE_SHOW_PAINT_RECTS:
181 ToggleShowPaintRects();
182 break;
183 default:
184 break;
188 } // namespace debug
189 } // namespace ash