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

Unified 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: sadruls comments 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
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 f3f3c85322409cdc3427728a1e89feb8c0b004bd..16e9059bdf585407db664ea77fbda7455c25e826 100644
--- a/ash/common/devtools/ash_devtools_dom_agent.cc
+++ b/ash/common/devtools/ash_devtools_dom_agent.cc
@@ -4,10 +4,9 @@
#include "ash/common/devtools/ash_devtools_dom_agent.h"
+#include "ash/common/wm_lookup.h"
#include "ash/common/wm_window.h"
#include "components/ui_devtools/devtools_server.h"
-#include "ui/views/view.h"
-#include "ui/views/widget/widget.h"
namespace ash {
namespace devtools {
@@ -57,19 +56,6 @@ std::unique_ptr<Array<std::string>> GetAttributes(const views::View* view) {
return attributes;
}
-std::unique_ptr<DOM::Node> BuildTreeForView(views::View* view) {
- std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
- for (int i = 0, count = view->child_count(); i < count; i++) {
- children->addItem(BuildTreeForView(view->child_at(i)));
- }
- return BuildNode("View", GetAttributes(view), std::move(children));
-}
-
-std::unique_ptr<DOM::Node> BuildTreeForRootWidget(views::Widget* widget) {
- std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
- children->addItem(BuildTreeForView(widget->GetRootView()));
- return BuildNode("Widget", GetAttributes(widget), std::move(children));
-}
WmWindow* FindPreviousSibling(WmWindow* window) {
std::vector<WmWindow*> siblings = window->GetParent()->GetChildren();
@@ -132,6 +118,60 @@ void AshDevToolsDOMAgent::OnWindowStackingChanged(WmWindow* window) {
AddWindowNode(window);
}
+WmWindow* AshDevToolsDOMAgent::GetWindowFromNodeId(int nodeId) {
+ return node_id_to_window_map_.count(nodeId) ? node_id_to_window_map_[nodeId]
+ : nullptr;
+}
+
+views::Widget* AshDevToolsDOMAgent::GetWidgetFromNodeId(int nodeId) {
+ return node_id_to_widget_map_.count(nodeId) ? node_id_to_widget_map_[nodeId]
+ : nullptr;
+}
+
+views::View* AshDevToolsDOMAgent::GetViewFromNodeId(int nodeId) {
+ return node_id_to_view_map_.count(nodeId) ? node_id_to_view_map_[nodeId]
+ : nullptr;
+}
+
+int AshDevToolsDOMAgent::GetNodeIdFromWindow(WmWindow* window) {
+ DCHECK(window_to_node_id_map_.count(window));
+ return window_to_node_id_map_[window];
+}
+
+int AshDevToolsDOMAgent::GetNodeIdFromWidget(views::Widget* widget) {
+ DCHECK(widget_to_node_id_map_.count(widget));
+ return widget_to_node_id_map_[widget];
+}
+
+int AshDevToolsDOMAgent::GetNodeIdFromView(views::View* view) {
+ DCHECK(view_to_node_id_map_.count(view));
+ return view_to_node_id_map_[view];
+}
+
+std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForView(
+ views::View* view) {
+ std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
+ for (int i = 0, count = view->child_count(); i < count; i++) {
+ children->addItem(BuildTreeForView(view->child_at(i)));
+ }
+ std::unique_ptr<ui::devtools::protocol::DOM::Node> node =
+ BuildNode("View", GetAttributes(view), std::move(children));
+ view_to_node_id_map_[view] = node->getNodeId();
+ node_id_to_view_map_[node->getNodeId()] = view;
+ return node;
+}
+
+std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForRootWidget(
+ views::Widget* widget) {
+ std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
+ children->addItem(BuildTreeForView(widget->GetRootView()));
+ std::unique_ptr<ui::devtools::protocol::DOM::Node> node =
+ BuildNode("Widget", GetAttributes(widget), std::move(children));
+ widget_to_node_id_map_[widget] = node->getNodeId();
+ node_id_to_widget_map_[node->getNodeId()] = widget;
+ return node;
+}
+
std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForWindow(
ash::WmWindow* window) {
std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
@@ -147,6 +187,7 @@ std::unique_ptr<DOM::Node> AshDevToolsDOMAgent::BuildTreeForWindow(
if (!window_to_node_id_map_.count(window))
window->AddObserver(this);
window_to_node_id_map_[window] = node->getNodeId();
+ node_id_to_window_map_[node->getNodeId()] = window;
return node;
}
@@ -171,18 +212,52 @@ void AshDevToolsDOMAgent::AddWindowNode(WmWindow* window) {
void AshDevToolsDOMAgent::RemoveWindowNode(WmWindow* window) {
WmWindow* parent = window->GetParent();
DCHECK(parent);
- DCHECK(window_to_node_id_map_.count(parent));
- WindowToNodeIdMap::iterator it = window_to_node_id_map_.find(window);
- DCHECK(it != window_to_node_id_map_.end());
+ WindowToNodeIdMap::iterator window_to_node_id_it =
+ window_to_node_id_map_.find(window);
+ DCHECK(window_to_node_id_it != window_to_node_id_map_.end());
+
+ int node_id = window_to_node_id_it->second;
+ int parent_id = GetNodeIdFromWindow(parent);
- int node_id = it->second;
- int parent_id = window_to_node_id_map_[parent];
+ NodeIdToWindowMap::iterator node_id_to_window_it =
+ node_id_to_window_map_.find(node_id);
+ DCHECK(node_id_to_window_it != node_id_to_window_map_.end());
+
+ views::Widget* widget = window->GetInternalWidget();
+ if (widget)
+ RemoveWidgetNode(widget);
window->RemoveObserver(this);
- window_to_node_id_map_.erase(it);
+ node_id_to_window_map_.erase(node_id_to_window_it);
+ window_to_node_id_map_.erase(window_to_node_id_it);
+ frontend()->childNodeRemoved(parent_id, node_id);
+}
+
+void AshDevToolsDOMAgent::RemoveWidgetNode(views::Widget* widget) {
+ WidgetToNodeIdMap::iterator widget_to_node_id_it =
+ widget_to_node_id_map_.find(widget);
+ DCHECK(widget_to_node_id_it != widget_to_node_id_map_.end());
+
+ int node_id = widget_to_node_id_it->second;
+ int parent_id =
+ GetNodeIdFromWindow(WmLookup::Get()->GetWindowForWidget(widget));
+
+ RemoveViewNode(widget->GetRootView());
+
+ NodeIdToWidgetMap::iterator node_id_to_widget_it =
+ node_id_to_widget_map_.find(node_id);
+ DCHECK(node_id_to_widget_it != node_id_to_widget_map_.end());
+
+ widget_to_node_id_map_.erase(widget_to_node_id_it);
+ node_id_to_widget_map_.erase(node_id_to_widget_it);
frontend()->childNodeRemoved(parent_id, node_id);
}
+void AshDevToolsDOMAgent::RemoveViewNode(views::View* view) {
+ // TODO(mhashmi): Add observers to views/widgets so new views exist
+ // in the map and can be removed here
+}
+
void AshDevToolsDOMAgent::RemoveObserverFromAllWindows() {
for (auto& pair : window_to_node_id_map_)
pair.first->RemoveObserver(this);
@@ -191,6 +266,11 @@ void AshDevToolsDOMAgent::RemoveObserverFromAllWindows() {
void AshDevToolsDOMAgent::Reset() {
RemoveObserverFromAllWindows();
window_to_node_id_map_.clear();
+ widget_to_node_id_map_.clear();
+ view_to_node_id_map_.clear();
+ node_id_to_window_map_.clear();
+ node_id_to_widget_map_.clear();
+ node_id_to_view_map_.clear();
node_ids = 1;
}
« 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