summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/mac/ClipboardMac.mm
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/mac/ClipboardMac.mm')
-rw-r--r--WebCore/platform/mac/ClipboardMac.mm77
1 files changed, 46 insertions, 31 deletions
diff --git a/WebCore/platform/mac/ClipboardMac.mm b/WebCore/platform/mac/ClipboardMac.mm
index 52bc952..78fb659 100644
--- a/WebCore/platform/mac/ClipboardMac.mm
+++ b/WebCore/platform/mac/ClipboardMac.mm
@@ -63,7 +63,7 @@ bool ClipboardMac::hasData()
return m_pasteboard && [m_pasteboard.get() types] && [[m_pasteboard.get() types] count] > 0;
}
-static NSString *cocoaTypeFromMIMEType(const String& type)
+static NSString *cocoaTypeFromHTMLClipboardType(const String& type)
{
String qType = type.stripWhiteSpace();
@@ -82,10 +82,9 @@ static NSString *cocoaTypeFromMIMEType(const String& type)
// Try UTI now
NSString *mimeType = qType;
- CFStringRef UTIType = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (CFStringRef)mimeType, NULL);
- if (UTIType) {
- CFStringRef pbType = UTTypeCopyPreferredTagWithClass(UTIType, kUTTagClassNSPboardType);
- CFRelease(UTIType);
+ RetainPtr<CFStringRef> utiType(AdoptCF, UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (CFStringRef)mimeType, NULL));
+ if (utiType) {
+ CFStringRef pbType = UTTypeCopyPreferredTagWithClass(utiType.get(), kUTTagClassNSPboardType);
if (pbType)
return HardAutorelease(pbType);
}
@@ -94,28 +93,41 @@ static NSString *cocoaTypeFromMIMEType(const String& type)
return qType;
}
-static String MIMETypeFromCocoaType(NSString *type)
+static String utiTypeFromCocoaType(NSString *type)
+{
+ RetainPtr<CFStringRef> utiType(AdoptCF, UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (CFStringRef)type, NULL));
+ if (utiType) {
+ RetainPtr<CFStringRef> mimeType(AdoptCF, UTTypeCopyPreferredTagWithClass(utiType.get(), kUTTagClassMIMEType));
+ if (mimeType)
+ return String(mimeType.get());
+ }
+ return String();
+}
+
+static void addHTMLClipboardTypesForCocoaType(HashSet<String>& resultTypes, NSString *cocoaType, NSPasteboard *pasteboard)
{
// UTI may not do these right, so make sure we get the right, predictable result
- if ([type isEqualToString:NSStringPboardType])
- return "text/plain";
- if ([type isEqualToString:NSURLPboardType] || [type isEqualToString:NSFilenamesPboardType])
- return "text/uri-list";
-
- // Now try the general UTI mechanism
- CFStringRef UTIType = UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (CFStringRef)type, NULL);
- if (UTIType) {
- CFStringRef mimeType = UTTypeCopyPreferredTagWithClass(UTIType, kUTTagClassMIMEType);
- CFRelease(UTIType);
- if (mimeType) {
- String result = mimeType;
- CFRelease(mimeType);
- return result;
+ if ([cocoaType isEqualToString:NSStringPboardType])
+ resultTypes.add("text/plain");
+ else if ([cocoaType isEqualToString:NSURLPboardType])
+ resultTypes.add("text/uri-list");
+ else if ([cocoaType isEqualToString:NSFilenamesPboardType]) {
+ // If file list is empty, add nothing.
+ // Note that there is a chance that the file list count could have changed since we grabbed the types array.
+ // However, this is not really an issue for us doing a sanity check here.
+ NSArray *fileList = [pasteboard propertyListForType:NSFilenamesPboardType];
+ if ([fileList count]) {
+ // It is unknown if NSFilenamesPboardType always implies NSURLPboardType in Cocoa,
+ // but NSFilenamesPboardType should imply both 'text/uri-list' and 'Files'
+ resultTypes.add("text/uri-list");
+ resultTypes.add("Files");
}
+ } else if (String utiType = utiTypeFromCocoaType(cocoaType))
+ resultTypes.add(utiType);
+ else {
+ // No mapping, just pass the whole string though
+ resultTypes.add(cocoaType);
}
-
- // No mapping, just pass the whole string though
- return type;
}
void ClipboardMac::clearData(const String& type)
@@ -125,7 +137,7 @@ void ClipboardMac::clearData(const String& type)
// note NSPasteboard enforces changeCount itself on writing - can't write if not the owner
- NSString *cocoaType = cocoaTypeFromMIMEType(type);
+ NSString *cocoaType = cocoaTypeFromHTMLClipboardType(type);
if (cocoaType)
[m_pasteboard.get() setString:@"" forType:cocoaType];
}
@@ -192,12 +204,12 @@ String ClipboardMac::getData(const String& type, bool& success) const
if (policy() != ClipboardReadable)
return String();
- NSString *cocoaType = cocoaTypeFromMIMEType(type);
+ NSString *cocoaType = cocoaTypeFromHTMLClipboardType(type);
NSString *cocoaValue = nil;
// Grab the value off the pasteboard corresponding to the cocoaType
if ([cocoaType isEqualToString:NSURLPboardType]) {
- // "URL" and "text/url-list" both map to NSURLPboardType in cocoaTypeFromMIMEType(), "URL" only wants the first URL
+ // "URL" and "text/url-list" both map to NSURLPboardType in cocoaTypeFromHTMLClipboardType(), "URL" only wants the first URL
bool onlyFirstURL = (type == "URL");
NSArray *absoluteURLs = absoluteURLsFromPasteboard(m_pasteboard.get(), onlyFirstURL);
cocoaValue = [absoluteURLs componentsJoinedByString:@"\n"];
@@ -222,7 +234,7 @@ bool ClipboardMac::setData(const String &type, const String &data)
return false;
// note NSPasteboard enforces changeCount itself on writing - can't write if not the owner
- NSString *cocoaType = cocoaTypeFromMIMEType(type);
+ NSString *cocoaType = cocoaTypeFromHTMLClipboardType(type);
NSString *cocoaData = data;
if ([cocoaType isEqualToString:NSURLPboardType]) {
@@ -263,15 +275,16 @@ HashSet<String> ClipboardMac::types() const
HashSet<String> result;
NSUInteger count = [types count];
+ // FIXME: This loop could be split into two stages. One which adds all the HTML5 specified types
+ // and a second which adds all the extra types from the cocoa clipboard (which is Mac-only behavior).
for (NSUInteger i = 0; i < count; i++) {
NSString *pbType = [types objectAtIndex:i];
if ([pbType isEqualToString:@"NeXT plain ascii pasteboard type"])
continue; // skip this ancient type that gets auto-supplied by some system conversion
- String str = MIMETypeFromCocoaType(pbType);
- if (!result.contains(str))
- result.add(str);
+ addHTMLClipboardTypesForCocoaType(result, pbType, m_pasteboard.get());
}
+
return result;
}
@@ -283,7 +296,7 @@ PassRefPtr<FileList> ClipboardMac::files() const
if (policy() != ClipboardReadable)
return FileList::create();
- NSArray *absoluteURLs = absoluteURLsFromPasteboard(m_pasteboard.get());
+ NSArray *absoluteURLs = absoluteURLsFromPasteboardFilenames(m_pasteboard.get());
NSUInteger count = [absoluteURLs count];
RefPtr<FileList> fileList = FileList::create();
@@ -355,12 +368,14 @@ void ClipboardMac::writeURL(const KURL& url, const String& title, Frame* frame)
Pasteboard::writeURL(m_pasteboard.get(), nil, url, title, frame);
}
+#if ENABLE(DRAG_SUPPORT)
void ClipboardMac::declareAndWriteDragImage(Element* element, const KURL& url, const String& title, Frame* frame)
{
ASSERT(frame);
if (Page* page = frame->page())
page->dragController()->client()->declareAndWriteDragImage(m_pasteboard.get(), kit(element), url, title, frame);
}
+#endif // ENABLE(DRAG_SUPPORT)
DragImageRef ClipboardMac::createDragImage(IntPoint& loc) const
{