Index: ui/views/win/hwnd_message_handler.cc |
diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc |
index bd2072b47ee7d0b71d538d9f065151da85262315..23f09dcf08871f9814b8d2184d100e5de0568f3e 100644 |
--- a/ui/views/win/hwnd_message_handler.cc |
+++ b/ui/views/win/hwnd_message_handler.cc |
@@ -695,7 +695,23 @@ bool HWNDMessageHandler::RunMoveLoop(const gfx::Vector2d& drag_offset, |
base::MessageLoop::ScopedNestableTaskAllower allow_nested( |
base::MessageLoop::current()); |
- SendMessage(hwnd(), WM_SYSCOMMAND, SC_MOVE | 0x0002, GetMessagePos()); |
+ // SC_MOVE ignores the lParam cursor argument, so first ensure the point |
+ // |drag_offset| into the window lies under the cursor. Note that the offset |
+ // is in window coordinates, the cursor in screen coordinates, and the call to |
+ // SetWindowPos must be client area coordinates. |
+ DWORD message_pos = GetMessagePos(); |
+ POINTS cursor_pos = MAKEPOINTS(message_pos); |
+ POINT anchor_pos = { drag_offset.x(), drag_offset.y() }; |
+ //MapWindowPoints(hwnd(), HWND_DESKTOP, &anchor_pos, 1); |
+ ClientToScreen(hwnd(), &anchor_pos); |
+ RECT client_rect; |
+ GetClientRect(hwnd(), &client_rect); |
+ SetWindowPos(hwnd(), nullptr, |
+ client_rect.left + cursor_pos.x - anchor_pos.x, |
+ client_rect.top + cursor_pos.y - anchor_pos.y, |
+ 0, 0, SWP_NOSIZE); |
+ |
+ SendMessage(hwnd(), WM_SYSCOMMAND, SC_MOVE | 0x0002, 0); |
// Windows doesn't appear to offer a way to determine whether the user |
// canceled the move or not. We assume if the user released the mouse it was |
// successful. |