diff options
author | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-04 19:07:12 +0000 |
---|---|---|
committer | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-04 19:07:12 +0000 |
commit | 3a5a8f3ced18095419e5d79075bd2e0cfc9a88b4 (patch) | |
tree | 827bb68c510634260845f750642b7360b18cc33a /app/clipboard/clipboard_mac.mm | |
parent | 88e8e752268e85da7196e5dbd8c622a7b0565e19 (diff) | |
download | chromium_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 'app/clipboard/clipboard_mac.mm')
-rw-r--r-- | app/clipboard/clipboard_mac.mm | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/app/clipboard/clipboard_mac.mm b/app/clipboard/clipboard_mac.mm index 4673e6e..7ae3a1b 100644 --- a/app/clipboard/clipboard_mac.mm +++ b/app/clipboard/clipboard_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -14,6 +14,7 @@ #include "base/sys_string_conversions.h" #include "base/utf_string_conversions.h" #include "gfx/size.h" +#import "third_party/mozilla/NSPasteboard+Utils.h" namespace { @@ -165,6 +166,12 @@ bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format, NSPasteboard* pb = GetPasteboard(); NSArray* types = [pb types]; + // Safari only places RTF on the pasteboard, never HTML. We can convert RTF + // to HTML, so the presence of either indicates success when looking for HTML. + if ([format_ns isEqualToString:NSHTMLPboardType]) { + return [types containsObject:NSHTMLPboardType] || + [types containsObject:NSRTFPboardType]; + } return [types containsObject:format_ns]; } @@ -195,11 +202,14 @@ void Clipboard::ReadHTML(Clipboard::Buffer buffer, string16* markup, DCHECK_EQ(buffer, BUFFER_STANDARD); if (markup) { NSPasteboard* pb = GetPasteboard(); - NSArray *supportedTypes = [NSArray arrayWithObjects:NSHTMLPboardType, + NSArray* supportedTypes = [NSArray arrayWithObjects:NSHTMLPboardType, + NSRTFPboardType, NSStringPboardType, nil]; - NSString *bestType = [pb availableTypeFromArray:supportedTypes]; + NSString* bestType = [pb availableTypeFromArray:supportedTypes]; NSString* contents = [pb stringForType:bestType]; + if ([bestType isEqualToString:NSRTFPboardType]) + contents = [pb htmlFromRtf]; UTF8ToUTF16([contents UTF8String], [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], markup); |