Commit 58171a8d authored by Leonard Grey's avatar Leonard Grey Committed by Commit Bot

UIDevTools: Feed mouse event directly into FindElementIdTargetedByPoint

No behavior change intended, just pushing some code into the function
from the callsite. This will allow Mac to use the same interface, but
with mouse events targeting widgets instead of aura::Windows.

Bug: 769352
Change-Id: Ibfec8c567b6e28b1d9b77bf6a7c388e1b69e3395
Reviewed-on: https://chromium-review.googlesource.com/1237115
Commit-Queue: Leonard Grey <lgrey@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594718}
parent 67117548
......@@ -407,8 +407,10 @@ protocol::Response OverlayAgentAura::hideHighlight() {
}
int OverlayAgentAura::FindElementIdTargetedByPoint(
const gfx::Point& p,
gfx::NativeWindow root_window) const {
ui::LocatedEvent* event) const {
gfx::Point p = event->root_location();
aura::Window* target = static_cast<aura::Window*>(event->target());
gfx::NativeWindow root_window = target->GetRootWindow();
gfx::NativeWindow targeted_window = root_window->GetEventHandlerForPoint(p);
if (!targeted_window)
return 0;
......@@ -560,9 +562,7 @@ void OverlayAgentAura::OnMouseEvent(ui::MouseEvent* event) {
}
// Find node id of element whose bounds contain the mouse pointer location.
aura::Window* target = static_cast<aura::Window*>(event->target());
int element_id = FindElementIdTargetedByPoint(event->root_location(),
target->GetRootWindow());
int element_id = FindElementIdTargetedByPoint(event);
if (pinned_id_ == element_id) {
event->SetHandled();
......
......@@ -54,13 +54,11 @@ class OverlayAgentAura : public OverlayAgent,
return highlight_rect_config_;
};
// Return the id of the UI element targeted by an event located at |p|, where
// |p| is in the local coodinate space of |root_window|. The function
// first searches for the targeted window, then the targeted widget (if one
// exists), then the targeted view (if one exists). Return 0 if no valid
// target is found.
int FindElementIdTargetedByPoint(const gfx::Point& p,
gfx::NativeWindow root_window) const;
// Return the id of the UI element located at |event|'s root location.
// The function first searches for the targeted window, then the targeted
// widget (if one exists), then the targeted view (if one exists). Return 0 if
// no valid target is found.
int FindElementIdTargetedByPoint(ui::LocatedEvent* event) const;
// Shows the distances between the nodes identified by |pinned_id| and
// |element_id| in the highlight overlay.
......
......@@ -17,6 +17,7 @@
#include "ui/aura/client/window_parenting_client.h"
#include "ui/aura/window_tree_host.h"
#include "ui/display/display.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event_constants.h"
#include "ui/events/test/event_generator.h"
#include "ui/views/background.h"
......@@ -254,6 +255,14 @@ class UIDevToolsTest : public views::ViewsTestBase {
return dom_agent()->root_windows()[0];
}
std::unique_ptr<ui::MouseEvent> MouseEventAtRootLocation(gfx::Point p) {
auto event = std::make_unique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, p, p,
ui::EventTimeForNow(),
ui::EF_NONE, ui::EF_NONE);
ui::Event::DispatcherApi(event.get()).set_target(GetPrimaryRootWindow());
return event;
}
CSSAgent* css_agent() { return css_agent_.get(); }
DOMAgentAura* dom_agent() { return dom_agent_.get(); }
OverlayAgentAura* overlay_agent() { return overlay_agent_.get(); }
......@@ -280,7 +289,7 @@ TEST_F(UIDevToolsTest, FindElementIdTargetedByPoint) {
std::unique_ptr<DOM::Node> root;
dom_agent()->getDocument(&root);
EXPECT_NE(0, overlay_agent()->FindElementIdTargetedByPoint(
gfx::Point(1, 1), GetPrimaryRootWindow()));
MouseEventAtRootLocation(gfx::Point(1, 1)).get()));
}
// Test case R1_CONTAINS_R2.
......@@ -295,9 +304,9 @@ TEST_F(UIDevToolsTest, OneUIElementContainsAnother) {
dom_agent()->getDocument(&root);
int outside_rect_id = overlay_agent()->FindElementIdTargetedByPoint(
outside_rect.origin(), GetPrimaryRootWindow());
MouseEventAtRootLocation(outside_rect.origin()).get());
int inside_rect_id = overlay_agent()->FindElementIdTargetedByPoint(
inside_rect.origin(), GetPrimaryRootWindow());
MouseEventAtRootLocation(inside_rect.origin()).get());
overlay_agent()->ShowDistancesInHighlightOverlay(outside_rect_id,
inside_rect_id);
......@@ -337,9 +346,9 @@ TEST_F(UIDevToolsTest, OneUIElementStaysHorizontalAndLeftOfAnother) {
dom_agent()->getDocument(&root);
int outside_rect_id = overlay_agent()->FindElementIdTargetedByPoint(
outside_rect.origin(), GetPrimaryRootWindow());
MouseEventAtRootLocation(outside_rect.origin()).get());
int inside_rect_id = overlay_agent()->FindElementIdTargetedByPoint(
inside_rect.origin(), GetPrimaryRootWindow());
MouseEventAtRootLocation(inside_rect.origin()).get());
overlay_agent()->ShowDistancesInHighlightOverlay(outside_rect_id,
inside_rect_id);
......@@ -381,9 +390,9 @@ TEST_F(UIDevToolsTest, OneUIElementStaysFullyTopLeftOfAnother) {
dom_agent()->getDocument(&root);
int top_left_rect_id = overlay_agent()->FindElementIdTargetedByPoint(
top_left_rect.origin(), GetPrimaryRootWindow());
MouseEventAtRootLocation(top_left_rect.origin()).get());
int bottom_right_rect_id = overlay_agent()->FindElementIdTargetedByPoint(
bottom_right_rect.origin(), GetPrimaryRootWindow());
MouseEventAtRootLocation(bottom_right_rect.origin()).get());
overlay_agent()->ShowDistancesInHighlightOverlay(top_left_rect_id,
bottom_right_rect_id);
......@@ -425,9 +434,9 @@ TEST_F(UIDevToolsTest, OneUIElementStaysFullyBottomLeftOfAnother) {
dom_agent()->getDocument(&root);
int bottom_left_rect_id = overlay_agent()->FindElementIdTargetedByPoint(
bottom_left_rect.origin(), GetPrimaryRootWindow());
MouseEventAtRootLocation(bottom_left_rect.origin()).get());
int top_right_rect_id = overlay_agent()->FindElementIdTargetedByPoint(
top_right_rect.origin(), GetPrimaryRootWindow());
MouseEventAtRootLocation(top_right_rect.origin()).get());
overlay_agent()->ShowDistancesInHighlightOverlay(bottom_left_rect_id,
top_right_rect_id);
......@@ -470,9 +479,9 @@ TEST_F(UIDevToolsTest, OneUIElementStaysPartiallyTopLeftOfAnother) {
dom_agent()->getDocument(&root);
int top_left_rect_id = overlay_agent()->FindElementIdTargetedByPoint(
top_left_rect.origin(), GetPrimaryRootWindow());
MouseEventAtRootLocation(top_left_rect.origin()).get());
int bottom_right_rect_id = overlay_agent()->FindElementIdTargetedByPoint(
bottom_right_rect.origin(), GetPrimaryRootWindow());
MouseEventAtRootLocation(bottom_right_rect.origin()).get());
overlay_agent()->ShowDistancesInHighlightOverlay(top_left_rect_id,
bottom_right_rect_id);
......@@ -514,9 +523,9 @@ TEST_F(UIDevToolsTest, OneUIElementStaysPartiallyBottomLeftOfAnother) {
dom_agent()->getDocument(&root);
int bottom_left_rect_id = overlay_agent()->FindElementIdTargetedByPoint(
bottom_left_rect.origin(), GetPrimaryRootWindow());
MouseEventAtRootLocation(bottom_left_rect.origin()).get());
int top_right_rect_id = overlay_agent()->FindElementIdTargetedByPoint(
top_right_rect.origin(), GetPrimaryRootWindow());
MouseEventAtRootLocation(top_right_rect.origin()).get());
overlay_agent()->ShowDistancesInHighlightOverlay(bottom_left_rect_id,
top_right_rect_id);
......@@ -556,9 +565,9 @@ TEST_F(UIDevToolsTest, OneUIElementIntersectsAnother) {
dom_agent()->getDocument(&root);
int left_rect_id = overlay_agent()->FindElementIdTargetedByPoint(
left_rect.origin(), GetPrimaryRootWindow());
MouseEventAtRootLocation(left_rect.origin()).get());
int right_rect_id = overlay_agent()->FindElementIdTargetedByPoint(
right_rect.origin(), GetPrimaryRootWindow());
MouseEventAtRootLocation(right_rect.origin()).get());
overlay_agent()->ShowDistancesInHighlightOverlay(left_rect_id, right_rect_id);
HighlightRectsConfiguration highlight_rect_config =
......@@ -594,8 +603,8 @@ TEST_F(UIDevToolsTest, MouseEventsGenerateFEEventsInInspectMode) {
dom_agent()->getDocument(&root);
gfx::Point p(1, 1);
int node_id =
overlay_agent()->FindElementIdTargetedByPoint(p, GetPrimaryRootWindow());
int node_id = overlay_agent()->FindElementIdTargetedByPoint(
MouseEventAtRootLocation(p).get());
EXPECT_EQ(0, GetOverlayInspectNodeRequestedCount(node_id));
EXPECT_EQ(0, GetOverlayNodeHighlightRequestedCount(node_id));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment