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

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

Issue 2599643002: Fix reading PDF images from NSPasteboard. (Closed)
Patch Set: Comments from avi. Created 3 years, 12 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 | « ui/base/clipboard/clipboard_mac.h ('k') | ui/base/clipboard/clipboard_mac_unittest.mm » ('j') | 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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // This logic prevents loss of pixels from retina images, where size != pixel
333 // size. In an ideal world, the concept of "retina-ness" would be plumbed all
334 // the way through to the web, but the clipboard API doesn't support the
335 // additional metainformation.
336 if ([[image representations] count] == 1u) {
337 NSImageRep* rep = [[image representations] objectAtIndex:0];
338 NSInteger width = [rep pixelsWide];
339 NSInteger height = [rep pixelsHigh];
340 if (width != 0 && height != 0) {
330 return skia::NSImageRepToSkBitmapWithColorSpace( 341 return skia::NSImageRepToSkBitmapWithColorSpace(
331 rep, NSMakeSize([rep pixelsWide], [rep pixelsHigh]), 342 rep, NSMakeSize(width, height), /*is_opaque=*/false,
332 /*is_opaque=*/false, base::mac::GetSystemColorSpace()); 343 base::mac::GetSystemColorSpace());
333 } 344 }
334 return skia::NSImageToSkBitmapWithColorSpace(
335 image.get(), /*is_opaque=*/false, base::mac::GetSystemColorSpace());
336 } 345 }
337 return SkBitmap(); 346 return skia::NSImageToSkBitmapWithColorSpace(
347 image.get(), /*is_opaque=*/false, base::mac::GetSystemColorSpace());
338 } 348 }
339 349
340 SkBitmap ClipboardMac::ReadImage(ClipboardType type) const { 350 SkBitmap ClipboardMac::ReadImage(ClipboardType type) const {
341 return ReadImage(type, GetPasteboard()); 351 return ReadImage(type, GetPasteboard());
342 } 352 }
343 353
344 void ClipboardMac::ReadCustomData(ClipboardType clipboard_type, 354 void ClipboardMac::ReadCustomData(ClipboardType clipboard_type,
345 const base::string16& type, 355 const base::string16& type,
346 base::string16* result) const { 356 base::string16* result) const {
347 DCHECK(CalledOnValidThread()); 357 DCHECK(CalledOnValidThread());
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 // Write an extra flavor that signifies WebKit was the last to modify the 473 // Write an extra flavor that signifies WebKit was the last to modify the
464 // pasteboard. This flavor has no data. 474 // pasteboard. This flavor has no data.
465 void ClipboardMac::WriteWebSmartPaste() { 475 void ClipboardMac::WriteWebSmartPaste() {
466 NSPasteboard* pb = GetPasteboard(); 476 NSPasteboard* pb = GetPasteboard();
467 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); 477 NSString* format = GetWebKitSmartPasteFormatType().ToNSString();
468 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; 478 [pb addTypes:[NSArray arrayWithObject:format] owner:nil];
469 [pb setData:nil forType:format]; 479 [pb setData:nil forType:format];
470 } 480 }
471 481
472 } // namespace ui 482 } // namespace ui
OLDNEW
« 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