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

Unified Diff: ui/base/clipboard/clipboard_mac.mm

Issue 2599643002: Fix reading PDF images from NSPasteboard. (Closed)
Patch Set: Comments from avi. Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/clipboard/clipboard_mac.h ('k') | ui/base/clipboard/clipboard_mac_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/clipboard/clipboard_mac.mm
diff --git a/ui/base/clipboard/clipboard_mac.mm b/ui/base/clipboard/clipboard_mac.mm
index fcc4a3a662f02b6d5318a069904751a680a81aa3..ce4badae6549eafc0a405ed24be37f5eeaba58ae 100644
--- a/ui/base/clipboard/clipboard_mac.mm
+++ b/ui/base/clipboard/clipboard_mac.mm
@@ -324,17 +324,27 @@ SkBitmap ClipboardMac::ReadImage(ClipboardType type, NSPasteboard* pb) const {
} @catch (id exception) {
}
- if (image.get()) {
- if ([[image representations] count] == 1u) {
- NSImageRep* rep = [[image representations] objectAtIndex:0];
+ if (!image)
+ return SkBitmap();
+ if ([[image representations] count] == 0u)
+ return SkBitmap();
+
+ // This logic prevents loss of pixels from retina images, where size != pixel
+ // size. In an ideal world, the concept of "retina-ness" would be plumbed all
+ // the way through to the web, but the clipboard API doesn't support the
+ // additional metainformation.
+ if ([[image representations] count] == 1u) {
+ NSImageRep* rep = [[image representations] objectAtIndex:0];
+ NSInteger width = [rep pixelsWide];
+ NSInteger height = [rep pixelsHigh];
+ if (width != 0 && height != 0) {
return skia::NSImageRepToSkBitmapWithColorSpace(
- rep, NSMakeSize([rep pixelsWide], [rep pixelsHigh]),
- /*is_opaque=*/false, base::mac::GetSystemColorSpace());
+ rep, NSMakeSize(width, height), /*is_opaque=*/false,
+ base::mac::GetSystemColorSpace());
}
- return skia::NSImageToSkBitmapWithColorSpace(
- image.get(), /*is_opaque=*/false, base::mac::GetSystemColorSpace());
}
- return SkBitmap();
+ return skia::NSImageToSkBitmapWithColorSpace(
+ image.get(), /*is_opaque=*/false, base::mac::GetSystemColorSpace());
}
SkBitmap ClipboardMac::ReadImage(ClipboardType type) const {
« no previous file with comments | « ui/base/clipboard/clipboard_mac.h ('k') | ui/base/clipboard/clipboard_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698