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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « app/clipboard/clipboard.cc ('k') | webkit/api/src/ChromiumBridge.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "app/clipboard/clipboard.h" 5 #include "app/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/gfx/size.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/mac_util.h"
13 #include "base/scoped_cftyperef.h"
14 #include "base/scoped_nsobject.h"
11 #include "base/string_util.h" 15 #include "base/string_util.h"
12 #include "base/sys_string_conversions.h" 16 #include "base/sys_string_conversions.h"
13 17
14 namespace { 18 namespace {
15 19
16 // Would be nice if this were in UTCoreTypes.h, but it isn't 20 // Would be nice if this were in UTCoreTypes.h, but it isn't
17 const NSString* kUTTypeURLName = @"public.url-name"; 21 const NSString* kUTTypeURLName = @"public.url-name";
18 22
19 // Tells us if WebKit was the last to write to the pasteboard. There's no 23 // Tells us if WebKit was the last to write to the pasteboard. There's no
20 // actual data associated with this type. 24 // actual data associated with this type.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 current_filename_offset = i + 1; 116 current_filename_offset = i + 1;
113 continue; 117 continue;
114 } 118 }
115 } 119 }
116 120
117 NSPasteboard* pb = GetPasteboard(); 121 NSPasteboard* pb = GetPasteboard();
118 [pb addTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:nil]; 122 [pb addTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:nil];
119 [pb setPropertyList:fileList forType:NSFilenamesPboardType]; 123 [pb setPropertyList:fileList forType:NSFilenamesPboardType];
120 } 124 }
121 125
126 void Clipboard::WriteBitmap(const char* pixel_data, const char* size_data) {
127 const gfx::Size* size = reinterpret_cast<const gfx::Size*>(size_data);
128
129 // Safe because the image goes away before the call returns.
130 scoped_cftyperef<CFDataRef> data(
131 CFDataCreateWithBytesNoCopy(kCFAllocatorDefault,
132 reinterpret_cast<const UInt8*>(pixel_data),
133 size->width()*size->height()*4,
134 kCFAllocatorNull));
135
136 scoped_cftyperef<CGDataProviderRef> data_provider(
137 CGDataProviderCreateWithCFData(data));
138
139 scoped_cftyperef<CGImageRef> cgimage(
140 CGImageCreate(size->width(),
141 size->height(),
142 8,
143 32,
144 size->width()*4,
145 mac_util::GetSRGBColorSpace(), // TODO(avi): do better
146 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,
147 data_provider,
148 NULL,
149 false,
150 kCGRenderingIntentDefault));
151
152 scoped_nsobject<NSBitmapImageRep> bitmap(
153 [[NSBitmapImageRep alloc] initWithCGImage:cgimage]);
154
155 scoped_nsobject<NSImage> image([[NSImage alloc] init]);
156 [image addRepresentation:bitmap];
157
158 // An API to ask the NSImage to write itself to the clipboard comes in 10.6 :(
159 // For now, spit out the image as a TIFF.
160 NSPasteboard* pb = GetPasteboard();
161 [pb addTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:nil];
162 [pb setData:[image TIFFRepresentation] forType:NSTIFFPboardType];
163 }
164
122 // Write an extra flavor that signifies WebKit was the last to modify the 165 // Write an extra flavor that signifies WebKit was the last to modify the
123 // pasteboard. This flavor has no data. 166 // pasteboard. This flavor has no data.
124 void Clipboard::WriteWebSmartPaste() { 167 void Clipboard::WriteWebSmartPaste() {
125 NSPasteboard* pb = GetPasteboard(); 168 NSPasteboard* pb = GetPasteboard();
126 NSString* format = base::SysUTF8ToNSString(GetWebKitSmartPasteFormatType()); 169 NSString* format = base::SysUTF8ToNSString(GetWebKitSmartPasteFormatType());
127 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; 170 [pb addTypes:[NSArray arrayWithObject:format] owner:nil];
128 [pb setData:nil forType:format]; 171 [pb setData:nil forType:format];
129 } 172 }
130 173
131 bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format, 174 bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format,
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 static const std::string type = base::SysNSStringToUTF8(NSHTMLPboardType); 318 static const std::string type = base::SysNSStringToUTF8(NSHTMLPboardType);
276 return type; 319 return type;
277 } 320 }
278 321
279 // static 322 // static
280 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { 323 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() {
281 static const std::string type = 324 static const std::string type =
282 base::SysNSStringToUTF8(kWebSmartPastePboardType); 325 base::SysNSStringToUTF8(kWebSmartPastePboardType);
283 return type; 326 return type;
284 } 327 }
OLDNEW
« 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