• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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 "ui/views/debug_utils.h"
6 
7 #include <ostream>
8 
9 #include "base/logging.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "ui/views/view.h"
12 
13 namespace views {
14 namespace {
PrintViewHierarchyImp(const View * view,int indent,std::wostringstream * out)15 void PrintViewHierarchyImp(const View* view,
16                            int indent,
17                            std::wostringstream* out) {
18   int ind = indent;
19   while (ind-- > 0)
20     *out << L' ';
21   *out << base::UTF8ToWide(view->GetClassName());
22   *out << L' ';
23   *out << view->id();
24   *out << L' ';
25   *out << view->x() << L"," << view->y() << L",";
26   *out << view->bounds().right() << L"," << view->bounds().bottom();
27   *out << L' ';
28   *out << view;
29   *out << L'\n';
30 
31   for (int i = 0, count = view->child_count(); i < count; ++i)
32     PrintViewHierarchyImp(view->child_at(i), indent + 2, out);
33 }
34 
PrintFocusHierarchyImp(const View * view,int indent,std::wostringstream * out)35 void PrintFocusHierarchyImp(const View* view,
36                             int indent,
37                             std::wostringstream* out) {
38   int ind = indent;
39   while (ind-- > 0)
40     *out << L' ';
41   *out << base::UTF8ToWide(view->GetClassName());
42   *out << L' ';
43   *out << view->id();
44   *out << L' ';
45   *out << view->GetClassName();
46   *out << L' ';
47   *out << view;
48   *out << L'\n';
49 
50   if (view->child_count() > 0)
51     PrintFocusHierarchyImp(view->child_at(0), indent + 2, out);
52 
53   const View* next_focusable = view->GetNextFocusableView();
54   if (next_focusable)
55     PrintFocusHierarchyImp(next_focusable, indent, out);
56 }
57 }  // namespace
58 
PrintViewHierarchy(const View * view)59 void PrintViewHierarchy(const View* view) {
60   std::wostringstream out;
61   out << L"View hierarchy:\n";
62   PrintViewHierarchyImp(view, 0, &out);
63   // Error so users in the field can generate and upload logs.
64   LOG(ERROR) << out.str();
65 }
66 
PrintFocusHierarchy(const View * view)67 void PrintFocusHierarchy(const View* view) {
68   std::wostringstream out;
69   out << L"Focus hierarchy:\n";
70   PrintFocusHierarchyImp(view, 0, &out);
71   // Error so users in the field can generate and upload logs.
72   LOG(ERROR) << out.str();
73 }
74 
75 }  // namespace views
76