Bug 1562048 - Draw the fallback drag image using a different API. r=spohl
authorMarkus Stange <mstange@themasta.com>
Fri, 28 Jun 2019 13:44:15 +0000
changeset 543384 0c6e149ba01d55dfa0e21e0eed6cfa2ec9aad90f
parent 543383 0d7b68ec3e0aceeb63acd84bf99ab43b5c7d7a72
child 543385 9823d19217e209619c3f8d0e52d88119ba238fef
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersspohl
bugs1562048
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1562048 - Draw the fallback drag image using a different API. r=spohl This also fixes a leak - the return value is expected to be autoreleased. Differential Revision: https://phabricator.services.mozilla.com/D36252
widget/cocoa/nsDragService.mm
--- a/widget/cocoa/nsDragService.mm
+++ b/widget/cocoa/nsDragService.mm
@@ -67,28 +67,25 @@ NSImage* nsDragService::ConstructDragIma
 
   LayoutDeviceIntRect dragRect(0, 0, 20, 20);
   NSImage* image = ConstructDragImage(mSourceNode, aRegion, mScreenPosition, &dragRect);
   if (!image) {
     // if no image was returned, just draw a rectangle
     NSSize size;
     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];
+    image = [NSImage imageWithSize:size
+                           flipped:YES
+                    drawingHandler:^BOOL(NSRect dstRect) {
+                      [[NSColor grayColor] set];
+                      NSBezierPath* path = [NSBezierPath bezierPathWithRect:dstRect];
+                      [path setLineWidth:2.0];
+                      [path stroke];
+                      return YES;
+                    }];
   }
 
   LayoutDeviceIntPoint pt(dragRect.x, dragRect.YMost());
   NSPoint point = nsCocoaUtils::DevPixelsToCocoaPoints(pt, scaleFactor);
   point.y = nsCocoaUtils::FlippedScreenY(point.y);
 
   point = nsCocoaUtils::ConvertPointFromScreen([mNativeDragView window], point);
   *aDragPoint = [mNativeDragView convertPoint:point fromView:nil];