]> khamidou — GitHub mirrors - electron.git/commitdiff
tray: Support file-drop from OS X Dock
authorNishanth Shanmugham <nishanth.gerrard@gmail.com>
Tue, 29 Dec 2015 09:25:21 +0000 (03:25 -0600)
committerNishanth Shanmugham <nishanth.gerrard@gmail.com>
Tue, 29 Dec 2015 09:27:59 +0000 (03:27 -0600)
A long-standing Apple bug does not call `prepareForDragOperation:sender`
for file drag-and-drop operations from the Dock. So we manually
call our custom `handleDrop:sender` for all drag-and-drop cases (that
is, from the Dock and from Finder).

References to the bug in question:
- http://stackoverflow.com/q/9534543/3309046
- http://openradar.appspot.com/radar?id=1745403

However, we still need to return YES from `prepareForDragOperation:sender`,
otherwise the "drag failed" animation occurs. For the same reason, we also
return YES from `performDragOperation:sender`.

atom/browser/ui/tray_icon_cocoa.mm

index 997ac6fd3134e48385141faabec0f9eb57aaa7d4..62da2015e5756986eeb09951c93ecb3556ddb57b 100644 (file)
@@ -281,14 +281,14 @@ const CGFloat kVerticalTitleMargin = 2;
 
 - (void)draggingEnded:(id <NSDraggingInfo>)sender {
   trayIcon_->NotifyDragEnded();
-}
 
-- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender {
-  trayIcon_->NotifyDrop();
-  return YES;
+  if (NSPointInRect([sender draggingLocation], self.frame)) {
+    trayIcon_->NotifyDrop();
+    [self handleDrop:sender];
+  }
 }
 
-- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
+- (BOOL)handleDrop:(id <NSDraggingInfo>)sender {
   NSPasteboard* pboard = [sender draggingPasteboard];
 
   if ([[pboard types] containsObject:NSFilenamesPboardType]) {
@@ -302,6 +302,14 @@ const CGFloat kVerticalTitleMargin = 2;
   return NO;
 }
 
+- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender {
+  return YES;
+}
+
+- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
+  return YES;
+}
+
 - (BOOL)shouldHighlight {
   if (isHighlightEnable_ && forceHighlight_)
     return true;