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

Unified Diff: ash/common/devtools/ash_devtools_dom_agent.cc

Issue 2466073003: Push updates to inspector when windows are added, destroyed or reorganized (Closed)
Patch Set: Push updates to inspector when windows are added, destroyed or reorganized 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 side-by-side diff with in-line comments
Download patch
Index: ash/common/devtools/ash_devtools_dom_agent.cc
diff --git a/ash/common/devtools/ash_devtools_dom_agent.cc b/ash/common/devtools/ash_devtools_dom_agent.cc
index ebb928589c6de9927ce987adebbb71e9e501abf2..7c2f29eac3d58c1a54362e1062ced8a41ff3d72a 100644
--- a/ash/common/devtools/ash_devtools_dom_agent.cc
+++ b/ash/common/devtools/ash_devtools_dom_agent.cc
@@ -14,12 +14,12 @@ namespace devtools {
namespace {
using namespace ui::devtools::protocol;
+DOM::NodeId node_ids = 1;
std::unique_ptr<DOM::Node> BuildNode(
const std::string& name,
std::unique_ptr<Array<std::string>> attributes,
std::unique_ptr<Array<DOM::Node>> children) {
- static DOM::NodeId node_ids = 0;
constexpr int kDomElementNodeType = 1;
std::unique_ptr<DOM::Node> node = DOM::Node::create()
.setNodeId(node_ids++)
@@ -71,7 +71,41 @@ std::unique_ptr<DOM::Node> BuildTreeForRootWidget(views::Widget* widget) {
return BuildNode("Widget", GetAttributes(widget), std::move(children));
}
-std::unique_ptr<DOM::Node> BuildTreeForWindow(ash::WmWindow* window) {
+} // namespace
+
+AshDevToolsDOMAgent::AshDevToolsDOMAgent(ash::WmShell* shell) : shell_(shell) {
+ DCHECK(shell_);
+}
+
+AshDevToolsDOMAgent::~AshDevToolsDOMAgent() {
+ RemoveObserverFromRootWindows();
+}
+
+void AshDevToolsDOMAgent::disable(ui::devtools::protocol::ErrorString* error) {
+ RemoveObserverFromRootWindows();
+}
+
+void AshDevToolsDOMAgent::getDocument(
+ ui::devtools::protocol::ErrorString* error,
+ std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) {
+ Reset();
+ *out_root = BuildInitialTree();
+}
+
+void AshDevToolsDOMAgent::OnWindowTreeChanging(WmWindow* window,
sadrul 2016/11/02 02:04:36 I don't think this gets called if sibling windows
Sarmad Hashmi 2016/11/03 01:42:17 Done.
+ const TreeChangeParams& params) {
+ // If there is an old_parent + new_parent, then this window is being moved
+ // which requires a remove followed by an add. If only old_parent exists, then
+ // this is being destroyed, only remove is called. Finally, if only new_parent
+ // exists, then this is being created so only add is called.
+ if (params.old_parent)
+ RemoveWindowNode(params.target);
+ if (params.new_parent)
+ AddWindowNode(params.target, params.new_parent);
+}
+
+std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForWindow(
+ ash::WmWindow* window) {
std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
for (ash::WmWindow* child : window->GetChildren()) {
children->addItem(BuildTreeForWindow(child));
@@ -79,17 +113,12 @@ std::unique_ptr<DOM::Node> BuildTreeForWindow(ash::WmWindow* window) {
if (widget)
children->addItem(BuildTreeForRootWidget(widget));
}
- return BuildNode("Window", GetAttributes(window), std::move(children));
-}
-
-} // namespace
-
-AshDevToolsDOMAgent::AshDevToolsDOMAgent(ash::WmShell* shell) : shell_(shell) {
- DCHECK(shell_);
+ std::unique_ptr<ui::devtools::protocol::DOM::Node> node =
+ BuildNode("Window", GetAttributes(window), std::move(children));
+ window_to_node_id_map_[window] = node->getNodeId();
+ return node;
}
-AshDevToolsDOMAgent::~AshDevToolsDOMAgent() {}
-
std::unique_ptr<ui::devtools::protocol::DOM::Node>
AshDevToolsDOMAgent::BuildInitialTree() {
std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
@@ -99,10 +128,41 @@ AshDevToolsDOMAgent::BuildInitialTree() {
return BuildNode("root", nullptr, std::move(children));
}
-void AshDevToolsDOMAgent::getDocument(
- ui::devtools::protocol::ErrorString* error,
- std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) {
- *out_root = BuildInitialTree();
+void AshDevToolsDOMAgent::AddWindowNode(WmWindow* window, WmWindow* parent) {
+ frontend()->childNodeInserted(window_to_node_id_map_[parent], 0,
sadrul 2016/11/02 02:04:36 Should 'prev_sibling' be correctly computed? (e.g.
Sarmad Hashmi 2016/11/03 01:42:17 Done.
+ BuildTreeForWindow(window));
+}
+
+void AshDevToolsDOMAgent::RemoveWindowNode(WmWindow* window) {
+ WindowToNodeIdMap::iterator it = window_to_node_id_map_.find(window);
+ DCHECK(it != window_to_node_id_map_.end());
+
+ int node_id = it->second;
+ int parent_id =
+ window->GetParent() ? window_to_node_id_map_[window->GetParent()] : 0;
sadrul 2016/11/02 02:04:36 window->GetParent() should never be null here, rig
Sarmad Hashmi 2016/11/03 01:42:18 Discussed in-person. It can be null for root windo
+
+ window_to_node_id_map_.erase(it);
+ frontend()->childNodeRemoved(parent_id, node_id);
+}
+
+void AshDevToolsDOMAgent::AddObserverToRootWindows() {
+ // TODO(mhashmi): Use ShellObserver events to add observers to new root
+ // windows
+ for (ash::WmWindow* window : shell_->GetAllRootWindows()) {
+ window->AddObserver(this);
sadrul 2016/11/02 02:04:36 No {}
Sarmad Hashmi 2016/11/03 01:42:17 Done.
+ }
+}
+
+void AshDevToolsDOMAgent::RemoveObserverFromRootWindows() {
+ for (ash::WmWindow* window : shell_->GetAllRootWindows()) {
sadrul 2016/11/02 02:04:36 ditto
Sarmad Hashmi 2016/11/03 01:42:18 Done.
+ window->RemoveObserver(this);
+ }
+}
+
+void AshDevToolsDOMAgent::Reset() {
+ AddObserverToRootWindows();
+ window_to_node_id_map_.clear();
+ node_ids = 1;
}
} // namespace devtools

Powered by Google App Engine
This is Rietveld 408576698