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

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

Issue 2276183002: mac: Don't lose pixels when copying a retina image from the clipboard. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp85
Patch Set: Export ClipboardMac to fix link error. Created 4 years, 3 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 SkBitmap bitmap;
328 if (image.get()) { 327 if (image.get()) {
329 bitmap = skia::NSImageToSkBitmapWithColorSpace( 328 if ([[image representations] count] == 1u) {
330 image.get(), /*is_opaque=*/ false, base::mac::GetSystemColorSpace()); 329 NSBitmapImageRep* rep = [[image representations] objectAtIndex:0];
Avi (use Gerrit) 2016/08/25 18:57:25 NSImageRep* rep = not NSBitmapImageRep* rep = You
erikchen 2016/08/26 17:55:33 Done.
330 return skia::NSImageRepToSkBitmapWithColorSpace(
331 rep, NSMakeSize([rep pixelsWide], [rep pixelsHigh]),
332 /*is_opaque=*/false, base::mac::GetSystemColorSpace());
333 }
334 return skia::NSImageToSkBitmapWithColorSpace(
335 image.get(), /*is_opaque=*/false, base::mac::GetSystemColorSpace());
331 } 336 }
332 return bitmap; 337 return SkBitmap();
333 } 338 }
334 339
335 SkBitmap ClipboardMac::ReadImage(ClipboardType type) const { 340 SkBitmap ClipboardMac::ReadImage(ClipboardType type) const {
336 return ReadImage(type, GetPasteboard()); 341 return ReadImage(type, GetPasteboard());
337 } 342 }
338 343
339 void ClipboardMac::ReadCustomData(ClipboardType clipboard_type, 344 void ClipboardMac::ReadCustomData(ClipboardType clipboard_type,
340 const base::string16& type, 345 const base::string16& type,
341 base::string16* result) const { 346 base::string16* result) const {
342 DCHECK(CalledOnValidThread()); 347 DCHECK(CalledOnValidThread());
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 // Write an extra flavor that signifies WebKit was the last to modify the 463 // Write an extra flavor that signifies WebKit was the last to modify the
459 // pasteboard. This flavor has no data. 464 // pasteboard. This flavor has no data.
460 void ClipboardMac::WriteWebSmartPaste() { 465 void ClipboardMac::WriteWebSmartPaste() {
461 NSPasteboard* pb = GetPasteboard(); 466 NSPasteboard* pb = GetPasteboard();
462 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); 467 NSString* format = GetWebKitSmartPasteFormatType().ToNSString();
463 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; 468 [pb addTypes:[NSArray arrayWithObject:format] owner:nil];
464 [pb setData:nil forType:format]; 469 [pb setData:nil forType:format];
465 } 470 }
466 471
467 } // namespace ui 472 } // 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