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

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

Issue 7572031: Always call the class methods to save/restore contexts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: style nits 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"
11 #include "base/mac/mac_util.h" 11 #include "base/mac/mac_util.h"
12 #include "base/mac/scoped_cftyperef.h" 12 #include "base/mac/scoped_cftyperef.h"
13 #include "base/memory/scoped_nsobject.h" 13 #include "base/memory/scoped_nsobject.h"
14 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #import "third_party/mozilla/NSPasteboard+Utils.h" 16 #import "third_party/mozilla/NSPasteboard+Utils.h"
17 #include "third_party/skia/include/core/SkBitmap.h" 17 #include "third_party/skia/include/core/SkBitmap.h"
18 #include "ui/gfx/canvas_skia.h" 18 #include "ui/gfx/canvas_skia.h"
19 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
19 #include "ui/gfx/size.h" 20 #include "ui/gfx/size.h"
20 21
21 namespace ui { 22 namespace ui {
22 23
23 namespace { 24 namespace {
24 25
25 // Would be nice if this were in UTCoreTypes.h, but it isn't 26 // Would be nice if this were in UTCoreTypes.h, but it isn't
26 NSString* const kUTTypeURLName = @"public.url-name"; 27 NSString* const kUTTypeURLName = @"public.url-name";
27 28
28 // Tells us if WebKit was the last to write to the pasteboard. There's no 29 // Tells us if WebKit was the last to write to the pasteboard. There's no
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 if (src_url) 242 if (src_url)
242 src_url->clear(); 243 src_url->clear();
243 } 244 }
244 245
245 SkBitmap Clipboard::ReadImage(Buffer buffer) const { 246 SkBitmap Clipboard::ReadImage(Buffer buffer) const {
246 DCHECK_EQ(buffer, BUFFER_STANDARD); 247 DCHECK_EQ(buffer, BUFFER_STANDARD);
247 248
248 scoped_nsobject<NSImage> image( 249 scoped_nsobject<NSImage> image(
249 [[NSImage alloc] initWithPasteboard:GetPasteboard()]); 250 [[NSImage alloc] initWithPasteboard:GetPasteboard()]);
250 if (image.get()) { 251 if (image.get()) {
252 gfx::ScopedNSGraphicsContextSaveGState scoped_state;
251 [image setFlipped:YES]; 253 [image setFlipped:YES];
252 int width = [image size].width; 254 int width = [image size].width;
253 int height = [image size].height; 255 int height = [image size].height;
254 256
255 gfx::CanvasSkia canvas(width, height, false); 257 gfx::CanvasSkia canvas(width, height, false);
256 skia::ScopedPlatformPaint scoped_platform_paint(&canvas); 258 skia::ScopedPlatformPaint scoped_platform_paint(&canvas);
257 CGContextRef gc = scoped_platform_paint.GetPlatformSurface(); 259 CGContextRef gc = scoped_platform_paint.GetPlatformSurface();
258 NSGraphicsContext* cocoa_gc = 260 NSGraphicsContext* cocoa_gc =
259 [NSGraphicsContext graphicsContextWithGraphicsPort:gc flipped:NO]; 261 [NSGraphicsContext graphicsContextWithGraphicsPort:gc flipped:NO];
260 [NSGraphicsContext setCurrentContext:cocoa_gc]; 262 [NSGraphicsContext setCurrentContext:cocoa_gc];
Mark Mentovai 2011/08/05 01:15:45
261 [image drawInRect:NSMakeRect(0, 0, width, height) 263 [image drawInRect:NSMakeRect(0, 0, width, height)
262 fromRect:NSZeroRect 264 fromRect:NSZeroRect
263 operation:NSCompositeCopy 265 operation:NSCompositeCopy
264 fraction:1.0]; 266 fraction:1.0];
265 [NSGraphicsContext restoreGraphicsState];
266 return canvas.ExtractBitmap(); 267 return canvas.ExtractBitmap();
267 } 268 }
268 return SkBitmap(); 269 return SkBitmap();
269 } 270 }
270 271
271 void Clipboard::ReadBookmark(string16* title, std::string* url) const { 272 void Clipboard::ReadBookmark(string16* title, std::string* url) const {
272 NSPasteboard* pb = GetPasteboard(); 273 NSPasteboard* pb = GetPasteboard();
273 274
274 if (title) { 275 if (title) {
275 NSString* contents = [pb stringForType:kUTTypeURLName]; 276 NSString* contents = [pb stringForType:kUTTypeURLName];
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } 376 }
376 377
377 // static 378 // static
378 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { 379 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() {
379 static const std::string type = 380 static const std::string type =
380 base::SysNSStringToUTF8(kWebSmartPastePboardType); 381 base::SysNSStringToUTF8(kWebSmartPastePboardType);
381 return type; 382 return type;
382 } 383 }
383 384
384 } // namespace ui 385 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698