diff options
Diffstat (limited to 'third_party/mozilla')
-rw-r--r-- | third_party/mozilla/NSPasteboard+Utils.h | 7 | ||||
-rw-r--r-- | third_party/mozilla/NSPasteboard+Utils.mm | 25 | ||||
-rw-r--r-- | third_party/mozilla/README.chromium | 1 |
3 files changed, 33 insertions, 0 deletions
diff --git a/third_party/mozilla/NSPasteboard+Utils.h b/third_party/mozilla/NSPasteboard+Utils.h index c75de6a..79d3bfb 100644 --- a/third_party/mozilla/NSPasteboard+Utils.h +++ b/third_party/mozilla/NSPasteboard+Utils.h @@ -58,3 +58,10 @@ extern NSString* const kWebURLsWithTitlesPboardType; @end +@interface NSPasteboard(ChromiumHTMLUtils) + +// Returns the HTML converted from RTF data on the pasteboard. If there is +// none, returns an empty string. +- (NSString*)htmlFromRtf; + +@end diff --git a/third_party/mozilla/NSPasteboard+Utils.mm b/third_party/mozilla/NSPasteboard+Utils.mm index 8ac1ba5..0af5c48 100644 --- a/third_party/mozilla/NSPasteboard+Utils.mm +++ b/third_party/mozilla/NSPasteboard+Utils.mm @@ -279,3 +279,28 @@ NSString* const kWebURLsWithTitlesPboardType = @"WebURLsWithTitlesPboardType"; 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 diff --git a/third_party/mozilla/README.chromium b/third_party/mozilla/README.chromium index fc5779c..fe93bb8 100644 --- a/third_party/mozilla/README.chromium +++ b/third_party/mozilla/README.chromium @@ -19,3 +19,4 @@ Local modifications: - NSPasteboard+Utils.mm was modified to add an argument to -[NSPasteboard getURLs:andTitles:] to determine whether or not filenames in the drag should be converted to file URLs. + -[NSPasteboard htmlFromRtf] added to do rtf->html conversion. |