mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Bug 1462262 - Handle pasting image files on macOS. r=spohl
MozReview-Commit-ID: Inp8jmtcoQi --HG-- extra : rebase_source : 42d27a6fef35e952332e366731c267e5be464c12
This commit is contained in:
parent
4a43be2522
commit
643475f237
@ -288,6 +288,7 @@ nsClipboard::TransferableFromPasteboard(nsITransferable *aTransferable, NSPasteb
|
||||
NSString* type =
|
||||
[cocoaPasteboard availableTypeFromArray:
|
||||
[NSArray arrayWithObjects:
|
||||
[UTIHelper stringFromPboardType:(NSString*)kUTTypeFileURL],
|
||||
[UTIHelper stringFromPboardType:NSPasteboardTypeTIFF],
|
||||
[UTIHelper stringFromPboardType:NSPasteboardTypePNG],
|
||||
nil]];
|
||||
@ -314,17 +315,22 @@ nsClipboard::TransferableFromPasteboard(nsITransferable *aTransferable, NSPasteb
|
||||
// Use ImageIO to interpret the data on the clipboard and transcode.
|
||||
// Note that ImageIO, like all CF APIs, allows NULLs to propagate freely
|
||||
// and safely in most cases (like ObjC). A notable exception is CFRelease.
|
||||
NSDictionary *options =
|
||||
[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
(NSNumber*)kCFBooleanTrue,
|
||||
kCGImageSourceShouldAllowFloat,
|
||||
(type == [UTIHelper stringFromPboardType:NSPasteboardTypeTIFF] ?
|
||||
[UTIHelper stringFromPboardType:NSPasteboardTypeTIFF] :
|
||||
[UTIHelper stringFromPboardType:NSPasteboardTypePNG]),
|
||||
kCGImageSourceTypeIdentifierHint, nil];
|
||||
NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
(NSNumber*)kCFBooleanTrue,
|
||||
kCGImageSourceShouldAllowFloat,
|
||||
type,
|
||||
kCGImageSourceTypeIdentifierHint, nil];
|
||||
CGImageSourceRef source = nullptr;
|
||||
if (type == [UTIHelper stringFromPboardType:(NSString*)kUTTypeFileURL]) {
|
||||
NSString* urlStr = [cocoaPasteboard stringForType:type];
|
||||
NSURL* url = [NSURL URLWithString:urlStr];
|
||||
source = CGImageSourceCreateWithURL((CFURLRef)url,
|
||||
(CFDictionaryRef)options);
|
||||
} else {
|
||||
source = CGImageSourceCreateWithData((CFDataRef)pasteboardData,
|
||||
(CFDictionaryRef)options);
|
||||
}
|
||||
|
||||
CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)pasteboardData,
|
||||
(CFDictionaryRef)options);
|
||||
NSMutableData *encodedData = [NSMutableData data];
|
||||
CGImageDestinationRef dest = CGImageDestinationCreateWithData((CFMutableDataRef)encodedData,
|
||||
outputType,
|
||||
|
Loading…
Reference in New Issue
Block a user