| 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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 initWithContentsOfURL:[NSURL fileURLWithPath:[paths lastObject]]]); | 322 initWithContentsOfURL:[NSURL fileURLWithPath:[paths lastObject]]]); |
| 323 } | 323 } |
| 324 } else { | 324 } else { |
| 325 image.reset([[NSImage alloc] initWithPasteboard:pb]); | 325 image.reset([[NSImage alloc] initWithPasteboard:pb]); |
| 326 } | 326 } |
| 327 } @catch (id exception) { | 327 } @catch (id exception) { |
| 328 } | 328 } |
| 329 | 329 |
| 330 SkBitmap bitmap; | 330 SkBitmap bitmap; |
| 331 if (image.get()) { | 331 if (image.get()) { |
| 332 bitmap = gfx::NSImageToSkBitmapWithColorSpace( | 332 bitmap = skia::NSImageToSkBitmapWithColorSpace( |
| 333 image.get(), /*is_opaque=*/ false, base::mac::GetSystemColorSpace()); | 333 image.get(), /*is_opaque=*/ false, base::mac::GetSystemColorSpace()); |
| 334 } | 334 } |
| 335 return bitmap; | 335 return bitmap; |
| 336 } | 336 } |
| 337 | 337 |
| 338 void ClipboardMac::ReadCustomData(ClipboardType clipboard_type, | 338 void ClipboardMac::ReadCustomData(ClipboardType clipboard_type, |
| 339 const base::string16& type, | 339 const base::string16& type, |
| 340 base::string16* result) const { | 340 base::string16* result) const { |
| 341 DCHECK(CalledOnValidThread()); | 341 DCHECK(CalledOnValidThread()); |
| 342 DCHECK_EQ(clipboard_type, CLIPBOARD_TYPE_COPY_PASTE); | 342 DCHECK_EQ(clipboard_type, CLIPBOARD_TYPE_COPY_PASTE); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 | 433 |
| 434 NSPasteboard* pb = GetPasteboard(); | 434 NSPasteboard* pb = GetPasteboard(); |
| 435 // passing UTIs into the pasteboard methods is valid >= 10.5 | 435 // passing UTIs into the pasteboard methods is valid >= 10.5 |
| 436 [pb addTypes:[NSArray arrayWithObjects:NSURLPboardType, kUTTypeURLName, nil] | 436 [pb addTypes:[NSArray arrayWithObjects:NSURLPboardType, kUTTypeURLName, nil] |
| 437 owner:nil]; | 437 owner:nil]; |
| 438 [nsurl writeToPasteboard:pb]; | 438 [nsurl writeToPasteboard:pb]; |
| 439 [pb setString:title forType:kUTTypeURLName]; | 439 [pb setString:title forType:kUTTypeURLName]; |
| 440 } | 440 } |
| 441 | 441 |
| 442 void ClipboardMac::WriteBitmap(const SkBitmap& bitmap) { | 442 void ClipboardMac::WriteBitmap(const SkBitmap& bitmap) { |
| 443 NSImage* image = gfx::SkBitmapToNSImageWithColorSpace( | 443 NSImage* image = skia::SkBitmapToNSImageWithColorSpace( |
| 444 bitmap, base::mac::GetSystemColorSpace()); | 444 bitmap, base::mac::GetSystemColorSpace()); |
| 445 // An API to ask the NSImage to write itself to the clipboard comes in 10.6 :( | 445 // An API to ask the NSImage to write itself to the clipboard comes in 10.6 :( |
| 446 // For now, spit out the image as a TIFF. | 446 // For now, spit out the image as a TIFF. |
| 447 NSPasteboard* pb = GetPasteboard(); | 447 NSPasteboard* pb = GetPasteboard(); |
| 448 [pb addTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:nil]; | 448 [pb addTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:nil]; |
| 449 NSData* tiff_data = [image TIFFRepresentation]; | 449 NSData* tiff_data = [image TIFFRepresentation]; |
| 450 LOG_IF(ERROR, tiff_data == NULL) << "Failed to allocate image for clipboard"; | 450 LOG_IF(ERROR, tiff_data == NULL) << "Failed to allocate image for clipboard"; |
| 451 if (tiff_data) { | 451 if (tiff_data) { |
| 452 [pb setData:tiff_data forType:NSTIFFPboardType]; | 452 [pb setData:tiff_data forType:NSTIFFPboardType]; |
| 453 } | 453 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 465 // Write an extra flavor that signifies WebKit was the last to modify the | 465 // Write an extra flavor that signifies WebKit was the last to modify the |
| 466 // pasteboard. This flavor has no data. | 466 // pasteboard. This flavor has no data. |
| 467 void ClipboardMac::WriteWebSmartPaste() { | 467 void ClipboardMac::WriteWebSmartPaste() { |
| 468 NSPasteboard* pb = GetPasteboard(); | 468 NSPasteboard* pb = GetPasteboard(); |
| 469 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); | 469 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); |
| 470 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; | 470 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; |
| 471 [pb setData:nil forType:format]; | 471 [pb setData:nil forType:format]; |
| 472 } | 472 } |
| 473 | 473 |
| 474 } // namespace ui | 474 } // namespace ui |
| OLD | NEW |