Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(654)

Unified Diff: third_party/mozilla/NSPasteboard+Utils.mm

Issue 2674002: Convert RTF on the pasteboard to HTML and all it to substitute if present and... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/mozilla/NSPasteboard+Utils.h ('k') | third_party/mozilla/README.chromium » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/mozilla/NSPasteboard+Utils.mm
===================================================================
--- third_party/mozilla/NSPasteboard+Utils.mm (revision 48762)
+++ third_party/mozilla/NSPasteboard+Utils.mm (working copy)
@@ -279,3 +279,28 @@
return NO;
}
@end
+
+@implementation NSPasteboard(ChromiumHTMLUtils)
+
+// Convert the RTF to HTML via an NSAttributedString.
+- (NSString*)htmlFromRtf {
+ if (![[self types] containsObject:NSRTFPboardType])
+ return @"";
+
+ NSAttributedString* attributed =
+ [[[NSAttributedString alloc]
+ initWithRTF:[self dataForType:NSRTFPboardType]
+ documentAttributes:nil] autorelease];
+ NSDictionary* attributeDict =
+ [NSDictionary dictionaryWithObject:NSHTMLTextDocumentType
+ forKey:NSDocumentTypeDocumentAttribute];
+ NSData* htmlData =
+ [attributed dataFromRange:NSMakeRange(0, [attributed length])
+ documentAttributes:attributeDict
+ error:nil];
+ // According to the docs, NSHTMLTextDocumentType is UTF8.
+ return [[[NSString alloc]
+ initWithData:htmlData encoding:NSUTF8StringEncoding] autorelease];
+}
+
+@end
« no previous file with comments | « third_party/mozilla/NSPasteboard+Utils.h ('k') | third_party/mozilla/README.chromium » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698