| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 "ash/common/devtools/devtools_dom_agent.h" | |
| 6 | |
| 7 #include "ash/common/wm_shell.h" | |
| 8 #include "ash/common/wm_window.h" | |
| 9 #include "components/ui_devtools/DOM.h" | |
| 10 #include "components/ui_devtools/devtools_server.h" | |
| 11 #include "ui/views/view.h" | |
| 12 #include "ui/views/widget/widget.h" | |
| 13 | |
| 14 namespace ash { | |
| 15 namespace devtools { | |
| 16 | |
| 17 namespace { | |
| 18 using namespace ui::devtools::protocol; | |
| 19 | |
| 20 std::unique_ptr<DOM::Node> BuildNode( | |
| 21 const std::string& name, | |
| 22 std::unique_ptr<Array<std::string>> attributes, | |
| 23 std::unique_ptr<Array<DOM::Node>> children) { | |
| 24 static DOM::NodeId node_ids = 0; | |
| 25 constexpr int kDomElementNodeType = 1; | |
| 26 return DOM::Node::create() | |
| 27 .setNodeId(node_ids++) | |
| 28 .setNodeName(name) | |
| 29 .setNodeType(kDomElementNodeType) | |
| 30 .setAttributes(std::move(attributes)) | |
| 31 .setChildNodeCount(children->length()) | |
| 32 .setChildren(std::move(children)) | |
| 33 .build(); | |
| 34 } | |
| 35 | |
| 36 std::unique_ptr<Array<std::string>> GetAttributes(const ash::WmWindow* window) { | |
| 37 std::unique_ptr<Array<std::string>> attributes = Array<std::string>::create(); | |
| 38 attributes->addItem("name"); | |
| 39 attributes->addItem(window->GetName()); | |
| 40 attributes->addItem("active"); | |
| 41 attributes->addItem(window->IsActive() ? "true" : "false"); | |
| 42 return attributes; | |
| 43 } | |
| 44 | |
| 45 std::unique_ptr<Array<std::string>> GetAttributes(const views::Widget* widget) { | |
| 46 std::unique_ptr<Array<std::string>> attributes = Array<std::string>::create(); | |
| 47 attributes->addItem("name"); | |
| 48 attributes->addItem(widget->GetName()); | |
| 49 attributes->addItem("active"); | |
| 50 attributes->addItem(widget->IsActive() ? "true" : "false"); | |
| 51 return attributes; | |
| 52 } | |
| 53 | |
| 54 std::unique_ptr<Array<std::string>> GetAttributes(const views::View* view) { | |
| 55 std::unique_ptr<Array<std::string>> attributes = Array<std::string>::create(); | |
| 56 attributes->addItem("name"); | |
| 57 attributes->addItem(view->GetClassName()); | |
| 58 return attributes; | |
| 59 } | |
| 60 | |
| 61 std::unique_ptr<DOM::Node> BuildTreeForView(views::View* view) { | |
| 62 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); | |
| 63 for (int i = 0, count = view->child_count(); i < count; i++) { | |
| 64 children->addItem(BuildTreeForView(view->child_at(i))); | |
| 65 } | |
| 66 return BuildNode("View", GetAttributes(view), std::move(children)); | |
| 67 } | |
| 68 | |
| 69 std::unique_ptr<DOM::Node> BuildTreeForRootWidget(views::Widget* widget) { | |
| 70 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); | |
| 71 children->addItem(BuildTreeForView(widget->GetRootView())); | |
| 72 return BuildNode("Widget", GetAttributes(widget), std::move(children)); | |
| 73 } | |
| 74 | |
| 75 std::unique_ptr<DOM::Node> BuildTreeForWindow(ash::WmWindow* window) { | |
| 76 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); | |
| 77 for (ash::WmWindow* child : window->GetChildren()) { | |
| 78 children->addItem(BuildTreeForWindow(child)); | |
| 79 views::Widget* widget = child->GetInternalWidget(); | |
| 80 if (widget) | |
| 81 children->addItem(BuildTreeForRootWidget(widget)); | |
| 82 } | |
| 83 return BuildNode("Window", GetAttributes(window), std::move(children)); | |
| 84 } | |
| 85 | |
| 86 } // namespace | |
| 87 | |
| 88 AshDevToolsDOMAgent::AshDevToolsDOMAgent(ash::WmShell* shell) : shell_(shell) { | |
| 89 DCHECK(shell_); | |
| 90 } | |
| 91 | |
| 92 AshDevToolsDOMAgent::~AshDevToolsDOMAgent() {} | |
| 93 | |
| 94 std::unique_ptr<ui::devtools::protocol::DOM::Node> | |
| 95 AshDevToolsDOMAgent::BuildInitialTree() { | |
| 96 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); | |
| 97 for (ash::WmWindow* window : shell_->GetAllRootWindows()) { | |
| 98 children->addItem(BuildTreeForWindow(window)); | |
| 99 } | |
| 100 return BuildNode("root", nullptr, std::move(children)); | |
| 101 } | |
| 102 | |
| 103 void AshDevToolsDOMAgent::getDocument( | |
| 104 ui::devtools::protocol::ErrorString* error, | |
| 105 std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) { | |
| 106 *out_root = BuildInitialTree(); | |
| 107 } | |
| 108 | |
| 109 } // namespace devtools | |
| 110 } // namespace ash | |
| OLD | NEW |