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

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

Issue 7471008: Fix Clipboard::ReadImage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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.h" 5 #include "ui/base/clipboard/clipboard.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // TODO(avi): src_url? 240 // TODO(avi): src_url?
241 if (src_url) 241 if (src_url)
242 src_url->clear(); 242 src_url->clear();
243 } 243 }
244 244
245 SkBitmap Clipboard::ReadImage(Buffer buffer) const { 245 SkBitmap Clipboard::ReadImage(Buffer buffer) const {
246 DCHECK_EQ(buffer, BUFFER_STANDARD); 246 DCHECK_EQ(buffer, BUFFER_STANDARD);
247 247
248 scoped_nsobject<NSImage> image( 248 scoped_nsobject<NSImage> image(
249 [[NSImage alloc] initWithPasteboard:GetPasteboard()]); 249 [[NSImage alloc] initWithPasteboard:GetPasteboard()]);
250 if (image.get()) { 250 if (!image.get())
251 [image setFlipped:YES]; 251 return SkBitmap();
252 int width = [image size].width;
253 int height = [image size].height;
254 252
255 gfx::CanvasSkia canvas(width, height, false); 253 [image setFlipped:YES];
254 int width = [image size].width;
255 int height = [image size].height;
256
257 gfx::CanvasSkia canvas(width, height, false);
258 {
256 skia::ScopedPlatformPaint scoped_platform_paint(&canvas); 259 skia::ScopedPlatformPaint scoped_platform_paint(&canvas);
257 CGContextRef gc = scoped_platform_paint.GetPlatformSurface(); 260 CGContextRef gc = scoped_platform_paint.GetPlatformSurface();
258 NSGraphicsContext* cocoa_gc = 261 NSGraphicsContext* cocoa_gc =
259 [NSGraphicsContext graphicsContextWithGraphicsPort:gc flipped:NO]; 262 [NSGraphicsContext graphicsContextWithGraphicsPort:gc flipped:NO];
260 [NSGraphicsContext setCurrentContext:cocoa_gc]; 263 [NSGraphicsContext setCurrentContext:cocoa_gc];
261 [image drawInRect:NSMakeRect(0, 0, width, height) 264 [image drawInRect:NSMakeRect(0, 0, width, height)
262 fromRect:NSZeroRect 265 fromRect:NSZeroRect
263 operation:NSCompositeCopy 266 operation:NSCompositeCopy
264 fraction:1.0]; 267 fraction:1.0];
265 [NSGraphicsContext restoreGraphicsState]; 268 [NSGraphicsContext restoreGraphicsState];
266 return canvas.ExtractBitmap();
267 } 269 }
268 return SkBitmap(); 270 return canvas.ExtractBitmap();
269 } 271 }
270 272
271 void Clipboard::ReadBookmark(string16* title, std::string* url) const { 273 void Clipboard::ReadBookmark(string16* title, std::string* url) const {
272 NSPasteboard* pb = GetPasteboard(); 274 NSPasteboard* pb = GetPasteboard();
273 275
274 if (title) { 276 if (title) {
275 NSString* contents = [pb stringForType:kUTTypeURLName]; 277 NSString* contents = [pb stringForType:kUTTypeURLName];
276 UTF8ToUTF16([contents UTF8String], 278 UTF8ToUTF16([contents UTF8String],
277 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], 279 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
278 title); 280 title);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } 377 }
376 378
377 // static 379 // static
378 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { 380 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() {
379 static const std::string type = 381 static const std::string type =
380 base::SysNSStringToUTF8(kWebSmartPastePboardType); 382 base::SysNSStringToUTF8(kWebSmartPastePboardType);
381 return type; 383 return type;
382 } 384 }
383 385
384 } // namespace ui 386 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698