diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-22 20:40:40 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-22 20:40:40 +0000 |
commit | 25d966fd574046979b48ee09f8e1dfffe28c1eda (patch) | |
tree | 5c81b5c3595605d25500ba8668e1f6f743c092c4 /app | |
parent | 0a10a0c4763019391f6d5e98992524f1fbd04c4c (diff) | |
download | chromium_src-25d966fd574046979b48ee09f8e1dfffe28c1eda.zip chromium_src-25d966fd574046979b48ee09f8e1dfffe28c1eda.tar.gz chromium_src-25d966fd574046979b48ee09f8e1dfffe28c1eda.tar.bz2 |
Chromium fix for "Copy Image". (WebCore fix is http://codereview.chromium.org/294023 .)
BUG=http://crbug.com/13099
TEST="Copy Image" works; see bug
Review URL: http://codereview.chromium.org/308001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29812 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/clipboard/clipboard.cc | 2 | ||||
-rw-r--r-- | app/clipboard/clipboard_mac.mm | 43 |
2 files changed, 44 insertions, 1 deletions
diff --git a/app/clipboard/clipboard.cc b/app/clipboard/clipboard.cc index bc91408..0b5d919 100644 --- a/app/clipboard/clipboard.cc +++ b/app/clipboard/clipboard.cc @@ -46,13 +46,13 @@ void Clipboard::DispatchObject(ObjectType type, const ObjectMapParams& params) { WriteWebSmartPaste(); break; -#if defined(OS_WIN) || defined(OS_LINUX) case CBF_BITMAP: if (!IsBitmapSafe(params)) return; WriteBitmap(&(params[0].front()), &(params[1].front())); break; +#if defined(OS_WIN) || defined(OS_LINUX) case CBF_DATA: WriteData(&(params[0].front()), params[0].size(), &(params[1].front()), params[1].size()); diff --git a/app/clipboard/clipboard_mac.mm b/app/clipboard/clipboard_mac.mm index 77f286a..990f5d0 100644 --- a/app/clipboard/clipboard_mac.mm +++ b/app/clipboard/clipboard_mac.mm @@ -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 @@ void Clipboard::WriteFiles(const char* file_data, size_t file_len) { [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() { |