OLD | NEW |
| (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/accelerators/debug_commands.h" | |
6 | |
7 #include "ash/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/wm/maximize_mode/maximize_mode_controller.h" | |
13 #include "ash/common/wm_root_window_controller.h" | |
14 #include "ash/common/wm_shell.h" | |
15 #include "ash/common/wm_window.h" | |
16 #include "base/command_line.h" | |
17 #include "base/metrics/user_metrics.h" | |
18 #include "base/metrics/user_metrics_action.h" | |
19 #include "ui/compositor/debug_utils.h" | |
20 #include "ui/views/debug_utils.h" | |
21 #include "ui/views/widget/widget.h" | |
22 | |
23 namespace ash { | |
24 namespace debug { | |
25 namespace { | |
26 | |
27 void HandlePrintLayerHierarchy() { | |
28 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) { | |
29 ui::Layer* layer = root->GetLayer(); | |
30 if (layer) | |
31 ui::PrintLayerHierarchy( | |
32 layer, root->GetRootWindowController()->GetLastMouseLocationInRoot()); | |
33 } | |
34 } | |
35 | |
36 void HandlePrintViewHierarchy() { | |
37 WmWindow* active_window = WmShell::Get()->GetActiveWindow(); | |
38 if (!active_window) | |
39 return; | |
40 views::Widget* widget = active_window->GetInternalWidget(); | |
41 if (!widget) | |
42 return; | |
43 views::PrintViewHierarchy(widget->GetRootView()); | |
44 } | |
45 | |
46 void PrintWindowHierarchy(const WmWindow* active_window, | |
47 WmWindow* window, | |
48 int indent, | |
49 std::ostringstream* out) { | |
50 std::string indent_str(indent, ' '); | |
51 std::string name(window->GetName()); | |
52 if (name.empty()) | |
53 name = "\"\""; | |
54 *out << indent_str << name << " (" << window << ")" | |
55 << " type=" << window->GetType() | |
56 << ((window == active_window) ? " [active] " : " ") | |
57 << (window->IsVisible() ? " visible " : " ") | |
58 << window->GetBounds().ToString() << '\n'; | |
59 | |
60 for (WmWindow* child : window->GetChildren()) | |
61 PrintWindowHierarchy(active_window, child, indent + 3, out); | |
62 } | |
63 | |
64 void HandlePrintWindowHierarchy() { | |
65 WmWindow* active_window = WmShell::Get()->GetActiveWindow(); | |
66 WmWindow::Windows roots = WmShell::Get()->GetAllRootWindows(); | |
67 for (size_t i = 0; i < roots.size(); ++i) { | |
68 std::ostringstream out; | |
69 out << "RootWindow " << i << ":\n"; | |
70 PrintWindowHierarchy(active_window, roots[i], 0, &out); | |
71 // Error so logs can be collected from end-users. | |
72 LOG(ERROR) << out.str(); | |
73 } | |
74 } | |
75 | |
76 #if defined(OS_CHROMEOS) | |
77 | |
78 void HandleToggleTouchpad() { | |
79 base::RecordAction(base::UserMetricsAction("Accel_Toggle_Touchpad")); | |
80 ash::WmShell::Get()->delegate()->ToggleTouchpad(); | |
81 } | |
82 | |
83 void HandleToggleTouchscreen() { | |
84 base::RecordAction(base::UserMetricsAction("Accel_Toggle_Touchscreen")); | |
85 ash::WmShell::Get()->delegate()->ToggleTouchscreen(); | |
86 } | |
87 | |
88 void HandleToggleToggleTouchView() { | |
89 MaximizeModeController* controller = | |
90 WmShell::Get()->maximize_mode_controller(); | |
91 controller->EnableMaximizeModeWindowManager( | |
92 !controller->IsMaximizeModeWindowManagerEnabled()); | |
93 } | |
94 | |
95 #endif // defined(OS_CHROMEOS) | |
96 | |
97 } // namespace | |
98 | |
99 void PrintUIHierarchies() { | |
100 // This is a separate command so the user only has to hit one key to generate | |
101 // all the logs. Developers use the individual dumps repeatedly, so keep | |
102 // those as separate commands to avoid spamming their logs. | |
103 HandlePrintLayerHierarchy(); | |
104 HandlePrintWindowHierarchy(); | |
105 HandlePrintViewHierarchy(); | |
106 } | |
107 | |
108 bool DebugAcceleratorsEnabled() { | |
109 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
110 switches::kAshDebugShortcuts); | |
111 } | |
112 | |
113 void PerformDebugActionIfEnabled(AcceleratorAction action) { | |
114 if (!DebugAcceleratorsEnabled()) | |
115 return; | |
116 | |
117 switch (action) { | |
118 #if defined(OS_CHROMEOS) | |
119 case DEBUG_SHOW_TOAST: | |
120 WmShell::Get()->toast_manager()->Show( | |
121 ToastData("id", "Toast", 5000 /* duration_ms */, "Dismiss")); | |
122 break; | |
123 case DEBUG_TOGGLE_TOUCH_PAD: | |
124 HandleToggleTouchpad(); | |
125 break; | |
126 case DEBUG_TOGGLE_TOUCH_SCREEN: | |
127 HandleToggleTouchscreen(); | |
128 break; | |
129 case DEBUG_TOGGLE_TOUCH_VIEW: | |
130 HandleToggleToggleTouchView(); | |
131 break; | |
132 #endif | |
133 case DEBUG_PRINT_LAYER_HIERARCHY: | |
134 HandlePrintLayerHierarchy(); | |
135 break; | |
136 case DEBUG_PRINT_VIEW_HIERARCHY: | |
137 HandlePrintViewHierarchy(); | |
138 break; | |
139 case DEBUG_PRINT_WINDOW_HIERARCHY: | |
140 HandlePrintWindowHierarchy(); | |
141 break; | |
142 default: | |
143 break; | |
144 } | |
145 } | |
146 | |
147 } // namespace debug | |
148 } // namespace ash | |
OLD | NEW |