OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_mac.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
13 #include "base/mac/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
14 #import "base/mac/scoped_nsexception_enabler.h" | 14 #import "base/mac/scoped_nsexception_enabler.h" |
15 #include "base/mac/scoped_nsobject.h" | 15 #include "base/mac/scoped_nsobject.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kWebCustomDataPboardType)); | 158 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kWebCustomDataPboardType)); |
159 return type; | 159 return type; |
160 } | 160 } |
161 | 161 |
162 // static | 162 // static |
163 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { | 163 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { |
164 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPepperCustomDataPboardType)); | 164 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPepperCustomDataPboardType)); |
165 return type; | 165 return type; |
166 } | 166 } |
167 | 167 |
168 // Clipboard implementation. | 168 // Clipboard factory method. |
169 Clipboard::Clipboard() { | 169 // static |
| 170 Clipboard* Clipboard::Create() { |
| 171 return new ClipboardMac; |
| 172 } |
| 173 |
| 174 // ClipboardMac implementation. |
| 175 ClipboardMac::ClipboardMac() { |
170 DCHECK(CalledOnValidThread()); | 176 DCHECK(CalledOnValidThread()); |
171 } | 177 } |
172 | 178 |
173 Clipboard::~Clipboard() { | 179 ClipboardMac::~ClipboardMac() { |
174 DCHECK(CalledOnValidThread()); | 180 DCHECK(CalledOnValidThread()); |
175 } | 181 } |
176 | 182 |
177 uint64 Clipboard::GetSequenceNumber(ClipboardType type) { | 183 uint64 ClipboardMac::GetSequenceNumber(ClipboardType type) { |
178 DCHECK(CalledOnValidThread()); | 184 DCHECK(CalledOnValidThread()); |
179 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); | 185 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); |
180 | 186 |
181 NSPasteboard* pb = GetPasteboard(); | 187 NSPasteboard* pb = GetPasteboard(); |
182 return [pb changeCount]; | 188 return [pb changeCount]; |
183 } | 189 } |
184 | 190 |
185 bool Clipboard::IsFormatAvailable(const FormatType& format, | 191 bool ClipboardMac::IsFormatAvailable(const FormatType& format, |
186 ClipboardType type) const { | 192 ClipboardType type) const { |
187 DCHECK(CalledOnValidThread()); | 193 DCHECK(CalledOnValidThread()); |
188 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); | 194 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); |
189 | 195 |
190 NSPasteboard* pb = GetPasteboard(); | 196 NSPasteboard* pb = GetPasteboard(); |
191 NSArray* types = [pb types]; | 197 NSArray* types = [pb types]; |
192 | 198 |
193 // Safari only places RTF on the pasteboard, never HTML. We can convert RTF | 199 // Safari only places RTF on the pasteboard, never HTML. We can convert RTF |
194 // to HTML, so the presence of either indicates success when looking for HTML. | 200 // to HTML, so the presence of either indicates success when looking for HTML. |
195 if ([format.ToNSString() isEqualToString:NSHTMLPboardType]) { | 201 if ([format.ToNSString() isEqualToString:NSHTMLPboardType]) { |
196 return [types containsObject:NSHTMLPboardType] || | 202 return [types containsObject:NSHTMLPboardType] || |
197 [types containsObject:NSRTFPboardType]; | 203 [types containsObject:NSRTFPboardType]; |
198 } | 204 } |
199 return [types containsObject:format.ToNSString()]; | 205 return [types containsObject:format.ToNSString()]; |
200 } | 206 } |
201 | 207 |
202 void Clipboard::Clear(ClipboardType type) { | 208 void ClipboardMac::Clear(ClipboardType type) { |
203 DCHECK(CalledOnValidThread()); | 209 DCHECK(CalledOnValidThread()); |
204 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); | 210 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); |
205 | 211 |
206 NSPasteboard* pb = GetPasteboard(); | 212 NSPasteboard* pb = GetPasteboard(); |
207 [pb declareTypes:[NSArray array] owner:nil]; | 213 [pb declareTypes:[NSArray array] owner:nil]; |
208 } | 214 } |
209 | 215 |
210 void Clipboard::ReadAvailableTypes(ClipboardType type, | 216 void ClipboardMac::ReadAvailableTypes(ClipboardType type, |
211 std::vector<base::string16>* types, | 217 std::vector<base::string16>* types, |
212 bool* contains_filenames) const { | 218 bool* contains_filenames) const { |
213 DCHECK(CalledOnValidThread()); | 219 DCHECK(CalledOnValidThread()); |
214 types->clear(); | 220 types->clear(); |
215 if (IsFormatAvailable(Clipboard::GetPlainTextFormatType(), type)) | 221 if (IsFormatAvailable(Clipboard::GetPlainTextFormatType(), type)) |
216 types->push_back(base::UTF8ToUTF16(kMimeTypeText)); | 222 types->push_back(base::UTF8ToUTF16(kMimeTypeText)); |
217 if (IsFormatAvailable(Clipboard::GetHtmlFormatType(), type)) | 223 if (IsFormatAvailable(Clipboard::GetHtmlFormatType(), type)) |
218 types->push_back(base::UTF8ToUTF16(kMimeTypeHTML)); | 224 types->push_back(base::UTF8ToUTF16(kMimeTypeHTML)); |
219 if (IsFormatAvailable(Clipboard::GetRtfFormatType(), type)) | 225 if (IsFormatAvailable(Clipboard::GetRtfFormatType(), type)) |
220 types->push_back(base::UTF8ToUTF16(kMimeTypeRTF)); | 226 types->push_back(base::UTF8ToUTF16(kMimeTypeRTF)); |
221 if ([NSImage canInitWithPasteboard:GetPasteboard()]) | 227 if ([NSImage canInitWithPasteboard:GetPasteboard()]) |
222 types->push_back(base::UTF8ToUTF16(kMimeTypePNG)); | 228 types->push_back(base::UTF8ToUTF16(kMimeTypePNG)); |
223 *contains_filenames = false; | 229 *contains_filenames = false; |
224 | 230 |
225 NSPasteboard* pb = GetPasteboard(); | 231 NSPasteboard* pb = GetPasteboard(); |
226 if ([[pb types] containsObject:kWebCustomDataPboardType]) { | 232 if ([[pb types] containsObject:kWebCustomDataPboardType]) { |
227 NSData* data = [pb dataForType:kWebCustomDataPboardType]; | 233 NSData* data = [pb dataForType:kWebCustomDataPboardType]; |
228 if ([data length]) | 234 if ([data length]) |
229 ReadCustomDataTypes([data bytes], [data length], types); | 235 ReadCustomDataTypes([data bytes], [data length], types); |
230 } | 236 } |
231 } | 237 } |
232 | 238 |
233 void Clipboard::ReadText(ClipboardType type, base::string16* result) const { | 239 void ClipboardMac::ReadText(ClipboardType type, base::string16* result) const { |
234 DCHECK(CalledOnValidThread()); | 240 DCHECK(CalledOnValidThread()); |
235 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); | 241 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); |
236 NSPasteboard* pb = GetPasteboard(); | 242 NSPasteboard* pb = GetPasteboard(); |
237 NSString* contents = [pb stringForType:NSStringPboardType]; | 243 NSString* contents = [pb stringForType:NSStringPboardType]; |
238 | 244 |
239 *result = base::SysNSStringToUTF16(contents); | 245 *result = base::SysNSStringToUTF16(contents); |
240 } | 246 } |
241 | 247 |
242 void Clipboard::ReadAsciiText(ClipboardType type, std::string* result) const { | 248 void ClipboardMac::ReadAsciiText(ClipboardType type, |
| 249 std::string* result) const { |
243 DCHECK(CalledOnValidThread()); | 250 DCHECK(CalledOnValidThread()); |
244 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); | 251 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); |
245 NSPasteboard* pb = GetPasteboard(); | 252 NSPasteboard* pb = GetPasteboard(); |
246 NSString* contents = [pb stringForType:NSStringPboardType]; | 253 NSString* contents = [pb stringForType:NSStringPboardType]; |
247 | 254 |
248 if (!contents) | 255 if (!contents) |
249 result->clear(); | 256 result->clear(); |
250 else | 257 else |
251 result->assign([contents UTF8String]); | 258 result->assign([contents UTF8String]); |
252 } | 259 } |
253 | 260 |
254 void Clipboard::ReadHTML(ClipboardType type, | 261 void ClipboardMac::ReadHTML(ClipboardType type, |
255 base::string16* markup, | 262 base::string16* markup, |
256 std::string* src_url, | 263 std::string* src_url, |
257 uint32* fragment_start, | 264 uint32* fragment_start, |
258 uint32* fragment_end) const { | 265 uint32* fragment_end) const { |
259 DCHECK(CalledOnValidThread()); | 266 DCHECK(CalledOnValidThread()); |
260 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); | 267 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); |
261 | 268 |
262 // TODO(avi): src_url? | 269 // TODO(avi): src_url? |
263 markup->clear(); | 270 markup->clear(); |
264 if (src_url) | 271 if (src_url) |
265 src_url->clear(); | 272 src_url->clear(); |
266 | 273 |
267 NSPasteboard* pb = GetPasteboard(); | 274 NSPasteboard* pb = GetPasteboard(); |
268 NSArray* supportedTypes = [NSArray arrayWithObjects:NSHTMLPboardType, | 275 NSArray* supportedTypes = [NSArray arrayWithObjects:NSHTMLPboardType, |
269 NSRTFPboardType, | 276 NSRTFPboardType, |
270 NSStringPboardType, | 277 NSStringPboardType, |
271 nil]; | 278 nil]; |
272 NSString* bestType = [pb availableTypeFromArray:supportedTypes]; | 279 NSString* bestType = [pb availableTypeFromArray:supportedTypes]; |
273 if (bestType) { | 280 if (bestType) { |
274 NSString* contents = [pb stringForType:bestType]; | 281 NSString* contents = [pb stringForType:bestType]; |
275 if ([bestType isEqualToString:NSRTFPboardType]) | 282 if ([bestType isEqualToString:NSRTFPboardType]) |
276 contents = [pb htmlFromRtf]; | 283 contents = [pb htmlFromRtf]; |
277 *markup = base::SysNSStringToUTF16(contents); | 284 *markup = base::SysNSStringToUTF16(contents); |
278 } | 285 } |
279 | 286 |
280 *fragment_start = 0; | 287 *fragment_start = 0; |
281 DCHECK(markup->length() <= kuint32max); | 288 DCHECK(markup->length() <= kuint32max); |
282 *fragment_end = static_cast<uint32>(markup->length()); | 289 *fragment_end = static_cast<uint32>(markup->length()); |
283 } | 290 } |
284 | 291 |
285 void Clipboard::ReadRTF(ClipboardType type, std::string* result) const { | 292 void ClipboardMac::ReadRTF(ClipboardType type, std::string* result) const { |
286 DCHECK(CalledOnValidThread()); | 293 DCHECK(CalledOnValidThread()); |
287 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); | 294 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); |
288 | 295 |
289 return ReadData(GetRtfFormatType(), result); | 296 return ReadData(GetRtfFormatType(), result); |
290 } | 297 } |
291 | 298 |
292 SkBitmap Clipboard::ReadImage(ClipboardType type) const { | 299 SkBitmap ClipboardMac::ReadImage(ClipboardType type) const { |
293 DCHECK(CalledOnValidThread()); | 300 DCHECK(CalledOnValidThread()); |
294 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); | 301 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); |
295 | 302 |
296 // If the pasteboard's image data is not to its liking, the guts of NSImage | 303 // If the pasteboard's image data is not to its liking, the guts of NSImage |
297 // may throw, and that exception will leak. Prevent a crash in that case; | 304 // may throw, and that exception will leak. Prevent a crash in that case; |
298 // a blank image is better. | 305 // a blank image is better. |
299 base::scoped_nsobject<NSImage> image(base::mac::RunBlockIgnoringExceptions(^{ | 306 base::scoped_nsobject<NSImage> image(base::mac::RunBlockIgnoringExceptions(^{ |
300 return [[NSImage alloc] initWithPasteboard:GetPasteboard()]; | 307 return [[NSImage alloc] initWithPasteboard:GetPasteboard()]; |
301 })); | 308 })); |
302 SkBitmap bitmap; | 309 SkBitmap bitmap; |
303 if (image.get()) { | 310 if (image.get()) { |
304 bitmap = gfx::NSImageToSkBitmapWithColorSpace( | 311 bitmap = gfx::NSImageToSkBitmapWithColorSpace( |
305 image.get(), /*is_opaque=*/ false, base::mac::GetSystemColorSpace()); | 312 image.get(), /*is_opaque=*/ false, base::mac::GetSystemColorSpace()); |
306 } | 313 } |
307 return bitmap; | 314 return bitmap; |
308 } | 315 } |
309 | 316 |
310 void Clipboard::ReadCustomData(ClipboardType clipboard_type, | 317 void ClipboardMac::ReadCustomData(ClipboardType clipboard_type, |
311 const base::string16& type, | 318 const base::string16& type, |
312 base::string16* result) const { | 319 base::string16* result) const { |
313 DCHECK(CalledOnValidThread()); | 320 DCHECK(CalledOnValidThread()); |
314 DCHECK_EQ(clipboard_type, CLIPBOARD_TYPE_COPY_PASTE); | 321 DCHECK_EQ(clipboard_type, CLIPBOARD_TYPE_COPY_PASTE); |
315 | 322 |
316 NSPasteboard* pb = GetPasteboard(); | 323 NSPasteboard* pb = GetPasteboard(); |
317 if ([[pb types] containsObject:kWebCustomDataPboardType]) { | 324 if ([[pb types] containsObject:kWebCustomDataPboardType]) { |
318 NSData* data = [pb dataForType:kWebCustomDataPboardType]; | 325 NSData* data = [pb dataForType:kWebCustomDataPboardType]; |
319 if ([data length]) | 326 if ([data length]) |
320 ReadCustomDataForType([data bytes], [data length], type, result); | 327 ReadCustomDataForType([data bytes], [data length], type, result); |
321 } | 328 } |
322 } | 329 } |
323 | 330 |
324 void Clipboard::ReadBookmark(base::string16* title, std::string* url) const { | 331 void ClipboardMac::ReadBookmark(base::string16* title, std::string* url) const { |
325 DCHECK(CalledOnValidThread()); | 332 DCHECK(CalledOnValidThread()); |
326 NSPasteboard* pb = GetPasteboard(); | 333 NSPasteboard* pb = GetPasteboard(); |
327 | 334 |
328 if (title) { | 335 if (title) { |
329 NSString* contents = [pb stringForType:kUTTypeURLName]; | 336 NSString* contents = [pb stringForType:kUTTypeURLName]; |
330 *title = base::SysNSStringToUTF16(contents); | 337 *title = base::SysNSStringToUTF16(contents); |
331 } | 338 } |
332 | 339 |
333 if (url) { | 340 if (url) { |
334 NSString* url_string = [[NSURL URLFromPasteboard:pb] absoluteString]; | 341 NSString* url_string = [[NSURL URLFromPasteboard:pb] absoluteString]; |
335 if (!url_string) | 342 if (!url_string) |
336 url->clear(); | 343 url->clear(); |
337 else | 344 else |
338 url->assign([url_string UTF8String]); | 345 url->assign([url_string UTF8String]); |
339 } | 346 } |
340 } | 347 } |
341 | 348 |
342 void Clipboard::ReadData(const FormatType& format, std::string* result) const { | 349 void ClipboardMac::ReadData(const FormatType& format, |
| 350 std::string* result) const { |
343 DCHECK(CalledOnValidThread()); | 351 DCHECK(CalledOnValidThread()); |
344 NSPasteboard* pb = GetPasteboard(); | 352 NSPasteboard* pb = GetPasteboard(); |
345 NSData* data = [pb dataForType:format.ToNSString()]; | 353 NSData* data = [pb dataForType:format.ToNSString()]; |
346 if ([data length]) | 354 if ([data length]) |
347 result->assign(static_cast<const char*>([data bytes]), [data length]); | 355 result->assign(static_cast<const char*>([data bytes]), [data length]); |
348 } | 356 } |
349 | 357 |
350 void Clipboard::WriteObjects(ClipboardType type, const ObjectMap& objects) { | 358 void ClipboardMac::WriteObjects(ClipboardType type, const ObjectMap& objects) { |
351 DCHECK(CalledOnValidThread()); | 359 DCHECK(CalledOnValidThread()); |
352 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); | 360 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); |
353 | 361 |
354 NSPasteboard* pb = GetPasteboard(); | 362 NSPasteboard* pb = GetPasteboard(); |
355 [pb declareTypes:[NSArray array] owner:nil]; | 363 [pb declareTypes:[NSArray array] owner:nil]; |
356 | 364 |
357 for (ObjectMap::const_iterator iter = objects.begin(); | 365 for (ObjectMap::const_iterator iter = objects.begin(); iter != objects.end(); |
358 iter != objects.end(); ++iter) { | 366 ++iter) { |
359 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); | 367 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); |
360 } | 368 } |
361 } | 369 } |
362 | 370 |
363 void Clipboard::WriteText(const char* text_data, size_t text_len) { | 371 void ClipboardMac::WriteText(const char* text_data, size_t text_len) { |
364 std::string text_str(text_data, text_len); | 372 std::string text_str(text_data, text_len); |
365 NSString *text = base::SysUTF8ToNSString(text_str); | 373 NSString* text = base::SysUTF8ToNSString(text_str); |
366 NSPasteboard* pb = GetPasteboard(); | 374 NSPasteboard* pb = GetPasteboard(); |
367 [pb addTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; | 375 [pb addTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; |
368 [pb setString:text forType:NSStringPboardType]; | 376 [pb setString:text forType:NSStringPboardType]; |
369 } | 377 } |
370 | 378 |
371 void Clipboard::WriteHTML(const char* markup_data, | 379 void ClipboardMac::WriteHTML(const char* markup_data, |
372 size_t markup_len, | 380 size_t markup_len, |
373 const char* url_data, | 381 const char* url_data, |
374 size_t url_len) { | 382 size_t url_len) { |
375 // We need to mark it as utf-8. (see crbug.com/11957) | 383 // We need to mark it as utf-8. (see crbug.com/11957) |
376 std::string html_fragment_str("<meta charset='utf-8'>"); | 384 std::string html_fragment_str("<meta charset='utf-8'>"); |
377 html_fragment_str.append(markup_data, markup_len); | 385 html_fragment_str.append(markup_data, markup_len); |
378 NSString *html_fragment = base::SysUTF8ToNSString(html_fragment_str); | 386 NSString* html_fragment = base::SysUTF8ToNSString(html_fragment_str); |
379 | 387 |
380 // TODO(avi): url_data? | 388 // TODO(avi): url_data? |
381 NSPasteboard* pb = GetPasteboard(); | 389 NSPasteboard* pb = GetPasteboard(); |
382 [pb addTypes:[NSArray arrayWithObject:NSHTMLPboardType] owner:nil]; | 390 [pb addTypes:[NSArray arrayWithObject:NSHTMLPboardType] owner:nil]; |
383 [pb setString:html_fragment forType:NSHTMLPboardType]; | 391 [pb setString:html_fragment forType:NSHTMLPboardType]; |
384 } | 392 } |
385 | 393 |
386 void Clipboard::WriteRTF(const char* rtf_data, size_t data_len) { | 394 void ClipboardMac::WriteRTF(const char* rtf_data, size_t data_len) { |
387 WriteData(GetRtfFormatType(), rtf_data, data_len); | 395 WriteData(GetRtfFormatType(), rtf_data, data_len); |
388 } | 396 } |
389 | 397 |
390 void Clipboard::WriteBookmark(const char* title_data, | 398 void ClipboardMac::WriteBookmark(const char* title_data, |
391 size_t title_len, | 399 size_t title_len, |
392 const char* url_data, | 400 const char* url_data, |
393 size_t url_len) { | 401 size_t url_len) { |
394 std::string title_str(title_data, title_len); | 402 std::string title_str(title_data, title_len); |
395 NSString *title = base::SysUTF8ToNSString(title_str); | 403 NSString* title = base::SysUTF8ToNSString(title_str); |
396 std::string url_str(url_data, url_len); | 404 std::string url_str(url_data, url_len); |
397 NSString *url = base::SysUTF8ToNSString(url_str); | 405 NSString* url = base::SysUTF8ToNSString(url_str); |
398 | 406 |
399 // TODO(playmobil): In the Windows version of this function, an HTML | 407 // TODO(playmobil): In the Windows version of this function, an HTML |
400 // representation of the bookmark is also added to the clipboard, to support | 408 // representation of the bookmark is also added to the clipboard, to support |
401 // drag and drop of web shortcuts. I don't think we need to do this on the | 409 // drag and drop of web shortcuts. I don't think we need to do this on the |
402 // Mac, but we should double check later on. | 410 // Mac, but we should double check later on. |
403 NSURL* nsurl = [NSURL URLWithString:url]; | 411 NSURL* nsurl = [NSURL URLWithString:url]; |
404 | 412 |
405 NSPasteboard* pb = GetPasteboard(); | 413 NSPasteboard* pb = GetPasteboard(); |
406 // passing UTIs into the pasteboard methods is valid >= 10.5 | 414 // passing UTIs into the pasteboard methods is valid >= 10.5 |
407 [pb addTypes:[NSArray arrayWithObjects:NSURLPboardType, | 415 [pb addTypes:[NSArray arrayWithObjects:NSURLPboardType, kUTTypeURLName, nil] |
408 kUTTypeURLName, | |
409 nil] | |
410 owner:nil]; | 416 owner:nil]; |
411 [nsurl writeToPasteboard:pb]; | 417 [nsurl writeToPasteboard:pb]; |
412 [pb setString:title forType:kUTTypeURLName]; | 418 [pb setString:title forType:kUTTypeURLName]; |
413 } | 419 } |
414 | 420 |
415 void Clipboard::WriteBitmap(const SkBitmap& bitmap) { | 421 void ClipboardMac::WriteBitmap(const SkBitmap& bitmap) { |
416 NSImage* image = gfx::SkBitmapToNSImageWithColorSpace( | 422 NSImage* image = gfx::SkBitmapToNSImageWithColorSpace( |
417 bitmap, base::mac::GetSystemColorSpace()); | 423 bitmap, base::mac::GetSystemColorSpace()); |
418 // An API to ask the NSImage to write itself to the clipboard comes in 10.6 :( | 424 // An API to ask the NSImage to write itself to the clipboard comes in 10.6 :( |
419 // For now, spit out the image as a TIFF. | 425 // For now, spit out the image as a TIFF. |
420 NSPasteboard* pb = GetPasteboard(); | 426 NSPasteboard* pb = GetPasteboard(); |
421 [pb addTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:nil]; | 427 [pb addTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:nil]; |
422 NSData *tiff_data = [image TIFFRepresentation]; | 428 NSData* tiff_data = [image TIFFRepresentation]; |
423 LOG_IF(ERROR, tiff_data == NULL) << "Failed to allocate image for clipboard"; | 429 LOG_IF(ERROR, tiff_data == NULL) << "Failed to allocate image for clipboard"; |
424 if (tiff_data) { | 430 if (tiff_data) { |
425 [pb setData:tiff_data forType:NSTIFFPboardType]; | 431 [pb setData:tiff_data forType:NSTIFFPboardType]; |
426 } | 432 } |
427 } | 433 } |
428 | 434 |
429 void Clipboard::WriteData(const FormatType& format, | 435 void ClipboardMac::WriteData(const FormatType& format, |
430 const char* data_data, | 436 const char* data_data, |
431 size_t data_len) { | 437 size_t data_len) { |
432 NSPasteboard* pb = GetPasteboard(); | 438 NSPasteboard* pb = GetPasteboard(); |
433 [pb addTypes:[NSArray arrayWithObject:format.ToNSString()] owner:nil]; | 439 [pb addTypes:[NSArray arrayWithObject:format.ToNSString()] owner:nil]; |
434 [pb setData:[NSData dataWithBytes:data_data length:data_len] | 440 [pb setData:[NSData dataWithBytes:data_data length:data_len] |
435 forType:format.ToNSString()]; | 441 forType:format.ToNSString()]; |
436 } | 442 } |
437 | 443 |
438 // Write an extra flavor that signifies WebKit was the last to modify the | 444 // Write an extra flavor that signifies WebKit was the last to modify the |
439 // pasteboard. This flavor has no data. | 445 // pasteboard. This flavor has no data. |
440 void Clipboard::WriteWebSmartPaste() { | 446 void ClipboardMac::WriteWebSmartPaste() { |
441 NSPasteboard* pb = GetPasteboard(); | 447 NSPasteboard* pb = GetPasteboard(); |
442 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); | 448 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); |
443 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; | 449 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; |
444 [pb setData:nil forType:format]; | 450 [pb setData:nil forType:format]; |
445 } | 451 } |
446 | 452 |
447 } // namespace ui | 453 } // namespace ui |
OLD | NEW |