Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/base/clipboard/custom_data_helper.h" | |
| 18 #include "ui/gfx/canvas_skia.h" | 19 #include "ui/gfx/canvas_skia.h" |
| 19 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 20 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 20 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
| 21 | 22 |
| 22 namespace ui { | 23 namespace ui { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 // Would be nice if this were in UTCoreTypes.h, but it isn't | 27 // Would be nice if this were in UTCoreTypes.h, but it isn't |
| 27 NSString* const kUTTypeURLName = @"public.url-name"; | 28 NSString* const kUTTypeURLName = @"public.url-name"; |
| 28 | 29 |
| 29 // Tells us if WebKit was the last to write to the pasteboard. There's no | 30 // Tells us if WebKit was the last to write to the pasteboard. There's no |
| 30 // actual data associated with this type. | 31 // actual data associated with this type. |
| 31 NSString* const kWebSmartPastePboardType = @"NeXT smart paste pasteboard type"; | 32 NSString* const kWebSmartPastePboardType = @"NeXT smart paste pasteboard type"; |
| 32 | 33 |
| 34 NSString* const kWebCustomDataType = @"org.chromium.web-custom-data"; | |
|
tony
2011/12/05 20:24:50
Same bug comment here (they can share a bug).
dcheng
2011/12/05 20:51:04
Done.
| |
| 35 | |
| 33 NSPasteboard* GetPasteboard() { | 36 NSPasteboard* GetPasteboard() { |
| 34 // The pasteboard should not be nil in a UI session, but this handy DCHECK | 37 // The pasteboard should not be nil in a UI session, but this handy DCHECK |
| 35 // can help track down problems if someone tries using clipboard code outside | 38 // can help track down problems if someone tries using clipboard code outside |
| 36 // of a UI session. | 39 // of a UI session. |
| 37 NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; | 40 NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; |
| 38 DCHECK(pasteboard); | 41 DCHECK(pasteboard); |
| 39 return pasteboard; | 42 return pasteboard; |
| 40 } | 43 } |
| 41 | 44 |
| 42 } // namespace | 45 } // namespace |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 } | 218 } |
| 216 | 219 |
| 217 types->clear(); | 220 types->clear(); |
| 218 if (IsFormatAvailable(Clipboard::GetPlainTextFormatType(), buffer)) | 221 if (IsFormatAvailable(Clipboard::GetPlainTextFormatType(), buffer)) |
| 219 types->push_back(UTF8ToUTF16(kMimeTypeText)); | 222 types->push_back(UTF8ToUTF16(kMimeTypeText)); |
| 220 if (IsFormatAvailable(Clipboard::GetHtmlFormatType(), buffer)) | 223 if (IsFormatAvailable(Clipboard::GetHtmlFormatType(), buffer)) |
| 221 types->push_back(UTF8ToUTF16(kMimeTypeHTML)); | 224 types->push_back(UTF8ToUTF16(kMimeTypeHTML)); |
| 222 if ([NSImage canInitWithPasteboard:GetPasteboard()]) | 225 if ([NSImage canInitWithPasteboard:GetPasteboard()]) |
| 223 types->push_back(UTF8ToUTF16(kMimeTypePNG)); | 226 types->push_back(UTF8ToUTF16(kMimeTypePNG)); |
| 224 *contains_filenames = false; | 227 *contains_filenames = false; |
| 228 | |
| 229 NSPasteboard* pb = GetPasteboard(); | |
| 230 if ([[pb types] containsObject:kWebCustomDataType]) { | |
| 231 NSData* data = [pb dataForType:kWebCustomDataType]; | |
| 232 if ([data length]) | |
| 233 ReadCustomDataTypes([data bytes], [data length], types); | |
| 234 } | |
| 225 } | 235 } |
| 226 | 236 |
| 227 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const { | 237 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const { |
| 228 DCHECK_EQ(buffer, BUFFER_STANDARD); | 238 DCHECK_EQ(buffer, BUFFER_STANDARD); |
| 229 NSPasteboard* pb = GetPasteboard(); | 239 NSPasteboard* pb = GetPasteboard(); |
| 230 NSString* contents = [pb stringForType:NSStringPboardType]; | 240 NSString* contents = [pb stringForType:NSStringPboardType]; |
| 231 | 241 |
| 232 UTF8ToUTF16([contents UTF8String], | 242 UTF8ToUTF16([contents UTF8String], |
| 233 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], | 243 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], |
| 234 result); | 244 result); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 fromRect:NSZeroRect | 310 fromRect:NSZeroRect |
| 301 operation:NSCompositeCopy | 311 operation:NSCompositeCopy |
| 302 fraction:1.0]; | 312 fraction:1.0]; |
| 303 } | 313 } |
| 304 return canvas.ExtractBitmap(); | 314 return canvas.ExtractBitmap(); |
| 305 } | 315 } |
| 306 | 316 |
| 307 void Clipboard::ReadCustomData(Buffer buffer, | 317 void Clipboard::ReadCustomData(Buffer buffer, |
| 308 const string16& type, | 318 const string16& type, |
| 309 string16* result) const { | 319 string16* result) const { |
| 310 // TODO(dcheng): Implement this. | 320 DCHECK_EQ(buffer, BUFFER_STANDARD); |
| 311 NOTIMPLEMENTED(); | 321 |
| 322 NSPasteboard* pb = GetPasteboard(); | |
| 323 if ([[pb types] containsObject:kWebCustomDataType]) { | |
| 324 NSData* data = [pb dataForType:kWebCustomDataType]; | |
| 325 if ([data length]) | |
| 326 ReadCustomDataForType([data bytes], [data length], type, result); | |
| 327 } | |
| 312 } | 328 } |
| 313 | 329 |
| 314 void Clipboard::ReadBookmark(string16* title, std::string* url) const { | 330 void Clipboard::ReadBookmark(string16* title, std::string* url) const { |
| 315 NSPasteboard* pb = GetPasteboard(); | 331 NSPasteboard* pb = GetPasteboard(); |
| 316 | 332 |
| 317 if (title) { | 333 if (title) { |
| 318 NSString* contents = [pb stringForType:kUTTypeURLName]; | 334 NSString* contents = [pb stringForType:kUTTypeURLName]; |
| 319 UTF8ToUTF16([contents UTF8String], | 335 UTF8ToUTF16([contents UTF8String], |
| 320 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], | 336 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], |
| 321 title); | 337 title); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 // static | 423 // static |
| 408 Clipboard::FormatType Clipboard::GetBitmapFormatType() { | 424 Clipboard::FormatType Clipboard::GetBitmapFormatType() { |
| 409 return base::SysNSStringToUTF8(NSTIFFPboardType); | 425 return base::SysNSStringToUTF8(NSTIFFPboardType); |
| 410 } | 426 } |
| 411 | 427 |
| 412 // static | 428 // static |
| 413 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { | 429 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { |
| 414 return base::SysNSStringToUTF8(kWebSmartPastePboardType); | 430 return base::SysNSStringToUTF8(kWebSmartPastePboardType); |
| 415 } | 431 } |
| 416 | 432 |
| 433 // static | |
| 434 Clipboard::FormatType Clipboard::GetWebCustomDataFormatType() { | |
| 435 return base::SysNSStringToUTF8(kWebCustomDataType); | |
| 436 } | |
| 437 | |
| 417 } // namespace ui | 438 } // namespace ui |
| OLD | NEW |