From 05f7888960f6e3393b2ad5f5835028404737c584 Mon Sep 17 00:00:00 2001 From: ananta Date: Wed, 4 Mar 2015 17:01:46 -0800 Subject: [PATCH] Ensure that pointer lock works correctly in Windows 7+ with HiDPI scale factors above 1 We were not scaling the mouse coordinate by the scale factor before invoking the ClientToScreen API. With this change the blink::WebMouseEvent.globalX and globalY values have to be converted back to DIP after convering them to screen. This should fix the mouse locking issue. BUG=411634 TEST= The main test case in bug 411634 Review URL: https://codereview.chromium.org/973123003 Cr-Commit-Position: refs/heads/master@{#319181} --- .../input/web_input_event_builders_win.cc | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/content/browser/renderer_host/input/web_input_event_builders_win.cc b/content/browser/renderer_host/input/web_input_event_builders_win.cc index 73c9174bfe4d..831f4034b279 100644 --- a/content/browser/renderer_host/input/web_input_event_builders_win.cc +++ b/content/browser/renderer_host/input/web_input_event_builders_win.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "content/browser/renderer_host/input/web_input_event_util.h" +#include "ui/gfx/win/dpi.h" using blink::WebInputEvent; using blink::WebKeyboardEvent; @@ -250,11 +251,24 @@ WebMouseEvent WebMouseEventBuilder::Build(HWND hwnd, result.windowX = result.x; result.windowY = result.y; - POINT global_point = { result.x, result.y }; + // The mouse coordinates received here are device independent (DIPs). We need + // to convert them to physical coordinates before calling Windows APIs like + // ClientToScreen, etc. + gfx::Point scaled_screen_point(result.x, result.y); + scaled_screen_point = gfx::win::DIPToScreenPoint(scaled_screen_point); + + POINT global_point = { scaled_screen_point.x(), scaled_screen_point.y() }; ClientToScreen(hwnd, &global_point); - result.globalX = global_point.x; - result.globalY = global_point.y; + scaled_screen_point.set_x(global_point.x); + scaled_screen_point.set_y(global_point.y); + + // We need to convert the point back to DIP before using it. + gfx::Point dip_screen_point = gfx::win::ScreenToDIPPoint( + scaled_screen_point); + + result.globalX = dip_screen_point.x(); + result.globalY = dip_screen_point.y(); // calculate number of clicks: -- 2.11.4.GIT