From 2bbf86c524d8d5b4dbf09a48246eaac8767cdafc Mon Sep 17 00:00:00 2001 From: Nishanth Shanmugham Date: Tue, 29 Dec 2015 03:25:21 -0600 Subject: [PATCH] tray: Support file-drop from OS X Dock 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 | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/atom/browser/ui/tray_icon_cocoa.mm b/atom/browser/ui/tray_icon_cocoa.mm index 997ac6fd3134..62da2015e575 100644 --- a/atom/browser/ui/tray_icon_cocoa.mm +++ b/atom/browser/ui/tray_icon_cocoa.mm @@ -281,14 +281,14 @@ const CGFloat kVerticalTitleMargin = 2; - (void)draggingEnded:(id )sender { trayIcon_->NotifyDragEnded(); + + if (NSPointInRect([sender draggingLocation], self.frame)) { + trayIcon_->NotifyDrop(); + [self handleDrop:sender]; + } } -- (BOOL)prepareForDragOperation:(id )sender { - trayIcon_->NotifyDrop(); - return YES; -} - -- (BOOL)performDragOperation:(id )sender { +- (BOOL)handleDrop:(id )sender { NSPasteboard* pboard = [sender draggingPasteboard]; if ([[pboard types] containsObject:NSFilenamesPboardType]) { @@ -302,6 +302,14 @@ const CGFloat kVerticalTitleMargin = 2; return NO; } +- (BOOL)prepareForDragOperation:(id )sender { + return YES; +} + +- (BOOL)performDragOperation:(id )sender { + return YES; +} + - (BOOL)shouldHighlight { if (isHighlightEnable_ && forceHighlight_) return true;