Chromium Code Reviews| 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 3adba64ea7dd680169318f3096a0bed53624b176..3f551b4cd6e7d804696953b185923889bcbcfa49 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" |
| @@ -114,9 +116,31 @@ std::unique_ptr<DOM::Node> BuildDomNodeFromUIElement(UIElement* root) { |
| return node; |
| } |
| +void FindElement(UIElement* root, |
| + const int x, |
| + const int y, |
|
sadrul
2017/07/13 20:17:20
Take a const gfx::Point& as the location input.
thanhph
2017/07/14 16:59:46
Done.
|
| + int* min_bounds, |
| + int* element_id) { |
| + LOG(ERROR) << "FindElement root->node_id(): " << root->node_id(); |
| + gfx::Rect bounds; |
| + for (auto* child : root->children()) { |
| + child->GetBounds(&bounds); |
| + if (bounds.x() <= x && bounds.y() <= y && bounds.right() >= x && |
| + bounds.bottom() >= y && |
|
sadrul
2017/07/13 20:17:20
Use gfx::Rect::Contains(gfx::Point)
thanhph
2017/07/14 16:59:46
Done.
|
| + (*min_bounds) > bounds.width() + bounds.height()) { |
| + *element_id = child->node_id(); |
| + *min_bounds = bounds.width() + bounds.height(); |
|
sadrul
2017/07/13 20:17:20
I don't understand why you need |min_bounds| here.
thanhph
2017/07/14 16:59:46
Acknowledged. We just select the deepest element i
|
| + LOG(ERROR) << "*min_bounds: " << *min_bounds; |
| + LOG(ERROR) << "*element_id: " << *element_id; |
| + } |
| + FindElement(child, x, y, min_bounds, element_id); |
| + } |
| +} |
| + |
| } // namespace |
| -UIDevToolsDOMAgent::UIDevToolsDOMAgent() : is_building_tree_(false) { |
| +UIDevToolsDOMAgent::UIDevToolsDOMAgent(UIDevToolsOverlayAgent* overlay_agent) |
| + : overlay_agent_(overlay_agent), is_building_tree_(false) { |
| aura::Env::GetInstance()->AddObserver(this); |
| } |
| @@ -143,6 +167,20 @@ ui_devtools::protocol::Response UIDevToolsDOMAgent::highlightNode( |
| return HighlightNode(std::move(highlight_config), node_id.fromJust()); |
| } |
| +ui_devtools::protocol::Response UIDevToolsDOMAgent::setInspectMode( |
| + ui_devtools::protocol::Maybe<String> mode, |
| + std::unique_ptr<ui_devtools::protocol::DOM::HighlightConfig> |
| + highlight_config, |
| + ui_devtools::protocol::Maybe<int> node_id) { |
| + LOG(ERROR) << __PRETTY_FUNCTION__; |
| + if (mode.fromJust().compare("searchForUAShadowDOM") == 0) |
| + aura::Env::GetInstance()->PrependPreTargetHandler(this); |
| + else if (mode.fromJust().compare("none") == 0) |
| + aura::Env::GetInstance()->RemovePreTargetHandler(this); |
| + |
| + return ui_devtools::protocol::Response::OK(); |
| +} |
| + |
| ui_devtools::protocol::Response UIDevToolsDOMAgent::hideHighlight() { |
| if (widget_for_highlighting_ && widget_for_highlighting_->IsVisible()) |
| widget_for_highlighting_->Hide(); |
| @@ -198,6 +236,38 @@ bool UIDevToolsDOMAgent::IsHighlightingWindow(aura::Window* window) { |
| GetWidgetFromWindow(window) == widget_for_highlighting_.get(); |
| } |
| +void UIDevToolsDOMAgent::OnMouseEvent(ui::MouseEvent* event) { |
| + if (!window_element_root_) |
| + return; |
| + |
| + if (event->type() == ui::ET_MOUSE_PRESSED) { |
| + // TODO(thanhph): needs to disable the highlighting inspection arrow. |
| + frontend()->setInspectMode(Maybe<ui_devtools::String>("none")); |
| + overlay_agent_->setInspectMode( |
| + "none", protocol::Maybe<protocol::Overlay::HighlightConfig>()); |
| + aura::Env::GetInstance()->RemovePreTargetHandler(this); |
| + return; |
| + } |
| + if (event->type() != ui::ET_MOUSEWHEEL) |
| + return; |
| + |
| + // maxmium of width + height of a screen. |
| + int min_bounds = 1000000; |
| + |
| + // Node id of the element whose bounds contain the mouse pointer location. |
| + int element_id = 1; |
| + FindElement(window_element_root_.get(), event->location().x(), |
|
sadrul
2017/07/13 20:17:20
event->location() is in the coordinate space of |e
thanhph
2017/07/14 16:59:46
I picked the 1st approach.
|
| + event->location().y(), &min_bounds, &element_id); |
| + LOG(ERROR) << "Find - event->location().x():" << event->location().x() |
| + << "event->location().y(): " << event->location().y(); |
| + gfx::Rect bounds1; |
| + node_id_to_ui_element_[element_id]->GetBounds(&bounds1); |
| + LOG(ERROR) << "bounds1 node_id_to_ui_element_[element_id]: " << bounds1.x() |
| + << " - " << bounds1.y() << " - " << bounds1.right() << " - " |
| + << bounds1.bottom(); |
| + frontend()->nodeHighlightRequested(element_id); |
| +} |
| + |
| void UIDevToolsDOMAgent::AddObserver(UIDevToolsDOMAgentObserver* observer) { |
| observers_.AddObserver(observer); |
| } |