Skip to content

Commit

Permalink
Avoid two targeting phases in aura client-lib and EventProcessor.
Browse files Browse the repository at this point in the history
1. Client-lib now skips the step where it converted the event location from
target window's coordinate system to root window's coordinate system; and
sets the target window received from mus-ws to be the target for that event.

2. Added two virtual functions in EventProcessor responsible for getting the
window with the right targeter (either root window or the farthest ancestor
with a targeter set) and for getting the default targeter (WindowTargeter)
respectively.

3. WindowEventDispatcher now is responsible for finding the right target and
doing the conversion between their coordinate systems.

4. WindowTreeHost only sets a targeter for the root window in non-mus mode
so that we don't end up walking all the way up to the root window just to use
the default event targeter.

This also solves the bug where we were using DIP for conversion in the
client-lib but event location was still in pixels at that time.

BUG=687700
TEST=aura_unittests
     manual (--force-device-scale-factor=2)

Review-Url: https://codereview.chromium.org/2681613002
Cr-Commit-Position: refs/heads/master@{#452393}
  • Loading branch information
riaj authored and Commit bot committed Feb 23, 2017
1 parent 73b3f25 commit 6b3d980
Show file tree
Hide file tree
Showing 26 changed files with 477 additions and 70 deletions.
5 changes: 3 additions & 2 deletions ash/root_window_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,9 @@ WmWindow* RootWindowController::FindEventTarget(
location_in_root, ui::EventTimeForNow(),
ui::EF_NONE, ui::EF_NONE);
ui::EventTarget* event_handler =
static_cast<ui::EventTarget*>(root_window)
->GetEventTargeter()
root_window->GetHost()
->dispatcher()
->GetDefaultEventTargeter()
->FindTargetForEvent(root_window, &test_event);
return WmWindow::Get(static_cast<aura::Window*>(event_handler));
}
Expand Down
10 changes: 6 additions & 4 deletions ash/shelf/shelf_widget_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ TEST_F(ShelfWidgetTest, ShelfEdgeOverlappingWindowHitTestMouse) {
gfx::Rect widget_bounds = widget->GetWindowBoundsInScreen();
EXPECT_TRUE(widget_bounds.Intersects(shelf_bounds));

ui::EventTarget* root = widget->GetNativeWindow()->GetRootWindow();
ui::EventTargeter* targeter = root->GetEventTargeter();
aura::Window* root = widget->GetNativeWindow()->GetRootWindow();
ui::EventTargeter* targeter =
root->GetHost()->dispatcher()->GetDefaultEventTargeter();
{
// Create a mouse-event targeting the top of the shelf widget. The
// window-targeter should find |widget| as the target (instead of the
Expand Down Expand Up @@ -290,8 +291,9 @@ TEST_F(ShelfWidgetTest, HiddenShelfHitTestTouch) {
widget->Init(params);
widget->Show();

ui::EventTarget* root = shelf_widget->GetNativeWindow()->GetRootWindow();
ui::EventTargeter* targeter = root->GetEventTargeter();
aura::Window* root = shelf_widget->GetNativeWindow()->GetRootWindow();
ui::EventTargeter* targeter =
root->GetHost()->dispatcher()->GetDefaultEventTargeter();
// Touch just over the shelf. Since the shelf is visible, the window-targeter
// should not find the shelf as the target.
{
Expand Down
5 changes: 3 additions & 2 deletions ash/wm/immersive_fullscreen_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,9 @@ TEST_F(ImmersiveFullscreenControllerTest, EventsDoNotLeakToWindowUnderneath) {

ui::TouchEvent touch(ui::ET_TOUCH_MOVED, gfx::Point(10, top), 0,
ui::EventTimeForNow());
ui::EventTarget* root = window()->GetRootWindow();
ui::EventTargeter* targeter = root->GetEventTargeter();
aura::Window* root = window()->GetRootWindow();
ui::EventTargeter* targeter =
root->GetHost()->dispatcher()->GetDefaultEventTargeter();
EXPECT_EQ(window(), targeter->FindTargetForEvent(root, &touch));

SetEnabled(true);
Expand Down
3 changes: 2 additions & 1 deletion ash/wm/overview/window_selector_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,8 @@ TEST_F(WindowSelectorTest, WindowDoesNotReceiveEvents) {
ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);

ui::EventTarget* root_target = root_window;
ui::EventTargeter* targeter = root_target->GetEventTargeter();
ui::EventTargeter* targeter =
root_window->GetHost()->dispatcher()->GetDefaultEventTargeter();

// The event should target the window because we are still not in overview
// mode.
Expand Down
5 changes: 3 additions & 2 deletions ash/wm/panels/panel_layout_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -839,8 +839,9 @@ TEST_F(PanelLayoutManagerTest, TouchHitTestPanel) {
aura::test::TestWindowDelegate delegate;
std::unique_ptr<aura::Window> w(
CreatePanelWindowWithDelegate(&delegate, gfx::Rect(0, 0, 200, 200)));
ui::EventTarget* root = w->GetRootWindow();
ui::EventTargeter* targeter = root->GetEventTargeter();
aura::Window* root = w->GetRootWindow();
ui::EventTargeter* targeter =
root->GetHost()->dispatcher()->GetDefaultEventTargeter();

// Note that the constants used in the touch locations below are
// arbitrarily-selected small numbers which will ensure the point is
Expand Down
20 changes: 12 additions & 8 deletions ash/wm/workspace_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1481,8 +1481,9 @@ TEST_F(WorkspaceControllerTest, WindowEdgeHitTest) {
ParentWindowInPrimaryRootWindow(second.get());
second->Show();

ui::EventTarget* root = first->GetRootWindow();
ui::EventTargeter* targeter = root->GetEventTargeter();
aura::Window* root = first->GetRootWindow();
ui::EventTargeter* targeter =
root->GetHost()->dispatcher()->GetDefaultEventTargeter();

// The windows overlap, and |second| is on top of |first|. Events targeted
// slightly outside the edges of the |second| window should still be targeted
Expand Down Expand Up @@ -1530,8 +1531,9 @@ TEST_F(WorkspaceControllerTest, WindowEdgeMouseHitTestPanel) {
aura::test::TestWindowDelegate delegate;
std::unique_ptr<Window> window(
CreateTestPanel(&delegate, gfx::Rect(20, 10, 100, 50)));
ui::EventTarget* root = window->GetRootWindow();
ui::EventTargeter* targeter = root->GetEventTargeter();
aura::Window* root = window->GetRootWindow();
ui::EventTargeter* targeter =
root->GetHost()->dispatcher()->GetDefaultEventTargeter();
const gfx::Rect bounds = window->bounds();
const int kNumPoints = 5;
struct {
Expand Down Expand Up @@ -1566,8 +1568,9 @@ TEST_F(WorkspaceControllerTest, WindowEdgeTouchHitTestPanel) {
aura::test::TestWindowDelegate delegate;
std::unique_ptr<Window> window(
CreateTestPanel(&delegate, gfx::Rect(20, 10, 100, 50)));
ui::EventTarget* root = window->GetRootWindow();
ui::EventTargeter* targeter = root->GetEventTargeter();
aura::Window* root = window->GetRootWindow();
ui::EventTargeter* targeter =
root->GetHost()->dispatcher()->GetDefaultEventTargeter();
const gfx::Rect bounds = window->bounds();
const int kNumPoints = 5;
struct {
Expand Down Expand Up @@ -1607,8 +1610,9 @@ TEST_F(WorkspaceControllerTest, WindowEdgeHitTestDocked) {
window->GetRootWindow(), kShellWindowId_DockedContainer);
docked_container->AddChild(window.get());
window->Show();
ui::EventTarget* root = window->GetRootWindow();
ui::EventTargeter* targeter = root->GetEventTargeter();
aura::Window* root = window->GetRootWindow();
ui::EventTargeter* targeter =
root->GetHost()->dispatcher()->GetDefaultEventTargeter();
const gfx::Rect bounds = window->bounds();
const int kNumPoints = 5;
struct {
Expand Down
2 changes: 2 additions & 0 deletions ui/aura/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ static_library("test_support") {
"test/test_window_delegate.h",
"test/test_window_parenting_client.cc",
"test/test_window_parenting_client.h",
"test/test_window_targeter.cc",
"test/test_window_targeter.h",
"test/test_windows.cc",
"test/test_windows.h",
"test/ui_controls_factory_aura.h",
Expand Down
28 changes: 12 additions & 16 deletions ui/aura/mus/window_tree_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ void ConvertEventLocationToDip(int64_t display_id, ui::LocatedEvent* event) {
event->set_root_location(root_location);
}

// Set the |target| to be the target window of this |event| and send it to
// the EventProcessor.
void DispatchEventToTarget(ui::Event* event, WindowMus* target) {
ui::Event::DispatcherApi dispatch_helper(event);
dispatch_helper.set_target(target->GetWindow());
GetWindowTreeHostMus(target)->SendEventToProcessor(event);
}

} // namespace

WindowTreeClient::WindowTreeClient(
Expand Down Expand Up @@ -1150,34 +1158,22 @@ void WindowTreeClient::OnWindowInputEvent(uint32_t event_id,
return;
}

WindowTreeHostMus* host = GetWindowTreeHostMus(window);
DCHECK(host);

// The location of the event is relative to |window|. As the event is handed
// to WindowTreeHost we need it to be relative to WindowTreeHost.
if (event->IsLocatedEvent()) {
gfx::Point host_location = event->AsLocatedEvent()->location();
aura::Window::ConvertPointToTarget(window->GetWindow(), host->window(),
&host_location);
event->AsLocatedEvent()->set_location(host_location);
}

EventAckHandler ack_handler(CreateEventResultCallback(event_id));
// TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or
// ui::TouchEvent once we have proper support for pointer events.
if (event->IsMousePointerEvent()) {
if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) {
ui::MouseWheelEvent mapped_event(*event->AsPointerEvent());
host->SendEventToProcessor(&mapped_event);
DispatchEventToTarget(&mapped_event, window);
} else {
ui::MouseEvent mapped_event(*event->AsPointerEvent());
host->SendEventToProcessor(&mapped_event);
DispatchEventToTarget(&mapped_event, window);
}
} else if (event->IsTouchPointerEvent()) {
ui::TouchEvent mapped_event(*event->AsPointerEvent());
host->SendEventToProcessor(&mapped_event);
DispatchEventToTarget(&mapped_event, window);
} else {
host->SendEventToProcessor(event.get());
DispatchEventToTarget(event.get(), window);
}
ack_handler.set_handled(event->handled());
}
Expand Down
Loading

0 comments on commit 6b3d980

Please sign in to comment.