| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/base/clipboard/clipboard_mac.h" | 5 #include "ui/base/clipboard/clipboard_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 return type; | 105 return type; |
| 106 } | 106 } |
| 107 | 107 |
| 108 // static | 108 // static |
| 109 const Clipboard::FormatType& Clipboard::GetUrlWFormatType() { | 109 const Clipboard::FormatType& Clipboard::GetUrlWFormatType() { |
| 110 return GetUrlFormatType(); | 110 return GetUrlFormatType(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // static | 113 // static |
| 114 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { | 114 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { |
| 115 CR_DEFINE_STATIC_LOCAL(FormatType, type, (NSStringPboardType)); | 115 CR_DEFINE_STATIC_LOCAL(FormatType, type, (NSPasteboardTypeString)); |
| 116 return type; | 116 return type; |
| 117 } | 117 } |
| 118 | 118 |
| 119 // static | 119 // static |
| 120 const Clipboard::FormatType& Clipboard::GetPlainTextWFormatType() { | 120 const Clipboard::FormatType& Clipboard::GetPlainTextWFormatType() { |
| 121 return GetPlainTextFormatType(); | 121 return GetPlainTextFormatType(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 // static | 124 // static |
| 125 const Clipboard::FormatType& Clipboard::GetFilenameFormatType() { | 125 const Clipboard::FormatType& Clipboard::GetFilenameFormatType() { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 NSData* data = [pb dataForType:kWebCustomDataPboardType]; | 236 NSData* data = [pb dataForType:kWebCustomDataPboardType]; |
| 237 if ([data length]) | 237 if ([data length]) |
| 238 ReadCustomDataTypes([data bytes], [data length], types); | 238 ReadCustomDataTypes([data bytes], [data length], types); |
| 239 } | 239 } |
| 240 } | 240 } |
| 241 | 241 |
| 242 void ClipboardMac::ReadText(ClipboardType type, base::string16* result) const { | 242 void ClipboardMac::ReadText(ClipboardType type, base::string16* result) const { |
| 243 DCHECK(CalledOnValidThread()); | 243 DCHECK(CalledOnValidThread()); |
| 244 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); | 244 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); |
| 245 NSPasteboard* pb = GetPasteboard(); | 245 NSPasteboard* pb = GetPasteboard(); |
| 246 NSString* contents = [pb stringForType:NSStringPboardType]; | 246 NSString* contents = [pb stringForType:NSPasteboardTypeString]; |
| 247 | 247 |
| 248 *result = base::SysNSStringToUTF16(contents); | 248 *result = base::SysNSStringToUTF16(contents); |
| 249 } | 249 } |
| 250 | 250 |
| 251 void ClipboardMac::ReadAsciiText(ClipboardType type, | 251 void ClipboardMac::ReadAsciiText(ClipboardType type, |
| 252 std::string* result) const { | 252 std::string* result) const { |
| 253 DCHECK(CalledOnValidThread()); | 253 DCHECK(CalledOnValidThread()); |
| 254 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); | 254 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); |
| 255 NSPasteboard* pb = GetPasteboard(); | 255 NSPasteboard* pb = GetPasteboard(); |
| 256 NSString* contents = [pb stringForType:NSStringPboardType]; | 256 NSString* contents = [pb stringForType:NSPasteboardTypeString]; |
| 257 | 257 |
| 258 if (!contents) | 258 if (!contents) |
| 259 result->clear(); | 259 result->clear(); |
| 260 else | 260 else |
| 261 result->assign([contents UTF8String]); | 261 result->assign([contents UTF8String]); |
| 262 } | 262 } |
| 263 | 263 |
| 264 void ClipboardMac::ReadHTML(ClipboardType type, | 264 void ClipboardMac::ReadHTML(ClipboardType type, |
| 265 base::string16* markup, | 265 base::string16* markup, |
| 266 std::string* src_url, | 266 std::string* src_url, |
| 267 uint32_t* fragment_start, | 267 uint32_t* fragment_start, |
| 268 uint32_t* fragment_end) const { | 268 uint32_t* fragment_end) const { |
| 269 DCHECK(CalledOnValidThread()); | 269 DCHECK(CalledOnValidThread()); |
| 270 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); | 270 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); |
| 271 | 271 |
| 272 // TODO(avi): src_url? | 272 // TODO(avi): src_url? |
| 273 markup->clear(); | 273 markup->clear(); |
| 274 if (src_url) | 274 if (src_url) |
| 275 src_url->clear(); | 275 src_url->clear(); |
| 276 | 276 |
| 277 NSPasteboard* pb = GetPasteboard(); | 277 NSPasteboard* pb = GetPasteboard(); |
| 278 NSArray* supportedTypes = [NSArray arrayWithObjects:NSHTMLPboardType, | 278 NSArray* supportedTypes = [NSArray arrayWithObjects:NSHTMLPboardType, |
| 279 NSRTFPboardType, | 279 NSRTFPboardType, |
| 280 NSStringPboardType, | 280 NSPasteboardTypeString, |
| 281 nil]; | 281 nil]; |
| 282 NSString* bestType = [pb availableTypeFromArray:supportedTypes]; | 282 NSString* bestType = [pb availableTypeFromArray:supportedTypes]; |
| 283 if (bestType) { | 283 if (bestType) { |
| 284 NSString* contents = [pb stringForType:bestType]; | 284 NSString* contents = [pb stringForType:bestType]; |
| 285 if ([bestType isEqualToString:NSRTFPboardType]) | 285 if ([bestType isEqualToString:NSRTFPboardType]) |
| 286 contents = [pb htmlFromRtf]; | 286 contents = [pb htmlFromRtf]; |
| 287 *markup = base::SysNSStringToUTF16(contents); | 287 *markup = base::SysNSStringToUTF16(contents); |
| 288 } | 288 } |
| 289 | 289 |
| 290 *fragment_start = 0; | 290 *fragment_start = 0; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 for (ObjectMap::const_iterator iter = objects.begin(); iter != objects.end(); | 384 for (ObjectMap::const_iterator iter = objects.begin(); iter != objects.end(); |
| 385 ++iter) { | 385 ++iter) { |
| 386 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); | 386 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); |
| 387 } | 387 } |
| 388 } | 388 } |
| 389 | 389 |
| 390 void ClipboardMac::WriteText(const char* text_data, size_t text_len) { | 390 void ClipboardMac::WriteText(const char* text_data, size_t text_len) { |
| 391 std::string text_str(text_data, text_len); | 391 std::string text_str(text_data, text_len); |
| 392 NSString* text = base::SysUTF8ToNSString(text_str); | 392 NSString* text = base::SysUTF8ToNSString(text_str); |
| 393 NSPasteboard* pb = GetPasteboard(); | 393 NSPasteboard* pb = GetPasteboard(); |
| 394 [pb addTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; | 394 [pb addTypes:[NSArray arrayWithObject:NSPasteboardTypeString] owner:nil]; |
| 395 [pb setString:text forType:NSStringPboardType]; | 395 [pb setString:text forType:NSPasteboardTypeString]; |
| 396 } | 396 } |
| 397 | 397 |
| 398 void ClipboardMac::WriteHTML(const char* markup_data, | 398 void ClipboardMac::WriteHTML(const char* markup_data, |
| 399 size_t markup_len, | 399 size_t markup_len, |
| 400 const char* url_data, | 400 const char* url_data, |
| 401 size_t url_len) { | 401 size_t url_len) { |
| 402 // We need to mark it as utf-8. (see crbug.com/11957) | 402 // We need to mark it as utf-8. (see crbug.com/11957) |
| 403 std::string html_fragment_str("<meta charset='utf-8'>"); | 403 std::string html_fragment_str("<meta charset='utf-8'>"); |
| 404 html_fragment_str.append(markup_data, markup_len); | 404 html_fragment_str.append(markup_data, markup_len); |
| 405 NSString* html_fragment = base::SysUTF8ToNSString(html_fragment_str); | 405 NSString* html_fragment = base::SysUTF8ToNSString(html_fragment_str); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 // Write an extra flavor that signifies WebKit was the last to modify the | 455 // Write an extra flavor that signifies WebKit was the last to modify the |
| 456 // pasteboard. This flavor has no data. | 456 // pasteboard. This flavor has no data. |
| 457 void ClipboardMac::WriteWebSmartPaste() { | 457 void ClipboardMac::WriteWebSmartPaste() { |
| 458 NSPasteboard* pb = GetPasteboard(); | 458 NSPasteboard* pb = GetPasteboard(); |
| 459 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); | 459 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); |
| 460 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; | 460 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; |
| 461 [pb setData:nil forType:format]; | 461 [pb setData:nil forType:format]; |
| 462 } | 462 } |
| 463 | 463 |
| 464 } // namespace ui | 464 } // namespace ui |
| OLD | NEW |