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

Side by Side Diff: ui/base/clipboard/clipboard_mac.mm

Issue 1921713004: mac: Use more modern API for writing images to the pasteboard. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bleh Created 4 years, 8 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
« no previous file with comments | « no previous file | no next file » | 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) 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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ui::ClipboardUtil::AddDataToPasteboard(pb, item); 429 ui::ClipboardUtil::AddDataToPasteboard(pb, item);
430 } 430 }
431 431
432 void ClipboardMac::WriteBitmap(const SkBitmap& bitmap) { 432 void ClipboardMac::WriteBitmap(const SkBitmap& bitmap) {
433 NSPasteboard* pb = GetPasteboard();
434 [pb clearContents];
433 NSImage* image = skia::SkBitmapToNSImageWithColorSpace( 435 NSImage* image = skia::SkBitmapToNSImageWithColorSpace(
434 bitmap, base::mac::GetSystemColorSpace()); 436 bitmap, base::mac::GetSystemColorSpace());
435 // An API to ask the NSImage to write itself to the clipboard comes in 10.6 :( 437 [pb writeObjects:@[ image ]];
436 // For now, spit out the image as a TIFF.
437 NSPasteboard* pb = GetPasteboard();
438 [pb addTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:nil];
439 NSData* tiff_data = [image TIFFRepresentation];
440 LOG_IF(ERROR, tiff_data == NULL) << "Failed to allocate image for clipboard";
441 if (tiff_data) {
442 [pb setData:tiff_data forType:NSTIFFPboardType];
443 }
444 } 438 }
445 439
446 void ClipboardMac::WriteData(const FormatType& format, 440 void ClipboardMac::WriteData(const FormatType& format,
447 const char* data_data, 441 const char* data_data,
448 size_t data_len) { 442 size_t data_len) {
449 NSPasteboard* pb = GetPasteboard(); 443 NSPasteboard* pb = GetPasteboard();
450 [pb addTypes:[NSArray arrayWithObject:format.ToNSString()] owner:nil]; 444 [pb addTypes:[NSArray arrayWithObject:format.ToNSString()] owner:nil];
451 [pb setData:[NSData dataWithBytes:data_data length:data_len] 445 [pb setData:[NSData dataWithBytes:data_data length:data_len]
452 forType:format.ToNSString()]; 446 forType:format.ToNSString()];
453 } 447 }
454 448
455 // Write an extra flavor that signifies WebKit was the last to modify the 449 // Write an extra flavor that signifies WebKit was the last to modify the
456 // pasteboard. This flavor has no data. 450 // pasteboard. This flavor has no data.
457 void ClipboardMac::WriteWebSmartPaste() { 451 void ClipboardMac::WriteWebSmartPaste() {
458 NSPasteboard* pb = GetPasteboard(); 452 NSPasteboard* pb = GetPasteboard();
459 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); 453 NSString* format = GetWebKitSmartPasteFormatType().ToNSString();
460 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; 454 [pb addTypes:[NSArray arrayWithObject:format] owner:nil];
461 [pb setData:nil forType:format]; 455 [pb setData:nil forType:format];
462 } 456 }
463 457
464 } // namespace ui 458 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698