From 373e080995166cc280e58319e68d92b9122d5e1d Mon Sep 17 00:00:00 2001 From: Mirko Brodesser Date: Fri, 19 Feb 2021 09:04:34 +0000 Subject: [PATCH] Bug 1689992: part 0) Factor `nsClipboard::IsImageType` out. r=masayuki Differential Revision: https://phabricator.services.mozilla.com/D105277 --- widget/cocoa/nsClipboard.h | 1 + widget/cocoa/nsClipboard.mm | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/widget/cocoa/nsClipboard.h b/widget/cocoa/nsClipboard.h index ce4b7a6675a9..7f9d0e543be4 100644 --- a/widget/cocoa/nsClipboard.h +++ b/widget/cocoa/nsClipboard.h @@ -34,6 +34,7 @@ class nsClipboard : public nsIClipboard { static NSDictionary* PasteboardDictFromTransferable(nsITransferable* aTransferable); // aPasteboardType is being retained and needs to be released by the caller. static bool IsStringType(const nsCString& aMIMEType, NSString** aPasteboardType); + static bool IsImageType(const nsACString& aMIMEType); static NSString* WrapHtmlForSystemPasteboard(NSString* aString); static nsresult TransferableFromPasteboard(nsITransferable* aTransferable, NSPasteboard* pboard); diff --git a/widget/cocoa/nsClipboard.mm b/widget/cocoa/nsClipboard.mm index 054f201f4f79..e3f23f196b79 100644 --- a/widget/cocoa/nsClipboard.mm +++ b/widget/cocoa/nsClipboard.mm @@ -505,9 +505,7 @@ NSDictionary* nsClipboard::PasteboardDictFromTransferable(nsITransferable* aTran } [pasteboardOutputDict setObject:nativeData forKey:customType]; } - } else if (flavorStr.EqualsLiteral(kPNGImageMime) || flavorStr.EqualsLiteral(kJPEGImageMime) || - flavorStr.EqualsLiteral(kJPGImageMime) || flavorStr.EqualsLiteral(kGIFImageMime) || - flavorStr.EqualsLiteral(kNativeImageMime)) { + } else if (nsClipboard::IsImageType(flavorStr)) { nsCOMPtr transferSupports; rv = aTransferable->GetTransferData(flavorStr.get(), getter_AddRefs(transferSupports)); if (NS_FAILED(rv)) { @@ -656,6 +654,13 @@ bool nsClipboard::IsStringType(const nsCString& aMIMEType, NSString** aPasteboar } } +// static +bool nsClipboard::IsImageType(const nsACString& aMIMEType) { + return aMIMEType.EqualsLiteral(kPNGImageMime) || aMIMEType.EqualsLiteral(kJPEGImageMime) || + aMIMEType.EqualsLiteral(kJPGImageMime) || aMIMEType.EqualsLiteral(kGIFImageMime) || + aMIMEType.EqualsLiteral(kNativeImageMime); +} + NSString* nsClipboard::WrapHtmlForSystemPasteboard(NSString* aString) { NSString* wrapped = [NSString stringWithFormat:@""