| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/debug_utils.h" | 5 #include "ui/views/debug_utils.h" |
| 6 | 6 |
| 7 #include <iostream> |
| 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 9 #include "ui/views/view.h" | 11 #include "ui/views/view.h" |
| 10 | 12 |
| 11 #ifndef NDEBUG | |
| 12 #include <iostream> | |
| 13 #endif | |
| 14 | |
| 15 #ifndef NDEBUG | |
| 16 | |
| 17 namespace views { | 13 namespace views { |
| 18 namespace { | 14 namespace { |
| 19 void PrintViewHierarchyImp(const View* view, int indent) { | 15 void PrintViewHierarchyImp(const View* view, |
| 20 std::wostringstream buf; | 16 int indent, |
| 17 std::wostringstream* out) { |
| 21 int ind = indent; | 18 int ind = indent; |
| 22 while (ind-- > 0) | 19 while (ind-- > 0) |
| 23 buf << L' '; | 20 *out << L' '; |
| 24 buf << UTF8ToWide(view->GetClassName()); | 21 *out << UTF8ToWide(view->GetClassName()); |
| 25 buf << L' '; | 22 *out << L' '; |
| 26 buf << view->id(); | 23 *out << view->id(); |
| 27 buf << L' '; | 24 *out << L' '; |
| 28 buf << view->x() << L"," << view->y() << L","; | 25 *out << view->x() << L"," << view->y() << L","; |
| 29 buf << view->bounds().right() << L"," << view->bounds().bottom(); | 26 *out << view->bounds().right() << L"," << view->bounds().bottom(); |
| 30 buf << L' '; | 27 *out << L' '; |
| 31 buf << view; | 28 *out << view; |
| 32 | 29 *out << L'\n'; |
| 33 DVLOG(1) << buf.str(); | |
| 34 std::cout << buf.str() << std::endl; | |
| 35 | 30 |
| 36 for (int i = 0, count = view->child_count(); i < count; ++i) | 31 for (int i = 0, count = view->child_count(); i < count; ++i) |
| 37 PrintViewHierarchyImp(view->child_at(i), indent + 2); | 32 PrintViewHierarchyImp(view->child_at(i), indent + 2, out); |
| 38 } | 33 } |
| 39 | 34 |
| 40 void PrintFocusHierarchyImp(const View* view, int indent) { | 35 void PrintFocusHierarchyImp(const View* view, |
| 41 std::wostringstream buf; | 36 int indent, |
| 37 std::wostringstream* out) { |
| 42 int ind = indent; | 38 int ind = indent; |
| 43 while (ind-- > 0) | 39 while (ind-- > 0) |
| 44 buf << L' '; | 40 *out << L' '; |
| 45 buf << UTF8ToWide(view->GetClassName()); | 41 *out << UTF8ToWide(view->GetClassName()); |
| 46 buf << L' '; | 42 *out << L' '; |
| 47 buf << view->id(); | 43 *out << view->id(); |
| 48 buf << L' '; | 44 *out << L' '; |
| 49 buf << view->GetClassName().c_str(); | 45 *out << view->GetClassName().c_str(); |
| 50 buf << L' '; | 46 *out << L' '; |
| 51 buf << view; | 47 *out << view; |
| 52 | 48 *out << L'\n'; |
| 53 DVLOG(1) << buf.str(); | |
| 54 std::cout << buf.str() << std::endl; | |
| 55 | 49 |
| 56 if (view->child_count() > 0) | 50 if (view->child_count() > 0) |
| 57 PrintFocusHierarchyImp(view->child_at(0), indent + 2); | 51 PrintFocusHierarchyImp(view->child_at(0), indent + 2, out); |
| 58 | 52 |
| 59 const View* next_focusable = view->GetNextFocusableView(); | 53 const View* next_focusable = view->GetNextFocusableView(); |
| 60 if (next_focusable) | 54 if (next_focusable) |
| 61 PrintFocusHierarchyImp(next_focusable, indent); | 55 PrintFocusHierarchyImp(next_focusable, indent, out); |
| 62 } | 56 } |
| 63 } // namespace | 57 } // namespace |
| 64 | 58 |
| 65 void PrintViewHierarchy(const View* view) { | 59 void PrintViewHierarchy(const View* view) { |
| 66 PrintViewHierarchyImp(view, 0); | 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 } | 65 } |
| 68 | 66 |
| 69 void PrintFocusHierarchy(const View* view) { | 67 void PrintFocusHierarchy(const View* view) { |
| 70 PrintFocusHierarchyImp(view, 0); | 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(); |
| 71 } | 73 } |
| 72 | 74 |
| 73 } // namespace views | 75 } // namespace views |
| 74 | |
| 75 #endif // NDEBUG | |
| OLD | NEW |