Commit 9a0319e8 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

chromeos: adjust event location for capture

In interactive ui tests we generate events using
RemoteEventDispatcher. When there is capture we need to ensure the
location matches what happens on device, otherwise we won't find the
right target.

BUG=817112
TEST=covered by tests

Change-Id: Ic47b316058282db85d83b348f3b346f2132cd9a1
Reviewed-on: https://chromium-review.googlesource.com/955925
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541851}
parent dbc78bf2
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "services/ui/ws/display.h" #include "services/ui/ws/display.h"
#include "services/ui/ws/display_manager.h" #include "services/ui/ws/display_manager.h"
#include "services/ui/ws/platform_display.h"
#include "services/ui/ws/window_manager_state.h"
#include "services/ui/ws/window_server.h" #include "services/ui/ws/window_server.h"
namespace ui { namespace ui {
...@@ -16,6 +18,39 @@ RemoteEventDispatcherImpl::RemoteEventDispatcherImpl(WindowServer* server) ...@@ -16,6 +18,39 @@ RemoteEventDispatcherImpl::RemoteEventDispatcherImpl(WindowServer* server)
RemoteEventDispatcherImpl::~RemoteEventDispatcherImpl() {} RemoteEventDispatcherImpl::~RemoteEventDispatcherImpl() {}
void RemoteEventDispatcherImpl::AdjustEventLocationForPixelLayout(
Display* display,
ui::LocatedEvent* event) {
WindowManagerState* window_manager_state =
window_server_->GetWindowManagerState();
if (!window_manager_state)
return;
// Only need to adjust the location of events when there is capture.
PlatformDisplay* platform_display_with_capture =
window_manager_state->platform_display_with_capture();
if (!platform_display_with_capture ||
display->platform_display() == platform_display_with_capture) {
return;
}
// The event is from a display other than the display with capture. On device
// events originate from the display with capture and are in terms of the
// pixel layout (see comments in EventLocation). Convert the location to be
// relative to the display with capture in terms of the pixel layout to match
// what happens on device.
gfx::PointF capture_relative_location = event->location_f();
capture_relative_location += display->GetViewportMetrics()
.bounds_in_pixels.origin()
.OffsetFromOrigin();
capture_relative_location -=
platform_display_with_capture->GetViewportMetrics()
.bounds_in_pixels.origin()
.OffsetFromOrigin();
event->set_location_f(capture_relative_location);
event->set_root_location_f(capture_relative_location);
}
void RemoteEventDispatcherImpl::DispatchEvent(int64_t display_id, void RemoteEventDispatcherImpl::DispatchEvent(int64_t display_id,
std::unique_ptr<ui::Event> event, std::unique_ptr<ui::Event> event,
DispatchEventCallback cb) { DispatchEventCallback cb) {
...@@ -41,6 +76,8 @@ void RemoteEventDispatcherImpl::DispatchEvent(int64_t display_id, ...@@ -41,6 +76,8 @@ void RemoteEventDispatcherImpl::DispatchEvent(int64_t display_id,
return; return;
} }
AdjustEventLocationForPixelLayout(display, located_event);
// If this is a mouse pointer event, then we have to also update the // If this is a mouse pointer event, then we have to also update the
// location of the cursor on the screen. // location of the cursor on the screen.
if (event->IsMousePointerEvent()) if (event->IsMousePointerEvent())
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
namespace ui { namespace ui {
namespace ws { namespace ws {
class Display;
class WindowServer; class WindowServer;
class RemoteEventDispatcherImpl : public mojom::RemoteEventDispatcher { class RemoteEventDispatcherImpl : public mojom::RemoteEventDispatcher {
...@@ -18,6 +19,11 @@ class RemoteEventDispatcherImpl : public mojom::RemoteEventDispatcher { ...@@ -18,6 +19,11 @@ class RemoteEventDispatcherImpl : public mojom::RemoteEventDispatcher {
~RemoteEventDispatcherImpl() override; ~RemoteEventDispatcherImpl() override;
private: private:
// Adjusts the location as necessary of |event|. |display| is the display
// the event is targetted at.
void AdjustEventLocationForPixelLayout(Display* display,
ui::LocatedEvent* event);
// mojom::RemoteEventDispatcher: // mojom::RemoteEventDispatcher:
void DispatchEvent(int64_t display_id, void DispatchEvent(int64_t display_id,
std::unique_ptr<ui::Event> event, std::unique_ptr<ui::Event> event,
......
...@@ -110,6 +110,10 @@ class WindowManagerState : public EventDispatcherDelegate, ...@@ -110,6 +110,10 @@ class WindowManagerState : public EventDispatcherDelegate,
// notifies |closure| immediately if IsProcessingEvent() returns false. // notifies |closure| immediately if IsProcessingEvent() returns false.
void ScheduleCallbackWhenDoneProcessingEvents(base::OnceClosure closure); void ScheduleCallbackWhenDoneProcessingEvents(base::OnceClosure closure);
PlatformDisplay* platform_display_with_capture() {
return platform_display_with_capture_;
}
private: private:
class ProcessedEventTarget; class ProcessedEventTarget;
friend class Display; friend class Display;
......
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