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

Side by Side Diff: app/clipboard/clipboard_mac.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, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « app/DEPS ('k') | chrome/browser/cocoa/web_drop_target.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "app/clipboard/clipboard.h" 5 #include "app/clipboard/clipboard.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/mac_util.h" 11 #include "base/mac_util.h"
12 #include "base/scoped_cftyperef.h" 12 #include "base/scoped_cftyperef.h"
13 #include "base/scoped_nsobject.h" 13 #include "base/scoped_nsobject.h"
14 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "gfx/size.h" 16 #include "gfx/size.h"
17 #import "third_party/mozilla/NSPasteboard+Utils.h"
17 18
18 namespace { 19 namespace {
19 20
20 // Would be nice if this were in UTCoreTypes.h, but it isn't 21 // Would be nice if this were in UTCoreTypes.h, but it isn't
21 const NSString* kUTTypeURLName = @"public.url-name"; 22 const NSString* kUTTypeURLName = @"public.url-name";
22 23
23 // Tells us if WebKit was the last to write to the pasteboard. There's no 24 // Tells us if WebKit was the last to write to the pasteboard. There's no
24 // actual data associated with this type. 25 // actual data associated with this type.
25 const NSString *kWebSmartPastePboardType = @"NeXT smart paste pasteboard type"; 26 const NSString *kWebSmartPastePboardType = @"NeXT smart paste pasteboard type";
26 27
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 159 }
159 160
160 bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format, 161 bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format,
161 Clipboard::Buffer buffer) const { 162 Clipboard::Buffer buffer) const {
162 DCHECK_EQ(buffer, BUFFER_STANDARD); 163 DCHECK_EQ(buffer, BUFFER_STANDARD);
163 NSString* format_ns = base::SysUTF8ToNSString(format); 164 NSString* format_ns = base::SysUTF8ToNSString(format);
164 165
165 NSPasteboard* pb = GetPasteboard(); 166 NSPasteboard* pb = GetPasteboard();
166 NSArray* types = [pb types]; 167 NSArray* types = [pb types];
167 168
169 // Safari only places RTF on the pasteboard, never HTML. We can convert RTF
170 // to HTML, so the presence of either indicates success when looking for HTML.
171 if ([format_ns isEqualToString:NSHTMLPboardType]) {
172 return [types containsObject:NSHTMLPboardType] ||
173 [types containsObject:NSRTFPboardType];
174 }
168 return [types containsObject:format_ns]; 175 return [types containsObject:format_ns];
169 } 176 }
170 177
171 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const { 178 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const {
172 DCHECK_EQ(buffer, BUFFER_STANDARD); 179 DCHECK_EQ(buffer, BUFFER_STANDARD);
173 NSPasteboard* pb = GetPasteboard(); 180 NSPasteboard* pb = GetPasteboard();
174 NSString* contents = [pb stringForType:NSStringPboardType]; 181 NSString* contents = [pb stringForType:NSStringPboardType];
175 182
176 UTF8ToUTF16([contents UTF8String], 183 UTF8ToUTF16([contents UTF8String],
177 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], 184 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
(...skipping 10 matching lines...) Expand all
188 result->clear(); 195 result->clear();
189 else 196 else
190 result->assign([contents UTF8String]); 197 result->assign([contents UTF8String]);
191 } 198 }
192 199
193 void Clipboard::ReadHTML(Clipboard::Buffer buffer, string16* markup, 200 void Clipboard::ReadHTML(Clipboard::Buffer buffer, string16* markup,
194 std::string* src_url) const { 201 std::string* src_url) const {
195 DCHECK_EQ(buffer, BUFFER_STANDARD); 202 DCHECK_EQ(buffer, BUFFER_STANDARD);
196 if (markup) { 203 if (markup) {
197 NSPasteboard* pb = GetPasteboard(); 204 NSPasteboard* pb = GetPasteboard();
198 NSArray *supportedTypes = [NSArray arrayWithObjects:NSHTMLPboardType, 205 NSArray* supportedTypes = [NSArray arrayWithObjects:NSHTMLPboardType,
206 NSRTFPboardType,
199 NSStringPboardType, 207 NSStringPboardType,
200 nil]; 208 nil];
201 NSString *bestType = [pb availableTypeFromArray:supportedTypes]; 209 NSString* bestType = [pb availableTypeFromArray:supportedTypes];
202 NSString* contents = [pb stringForType:bestType]; 210 NSString* contents = [pb stringForType:bestType];
211 if ([bestType isEqualToString:NSRTFPboardType])
212 contents = [pb htmlFromRtf];
203 UTF8ToUTF16([contents UTF8String], 213 UTF8ToUTF16([contents UTF8String],
204 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], 214 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
205 markup); 215 markup);
206 } 216 }
207 217
208 // TODO(avi): src_url? 218 // TODO(avi): src_url?
209 if (src_url) 219 if (src_url)
210 src_url->clear(); 220 src_url->clear();
211 } 221 }
212 222
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 static const std::string type = base::SysNSStringToUTF8(NSTIFFPboardType); 320 static const std::string type = base::SysNSStringToUTF8(NSTIFFPboardType);
311 return type; 321 return type;
312 } 322 }
313 323
314 // static 324 // static
315 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { 325 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() {
316 static const std::string type = 326 static const std::string type =
317 base::SysNSStringToUTF8(kWebSmartPastePboardType); 327 base::SysNSStringToUTF8(kWebSmartPastePboardType);
318 return type; 328 return type;
319 } 329 }
OLDNEW
« no previous file with comments | « app/DEPS ('k') | chrome/browser/cocoa/web_drop_target.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698