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

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

Issue 2486543003: Add CSS agent for various window/widget/view attributes in devtools (Closed)
Patch Set: rebase 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
« no previous file with comments | « ash/common/devtools/ash_devtools_dom_agent.h ('k') | ash/common/wm_shell.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 "ash/common/devtools/ash_devtools_dom_agent.h" 5 #include "ash/common/devtools/ash_devtools_dom_agent.h"
6 6
7 #include "ash/common/wm_window.h" 7 #include "ash/common/wm_window.h"
8 #include "components/ui_devtools/devtools_server.h" 8 #include "components/ui_devtools/devtools_server.h"
9 #include "ui/views/view.h"
10 #include "ui/views/widget/widget.h"
11 9
12 namespace ash { 10 namespace ash {
13 namespace devtools { 11 namespace devtools {
14 12
15 namespace { 13 namespace {
16 using namespace ui::devtools::protocol; 14 using namespace ui::devtools::protocol;
17 DOM::NodeId node_ids = 1; 15 DOM::NodeId node_ids = 1;
18 16
19 std::unique_ptr<DOM::Node> BuildNode( 17 std::unique_ptr<DOM::Node> BuildNode(
20 const std::string& name, 18 const std::string& name,
(...skipping 29 matching lines...) Expand all
50 return attributes; 48 return attributes;
51 } 49 }
52 50
53 std::unique_ptr<Array<std::string>> GetAttributes(const views::View* view) { 51 std::unique_ptr<Array<std::string>> GetAttributes(const views::View* view) {
54 std::unique_ptr<Array<std::string>> attributes = Array<std::string>::create(); 52 std::unique_ptr<Array<std::string>> attributes = Array<std::string>::create();
55 attributes->addItem("name"); 53 attributes->addItem("name");
56 attributes->addItem(view->GetClassName()); 54 attributes->addItem(view->GetClassName());
57 return attributes; 55 return attributes;
58 } 56 }
59 57
60 std::unique_ptr<DOM::Node> BuildTreeForView(views::View* view) {
61 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
62 for (int i = 0, count = view->child_count(); i < count; i++) {
63 children->addItem(BuildTreeForView(view->child_at(i)));
64 }
65 return BuildNode("View", GetAttributes(view), std::move(children));
66 }
67
68 std::unique_ptr<DOM::Node> BuildTreeForRootWidget(views::Widget* widget) {
69 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
70 children->addItem(BuildTreeForView(widget->GetRootView()));
71 return BuildNode("Widget", GetAttributes(widget), std::move(children));
72 }
73 58
74 WmWindow* FindPreviousSibling(WmWindow* window) { 59 WmWindow* FindPreviousSibling(WmWindow* window) {
75 std::vector<WmWindow*> siblings = window->GetParent()->GetChildren(); 60 std::vector<WmWindow*> siblings = window->GetParent()->GetChildren();
76 std::vector<WmWindow*>::iterator it = 61 std::vector<WmWindow*>::iterator it =
77 std::find(siblings.begin(), siblings.end(), window); 62 std::find(siblings.begin(), siblings.end(), window);
78 DCHECK(it != siblings.end()); 63 DCHECK(it != siblings.end());
79 // If this is the first child of its parent, the previous sibling is null 64 // If this is the first child of its parent, the previous sibling is null
80 return it == siblings.begin() ? nullptr : *std::prev(it); 65 return it == siblings.begin() ? nullptr : *std::prev(it);
81 } 66 }
82 67
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // the window is only added here. 109 // the window is only added here.
125 if (window == params.new_parent) 110 if (window == params.new_parent)
126 AddWindowNode(params.target); 111 AddWindowNode(params.target);
127 } 112 }
128 113
129 void AshDevToolsDOMAgent::OnWindowStackingChanged(WmWindow* window) { 114 void AshDevToolsDOMAgent::OnWindowStackingChanged(WmWindow* window) {
130 RemoveWindowNode(window, window->GetParent()); 115 RemoveWindowNode(window, window->GetParent());
131 AddWindowNode(window); 116 AddWindowNode(window);
132 } 117 }
133 118
119 WmWindow* AshDevToolsDOMAgent::GetWindowFromNodeId(int nodeId) {
120 return node_id_to_window_map_.count(nodeId) ? node_id_to_window_map_[nodeId]
121 : nullptr;
122 }
123
124 views::Widget* AshDevToolsDOMAgent::GetWidgetFromNodeId(int nodeId) {
125 return node_id_to_widget_map_.count(nodeId) ? node_id_to_widget_map_[nodeId]
126 : nullptr;
127 }
128
129 views::View* AshDevToolsDOMAgent::GetViewFromNodeId(int nodeId) {
130 return node_id_to_view_map_.count(nodeId) ? node_id_to_view_map_[nodeId]
131 : nullptr;
132 }
133
134 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForView(
135 views::View* view) {
136 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
137 for (int i = 0, count = view->child_count(); i < count; i++) {
138 children->addItem(BuildTreeForView(view->child_at(i)));
139 }
140 std::unique_ptr<ui::devtools::protocol::DOM::Node> node =
141 BuildNode("View", GetAttributes(view), std::move(children));
142 node_id_to_view_map_[node->getNodeId()] = view;
143 return node;
144 }
145
146 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForRootWidget(
147 views::Widget* widget) {
148 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
149 children->addItem(BuildTreeForView(widget->GetRootView()));
150 std::unique_ptr<ui::devtools::protocol::DOM::Node> node =
151 BuildNode("Widget", GetAttributes(widget), std::move(children));
152 node_id_to_widget_map_[node->getNodeId()] = widget;
153 return node;
154 }
155
134 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForWindow( 156 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForWindow(
135 ash::WmWindow* window) { 157 ash::WmWindow* window) {
136 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); 158 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
137 views::Widget* widget = window->GetInternalWidget(); 159 views::Widget* widget = window->GetInternalWidget();
138 if (widget) 160 if (widget)
139 children->addItem(BuildTreeForRootWidget(widget)); 161 children->addItem(BuildTreeForRootWidget(widget));
140 for (ash::WmWindow* child : window->GetChildren()) { 162 for (ash::WmWindow* child : window->GetChildren()) {
141 children->addItem(BuildTreeForWindow(child)); 163 children->addItem(BuildTreeForWindow(child));
142 } 164 }
143 std::unique_ptr<ui::devtools::protocol::DOM::Node> node = 165 std::unique_ptr<ui::devtools::protocol::DOM::Node> node =
144 BuildNode("Window", GetAttributes(window), std::move(children)); 166 BuildNode("Window", GetAttributes(window), std::move(children));
145 // Only add as observer if window is not in map 167 // Only add as observer if window is not in map
146 if (!window_to_node_id_map_.count(window)) 168 if (!window_to_node_id_map_.count(window))
147 window->AddObserver(this); 169 window->AddObserver(this);
148 window_to_node_id_map_[window] = node->getNodeId(); 170 window_to_node_id_map_[window] = node->getNodeId();
171 node_id_to_window_map_[node->getNodeId()] = window;
149 return node; 172 return node;
150 } 173 }
151 174
152 std::unique_ptr<ui::devtools::protocol::DOM::Node> 175 std::unique_ptr<ui::devtools::protocol::DOM::Node>
153 AshDevToolsDOMAgent::BuildInitialTree() { 176 AshDevToolsDOMAgent::BuildInitialTree() {
154 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); 177 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
155 for (ash::WmWindow* window : shell_->GetAllRootWindows()) { 178 for (ash::WmWindow* window : shell_->GetAllRootWindows()) {
156 children->addItem(BuildTreeForWindow(window)); 179 children->addItem(BuildTreeForWindow(window));
157 } 180 }
158 return BuildNode("root", nullptr, std::move(children)); 181 return BuildNode("root", nullptr, std::move(children));
(...skipping 15 matching lines...) Expand all
174 DCHECK(it != window_to_node_id_map_.end()); 197 DCHECK(it != window_to_node_id_map_.end());
175 198
176 int node_id = it->second; 199 int node_id = it->second;
177 int parent_id = 0; 200 int parent_id = 0;
178 if (window != window->GetRootWindow()) { 201 if (window != window->GetRootWindow()) {
179 DCHECK(old_parent); 202 DCHECK(old_parent);
180 DCHECK(window_to_node_id_map_.count(old_parent)); 203 DCHECK(window_to_node_id_map_.count(old_parent));
181 parent_id = window_to_node_id_map_[old_parent]; 204 parent_id = window_to_node_id_map_[old_parent];
182 } 205 }
183 206
184 window_to_node_id_map_.erase(it); 207 window_to_node_id_map_.erase(it);
sadrul 2016/11/09 16:47:46 Remove node_id from node_id_to_window_map_? Shoul
Sarmad Hashmi 2016/11/09 20:51:38 Yes! Done. I'm not doing the removal of views in t
185 frontend()->childNodeRemoved(parent_id, node_id); 208 frontend()->childNodeRemoved(parent_id, node_id);
186 } 209 }
187 210
188 void AshDevToolsDOMAgent::RemoveObserverFromAllWindows() { 211 void AshDevToolsDOMAgent::RemoveObserverFromAllWindows() {
189 for (auto& pair : window_to_node_id_map_) 212 for (auto& pair : window_to_node_id_map_)
190 pair.first->RemoveObserver(this); 213 pair.first->RemoveObserver(this);
191 } 214 }
192 215
193 void AshDevToolsDOMAgent::Reset() { 216 void AshDevToolsDOMAgent::Reset() {
194 RemoveObserverFromAllWindows(); 217 RemoveObserverFromAllWindows();
195 window_to_node_id_map_.clear(); 218 window_to_node_id_map_.clear();
219 node_id_to_window_map_.clear();
220 node_id_to_widget_map_.clear();
221 node_id_to_view_map_.clear();
196 node_ids = 1; 222 node_ids = 1;
197 } 223 }
198 224
199 } // namespace devtools 225 } // namespace devtools
200 } // namespace ash 226 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/devtools/ash_devtools_dom_agent.h ('k') | ash/common/wm_shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698