Commit f5036cd4 authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Use the lowest targeter in parent chain.

The targeter can be null and in that case it should use the parents.

Bug: b/157910224
Test: covered by unittest. also tested manually. see bug for repro step.
Change-Id: I13db092a6ee062ef9547aec70b6f7cd077558e2d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2225854
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarJesse Schettler <jschettler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774375}
parent d729a010
......@@ -973,6 +973,24 @@ TEST_F(ShellSurfaceTest, PopupWithInputRegion) {
ui::Event::DispatcherApi(&event).set_target(target);
EXPECT_EQ(popup_surface.get(), GetTargetSurfaceForLocatedEvent(&event));
}
popup_surface.reset();
EXPECT_EQ(WMHelper::GetInstance()->GetCaptureClient()->GetCaptureWindow(),
nullptr);
auto window = std::make_unique<aura::Window>(nullptr);
window->Init(ui::LAYER_TEXTURED);
window->SetBounds(gfx::Rect(0, 0, 256, 256));
shell_surface->GetWidget()->GetNativeWindow()->AddChild(window.get());
window->Show();
{
// If non surface window covers the window,
/// GetTargetSurfaceForLocatedEvent should return nullptr.
ui::MouseEvent event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0),
gfx::Point(50, 50), ui::EventTimeForNow(), 0, 0);
ui::Event::DispatcherApi(&event).set_target(window.get());
EXPECT_EQ(nullptr, GetTargetSurfaceForLocatedEvent(&event));
}
}
TEST_F(ShellSurfaceTest, Caption) {
......
......@@ -58,6 +58,18 @@ bool ShouldHTComponentBlocked(int component) {
}
}
// Find the lowest targeter in the parent chain.
aura::WindowTargeter* FindTargeter(ui::EventTarget* target) {
do {
ui::EventTargeter* targeter = target->GetEventTargeter();
if (targeter)
return static_cast<aura::WindowTargeter*>(targeter);
target = target->GetParentTarget();
} while (target);
return nullptr;
}
} // namespace
void SetShellApplicationId(aura::Window* window,
......@@ -135,9 +147,10 @@ Surface* GetTargetSurfaceForLocatedEvent(
const ui::LocatedEvent* original_event) {
aura::Window* window =
WMHelper::GetInstance()->GetCaptureClient()->GetCaptureWindow();
if (!window)
if (!window) {
return Surface::AsSurface(
static_cast<aura::Window*>(original_event->target()));
}
Surface* main_surface = GetShellMainSurface(window);
// Skip if the event is captured by non exo windows.
......@@ -160,8 +173,8 @@ Surface* GetTargetSurfaceForLocatedEvent(
gfx::PointF location_in_target_f = event->location_f();
gfx::Point location_in_target = event->location();
ui::EventTarget* event_target = window;
aura::WindowTargeter* targeter =
static_cast<aura::WindowTargeter*>(event_target->GetEventTargeter());
aura::WindowTargeter* targeter = FindTargeter(event_target);
DCHECK(targeter);
aura::Window* focused =
static_cast<aura::Window*>(targeter->FindTargetForEvent(window, event));
......
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