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

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

Issue 1855583002: Refactor more clipboard/bookmark logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp15_dnd
Patch Set: Comments from avi. 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
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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
OLDNEW
« no previous file with comments | « components/bookmarks/browser/bookmark_pasteboard_helper_mac.mm ('k') | ui/base/clipboard/clipboard_util_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698