diff options
Diffstat (limited to 'chromium/ui/base/clipboard/clipboard_util_mac.mm')
-rw-r--r-- | chromium/ui/base/clipboard/clipboard_util_mac.mm | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/chromium/ui/base/clipboard/clipboard_util_mac.mm b/chromium/ui/base/clipboard/clipboard_util_mac.mm index b7bf6229dda..3611b997d66 100644 --- a/chromium/ui/base/clipboard/clipboard_util_mac.mm +++ b/chromium/ui/base/clipboard/clipboard_util_mac.mm @@ -150,10 +150,8 @@ bool ClipboardUtil::URLsAndTitlesFromPasteboard(NSPasteboard* pboard, if ([bookmarkPairs count] != 2) return false; - NSArray* urlsArr = - base::mac::ObjCCast<NSArray>([bookmarkPairs objectAtIndex:0]); - NSArray* titlesArr = - base::mac::ObjCCast<NSArray>([bookmarkPairs objectAtIndex:1]); + NSArray* urlsArr = base::mac::ObjCCast<NSArray>(bookmarkPairs[0]); + NSArray* titlesArr = base::mac::ObjCCast<NSArray>(bookmarkPairs[1]); if (!urlsArr || !titlesArr) return false; @@ -195,4 +193,25 @@ NSPasteboard* ClipboardUtil::PasteboardFromType(ui::ClipboardType type) { return [NSPasteboard pasteboardWithName:type_string]; } +// static +NSString* ClipboardUtil::GetHTMLFromRTFOnPasteboard(NSPasteboard* pboard) { + NSData* rtfData = [pboard dataForType:NSRTFPboardType]; + if (!rtfData) + return nil; + + NSAttributedString* attributed = + [[[NSAttributedString alloc] initWithRTF:rtfData + documentAttributes:nil] autorelease]; + NSData* htmlData = + [attributed dataFromRange:NSMakeRange(0, [attributed length]) + documentAttributes:@{ + NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType + } + error:nil]; + + // According to the docs, NSHTMLTextDocumentType is UTF8. + return [[[NSString alloc] initWithData:htmlData + encoding:NSUTF8StringEncoding] autorelease]; +} + } // namespace ui |