| Index: components/ui_devtools/views/ui_devtools_dom_agent.cc
|
| diff --git a/components/ui_devtools/views/ui_devtools_dom_agent.cc b/components/ui_devtools/views/ui_devtools_dom_agent.cc
|
| index c4c3cbf59a8292ca6410d95cdfc23518f15237e9..503e4d0ec2d29f09199932bcfab9c9e2f07117ca 100644
|
| --- a/components/ui_devtools/views/ui_devtools_dom_agent.cc
|
| +++ b/components/ui_devtools/views/ui_devtools_dom_agent.cc
|
| @@ -5,6 +5,7 @@
|
| #include "components/ui_devtools/views/ui_devtools_dom_agent.h"
|
|
|
| #include "components/ui_devtools/devtools_server.h"
|
| +#include "components/ui_devtools/views/ui_devtools_overlay_agent.h"
|
| #include "components/ui_devtools/views/ui_element.h"
|
| #include "components/ui_devtools/views/view_element.h"
|
| #include "components/ui_devtools/views/widget_element.h"
|
| @@ -18,6 +19,7 @@
|
| #include "ui/display/screen.h"
|
| #include "ui/views/background.h"
|
| #include "ui/views/border.h"
|
| +#include "ui/views/pointer_watcher.h"
|
| #include "ui/views/view.h"
|
| #include "ui/views/widget/widget.h"
|
| #include "ui/wm/core/window_util.h"
|
| @@ -36,6 +38,7 @@ std::unique_ptr<DOM::Node> BuildNode(
|
| constexpr int kDomElementNodeType = 1;
|
| std::unique_ptr<DOM::Node> node = DOM::Node::create()
|
| .setNodeId(node_ids)
|
| + .setBackendNodeId(node_ids)
|
| .setNodeName(name)
|
| .setNodeType(kDomElementNodeType)
|
| .setAttributes(std::move(attributes))
|
| @@ -105,6 +108,7 @@ std::unique_ptr<DOM::Node> BuildDomNodeFromUIElement(UIElement* root) {
|
| constexpr int kDomElementNodeType = 1;
|
| std::unique_ptr<DOM::Node> node = DOM::Node::create()
|
| .setNodeId(root->node_id())
|
| + .setBackendNodeId(root->node_id())
|
| .setNodeName(root->GetTypeName())
|
| .setNodeType(kDomElementNodeType)
|
| .setAttributes(GetAttributes(root))
|
| @@ -114,6 +118,47 @@ std::unique_ptr<DOM::Node> BuildDomNodeFromUIElement(UIElement* root) {
|
| return node;
|
| }
|
|
|
| +int FindUIElementIdForView(UIElement* root, views::View* element) {
|
| + if (root->type() == UIElementType::VIEW &&
|
| + UIElement::GetBackingElement<views::View, ViewElement>(root) == element)
|
| + return root->node_id();
|
| +
|
| + for (auto* child : root->children()) {
|
| + int ui_element_id = FindUIElementIdForView(child, element);
|
| + if (ui_element_id)
|
| + return ui_element_id;
|
| + }
|
| + return 0;
|
| +}
|
| +
|
| +int FindUIElementIdForWidget(UIElement* root, views::Widget* element) {
|
| + if (root->type() == UIElementType::WIDGET &&
|
| + UIElement::GetBackingElement<views::Widget, WidgetElement>(root) ==
|
| + element)
|
| + return root->node_id();
|
| +
|
| + for (auto* child : root->children()) {
|
| + int ui_element_id = FindUIElementIdForWidget(child, element);
|
| + if (ui_element_id)
|
| + return ui_element_id;
|
| + }
|
| + return 0;
|
| +}
|
| +
|
| +int FindUIElementIdForWindow(UIElement* root, aura::Window* element) {
|
| + if (root->type() == UIElementType::WINDOW &&
|
| + UIElement::GetBackingElement<aura::Window, WindowElement>(root) ==
|
| + element)
|
| + return root->node_id();
|
| +
|
| + for (auto* child : root->children()) {
|
| + int ui_element_id = FindUIElementIdForWindow(child, element);
|
| + if (ui_element_id)
|
| + return ui_element_id;
|
| + }
|
| + return 0;
|
| +}
|
| +
|
| } // namespace
|
|
|
| UIDevToolsDOMAgent::UIDevToolsDOMAgent() : is_building_tree_(false) {
|
| @@ -136,19 +181,27 @@ ui_devtools::protocol::Response UIDevToolsDOMAgent::getDocument(
|
| return ui_devtools::protocol::Response::OK();
|
| }
|
|
|
| -ui_devtools::protocol::Response UIDevToolsDOMAgent::highlightNode(
|
| - std::unique_ptr<ui_devtools::protocol::DOM::HighlightConfig>
|
| - highlight_config,
|
| - ui_devtools::protocol::Maybe<int> node_id) {
|
| - return HighlightNode(std::move(highlight_config), node_id.fromJust());
|
| -}
|
| -
|
| ui_devtools::protocol::Response UIDevToolsDOMAgent::hideHighlight() {
|
| if (layer_for_highlighting_ && layer_for_highlighting_->visible())
|
| layer_for_highlighting_->SetVisible(false);
|
| return ui_devtools::protocol::Response::OK();
|
| }
|
|
|
| +ui_devtools::protocol::Response
|
| +UIDevToolsDOMAgent::pushNodesByBackendIdsToFrontend(
|
| + std::unique_ptr<protocol::Array<int>> backend_node_ids,
|
| + std::unique_ptr<protocol::Array<int>>* result) {
|
| + *result = protocol::Array<int>::create();
|
| + for (size_t index = 0; index < backend_node_ids->length(); ++index)
|
| + (*result)->addItem(backend_node_ids->get(index));
|
| + return ui_devtools::protocol::Response::OK();
|
| +}
|
| +
|
| +ui_devtools::protocol::Response UIDevToolsDOMAgent::setInspectedNode(
|
| + int node_id) {
|
| + return ui_devtools::protocol::Response::OK();
|
| +}
|
| +
|
| void UIDevToolsDOMAgent::OnUIElementAdded(UIElement* parent, UIElement* child) {
|
| // When parent is null, only need to update |node_id_to_ui_element_|.
|
| if (!parent) {
|
| @@ -205,6 +258,68 @@ UIElement* UIDevToolsDOMAgent::GetElementFromNodeId(int node_id) {
|
| return node_id_to_ui_element_[node_id];
|
| }
|
|
|
| +ui_devtools::protocol::Response UIDevToolsDOMAgent::HighlightNode(
|
| + std::unique_ptr<ui_devtools::protocol::Overlay::HighlightConfig>
|
| + highlight_config,
|
| + int node_id) {
|
| + if (!layer_for_highlighting_) {
|
| + layer_for_highlighting_.reset(
|
| + new ui::Layer(ui::LayerType::LAYER_SOLID_COLOR));
|
| + layer_for_highlighting_->set_name("HighlightingLayer");
|
| + }
|
| +
|
| + std::pair<aura::Window*, gfx::Rect> window_and_bounds =
|
| + node_id_to_ui_element_.count(node_id)
|
| + ? node_id_to_ui_element_[node_id]->GetNodeWindowAndBounds()
|
| + : std::make_pair<aura::Window*, gfx::Rect>(nullptr, gfx::Rect());
|
| +
|
| + if (!window_and_bounds.first) {
|
| + return ui_devtools::protocol::Response::Error("No node found with that id");
|
| + }
|
| + SkColor content_color =
|
| + RGBAToSkColor(highlight_config->getContentColor(nullptr));
|
| + UpdateHighlight(window_and_bounds, content_color);
|
| +
|
| + if (!layer_for_highlighting_->visible())
|
| + layer_for_highlighting_->SetVisible(true);
|
| +
|
| + return ui_devtools::protocol::Response::OK();
|
| +}
|
| +
|
| +void UIDevToolsDOMAgent::FindElementByEventHandler(const gfx::Point& p,
|
| + int* element_id) {
|
| + for (auto* element_window : window_element_root_->children()) {
|
| + aura::Window* window =
|
| + UIElement::GetBackingElement<aura::Window, WindowElement>(
|
| + element_window);
|
| + if (!window->bounds().Contains(p))
|
| + return;
|
| + aura::Window* point_window = window->GetEventHandlerForPoint(p);
|
| +
|
| + if (point_window) {
|
| + views::Widget* widget =
|
| + views::Widget::GetWidgetForNativeWindow(point_window);
|
| +
|
| + if (widget) {
|
| + views::View* view = widget->GetRootView();
|
| +
|
| + if (view) {
|
| + gfx::Point p_inside(p);
|
| + aura::Window::ConvertPointToTarget(window, point_window, &p_inside);
|
| + views::View* point_view = view->GetEventHandlerForPoint(p_inside);
|
| +
|
| + DCHECK(point_view);
|
| + *element_id = FindUIElementIdForView(element_window, point_view);
|
| + } else {
|
| + *element_id = FindUIElementIdForWidget(element_window, widget);
|
| + }
|
| + } else {
|
| + *element_id = FindUIElementIdForWindow(element_window, point_window);
|
| + }
|
| + }
|
| + }
|
| +}
|
| +
|
| void UIDevToolsDOMAgent::OnHostInitialized(aura::WindowTreeHost* host) {
|
| root_windows_.push_back(host->window());
|
| }
|
| @@ -353,32 +468,4 @@ void UIDevToolsDOMAgent::UpdateHighlight(
|
| layer_for_highlighting_->SetBounds(bounds);
|
| }
|
|
|
| -ui_devtools::protocol::Response UIDevToolsDOMAgent::HighlightNode(
|
| - std::unique_ptr<ui_devtools::protocol::DOM::HighlightConfig>
|
| - highlight_config,
|
| - int node_id) {
|
| - if (!layer_for_highlighting_) {
|
| - layer_for_highlighting_.reset(
|
| - new ui::Layer(ui::LayerType::LAYER_SOLID_COLOR));
|
| - layer_for_highlighting_->set_name("HighlightingLayer");
|
| - }
|
| -
|
| - std::pair<aura::Window*, gfx::Rect> window_and_bounds =
|
| - node_id_to_ui_element_.count(node_id)
|
| - ? node_id_to_ui_element_[node_id]->GetNodeWindowAndBounds()
|
| - : std::make_pair<aura::Window*, gfx::Rect>(nullptr, gfx::Rect());
|
| -
|
| - if (!window_and_bounds.first) {
|
| - return ui_devtools::protocol::Response::Error("No node found with that id");
|
| - }
|
| - SkColor content_color =
|
| - RGBAToSkColor(highlight_config->getContentColor(nullptr));
|
| - UpdateHighlight(window_and_bounds, content_color);
|
| -
|
| - if (!layer_for_highlighting_->visible())
|
| - layer_for_highlighting_->SetVisible(true);
|
| -
|
| - return ui_devtools::protocol::Response::OK();
|
| -}
|
| -
|
| } // namespace ui_devtools
|
|
|