Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1079)

Side by Side Diff: ash/common/devtools/devtools_client_dom.cc

Issue 2372843002: Add ash devtools client (Closed)
Patch Set: Add OWNERS file Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_client_dom.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 ui {
15 namespace devtools {
16
17 namespace {
18 using namespace protocol;
19
20 std::unique_ptr<DOM::Node> BuildNode(
21 const String& name,
sadrul 2016/10/26 19:20:41 Is this std::string? If so, use std::string in all
Sarmad Hashmi 2016/10/26 20:22:58 Done.
22 std::unique_ptr<Array<String>> attributes,
23 std::unique_ptr<Array<DOM::Node>> children) {
24 static DOM::NodeId node_ids = 0;
25 return DOM::Node::create()
26 .setNodeId(node_ids++)
27 .setNodeName(name)
28 .setNodeType(1)
sadrul 2016/10/26 19:20:41 Let's give this a name so it's easier to read:
Sarmad Hashmi 2016/10/26 20:22:57 Done.
29 .setAttributes(std::move(attributes))
30 .setChildNodeCount(children->length())
31 .setChildren(std::move(children))
32 .build();
33 }
34
35 std::unique_ptr<Array<String>> GetAttributes(const ash::WmWindow* window) {
36 std::unique_ptr<Array<String>> attributes = Array<String>::create();
37 attributes->addItem("name");
38 attributes->addItem(window->GetName());
39 attributes->addItem("visible");
40 attributes->addItem(window->IsVisible() ? "true" : "false");
41 attributes->addItem("active");
42 attributes->addItem(window->IsActive() ? "true" : "false");
43 attributes->addItem("bounds_height");
44 attributes->addItem(base::IntToString(window->GetBounds().height()));
45 attributes->addItem("bounds_width");
46 attributes->addItem(base::IntToString(window->GetBounds().width()));
sadrul 2016/10/26 19:20:41 A number of these attributes (e.g. bounds, visibil
Sarmad Hashmi 2016/10/26 20:22:58 Yep you're right. Done.
47 return attributes;
48 }
49
50 std::unique_ptr<Array<String>> GetAttributes(const views::Widget* widget) {
51 std::unique_ptr<Array<String>> attributes = Array<String>::create();
52 attributes->addItem("name");
53 attributes->addItem(widget->GetName());
54 attributes->addItem("visible");
55 attributes->addItem(widget->IsVisible() ? "true" : "false");
56 attributes->addItem("active");
57 attributes->addItem(widget->IsActive() ? "true" : "false");
58 return attributes;
59 }
60
61 std::unique_ptr<Array<String>> GetAttributes(const views::View* view) {
62 std::unique_ptr<Array<String>> attributes = Array<String>::create();
63 attributes->addItem("name");
64 attributes->addItem(view->GetClassName());
65 attributes->addItem("visible");
66 attributes->addItem(view->visible() ? "true" : "false");
67 attributes->addItem("x");
68 attributes->addItem(base::IntToString(view->x()));
69 attributes->addItem("y");
70 attributes->addItem(base::IntToString(view->y()));
71 attributes->addItem("bounds_height");
72 attributes->addItem(base::IntToString(view->bounds().bottom()));
73 attributes->addItem("bounds_width");
74 attributes->addItem(base::IntToString(view->bounds().right()));
75 return attributes;
76 }
77
78 std::unique_ptr<DOM::Node> BuildTreeForRootView(views::View* view) {
sadrul 2016/10/26 19:20:41 BuildTreeForView, since this is called for all Vie
Sarmad Hashmi 2016/10/26 20:22:57 Done.
79 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
80 for (int i = 0, count = view->child_count(); i < count; i++) {
81 children->addItem(BuildTreeForRootView(view->child_at(i)));
82 }
83 return BuildNode("View", GetAttributes(view), std::move(children));
84 }
85
86 std::unique_ptr<DOM::Node> BuildTreeForRootWidget(views::Widget* widget) {
sadrul 2016/10/26 19:20:41 BuildTreeForWidget
Sarmad Hashmi 2016/10/26 20:22:58 Done.
87 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
88 children->addItem(BuildTreeForRootView(widget->GetRootView()));
89 return BuildNode("Widget", GetAttributes(widget), std::move(children));
90 }
91
92 std::unique_ptr<DOM::Node> BuildTreeForRootWindow(ash::WmWindow* window) {
sadrul 2016/10/26 19:20:41 BuildTreeForWindow
Sarmad Hashmi 2016/10/26 20:22:57 Done.
93 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
94 for (ash::WmWindow* child : window->GetChildren()) {
95 children->addItem(BuildTreeForRootWindow(child));
96 views::Widget* widget = child->GetInternalWidget();
97 if (widget)
98 children->addItem(BuildTreeForRootWidget(widget));
99 }
100 return BuildNode("Window", GetAttributes(window), std::move(children));
101 }
102
103 } // namespace
104
105 AshDevToolsClientDOM::AshDevToolsClientDOM(ash::WmShell* shell)
106 : shell_(shell) {
107 DCHECK(shell_);
108 }
109
110 AshDevToolsClientDOM::~AshDevToolsClientDOM() {}
111
112 std::unique_ptr<protocol::DOM::Node> AshDevToolsClientDOM::BuildInitialTree() {
113 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
114 for (ash::WmWindow* window : shell_->GetAllRootWindows()) {
115 children->addItem(BuildTreeForRootWindow(window));
116 }
117 return BuildNode("root", nullptr, std::move(children));
118 }
119
120 void AshDevToolsClientDOM::getDocument(
121 protocol::ErrorString* error,
122 std::unique_ptr<protocol::DOM::Node>* out_root) {
123 *out_root = BuildInitialTree();
124 }
125
126 } // namespace devtools
127 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698