summaryrefslogtreecommitdiffstats
path: root/third_party/mozilla/NSPasteboard+Utils.mm
diff options
context:
space:
mode:
authorpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-04 19:07:12 +0000
committerpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-04 19:07:12 +0000
commit3a5a8f3ced18095419e5d79075bd2e0cfc9a88b4 (patch)
tree827bb68c510634260845f750642b7360b18cc33a /third_party/mozilla/NSPasteboard+Utils.mm
parent88e8e752268e85da7196e5dbd8c622a7b0565e19 (diff)
downloadchromium_src-3a5a8f3ced18095419e5d79075bd2e0cfc9a88b4.zip
chromium_src-3a5a8f3ced18095419e5d79075bd2e0cfc9a88b4.tar.gz
chromium_src-3a5a8f3ced18095419e5d79075bd2e0cfc9a88b4.tar.bz2
Convert RTF on the pasteboard to HTML and all it to substitute if present and no HTML is on a paste or drop. Safari does not put HTML on the pasteboard, only RTF.
BUG=44661 TEST=dropping/pasting html should retain basic structure, but fonts/colors don't seem to propagate. Review URL: http://codereview.chromium.org/2674002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48962 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/mozilla/NSPasteboard+Utils.mm')
-rw-r--r--third_party/mozilla/NSPasteboard+Utils.mm25
1 files changed, 25 insertions, 0 deletions
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