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.
5 #include "ui/views/debug_utils.h"
9 #include "base/logging.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "ui/views/view.h"
15 void PrintViewHierarchyImp(const View
* view
,
17 std::wostringstream
* out
) {
21 *out
<< base::UTF8ToWide(view
->GetClassName());
25 *out
<< view
->x() << L
"," << view
->y() << L
",";
26 *out
<< view
->bounds().right() << L
"," << view
->bounds().bottom();
31 for (int i
= 0, count
= view
->child_count(); i
< count
; ++i
)
32 PrintViewHierarchyImp(view
->child_at(i
), indent
+ 2, out
);
35 void PrintFocusHierarchyImp(const View
* view
,
37 std::wostringstream
* out
) {
41 *out
<< base::UTF8ToWide(view
->GetClassName());
45 *out
<< view
->GetClassName();
50 if (view
->child_count() > 0)
51 PrintFocusHierarchyImp(view
->child_at(0), indent
+ 2, out
);
53 const View
* next_focusable
= view
->GetNextFocusableView();
55 PrintFocusHierarchyImp(next_focusable
, indent
, out
);
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();
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();