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

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

Issue 7541043: Revert 95611 - Always call the class methods to save/restore contexts. (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"
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"
20 #include "ui/gfx/size.h" 19 #include "ui/gfx/size.h"
21 20
22 namespace ui { 21 namespace ui {
23 22
24 namespace { 23 namespace {
25 24
26 // Would be nice if this were in UTCoreTypes.h, but it isn't 25 // Would be nice if this were in UTCoreTypes.h, but it isn't
27 NSString* const kUTTypeURLName = @"public.url-name"; 26 NSString* const kUTTypeURLName = @"public.url-name";
28 27
29 // Tells us if WebKit was the last to write to the pasteboard. There's no 28 // 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
242 if (src_url) 241 if (src_url)
243 src_url->clear(); 242 src_url->clear();
244 } 243 }
245 244
246 SkBitmap Clipboard::ReadImage(Buffer buffer) const { 245 SkBitmap Clipboard::ReadImage(Buffer buffer) const {
247 DCHECK_EQ(buffer, BUFFER_STANDARD); 246 DCHECK_EQ(buffer, BUFFER_STANDARD);
248 247
249 scoped_nsobject<NSImage> image( 248 scoped_nsobject<NSImage> image(
250 [[NSImage alloc] initWithPasteboard:GetPasteboard()]); 249 [[NSImage alloc] initWithPasteboard:GetPasteboard()]);
251 if (image.get()) { 250 if (image.get()) {
252 gfx::ScopedNSGraphicsContextSaveGState scoped_state;
253 [image setFlipped:YES]; 251 [image setFlipped:YES];
254 int width = [image size].width; 252 int width = [image size].width;
255 int height = [image size].height; 253 int height = [image size].height;
256 254
257 gfx::CanvasSkia canvas(width, height, false); 255 gfx::CanvasSkia canvas(width, height, false);
258 skia::ScopedPlatformPaint scoped_platform_paint(&canvas); 256 skia::ScopedPlatformPaint scoped_platform_paint(&canvas);
259 CGContextRef gc = scoped_platform_paint.GetPlatformSurface(); 257 CGContextRef gc = scoped_platform_paint.GetPlatformSurface();
260 NSGraphicsContext* cocoa_gc = 258 NSGraphicsContext* cocoa_gc =
261 [NSGraphicsContext graphicsContextWithGraphicsPort:gc flipped:NO]; 259 [NSGraphicsContext graphicsContextWithGraphicsPort:gc flipped:NO];
262 [NSGraphicsContext setCurrentContext:cocoa_gc]; 260 [NSGraphicsContext setCurrentContext:cocoa_gc];
263 [image drawInRect:NSMakeRect(0, 0, width, height) 261 [image drawInRect:NSMakeRect(0, 0, width, height)
264 fromRect:NSZeroRect 262 fromRect:NSZeroRect
265 operation:NSCompositeCopy 263 operation:NSCompositeCopy
266 fraction:1.0]; 264 fraction:1.0];
265 [NSGraphicsContext restoreGraphicsState];
267 return canvas.ExtractBitmap(); 266 return canvas.ExtractBitmap();
268 } 267 }
269 return SkBitmap(); 268 return SkBitmap();
270 } 269 }
271 270
272 void Clipboard::ReadBookmark(string16* title, std::string* url) const { 271 void Clipboard::ReadBookmark(string16* title, std::string* url) const {
273 NSPasteboard* pb = GetPasteboard(); 272 NSPasteboard* pb = GetPasteboard();
274 273
275 if (title) { 274 if (title) {
276 NSString* contents = [pb stringForType:kUTTypeURLName]; 275 NSString* contents = [pb stringForType:kUTTypeURLName];
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 } 375 }
377 376
378 // static 377 // static
379 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { 378 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() {
380 static const std::string type = 379 static const std::string type =
381 base::SysNSStringToUTF8(kWebSmartPastePboardType); 380 base::SysNSStringToUTF8(kWebSmartPastePboardType);
382 return type; 381 return type;
383 } 382 }
384 383
385 } // namespace ui 384 } // namespace ui
OLDNEW
« no previous file with comments | « chrome/default_plugin/plugin_impl_mac.mm ('k') | ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698