WebKit merge 94748:94770
[chromium-blink-merge.git] / views / debug_utils.cc
blobb4907368ac5b54cf9f9cf03038edb1a6d0b67335
1 // Copyright (c) 2011 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 "views/debug_utils.h"
7 #include "base/logging.h"
8 #include "base/utf_string_conversions.h"
9 #include "views/view.h"
11 #ifndef NDEBUG
12 #include <iostream>
13 #endif
15 namespace views {
17 #ifndef NDEBUG
19 namespace {
20 void PrintViewHierarchyImp(const View* view, int indent) {
21 std::wostringstream buf;
22 int ind = indent;
23 while (ind-- > 0)
24 buf << L' ';
25 buf << UTF8ToWide(view->GetClassName());
26 buf << L' ';
27 buf << view->id();
28 buf << L' ';
29 buf << view->x() << L"," << view->y() << L",";
30 buf << view->bounds().right() << L"," << view->bounds().bottom();
31 buf << L' ';
32 buf << view;
34 VLOG(1) << buf.str();
35 std::cout << buf.str() << std::endl;
37 for (int i = 0, count = view->child_count(); i < count; ++i)
38 PrintViewHierarchyImp(view->GetChildViewAt(i), indent + 2);
41 void PrintFocusHierarchyImp(const View* view, int indent) {
42 std::wostringstream buf;
43 int ind = indent;
44 while (ind-- > 0)
45 buf << L' ';
46 buf << UTF8ToWide(view->GetClassName());
47 buf << L' ';
48 buf << view->id();
49 buf << L' ';
50 buf << view->GetClassName().c_str();
51 buf << L' ';
52 buf << view;
54 VLOG(1) << buf.str();
55 std::cout << buf.str() << std::endl;
57 if (view->child_count() > 0)
58 PrintFocusHierarchyImp(view->GetChildViewAt(0), indent + 2);
60 const View* next_focusable = view->GetNextFocusableView();
61 if (next_focusable)
62 PrintFocusHierarchyImp(next_focusable, indent);
64 } // namespace
66 void PrintViewHierarchy(const View* view) {
67 PrintViewHierarchyImp(view, 0);
70 void PrintFocusHierarchy(const View* view) {
71 PrintFocusHierarchyImp(view, 0);
74 } // namespace views
76 #endif // NDEBUG