Commit a646d18a authored by ananta@chromium.org's avatar ananta@chromium.org

Ensure that mouse events on Windows reposted by the menu_controller are converted to pixel.

On HiDPI windows these coordinates are in DIPs. While posting them via the PostMessage API we
need to convert them back to pixel using the correct scale factor.

This caused bookmarks to get incorrectly saved at times.

Changes in this patch are as below:-
1. menu_controller.cc. Convert screen_loc to pixels before   invoking Win32 API's as they expect values in pixels.

2. screen_win.cc. Fix the GetWindowAtScreenPoint function   to convert the point to pixels before invoking  
   the WindowFromPoint API.

BUG=381605
R=sky

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278559 0039d316-1c4b-4281-b951-d872f2087c98
parent be23f89a
...@@ -76,7 +76,8 @@ gfx::NativeWindow ScreenWin::GetWindowUnderCursor() { ...@@ -76,7 +76,8 @@ gfx::NativeWindow ScreenWin::GetWindowUnderCursor() {
} }
gfx::NativeWindow ScreenWin::GetWindowAtScreenPoint(const gfx::Point& point) { gfx::NativeWindow ScreenWin::GetWindowAtScreenPoint(const gfx::Point& point) {
return GetNativeWindowFromHWND(WindowFromPoint(point.ToPOINT())); gfx::Point point_in_pixels = gfx::win::DIPToScreenPoint(point);
return GetNativeWindowFromHWND(WindowFromPoint(point_in_pixels.ToPOINT()));
} }
int ScreenWin::GetNumDisplays() const { int ScreenWin::GetNumDisplays() const {
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#if defined(OS_WIN) #if defined(OS_WIN)
#include "ui/base/win/internal_constants.h" #include "ui/base/win/internal_constants.h"
#include "ui/gfx/win/dpi.h"
#include "ui/views/win/hwnd_util.h" #include "ui/views/win/hwnd_util.h"
#endif #endif
...@@ -2051,12 +2052,16 @@ void MenuController::RepostEvent(SubmenuView* source, ...@@ -2051,12 +2052,16 @@ void MenuController::RepostEvent(SubmenuView* source,
gfx::NativeWindow window = screen->GetWindowAtScreenPoint(screen_loc); gfx::NativeWindow window = screen->GetWindowAtScreenPoint(screen_loc);
#if defined(OS_WIN) #if defined(OS_WIN)
// Convert screen_loc to pixels for the Win32 API's like WindowFromPoint,
// PostMessage/SendMessage to work correctly. These API's expect the
// coordinates to be in pixels.
// PostMessage() to metro windows isn't allowed (access will be denied). Don't // PostMessage() to metro windows isn't allowed (access will be denied). Don't
// try to repost with Win32 if the window under the mouse press is in metro. // try to repost with Win32 if the window under the mouse press is in metro.
if (!ViewsDelegate::views_delegate || if (!ViewsDelegate::views_delegate ||
!ViewsDelegate::views_delegate->IsWindowInMetro(window)) { !ViewsDelegate::views_delegate->IsWindowInMetro(window)) {
gfx::Point screen_loc_pixels = gfx::win::DIPToScreenPoint(screen_loc);
HWND target_window = window ? HWNDForNativeWindow(window) : HWND target_window = window ? HWNDForNativeWindow(window) :
WindowFromPoint(screen_loc.ToPOINT()); WindowFromPoint(screen_loc_pixels.ToPOINT());
HWND source_window = HWNDForNativeView(native_view); HWND source_window = HWNDForNativeView(native_view);
if (!target_window || !source_window || if (!target_window || !source_window ||
GetWindowThreadProcessId(source_window, NULL) != GetWindowThreadProcessId(source_window, NULL) !=
...@@ -2070,7 +2075,7 @@ void MenuController::RepostEvent(SubmenuView* source, ...@@ -2070,7 +2075,7 @@ void MenuController::RepostEvent(SubmenuView* source,
// Determine whether the click was in the client area or not. // Determine whether the click was in the client area or not.
// NOTE: WM_NCHITTEST coordinates are relative to the screen. // NOTE: WM_NCHITTEST coordinates are relative to the screen.
LPARAM coords = MAKELPARAM(screen_loc.x(), screen_loc.y()); LPARAM coords = MAKELPARAM(screen_loc_pixels.x(), screen_loc_pixels.y());
LRESULT nc_hit_result = SendMessage(target_window, WM_NCHITTEST, 0, coords); LRESULT nc_hit_result = SendMessage(target_window, WM_NCHITTEST, 0, coords);
const bool client_area = nc_hit_result == HTCLIENT; const bool client_area = nc_hit_result == HTCLIENT;
...@@ -2090,8 +2095,8 @@ void MenuController::RepostEvent(SubmenuView* source, ...@@ -2090,8 +2095,8 @@ void MenuController::RepostEvent(SubmenuView* source,
return; return;
} }
int window_x = screen_loc.x(); int window_x = screen_loc_pixels.x();
int window_y = screen_loc.y(); int window_y = screen_loc_pixels.y();
if (client_area) { if (client_area) {
POINT pt = { window_x, window_y }; POINT pt = { window_x, window_y };
ScreenToClient(target_window, &pt); ScreenToClient(target_window, &pt);
......
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