Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_lookup.h" | 7 #include "ash/common/wm_lookup.h" |
| 8 #include "ash/common/wm_window.h" | 8 #include "ash/common/wm_window.h" |
| 9 #include "components/ui_devtools/devtools_server.h" | 9 #include "components/ui_devtools/devtools_server.h" |
| 10 | 10 |
| 11 namespace ash { | 11 namespace ash { |
| 12 namespace devtools { | 12 namespace devtools { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 using namespace ui::devtools::protocol; | 15 using namespace ui::devtools::protocol; |
| 16 // TODO(mhashmi): Make ids reusable | |
| 16 DOM::NodeId node_ids = 1; | 17 DOM::NodeId node_ids = 1; |
| 17 | 18 |
| 18 std::unique_ptr<DOM::Node> BuildNode( | 19 std::unique_ptr<DOM::Node> BuildNode( |
| 19 const std::string& name, | 20 const std::string& name, |
| 20 std::unique_ptr<Array<std::string>> attributes, | 21 std::unique_ptr<Array<std::string>> attributes, |
| 21 std::unique_ptr<Array<DOM::Node>> children) { | 22 std::unique_ptr<Array<DOM::Node>> children) { |
| 22 constexpr int kDomElementNodeType = 1; | 23 constexpr int kDomElementNodeType = 1; |
| 23 std::unique_ptr<DOM::Node> node = DOM::Node::create() | 24 std::unique_ptr<DOM::Node> node = DOM::Node::create() |
| 24 .setNodeId(node_ids++) | 25 .setNodeId(node_ids++) |
| 25 .setNodeName(name) | 26 .setNodeName(name) |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 49 return attributes; | 50 return attributes; |
| 50 } | 51 } |
| 51 | 52 |
| 52 std::unique_ptr<Array<std::string>> GetAttributes(const views::View* view) { | 53 std::unique_ptr<Array<std::string>> GetAttributes(const views::View* view) { |
| 53 std::unique_ptr<Array<std::string>> attributes = Array<std::string>::create(); | 54 std::unique_ptr<Array<std::string>> attributes = Array<std::string>::create(); |
| 54 attributes->addItem("name"); | 55 attributes->addItem("name"); |
| 55 attributes->addItem(view->GetClassName()); | 56 attributes->addItem(view->GetClassName()); |
| 56 return attributes; | 57 return attributes; |
| 57 } | 58 } |
| 58 | 59 |
| 59 | |
| 60 WmWindow* FindPreviousSibling(WmWindow* window) { | 60 WmWindow* FindPreviousSibling(WmWindow* window) { |
| 61 std::vector<WmWindow*> siblings = window->GetParent()->GetChildren(); | 61 std::vector<WmWindow*> siblings = window->GetParent()->GetChildren(); |
| 62 std::vector<WmWindow*>::iterator it = | 62 std::vector<WmWindow*>::iterator it = |
| 63 std::find(siblings.begin(), siblings.end(), window); | 63 std::find(siblings.begin(), siblings.end(), window); |
| 64 DCHECK(it != siblings.end()); | 64 DCHECK(it != siblings.end()); |
| 65 // If this is the first child of its parent, the previous sibling is null | 65 // If this is the first child of its parent, the previous sibling is null |
| 66 return it == siblings.begin() ? nullptr : *std::prev(it); | 66 return it == siblings.begin() ? nullptr : *std::prev(it); |
| 67 } | 67 } |
| 68 | 68 |
| 69 } // namespace | 69 } // namespace |
| 70 | 70 |
| 71 AshDevToolsDOMAgent::AshDevToolsDOMAgent(ash::WmShell* shell) : shell_(shell) { | 71 AshDevToolsDOMAgent::AshDevToolsDOMAgent(ash::WmShell* shell) : shell_(shell) { |
| 72 DCHECK(shell_); | 72 DCHECK(shell_); |
| 73 } | 73 } |
| 74 | 74 |
| 75 AshDevToolsDOMAgent::~AshDevToolsDOMAgent() { | 75 AshDevToolsDOMAgent::~AshDevToolsDOMAgent() { |
| 76 RemoveObserverFromAllWindows(); | 76 RemoveObserverFromAllWindows(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // DOM::Backend implementation | |
|
sadrul
2016/11/25 18:19:20
Remove these comments.
Sarmad Hashmi
2016/11/25 23:27:30
Done.
| |
| 79 ui::devtools::protocol::Response AshDevToolsDOMAgent::disable() { | 80 ui::devtools::protocol::Response AshDevToolsDOMAgent::disable() { |
| 80 Reset(); | 81 Reset(); |
| 81 return ui::devtools::protocol::Response::OK(); | 82 return ui::devtools::protocol::Response::OK(); |
| 82 } | 83 } |
| 83 | 84 |
| 84 ui::devtools::protocol::Response AshDevToolsDOMAgent::getDocument( | 85 ui::devtools::protocol::Response AshDevToolsDOMAgent::getDocument( |
| 85 std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) { | 86 std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) { |
| 86 *out_root = BuildInitialTree(); | 87 *out_root = BuildInitialTree(); |
| 87 return ui::devtools::protocol::Response::OK(); | 88 return ui::devtools::protocol::Response::OK(); |
| 88 } | 89 } |
| 89 | 90 |
| 91 // WindowObserver implementation | |
| 90 // Handles removing windows. | 92 // Handles removing windows. |
| 91 void AshDevToolsDOMAgent::OnWindowTreeChanging(WmWindow* window, | 93 void AshDevToolsDOMAgent::OnWindowTreeChanging(WmWindow* window, |
| 92 const TreeChangeParams& params) { | 94 const TreeChangeParams& params) { |
| 93 // Only trigger this when window == params.old_parent. | 95 // Only trigger this when window == params.old_parent. |
| 94 // Only removals are handled here. Removing a node can occur as a result of | 96 // Only removals are handled here. Removing a node can occur as a result of |
| 95 // reorganizing a window or just destroying it. OnWindowTreeChanged | 97 // reorganizing a window or just destroying it. OnWindowTreeChanged |
| 96 // is only called if there is a new_parent. The only case this method isn't | 98 // is only called if there is a new_parent. The only case this method isn't |
| 97 // called is when adding a node because old_parent is then null. | 99 // called is when adding a node because old_parent is then null. |
| 98 // Finally, We only trigger this 0 or 1 times as an old_parent will | 100 // Finally, We only trigger this 0 or 1 times as an old_parent will |
| 99 // either exist and only call this callback once, or not at all. | 101 // either exist and only call this callback once, or not at all. |
| 100 if (window == params.old_parent) | 102 if (window == params.old_parent) |
| 101 RemoveWindowNode(params.target); | 103 RemoveWindowTree(params.target, true); |
| 102 } | 104 } |
| 103 | 105 |
| 104 // Handles adding windows. | 106 // Handles adding windows. |
| 105 void AshDevToolsDOMAgent::OnWindowTreeChanged(WmWindow* window, | 107 void AshDevToolsDOMAgent::OnWindowTreeChanged(WmWindow* window, |
| 106 const TreeChangeParams& params) { | 108 const TreeChangeParams& params) { |
| 107 // Only trigger this when window == params.new_parent. | 109 // Only trigger this when window == params.new_parent. |
| 108 // If there is an old_parent + new_parent, then this window's node was | 110 // If there is an old_parent + new_parent, then this window's node was |
| 109 // removed in OnWindowTreeChanging and will now be added to the new_parent. | 111 // removed in OnWindowTreeChanging and will now be added to the new_parent. |
| 110 // If there is only a new_parent, OnWindowTreeChanging is never called and | 112 // If there is only a new_parent, OnWindowTreeChanging is never called and |
| 111 // the window is only added here. | 113 // the window is only added here. |
| 112 if (window == params.new_parent) | 114 if (window == params.new_parent) |
| 113 AddWindowNode(params.target); | 115 AddWindowTree(params.target); |
| 114 } | 116 } |
| 115 | 117 |
| 116 void AshDevToolsDOMAgent::OnWindowStackingChanged(WmWindow* window) { | 118 void AshDevToolsDOMAgent::OnWindowStackingChanged(WmWindow* window) { |
| 117 RemoveWindowNode(window); | 119 RemoveWindowTree(window, false); |
| 118 AddWindowNode(window); | 120 AddWindowTree(window); |
| 119 } | 121 } |
| 120 | 122 |
| 121 WmWindow* AshDevToolsDOMAgent::GetWindowFromNodeId(int nodeId) { | 123 WmWindow* AshDevToolsDOMAgent::GetWindowFromNodeId(int nodeId) { |
| 122 return node_id_to_window_map_.count(nodeId) ? node_id_to_window_map_[nodeId] | 124 return node_id_to_window_map_.count(nodeId) ? node_id_to_window_map_[nodeId] |
| 123 : nullptr; | 125 : nullptr; |
| 124 } | 126 } |
| 125 | 127 |
| 126 views::Widget* AshDevToolsDOMAgent::GetWidgetFromNodeId(int nodeId) { | 128 views::Widget* AshDevToolsDOMAgent::GetWidgetFromNodeId(int nodeId) { |
| 127 return node_id_to_widget_map_.count(nodeId) ? node_id_to_widget_map_[nodeId] | 129 return node_id_to_widget_map_.count(nodeId) ? node_id_to_widget_map_[nodeId] |
| 128 : nullptr; | 130 : nullptr; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 141 int AshDevToolsDOMAgent::GetNodeIdFromWidget(views::Widget* widget) { | 143 int AshDevToolsDOMAgent::GetNodeIdFromWidget(views::Widget* widget) { |
| 142 DCHECK(widget_to_node_id_map_.count(widget)); | 144 DCHECK(widget_to_node_id_map_.count(widget)); |
| 143 return widget_to_node_id_map_[widget]; | 145 return widget_to_node_id_map_[widget]; |
| 144 } | 146 } |
| 145 | 147 |
| 146 int AshDevToolsDOMAgent::GetNodeIdFromView(views::View* view) { | 148 int AshDevToolsDOMAgent::GetNodeIdFromView(views::View* view) { |
| 147 DCHECK(view_to_node_id_map_.count(view)); | 149 DCHECK(view_to_node_id_map_.count(view)); |
| 148 return view_to_node_id_map_[view]; | 150 return view_to_node_id_map_[view]; |
| 149 } | 151 } |
| 150 | 152 |
| 151 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForView( | 153 std::unique_ptr<ui::devtools::protocol::DOM::Node> |
| 152 views::View* view) { | 154 AshDevToolsDOMAgent::BuildInitialTree() { |
| 153 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); | 155 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); |
| 154 for (int i = 0, count = view->child_count(); i < count; i++) { | 156 for (ash::WmWindow* window : shell_->GetAllRootWindows()) |
| 155 children->addItem(BuildTreeForView(view->child_at(i))); | 157 children->addItem(BuildTreeForWindow(window)); |
| 156 } | 158 return BuildNode("root", nullptr, std::move(children)); |
| 157 std::unique_ptr<ui::devtools::protocol::DOM::Node> node = | |
| 158 BuildNode("View", GetAttributes(view), std::move(children)); | |
| 159 view_to_node_id_map_[view] = node->getNodeId(); | |
| 160 node_id_to_view_map_[node->getNodeId()] = view; | |
| 161 return node; | |
| 162 } | |
| 163 | |
| 164 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForRootWidget( | |
| 165 views::Widget* widget) { | |
| 166 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); | |
| 167 children->addItem(BuildTreeForView(widget->GetRootView())); | |
| 168 std::unique_ptr<ui::devtools::protocol::DOM::Node> node = | |
| 169 BuildNode("Widget", GetAttributes(widget), std::move(children)); | |
| 170 widget_to_node_id_map_[widget] = node->getNodeId(); | |
| 171 node_id_to_widget_map_[node->getNodeId()] = widget; | |
| 172 return node; | |
| 173 } | 159 } |
| 174 | 160 |
| 175 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForWindow( | 161 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForWindow( |
| 176 ash::WmWindow* window) { | 162 ash::WmWindow* window) { |
| 163 DCHECK(!window_to_node_id_map_.count(window)); | |
| 177 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); | 164 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); |
| 178 views::Widget* widget = window->GetInternalWidget(); | 165 views::Widget* widget = window->GetInternalWidget(); |
| 179 if (widget) | 166 if (widget) |
| 180 children->addItem(BuildTreeForRootWidget(widget)); | 167 children->addItem(BuildTreeForRootWidget(widget)); |
| 181 for (ash::WmWindow* child : window->GetChildren()) { | 168 for (ash::WmWindow* child : window->GetChildren()) |
| 182 children->addItem(BuildTreeForWindow(child)); | 169 children->addItem(BuildTreeForWindow(child)); |
| 183 } | 170 |
| 184 std::unique_ptr<ui::devtools::protocol::DOM::Node> node = | 171 std::unique_ptr<ui::devtools::protocol::DOM::Node> node = |
| 185 BuildNode("Window", GetAttributes(window), std::move(children)); | 172 BuildNode("Window", GetAttributes(window), std::move(children)); |
| 186 // Only add as observer if window is not in map | 173 if (!window->HasObserver(this)) |
| 187 if (!window_to_node_id_map_.count(window)) | |
| 188 window->AddObserver(this); | 174 window->AddObserver(this); |
| 189 window_to_node_id_map_[window] = node->getNodeId(); | 175 window_to_node_id_map_[window] = node->getNodeId(); |
| 190 node_id_to_window_map_[node->getNodeId()] = window; | 176 node_id_to_window_map_[node->getNodeId()] = window; |
| 191 return node; | 177 return node; |
| 192 } | 178 } |
| 193 | 179 |
| 194 std::unique_ptr<ui::devtools::protocol::DOM::Node> | 180 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForRootWidget( |
| 195 AshDevToolsDOMAgent::BuildInitialTree() { | 181 views::Widget* widget) { |
| 182 DCHECK(!widget_to_node_id_map_.count(widget)); | |
| 196 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); | 183 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); |
| 197 for (ash::WmWindow* window : shell_->GetAllRootWindows()) { | 184 children->addItem(BuildTreeForView(widget->GetRootView())); |
| 198 children->addItem(BuildTreeForWindow(window)); | 185 std::unique_ptr<ui::devtools::protocol::DOM::Node> node = |
| 199 } | 186 BuildNode("Widget", GetAttributes(widget), std::move(children)); |
| 200 return BuildNode("root", nullptr, std::move(children)); | 187 // TODO(mhashmi): Add WidgetRemovalsObserver here |
| 188 widget_to_node_id_map_[widget] = node->getNodeId(); | |
| 189 node_id_to_widget_map_[node->getNodeId()] = widget; | |
| 190 return node; | |
| 201 } | 191 } |
| 202 | 192 |
| 203 void AshDevToolsDOMAgent::AddWindowNode(WmWindow* window) { | 193 std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForView( |
| 194 views::View* view) { | |
| 195 DCHECK(!view_to_node_id_map_.count(view)); | |
| 196 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create(); | |
| 197 for (int i = 0, count = view->child_count(); i < count; i++) | |
| 198 children->addItem(BuildTreeForView(view->child_at(i))); | |
| 199 std::unique_ptr<ui::devtools::protocol::DOM::Node> node = | |
| 200 BuildNode("View", GetAttributes(view), std::move(children)); | |
| 201 // TODO(mhashmi): Add ViewObserver here | |
| 202 view_to_node_id_map_[view] = node->getNodeId(); | |
| 203 node_id_to_view_map_[node->getNodeId()] = view; | |
| 204 return node; | |
| 205 } | |
| 206 | |
| 207 void AshDevToolsDOMAgent::AddWindowTree(WmWindow* window) { | |
| 204 DCHECK(window_to_node_id_map_.count(window->GetParent())); | 208 DCHECK(window_to_node_id_map_.count(window->GetParent())); |
| 205 WmWindow* prev_sibling = FindPreviousSibling(window); | 209 WmWindow* prev_sibling = FindPreviousSibling(window); |
| 206 frontend()->childNodeInserted( | 210 frontend()->childNodeInserted( |
| 207 window_to_node_id_map_[window->GetParent()], | 211 window_to_node_id_map_[window->GetParent()], |
| 208 prev_sibling ? window_to_node_id_map_[prev_sibling] : 0, | 212 prev_sibling ? window_to_node_id_map_[prev_sibling] : 0, |
| 209 BuildTreeForWindow(window)); | 213 BuildTreeForWindow(window)); |
| 210 } | 214 } |
| 211 | 215 |
| 212 void AshDevToolsDOMAgent::RemoveWindowNode(WmWindow* window) { | 216 void AshDevToolsDOMAgent::RemoveWindowTree(WmWindow* window, |
| 213 WmWindow* parent = window->GetParent(); | 217 bool remove_observer) { |
| 214 DCHECK(parent); | 218 DCHECK(window); |
| 219 if (window->GetInternalWidget()) | |
| 220 RemoveWidgetTree(window->GetInternalWidget(), remove_observer); | |
| 221 | |
| 222 for (ash::WmWindow* child : window->GetChildren()) | |
| 223 RemoveWindowTree(child, remove_observer); | |
| 224 | |
| 225 RemoveWindowNode(window, remove_observer); | |
| 226 } | |
| 227 | |
| 228 void AshDevToolsDOMAgent::RemoveWindowNode(WmWindow* window, | |
| 229 bool remove_observer) { | |
| 215 WindowToNodeIdMap::iterator window_to_node_id_it = | 230 WindowToNodeIdMap::iterator window_to_node_id_it = |
| 216 window_to_node_id_map_.find(window); | 231 window_to_node_id_map_.find(window); |
| 217 DCHECK(window_to_node_id_it != window_to_node_id_map_.end()); | 232 DCHECK(window_to_node_id_it != window_to_node_id_map_.end()); |
| 218 | 233 |
| 219 int node_id = window_to_node_id_it->second; | 234 int node_id = window_to_node_id_it->second; |
| 220 int parent_id = GetNodeIdFromWindow(parent); | 235 int parent_id = GetNodeIdFromWindow(window->GetParent()); |
| 221 | 236 |
| 222 NodeIdToWindowMap::iterator node_id_to_window_it = | 237 NodeIdToWindowMap::iterator node_id_to_window_it = |
| 223 node_id_to_window_map_.find(node_id); | 238 node_id_to_window_map_.find(node_id); |
| 224 DCHECK(node_id_to_window_it != node_id_to_window_map_.end()); | 239 DCHECK(node_id_to_window_it != node_id_to_window_map_.end()); |
| 225 | 240 |
| 226 views::Widget* widget = window->GetInternalWidget(); | 241 if (remove_observer) |
| 227 if (widget) | 242 window->RemoveObserver(this); |
| 228 RemoveWidgetNode(widget); | |
| 229 | |
| 230 window->RemoveObserver(this); | |
| 231 node_id_to_window_map_.erase(node_id_to_window_it); | 243 node_id_to_window_map_.erase(node_id_to_window_it); |
| 232 window_to_node_id_map_.erase(window_to_node_id_it); | 244 window_to_node_id_map_.erase(window_to_node_id_it); |
| 233 frontend()->childNodeRemoved(parent_id, node_id); | 245 frontend()->childNodeRemoved(parent_id, node_id); |
| 234 } | 246 } |
| 235 | 247 |
| 236 void AshDevToolsDOMAgent::RemoveWidgetNode(views::Widget* widget) { | 248 void AshDevToolsDOMAgent::RemoveWidgetTree(views::Widget* widget, |
| 249 bool remove_observer) { | |
| 250 DCHECK(widget); | |
| 251 if (widget->GetRootView()) | |
| 252 RemoveViewTree(widget->GetRootView(), nullptr, remove_observer); | |
| 253 RemoveWidgetNode(widget, remove_observer); | |
| 254 } | |
| 255 | |
| 256 void AshDevToolsDOMAgent::RemoveWidgetNode(views::Widget* widget, | |
| 257 bool remove_observer) { | |
| 237 WidgetToNodeIdMap::iterator widget_to_node_id_it = | 258 WidgetToNodeIdMap::iterator widget_to_node_id_it = |
| 238 widget_to_node_id_map_.find(widget); | 259 widget_to_node_id_map_.find(widget); |
| 239 DCHECK(widget_to_node_id_it != widget_to_node_id_map_.end()); | 260 DCHECK(widget_to_node_id_it != widget_to_node_id_map_.end()); |
| 240 | 261 |
| 241 int node_id = widget_to_node_id_it->second; | 262 int node_id = widget_to_node_id_it->second; |
| 242 int parent_id = | 263 int parent_id = |
| 243 GetNodeIdFromWindow(WmLookup::Get()->GetWindowForWidget(widget)); | 264 GetNodeIdFromWindow(WmLookup::Get()->GetWindowForWidget(widget)); |
| 244 | 265 |
| 245 RemoveViewNode(widget->GetRootView()); | 266 // TODO(mhashmi): Add WidgetRemovalsObserver and remove it here based on |
| 267 // |remove_observer| | |
| 246 | 268 |
| 247 NodeIdToWidgetMap::iterator node_id_to_widget_it = | 269 NodeIdToWidgetMap::iterator node_id_to_widget_it = |
| 248 node_id_to_widget_map_.find(node_id); | 270 node_id_to_widget_map_.find(node_id); |
| 249 DCHECK(node_id_to_widget_it != node_id_to_widget_map_.end()); | 271 DCHECK(node_id_to_widget_it != node_id_to_widget_map_.end()); |
| 250 | 272 |
| 251 widget_to_node_id_map_.erase(widget_to_node_id_it); | 273 widget_to_node_id_map_.erase(widget_to_node_id_it); |
| 252 node_id_to_widget_map_.erase(node_id_to_widget_it); | 274 node_id_to_widget_map_.erase(node_id_to_widget_it); |
| 253 frontend()->childNodeRemoved(parent_id, node_id); | 275 frontend()->childNodeRemoved(parent_id, node_id); |
| 254 } | 276 } |
| 255 | 277 |
| 256 void AshDevToolsDOMAgent::RemoveViewNode(views::View* view) { | 278 void AshDevToolsDOMAgent::RemoveViewTree(views::View* view, |
| 257 // TODO(mhashmi): Add observers to views/widgets so new views exist | 279 views::View* parent, |
| 258 // in the map and can be removed here | 280 bool remove_observer) { |
| 281 DCHECK(view); | |
| 282 for (int i = 0, count = view->child_count(); i < count; i++) | |
| 283 RemoveViewTree(view->child_at(i), view, remove_observer); | |
| 284 RemoveViewNode(view, parent, remove_observer); | |
| 285 } | |
| 286 | |
| 287 void AshDevToolsDOMAgent::RemoveViewNode(views::View* view, | |
| 288 views::View* parent, | |
| 289 bool remove_observer) { | |
| 290 ViewToNodeIdMap::iterator view_to_node_id_it = | |
| 291 view_to_node_id_map_.find(view); | |
| 292 DCHECK(view_to_node_id_it != view_to_node_id_map_.end()); | |
| 293 | |
| 294 int node_id = view_to_node_id_it->second; | |
| 295 int parent_id = 0; | |
| 296 if (parent) | |
| 297 parent_id = GetNodeIdFromView(parent); | |
| 298 else // views::RootView | |
| 299 parent_id = GetNodeIdFromWidget(view->GetWidget()); | |
| 300 | |
| 301 // TODO(mhashmi): Add ViewObserver and remove it here based on | |
| 302 // |remove_observer| | |
| 303 | |
| 304 NodeIdToViewMap::iterator node_id_to_view_it = | |
| 305 node_id_to_view_map_.find(node_id); | |
| 306 DCHECK(node_id_to_view_it != node_id_to_view_map_.end()); | |
| 307 | |
| 308 view_to_node_id_map_.erase(view_to_node_id_it); | |
| 309 node_id_to_view_map_.erase(node_id_to_view_it); | |
| 310 frontend()->childNodeRemoved(parent_id, node_id); | |
| 259 } | 311 } |
| 260 | 312 |
| 261 void AshDevToolsDOMAgent::RemoveObserverFromAllWindows() { | 313 void AshDevToolsDOMAgent::RemoveObserverFromAllWindows() { |
| 262 for (auto& pair : window_to_node_id_map_) | 314 for (auto& pair : window_to_node_id_map_) |
| 263 pair.first->RemoveObserver(this); | 315 pair.first->RemoveObserver(this); |
| 264 } | 316 } |
| 265 | 317 |
| 266 void AshDevToolsDOMAgent::Reset() { | 318 void AshDevToolsDOMAgent::Reset() { |
| 267 RemoveObserverFromAllWindows(); | 319 RemoveObserverFromAllWindows(); |
| 268 window_to_node_id_map_.clear(); | 320 window_to_node_id_map_.clear(); |
| 269 widget_to_node_id_map_.clear(); | 321 widget_to_node_id_map_.clear(); |
| 270 view_to_node_id_map_.clear(); | 322 view_to_node_id_map_.clear(); |
| 271 node_id_to_window_map_.clear(); | 323 node_id_to_window_map_.clear(); |
| 272 node_id_to_widget_map_.clear(); | 324 node_id_to_widget_map_.clear(); |
| 273 node_id_to_view_map_.clear(); | 325 node_id_to_view_map_.clear(); |
| 274 node_ids = 1; | 326 node_ids = 1; |
| 275 } | 327 } |
| 276 | 328 |
| 277 } // namespace devtools | 329 } // namespace devtools |
| 278 } // namespace ash | 330 } // namespace ash |
| OLD | NEW |