| 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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 const char* url_data, | 419 const char* url_data, |
| 420 size_t url_len) { | 420 size_t url_len) { |
| 421 std::string title_str(title_data, title_len); | 421 std::string title_str(title_data, title_len); |
| 422 NSString* title = base::SysUTF8ToNSString(title_str); | 422 NSString* title = base::SysUTF8ToNSString(title_str); |
| 423 std::string url_str(url_data, url_len); | 423 std::string url_str(url_data, url_len); |
| 424 NSString* url = base::SysUTF8ToNSString(url_str); | 424 NSString* url = base::SysUTF8ToNSString(url_str); |
| 425 | 425 |
| 426 base::scoped_nsobject<NSPasteboardItem> item( | 426 base::scoped_nsobject<NSPasteboardItem> item( |
| 427 ClipboardUtil::PasteboardItemFromUrl(url, title)); | 427 ClipboardUtil::PasteboardItemFromUrl(url, title)); |
| 428 NSPasteboard* pb = GetPasteboard(); | 428 NSPasteboard* pb = GetPasteboard(); |
| 429 | 429 ui::ClipboardUtil::AddDataToPasteboard(pb, item); |
| 430 NSSet* oldTypes = [NSSet setWithArray:[pb types]]; | |
| 431 NSMutableSet* newTypes = [NSMutableSet setWithArray:[item types]]; | |
| 432 [newTypes minusSet:oldTypes]; | |
| 433 | |
| 434 [pb addTypes:[newTypes allObjects] owner:nil]; | |
| 435 for (NSString* type in newTypes) { | |
| 436 // Technically, the object associated with |type| might be an NSString or a | |
| 437 // property list. It doesn't matter though, since the type gets pulled from | |
| 438 // and shoved into an NSDictionary. | |
| 439 [pb setData:[item dataForType:type] forType:type]; | |
| 440 } | |
| 441 } | 430 } |
| 442 | 431 |
| 443 void ClipboardMac::WriteBitmap(const SkBitmap& bitmap) { | 432 void ClipboardMac::WriteBitmap(const SkBitmap& bitmap) { |
| 444 NSImage* image = skia::SkBitmapToNSImageWithColorSpace( | 433 NSImage* image = skia::SkBitmapToNSImageWithColorSpace( |
| 445 bitmap, base::mac::GetSystemColorSpace()); | 434 bitmap, base::mac::GetSystemColorSpace()); |
| 446 // An API to ask the NSImage to write itself to the clipboard comes in 10.6 :( | 435 // An API to ask the NSImage to write itself to the clipboard comes in 10.6 :( |
| 447 // For now, spit out the image as a TIFF. | 436 // For now, spit out the image as a TIFF. |
| 448 NSPasteboard* pb = GetPasteboard(); | 437 NSPasteboard* pb = GetPasteboard(); |
| 449 [pb addTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:nil]; | 438 [pb addTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:nil]; |
| 450 NSData* tiff_data = [image TIFFRepresentation]; | 439 NSData* tiff_data = [image TIFFRepresentation]; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 466 // 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 |
| 467 // pasteboard. This flavor has no data. | 456 // pasteboard. This flavor has no data. |
| 468 void ClipboardMac::WriteWebSmartPaste() { | 457 void ClipboardMac::WriteWebSmartPaste() { |
| 469 NSPasteboard* pb = GetPasteboard(); | 458 NSPasteboard* pb = GetPasteboard(); |
| 470 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); | 459 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); |
| 471 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; | 460 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; |
| 472 [pb setData:nil forType:format]; | 461 [pb setData:nil forType:format]; |
| 473 } | 462 } |
| 474 | 463 |
| 475 } // namespace ui | 464 } // namespace ui |
| OLD | NEW |