Skip to content

Commit

Permalink
Fix mouse warp with 2x displays
Browse files Browse the repository at this point in the history
Mirroring displays always uses 1x DSF, so the screen point has to be coverted back to 1x too.

BUG=514877
TEST=manual.

I tried to write test but gave up for now. Mouse warp depends on native event, which is not available in test. Existing test emulates the native event by converting the screen point back to native, but this does not work well with 2x DSF because it'll lose the precision (249 -> 498, which should really be 499). I'll update the EventGenerator and write a test in a separate CL.

Review URL: https://codereview.chromium.org/1269773005

Cr-Commit-Position: refs/heads/master@{#341601}
  • Loading branch information
mitoshima authored and Commit bot committed Aug 3, 2015
1 parent 6fcfba9 commit ff861fd
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions ash/display/unified_mouse_warp_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,23 @@ bool UnifiedMouseWarpController::WarpMouseCursor(ui::MouseEvent* event) {
ComputeBounds();

aura::Window* target = static_cast<aura::Window*>(event->target());
gfx::Point point_in_screen = event->location();
::wm::ConvertPointToScreen(target, &point_in_screen);
gfx::Point point_in_unified_host = event->location();
::wm::ConvertPointToScreen(target, &point_in_unified_host);
// The display bounds of the mirroring windows isn't scaled, so
// transform back to the host coordinates.
target->GetHost()->GetRootTransform().TransformPoint(&point_in_unified_host);

// A native event may not exist in unit test. Generate the native point
// from the screen point instead.
if (!event->HasNativeEvent()) {
if (!allow_non_native_event_)
return false;
aura::Window* target_root = target->GetRootWindow();
gfx::Point point_in_native = point_in_screen;
::wm::ConvertPointFromScreen(target_root, &point_in_native);
gfx::Point point_in_native = point_in_unified_host;
aura::WindowTreeHost* host =
FindMirroringWindowTreeHostFromScreenPoint(point_in_screen);
FindMirroringWindowTreeHostFromScreenPoint(point_in_unified_host);
DCHECK(host);
host->ConvertPointToNativeScreen(&point_in_native);
return WarpMouseCursorInNativeCoords(point_in_native, point_in_screen,
return WarpMouseCursorInNativeCoords(point_in_native, point_in_unified_host,
true);
}

Expand All @@ -90,13 +91,14 @@ bool UnifiedMouseWarpController::WarpMouseCursor(ui::MouseEvent* event) {
// Native events in Ozone are in the native window coordinate system. We need
// to translate them to get the global position.
aura::WindowTreeHost* host =
FindMirroringWindowTreeHostFromScreenPoint(point_in_screen);
FindMirroringWindowTreeHostFromScreenPoint(point_in_unified_host);
if (!host)
return false;
point_in_native.Offset(host->GetBounds().x(), host->GetBounds().y());
#endif

return WarpMouseCursorInNativeCoords(point_in_native, point_in_screen, false);
return WarpMouseCursorInNativeCoords(point_in_native, point_in_unified_host,
false);
}

void UnifiedMouseWarpController::SetEnabled(bool enabled) {
Expand Down Expand Up @@ -132,7 +134,7 @@ void UnifiedMouseWarpController::ComputeBounds() {

bool UnifiedMouseWarpController::WarpMouseCursorInNativeCoords(
const gfx::Point& point_in_native,
const gfx::Point& point_in_screen,
const gfx::Point& point_in_unified_host,
bool update_mouse_location_now) {
bool in_first_edge = first_edge_bounds_in_native_.Contains(point_in_native);
bool in_second_edge = second_edge_bounds_in_native_.Contains(point_in_native);
Expand All @@ -145,7 +147,8 @@ bool UnifiedMouseWarpController::WarpMouseCursorInNativeCoords(
AshWindowTreeHost* target_ash_host =
GetMirroringAshWindowTreeHostForDisplayId(
in_first_edge ? display_list[1].id() : display_list[0].id());
MoveCursorTo(target_ash_host, point_in_screen, update_mouse_location_now);
MoveCursorTo(target_ash_host, point_in_unified_host,
update_mouse_location_now);
return true;
}

Expand Down

0 comments on commit ff861fd

Please sign in to comment.