Bug 1301673, use the correct coordinates when drag feedback is disabled or fails; this allows the drag feedback on Mac to appear as a grey rectangle, r=tn
authorNeil Deakin <neil@mozilla.com>
Wed, 19 Oct 2016 15:01:39 -0400
changeset 318651 4afa256ec14fc12798346eaf423ecc02c7135020
parent 318650 4c5656f3e0707a4ef8f885310dad4964a0f2c11c
child 318652 a8fd4f51596a460a2a5969329ac5d83eb86fb835
push id20725
push userphilringnalda@gmail.com
push dateThu, 20 Oct 2016 01:36:01 +0000
treeherderfx-team@998ad5a74da8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstn
bugs1301673
milestone52.0a1
Bug 1301673, use the correct coordinates when drag feedback is disabled or fails; this allows the drag feedback on Mac to appear as a grey rectangle, r=tn
widget/cocoa/nsDragService.mm
widget/nsBaseDragService.cpp
--- a/widget/cocoa/nsDragService.mm
+++ b/widget/cocoa/nsDragService.mm
@@ -302,39 +302,40 @@ nsDragService::InvokeDragSessionImpl(nsI
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   mDataItems = aTransferableArray;
 
   // put data on the clipboard
   if (NS_FAILED(SetUpDragClipboard(aTransferableArray)))
     return NS_ERROR_FAILURE;
 
+  CGFloat scaleFactor = nsCocoaUtils::GetBackingScaleFactor(gLastDragView);
+
   LayoutDeviceIntRect dragRect(0, 0, 20, 20);
   NSImage* image = ConstructDragImage(mSourceNode, &dragRect, aDragRgn);
   if (!image) {
     // if no image was returned, just draw a rectangle
     NSSize size;
-    size.width = dragRect.width;
-    size.height = dragRect.height;
+    size.width = nsCocoaUtils::DevPixelsToCocoaPoints(dragRect.width, scaleFactor);
+    size.height = nsCocoaUtils::DevPixelsToCocoaPoints(dragRect.height, scaleFactor);
     image = [[NSImage alloc] initWithSize:size];
     [image lockFocus];
     [[NSColor grayColor] set];
     NSBezierPath* path = [NSBezierPath bezierPath];
     [path setLineWidth:2.0];
     [path moveToPoint:NSMakePoint(0, 0)];
     [path lineToPoint:NSMakePoint(0, size.height)];
     [path lineToPoint:NSMakePoint(size.width, size.height)];
     [path lineToPoint:NSMakePoint(size.width, 0)];
     [path lineToPoint:NSMakePoint(0, 0)];
     [path stroke];
     [image unlockFocus];
   }
 
   LayoutDeviceIntPoint pt(dragRect.x, dragRect.YMost());
-  CGFloat scaleFactor = nsCocoaUtils::GetBackingScaleFactor(gLastDragView);
   NSPoint point = nsCocoaUtils::DevPixelsToCocoaPoints(pt, scaleFactor);
   point.y = nsCocoaUtils::FlippedScreenY(point.y);
 
   point = nsCocoaUtils::ConvertPointFromScreen([gLastDragView window], point);
   NSPoint localPoint = [gLastDragView convertPoint:point fromView:nil];
  
   // Save the transferables away in case a promised file callback is invoked.
   gDraggedTransferables = aTransferableArray;
--- a/widget/nsBaseDragService.cpp
+++ b/widget/nsBaseDragService.cpp
@@ -561,42 +561,38 @@ nsBaseDragService::DrawDrag(nsIDOMNode* 
 
   // check if drag images are disabled
   bool enableDragImages = Preferences::GetBool(DRAGIMAGES_PREF, true);
 
   // didn't want an image, so just set the screen rectangle to the frame size
   if (!enableDragImages || !mHasImage) {
     // if a region was specified, set the screen rectangle to the area that
     // the region occupies
+    nsIntRect dragRect;
     if (aRegion) {
       // the region's coordinates are relative to the root frame
+      aRegion->GetBoundingBox(&dragRect.x, &dragRect.y, &dragRect.width, &dragRect.height);
+
       nsIFrame* rootFrame = presShell->GetRootFrame();
-      if (rootFrame) {
-        nsIntRect dragRect;
-        aRegion->GetBoundingBox(&dragRect.x, &dragRect.y, &dragRect.width, &dragRect.height);
-        dragRect = ToAppUnits(dragRect, nsPresContext::AppUnitsPerCSSPixel()).
-                            ToOutsidePixels((*aPresContext)->AppUnitsPerDevPixel());
-
-        nsIntRect screenRect = rootFrame->GetScreenRect();
-        aScreenDragRect->SetRect(screenRect.x + dragRect.x, screenRect.y + dragRect.y,
-                                 dragRect.width, dragRect.height);
-      }
+      nsIntRect screenRect = rootFrame->GetScreenRect();
+      dragRect.MoveBy(screenRect.TopLeft());
     }
     else {
       // otherwise, there was no region so just set the rectangle to
       // the size of the primary frame of the content.
       nsCOMPtr<nsIContent> content = do_QueryInterface(dragNode);
       nsIFrame* frame = content->GetPrimaryFrame();
       if (frame) {
-        nsIntRect screenRect = frame->GetScreenRect();
-        aScreenDragRect->SetRect(screenRect.x, screenRect.y,
-                                 screenRect.width, screenRect.height);
+        dragRect = frame->GetScreenRect();
       }
     }
 
+    dragRect = ToAppUnits(dragRect, nsPresContext::AppUnitsPerCSSPixel()).
+                          ToOutsidePixels((*aPresContext)->AppUnitsPerDevPixel());
+    aScreenDragRect->SizeTo(dragRect.width, dragRect.height);
     return NS_OK;
   }
 
   // draw the image for selections
   if (mSelection) {
     LayoutDeviceIntPoint pnt(aScreenDragRect->TopLeft());
     *aSurface = presShell->RenderSelection(mSelection, pnt, aScreenDragRect,
         mImage ? 0 : nsIPresShell::RENDER_AUTO_SCALE);