summaryrefslogtreecommitdiffstats
path: root/third_party/mozilla
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
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')
-rw-r--r--third_party/mozilla/NSPasteboard+Utils.h7
-rw-r--r--third_party/mozilla/NSPasteboard+Utils.mm25
-rw-r--r--third_party/mozilla/README.chromium1
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.