[M108 Migration][Callback] Bring up ewk callbacks which are related with page loading
[platform/framework/web/chromium-efl.git] / ash / debug.cc
1 // Copyright 2013 The Chromium Authors
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/debug.h"
6
7 #include <memory>
8 #include <string>
9
10 #include "ash/public/cpp/debug_utils.h"
11 #include "ash/public/cpp/window_properties.h"
12 #include "ash/root_window_controller.h"
13 #include "ash/shell.h"
14 #include "ash/wm/window_properties.h"
15 #include "ash/wm/window_state.h"
16 #include "ash/wm/window_util.h"
17 #include "cc/debug/layer_tree_debug_state.h"
18 #include "ui/accessibility/aura/aura_window_properties.h"
19 #include "ui/aura/client/aura_constants.h"
20 #include "ui/aura/window_tree_host.h"
21 #include "ui/compositor/compositor.h"
22 #include "ui/compositor/debug_utils.h"
23 #include "ui/compositor/layer.h"
24 #include "ui/views/debug_utils.h"
25 #include "ui/views/widget/widget.h"
26
27 namespace ash {
28 namespace debug {
29
30 void PrintLayerHierarchy(std::ostringstream* out) {
31   for (aura::Window* root : Shell::Get()->GetAllRootWindows()) {
32     ui::Layer* layer = root->layer();
33     if (layer) {
34       ui::PrintLayerHierarchy(
35           layer,
36           RootWindowController::ForWindow(root)->GetLastMouseLocationInRoot(),
37           out);
38     }
39   }
40 }
41
42 void PrintViewHierarchy(std::ostringstream* out) {
43   aura::Window* active_window = window_util::GetActiveWindow();
44   if (!active_window)
45     return;
46   views::Widget* widget = views::Widget::GetWidgetForNativeView(active_window);
47   if (!widget)
48     return;
49
50   *out << "Host widget:\n";
51   views::PrintWidgetInformation(*widget, /*detailed*/ true, out);
52   views::PrintViewHierarchy(widget->GetRootView(), out);
53 }
54
55 void PrintWindowHierarchy(const aura::Window* active_window,
56                           const aura::Window* focused_window,
57                           const aura::Window* capture_window,
58                           aura::Window* window,
59                           int indent,
60                           bool scrub_data,
61                           std::vector<std::string>* out_window_titles,
62                           std::ostringstream* out) {
63   std::string indent_str(indent, ' ');
64   std::string name(window->GetName());
65   if (name.empty())
66     name = "\"\"";
67   const gfx::Vector2dF& subpixel_position_offset =
68       window->layer()->GetSubpixelOffset();
69   *out << indent_str;
70   *out << " [window]";
71   *out << " " << name << " (" << window << ")"
72        << " type=" << window->GetType();
73   int window_id = window->GetId();
74   if (window_id != aura::Window::kInitialId)
75     *out << " id=" << window_id;
76   if (window->GetProperty(kWindowStateKey))
77     *out << " " << WindowState::Get(window)->GetStateType();
78   *out << ((window == active_window) ? " [active]" : "")
79        << ((window == focused_window) ? " [focused]" : "")
80        << ((window == capture_window) ? " [capture]" : "")
81        << (window->GetTransparent() ? " [transparent]" : "")
82        << (window->IsVisible() ? " [visible]" : "") << " "
83        << (window->GetOcclusionState() != aura::Window::OcclusionState::UNKNOWN
84                ? base::UTF16ToUTF8(aura::Window::OcclusionStateToString(
85                                        window->GetOcclusionState()))
86                      .c_str()
87                : "")
88        << " " << window->bounds().ToString();
89   if (!subpixel_position_offset.IsZero())
90     *out << " subpixel offset=" + subpixel_position_offset.ToString();
91   std::string* tree_id = window->GetProperty(ui::kChildAXTreeID);
92   if (tree_id)
93     *out << " ax_tree_id=" << *tree_id;
94
95   std::u16string title(window->GetTitle());
96   if (!title.empty()) {
97     out_window_titles->push_back(base::UTF16ToUTF8(title));
98     if (!scrub_data) {
99       *out << " title=" << title;
100     }
101   }
102
103   int app_type = window->GetProperty(aura::client::kAppType);
104   *out << " app_type=" << app_type;
105   std::string* pkg_name = window->GetProperty(ash::kArcPackageNameKey);
106   if (pkg_name)
107     *out << " pkg_name=" << *pkg_name;
108   *out << '\n';
109
110   views::Widget* widget = views::Widget::GetWidgetForNativeView(window);
111   if (widget) {
112     *out << std::string(indent + 3, ' ');
113     *out << " [widget]";
114     views::PrintWidgetInformation(*widget, /*detailed*/ false, out);
115   }
116
117   for (aura::Window* child : window->children()) {
118     PrintWindowHierarchy(active_window, focused_window, capture_window, child,
119                          indent + 3, scrub_data, out_window_titles, out);
120   }
121 }
122
123 std::vector<std::string> PrintWindowHierarchy(std::ostringstream* out,
124                                               bool scrub_data) {
125   aura::Window* active_window = window_util::GetActiveWindow();
126   aura::Window* focused_window = window_util::GetFocusedWindow();
127   aura::Window* capture_window = window_util::GetCaptureWindow();
128   aura::Window::Windows roots = Shell::Get()->GetAllRootWindows();
129   std::vector<std::string> window_titles;
130   for (size_t i = 0; i < roots.size(); ++i) {
131     *out << "RootWindow " << i << ":\n";
132     PrintWindowHierarchy(active_window, focused_window, capture_window,
133                          roots[i], 0, scrub_data, &window_titles, out);
134   }
135   return window_titles;
136 }
137
138 void ToggleShowDebugBorders() {
139   aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
140   std::unique_ptr<cc::DebugBorderTypes> value;
141   for (auto* window : root_windows) {
142     ui::Compositor* compositor = window->GetHost()->compositor();
143     cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState();
144     if (!value.get())
145       value = std::make_unique<cc::DebugBorderTypes>(
146           state.show_debug_borders.flip());
147     state.show_debug_borders = *value.get();
148     compositor->SetLayerTreeDebugState(state);
149   }
150 }
151
152 void ToggleShowFpsCounter() {
153   aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
154   std::unique_ptr<bool> value;
155   for (auto* window : root_windows) {
156     ui::Compositor* compositor = window->GetHost()->compositor();
157     cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState();
158     if (!value.get())
159       value = std::make_unique<bool>(!state.show_fps_counter);
160     state.show_fps_counter = *value.get();
161     compositor->SetLayerTreeDebugState(state);
162   }
163 }
164
165 void ToggleShowPaintRects() {
166   aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
167   std::unique_ptr<bool> value;
168   for (auto* window : root_windows) {
169     ui::Compositor* compositor = window->GetHost()->compositor();
170     cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState();
171     if (!value.get())
172       value = std::make_unique<bool>(!state.show_paint_rects);
173     state.show_paint_rects = *value.get();
174     compositor->SetLayerTreeDebugState(state);
175   }
176 }
177
178 }  // namespace debug
179 }  // namespace ash