File: debug_util.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (103 lines) | stat: -rw-r--r-- 3,859 bytes parent folder | download | duplicates (6)
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
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromeos/ui/wm/debug_util.h"

#include "chromeos/ui/base/window_properties.h"
#include "chromeos/ui/base/window_state_type.h"
#include "ui/accessibility/aura/aura_window_properties.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/client/focus_client.h"
#include "ui/views/debug_utils.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/public/activation_client.h"

namespace chromeos::wm {
namespace {

void PrintWindowHierarchy(const aura::Window* active_window,
                          const aura::Window* focused_window,
                          const aura::Window* capture_window,
                          aura::Window* window,
                          int indent,
                          bool scrub_data,
                          GetChildrenCallback children_callback,
                          std::vector<std::string>* out_window_titles,
                          std::ostringstream* out) {
  *out << std::string(indent, ' ');
  *out << " [window]";
  window->GetDebugInfo(active_window, focused_window, capture_window, out);
  if (base::Contains(window->GetAllPropertyKeys(),
                     chromeos::kWindowStateTypeKey)) {
    *out << " state=" << window->GetProperty(chromeos::kWindowStateTypeKey);
  }

  std::u16string title(window->GetTitle());
  if (!title.empty()) {
    if (!scrub_data) {
      *out << " title=\"" << title << "\"";
    }
    out_window_titles->push_back(base::UTF16ToUTF8(title));
  }

  std::string* tree_id = window->GetProperty(ui::kChildAXTreeID);
  if (tree_id) {
    *out << " ax_tree_id=" << *tree_id;
  }

  *out << std::endl;
  views::Widget* widget = views::Widget::GetWidgetForNativeView(window);
  if (widget) {
    *out << std::string(indent + 3, ' ');
    *out << " [widget]";
    views::PrintWidgetInformation(*widget, /*detailed*/ false, out);
  }

  std::vector<raw_ptr<aura::Window, VectorExperimental>> children =
      children_callback.is_null() ? window->children()
                                  : children_callback.Run(window);
  for (aura::Window* child : children) {
    PrintWindowHierarchy(active_window, focused_window, capture_window, child,
                         indent + 3, scrub_data, children_callback,
                         out_window_titles, out);
  }
}

}  // namespace

std::vector<std::string> PrintWindowHierarchy(
    aura::Window::Windows roots,
    bool scrub_data,
    std::ostringstream* out,
    GetChildrenCallback children_callback) {
  // TODO(crbug.com/41496823): Make ActiveClient and FocusClient return the same
  // window across all instances of the clients on Lacros.
  aura::Window* root0 = roots[0];
  aura::Window* active_window =
      ::wm::GetActivationClient(root0)->GetActiveWindow();
  aura::Window* focused_window =
      aura::client::GetFocusClient(root0)->GetFocusedWindow();
  aura::Window* capture_window =
      aura::client::GetCaptureClient(root0)->GetCaptureWindow();

  std::vector<std::string> window_titles;
  for (size_t i = 0; i < roots.size(); ++i) {
    *out << "RootWindow " << i << ":\n";
    aura::Window* root = roots[i];
    // These windows must be the same across root windows.
    DCHECK_EQ(active_window,
              ::wm::GetActivationClient(root)->GetActiveWindow());
    DCHECK_EQ(focused_window,
              aura::client::GetFocusClient(root)->GetFocusedWindow());
    DCHECK_EQ(capture_window,
              aura::client::GetCaptureClient(root)->GetCaptureWindow());

    PrintWindowHierarchy(active_window, focused_window, capture_window, root, 0,
                         scrub_data, children_callback, &window_titles, out);
  }
  return window_titles;
}

}  // namespace chromeos::wm