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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 image.reset([[NSImage alloc] | 317 image.reset([[NSImage alloc] |
318 initWithContentsOfURL:[NSURL fileURLWithPath:[paths lastObject]]]); | 318 initWithContentsOfURL:[NSURL fileURLWithPath:[paths lastObject]]]); |
319 } | 319 } |
320 } else { | 320 } else { |
321 if (pb) | 321 if (pb) |
322 image.reset([[NSImage alloc] initWithPasteboard:pb]); | 322 image.reset([[NSImage alloc] initWithPasteboard:pb]); |
323 } | 323 } |
324 } @catch (id exception) { | 324 } @catch (id exception) { |
325 } | 325 } |
326 | 326 |
327 if (image.get()) { | 327 if (!image) |
328 if ([[image representations] count] == 1u) { | 328 return SkBitmap(); |
329 NSImageRep* rep = [[image representations] objectAtIndex:0]; | 329 if ([[image representations] count] == 0u) |
330 return SkBitmap(); | |
331 | |
332 if ([[image representations] count] == 1u) { | |
333 NSImageRep* rep = [[image representations] objectAtIndex:0]; | |
334 NSInteger width = [rep pixelsWide]; | |
335 NSInteger height = [rep pixelsHigh]; | |
336 if (width != 0 && height != 0) { | |
330 return skia::NSImageRepToSkBitmapWithColorSpace( | 337 return skia::NSImageRepToSkBitmapWithColorSpace( |
331 rep, NSMakeSize([rep pixelsWide], [rep pixelsHigh]), | 338 rep, NSMakeSize(width, height), /*is_opaque=*/false, |
332 /*is_opaque=*/false, base::mac::GetSystemColorSpace()); | 339 base::mac::GetSystemColorSpace()); |
333 } | 340 } |
334 return skia::NSImageToSkBitmapWithColorSpace( | |
335 image.get(), /*is_opaque=*/false, base::mac::GetSystemColorSpace()); | |
336 } | 341 } |
337 return SkBitmap(); | 342 return skia::NSImageToSkBitmapWithColorSpace( |
343 image.get(), /*is_opaque=*/false, base::mac::GetSystemColorSpace()); | |
Avi (use Gerrit)
2016/12/22 03:22:03
Wait... why don't we always go this path? Why do w
erikchen
2016/12/22 04:51:49
this loses pixels from retina images:
https://code
Avi (use Gerrit)
2016/12/22 05:42:25
Can you mention this in a comment?
erikchen
2016/12/22 18:19:21
Done.
| |
338 } | 344 } |
339 | 345 |
340 SkBitmap ClipboardMac::ReadImage(ClipboardType type) const { | 346 SkBitmap ClipboardMac::ReadImage(ClipboardType type) const { |
341 return ReadImage(type, GetPasteboard()); | 347 return ReadImage(type, GetPasteboard()); |
342 } | 348 } |
343 | 349 |
344 void ClipboardMac::ReadCustomData(ClipboardType clipboard_type, | 350 void ClipboardMac::ReadCustomData(ClipboardType clipboard_type, |
345 const base::string16& type, | 351 const base::string16& type, |
346 base::string16* result) const { | 352 base::string16* result) const { |
347 DCHECK(CalledOnValidThread()); | 353 DCHECK(CalledOnValidThread()); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 // Write an extra flavor that signifies WebKit was the last to modify the | 469 // Write an extra flavor that signifies WebKit was the last to modify the |
464 // pasteboard. This flavor has no data. | 470 // pasteboard. This flavor has no data. |
465 void ClipboardMac::WriteWebSmartPaste() { | 471 void ClipboardMac::WriteWebSmartPaste() { |
466 NSPasteboard* pb = GetPasteboard(); | 472 NSPasteboard* pb = GetPasteboard(); |
467 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); | 473 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); |
468 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; | 474 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; |
469 [pb setData:nil forType:format]; | 475 [pb setData:nil forType:format]; |
470 } | 476 } |
471 | 477 |
472 } // namespace ui | 478 } // namespace ui |
OLD | NEW |