Skip to content

Commit

Permalink
Bug 1330470: Restore ability to drag & drop entries from the download…
Browse files Browse the repository at this point in the history
… list to Finder on OSX. r=mstange
  • Loading branch information
Stephen A Pohl committed May 23, 2017
1 parent d0c7635 commit be66d25
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
19 changes: 12 additions & 7 deletions widget/cocoa/nsChildView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3269,10 +3269,11 @@ + (void)registerViewForDraggedTypes:(NSView*)aView
[aView registerForDraggedTypes:
[NSArray arrayWithObjects:
[UTIHelper stringFromPboardType:NSFilenamesPboardType],
[UTIHelper stringFromPboardType:kMozFileUrlsPboardType],
[UTIHelper stringFromPboardType:NSPasteboardTypeString],
[UTIHelper stringFromPboardType:NSPasteboardTypeHTML],
[UTIHelper stringFromPboardType:(NSString*)kPasteboardTypeFileURLPromise],
[UTIHelper stringFromPboardType:kWildcardPboardType],
[UTIHelper stringFromPboardType:kMozWildcardPboardType],
[UTIHelper stringFromPboardType:kPublicUrlPboardType],
[UTIHelper stringFromPboardType:kPublicUrlNamePboardType],
[UTIHelper stringFromPboardType:kUrlsWithTitlesPboardType],
Expand Down Expand Up @@ -6100,15 +6101,17 @@ - (void)pasteboard:(NSPasteboard*)aPasteboard
unsigned int typeCount = [pasteboardOutputDict count];
NSMutableArray* types = [NSMutableArray arrayWithCapacity:typeCount + 1];
[types addObjectsFromArray:[pasteboardOutputDict allKeys]];
[types addObject:[UTIHelper stringFromPboardType:kWildcardPboardType]];
[types addObject:[UTIHelper stringFromPboardType:kMozWildcardPboardType]];
for (unsigned int k = 0; k < typeCount; k++) {
NSString* curType = [types objectAtIndex:k];
if ([curType isEqualToString:
[UTIHelper stringFromPboardType:NSPasteboardTypeString]] ||
[curType isEqualToString:
[UTIHelper stringFromPboardType:kPublicUrlPboardType]] ||
[curType isEqualToString:
[UTIHelper stringFromPboardType:kPublicUrlNamePboardType]]) {
[UTIHelper stringFromPboardType:kPublicUrlNamePboardType]] ||
[curType isEqualToString:
[UTIHelper stringFromPboardType:(NSString*)kUTTypeFileURL]]) {
[aPasteboard setString:[pasteboardOutputDict valueForKey:curType]
forType:curType];
} else if ([curType isEqualToString:
Expand All @@ -6125,14 +6128,16 @@ - (void)pasteboard:(NSPasteboard*)aPasteboard
} else if ([curType isEqualToString:
[UTIHelper stringFromPboardType:NSPasteboardTypeTIFF]] ||
[curType isEqualToString:
[UTIHelper stringFromPboardType:kCustomTypesPboardType]]) {
[UTIHelper stringFromPboardType:kMozCustomTypesPboardType]]) {
[aPasteboard setData:[pasteboardOutputDict valueForKey:curType]
forType:curType];
} else if ([curType isEqualToString:
[UTIHelper stringFromPboardType:kMozFileUrlsPboardType]]) {
[aPasteboard writeObjects:[pasteboardOutputDict valueForKey:curType]];
} else if ([curType isEqualToString:
[UTIHelper stringFromPboardType:
(NSString*)kPasteboardTypeFileURLPromise]] ||
[curType isEqualToString:
[UTIHelper stringFromPboardType:NSFilenamesPboardType]]) {
(NSString*)kPasteboardTypeFileURLPromise]]) {


nsCOMPtr<nsIFile> targFile;
NS_NewLocalFile(EmptyString(), true, getter_AddRefs(targFile));
Expand Down
24 changes: 15 additions & 9 deletions widget/cocoa/nsClipboard.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ @implementation UTIHelper

+ (NSString*)stringFromPboardType:(NSString*)aType
{
if ([aType isEqualToString:kWildcardPboardType] ||
[aType isEqualToString:kCustomTypesPboardType] ||
if ([aType isEqualToString:kMozWildcardPboardType] ||
[aType isEqualToString:kMozCustomTypesPboardType] ||
[aType isEqualToString:kPublicUrlPboardType] ||
[aType isEqualToString:kPublicUrlNamePboardType] ||
[aType isEqualToString:kMozFileUrlsPboardType] ||
[aType isEqualToString:(NSString*)kPasteboardTypeFileURLPromise] ||
[aType isEqualToString:(NSString*)kPasteboardTypeFilePromiseContent] ||
[aType isEqualToString:(NSString*)kUTTypeFileURL] ||
[aType isEqualToString:NSPasteboardTypeString] ||
[aType isEqualToString:NSPasteboardTypeHTML] ||
[aType isEqualToString:NSPasteboardTypeRTF] ||
Expand Down Expand Up @@ -164,6 +166,9 @@ + (NSString*)stringFromPboardType:(NSString*)aType
[UTIHelper stringFromPboardType:NSPasteboardTypeHTML]]) {
[cocoaPasteboard setString:(nsClipboard::WrapHtmlForSystemPasteboard(currentValue))
forType:currentKey];
} else if ([currentKey isEqualToString:
[UTIHelper stringFromPboardType:kMozFileUrlsPboardType]]) {
[cocoaPasteboard writeObjects:currentValue];
} else {
[cocoaPasteboard setData:currentValue forType:currentKey];
}
Expand Down Expand Up @@ -250,7 +255,7 @@ + (NSString*)stringFromPboardType:(NSString*)aType
NSString* type =
[cocoaPasteboard availableTypeFromArray:
[NSArray arrayWithObject:
[UTIHelper stringFromPboardType:kCustomTypesPboardType]]];
[UTIHelper stringFromPboardType:kMozCustomTypesPboardType]]];
if (!type) {
continue;
}
Expand Down Expand Up @@ -467,7 +472,7 @@ + (NSString*)stringFromPboardType:(NSString*)aType
NSString* availableType =
[generalPBoard availableTypeFromArray:
[NSArray arrayWithObject:
[UTIHelper stringFromPboardType:kCustomTypesPboardType]]];
[UTIHelper stringFromPboardType:kMozCustomTypesPboardType]]];
if (availableType) {
*outResult = true;
break;
Expand Down Expand Up @@ -565,7 +570,7 @@ + (NSString*)stringFromPboardType:(NSString*)aType
if (data) {
NSData* nativeData = [NSData dataWithBytes:data length:dataSize];
NSString* customType =
[UTIHelper stringFromPboardType:kCustomTypesPboardType];
[UTIHelper stringFromPboardType:kMozCustomTypesPboardType];
[pasteboardOutputDict setObject:nativeData forKey:customType];
free(data);
}
Expand Down Expand Up @@ -656,10 +661,11 @@ + (NSString*)stringFromPboardType:(NSString*)aType
}

NSString* str = nsCocoaUtils::ToNSString(fileURI);
NSArray* fileList = [NSArray arrayWithObjects:str, nil];
NSString* filenamesType =
[UTIHelper stringFromPboardType:NSFilenamesPboardType];
[pasteboardOutputDict setObject:fileList forKey:filenamesType];
NSURL* url = [NSURL fileURLWithPath:str isDirectory:NO];
NSString* fileUTType =
[UTIHelper stringFromPboardType:(NSString*)kUTTypeFileURL];
[pasteboardOutputDict setObject:[url absoluteString]
forKey:fileUTType];
}
else if (flavorStr.EqualsLiteral(kFilePromiseMime)) {
NSString* urlPromise =
Expand Down
5 changes: 3 additions & 2 deletions widget/cocoa/nsDragService.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

#include <Cocoa/Cocoa.h>

extern NSString* const kWildcardPboardType;
extern NSString* const kPublicUrlPboardType;
extern NSString* const kPublicUrlNamePboardType;
extern NSString* const kUrlsWithTitlesPboardType;
extern NSString* const kCustomTypesPboardType;
extern NSString* const kMozWildcardPboardType;
extern NSString* const kMozCustomTypesPboardType;
extern NSString* const kMozFileUrlsPboardType;

class nsDragService : public nsBaseDragService
{
Expand Down
15 changes: 9 additions & 6 deletions widget/cocoa/nsDragService.mm
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@
// file destination callback.
nsIArray *gDraggedTransferables = nullptr;

NSString* const kWildcardPboardType = @"org.mozilla.MozillaWildcard";
NSString* const kPublicUrlPboardType = @"public.url";
NSString* const kPublicUrlNamePboardType = @"public.url-name";
NSString* const kUrlsWithTitlesPboardType = @"WebURLsWithTitlesPboardType";
NSString* const kCustomTypesPboardType = @"org.mozilla.custom-clipdata";
NSString* const kMozWildcardPboardType = @"org.mozilla.MozillaWildcard";
NSString* const kMozCustomTypesPboardType = @"org.mozilla.custom-clipdata";
NSString* const kMozFileUrlsPboardType = @"org.mozilla.file-urls";

nsDragService::nsDragService()
: mNativeDragView(nil), mNativeDragEvent(nil), mDragImageChanged(false)
Expand Down Expand Up @@ -337,7 +338,7 @@
// Gecko is initiating this drag so we always want its own views to
// consider it. Add our wildcard type to the pasteboard to accomplish
// this.
[types addObject:[UTIHelper stringFromPboardType:kWildcardPboardType]];
[types addObject:[UTIHelper stringFromPboardType:kMozWildcardPboardType]];
}
}
[pbItem setDataProvider:mNativeDragView forTypes:types];
Expand Down Expand Up @@ -459,7 +460,9 @@
break;
}
else if (flavorStr.EqualsLiteral(kCustomTypesMime)) {
NSString* availableType = [item availableTypeFromArray:[NSArray arrayWithObject:kCustomTypesPboardType]];
NSString* availableType =
[item availableTypeFromArray:
[NSArray arrayWithObject:kMozCustomTypesPboardType]];
if (!availableType || !IsValidType(availableType, false)) {
continue;
}
Expand Down Expand Up @@ -609,7 +612,7 @@
const NSString* type = nil;
bool allowFileURL = false;
if (dataFlavor.EqualsLiteral(kFileMime)) {
type = [UTIHelper stringFromPboardType:NSFilenamesPboardType];
type = [UTIHelper stringFromPboardType:kMozFileUrlsPboardType];
allowFileURL = true;
} else if (dataFlavor.EqualsLiteral(kUnicodeMime)) {
type = [UTIHelper stringFromPboardType:NSPasteboardTypeString];
Expand All @@ -623,7 +626,7 @@
} else if (dataFlavor.EqualsLiteral(kRTFMime)) {
type = [UTIHelper stringFromPboardType:NSPasteboardTypeRTF];
} else if (dataFlavor.EqualsLiteral(kCustomTypesMime)) {
type = [UTIHelper stringFromPboardType:kCustomTypesPboardType];
type = [UTIHelper stringFromPboardType:kMozCustomTypesPboardType];
}

NSString* availableType =
Expand Down

0 comments on commit be66d25

Please sign in to comment.