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

Unified Diff: app/clipboard/clipboard_mac.mm

Issue 308001: Chromium fix for "Copy Image".... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « app/clipboard/clipboard.cc ('k') | webkit/api/src/ChromiumBridge.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: app/clipboard/clipboard_mac.mm
===================================================================
--- app/clipboard/clipboard_mac.mm (revision 29796)
+++ app/clipboard/clipboard_mac.mm (working copy)
@@ -7,7 +7,11 @@
#import <Cocoa/Cocoa.h>
#include "base/file_path.h"
+#include "base/gfx/size.h"
#include "base/logging.h"
+#include "base/mac_util.h"
+#include "base/scoped_cftyperef.h"
+#include "base/scoped_nsobject.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
@@ -119,6 +123,45 @@
[pb setPropertyList:fileList forType:NSFilenamesPboardType];
}
+void Clipboard::WriteBitmap(const char* pixel_data, const char* size_data) {
+ const gfx::Size* size = reinterpret_cast<const gfx::Size*>(size_data);
+
+ // Safe because the image goes away before the call returns.
+ scoped_cftyperef<CFDataRef> data(
+ CFDataCreateWithBytesNoCopy(kCFAllocatorDefault,
+ reinterpret_cast<const UInt8*>(pixel_data),
+ size->width()*size->height()*4,
+ kCFAllocatorNull));
+
+ scoped_cftyperef<CGDataProviderRef> data_provider(
+ CGDataProviderCreateWithCFData(data));
+
+ scoped_cftyperef<CGImageRef> cgimage(
+ CGImageCreate(size->width(),
+ size->height(),
+ 8,
+ 32,
+ size->width()*4,
+ mac_util::GetSRGBColorSpace(), // TODO(avi): do better
+ kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,
+ data_provider,
+ NULL,
+ false,
+ kCGRenderingIntentDefault));
+
+ scoped_nsobject<NSBitmapImageRep> bitmap(
+ [[NSBitmapImageRep alloc] initWithCGImage:cgimage]);
+
+ scoped_nsobject<NSImage> image([[NSImage alloc] init]);
+ [image addRepresentation:bitmap];
+
+ // An API to ask the NSImage to write itself to the clipboard comes in 10.6 :(
+ // For now, spit out the image as a TIFF.
+ NSPasteboard* pb = GetPasteboard();
+ [pb addTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:nil];
+ [pb setData:[image TIFFRepresentation] forType:NSTIFFPboardType];
+}
+
// Write an extra flavor that signifies WebKit was the last to modify the
// pasteboard. This flavor has no data.
void Clipboard::WriteWebSmartPaste() {
« no previous file with comments | « app/clipboard/clipboard.cc ('k') | webkit/api/src/ChromiumBridge.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698