bug 818927 - convert drop location to logical pixels for Windows. r=jimm
authorJonathan Kew <jkew@mozilla.com>
Mon, 01 Apr 2013 10:10:09 +0100
changeset 127241 0517b64b90d24b1c654683c2ebc51177f5d377e6
parent 127240 40cde6c631d3b93c5863b8deae4011d0c61e5a44
child 127242 82c8aaa1e90977a7d27ec45af1e7ad5fd48fa342
push id1651
push userjandemooij@gmail.com
push dateMon, 01 Apr 2013 19:51:43 +0000
reviewersjimm
bugs818927
milestone22.0a1
bug 818927 - convert drop location to logical pixels for Windows. r=jimm
widget/windows/nsDragService.cpp
--- a/widget/windows/nsDragService.cpp
+++ b/widget/windows/nsDragService.cpp
@@ -34,16 +34,17 @@
 #include "nsToolkit.h"
 #include "nsCRT.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsUnicharUtils.h"
 #include "gfxASurface.h"
 #include "gfxContext.h"
 #include "nsRect.h"
 #include "nsMathUtils.h"
+#include "gfxWindowsPlatform.h"
 
 //-------------------------------------------------------------------------
 //
 // DragService constructor
 //
 //-------------------------------------------------------------------------
 nsDragService::nsDragService()
   : mDataObject(nullptr), mSentLocalDropEvent(false)
@@ -296,21 +297,24 @@ nsDragService::StartInvokingDragSession(
     }
   }
 
   mUserCancelled = nativeDragSrc->UserCancelled();
 
   // We're done dragging, get the cursor position and end the drag
   // Use GetMessagePos to get the position of the mouse at the last message
   // seen by the event loop. (Bug 489729)
+  // Note that we must convert this from device pixels back to Windows logical
+  // pixels (bug 818927).
   DWORD pos = ::GetMessagePos();
-  POINT cpos;
-  cpos.x = GET_X_LPARAM(pos);
-  cpos.y = GET_Y_LPARAM(pos);
-  SetDragEndPoint(nsIntPoint(cpos.x, cpos.y));
+  FLOAT scaleFactor = 96.0f /
+    GetDeviceCaps(gfxWindowsPlatform::GetPlatform()->GetScreenDC(), LOGPIXELSY);
+  nsIntPoint logPos(NSToIntRound(scaleFactor * GET_X_LPARAM(pos)),
+                    NSToIntRound(scaleFactor * GET_Y_LPARAM(pos)));
+  SetDragEndPoint(logPos);
   EndDragSession(true);
 
   mDoingDrag = false;
 
   return DRAGDROP_S_DROP == res ? NS_OK : NS_ERROR_FAILURE;
 }
 
 //-------------------------------------------------------------------------