| 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.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" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 std::string Clipboard::FormatType::Serialize() const { | 77 std::string Clipboard::FormatType::Serialize() const { |
| 78 return base::SysNSStringToUTF8(data_); | 78 return base::SysNSStringToUTF8(data_); |
| 79 } | 79 } |
| 80 | 80 |
| 81 // static | 81 // static |
| 82 Clipboard::FormatType Clipboard::FormatType::Deserialize( | 82 Clipboard::FormatType Clipboard::FormatType::Deserialize( |
| 83 const std::string& serialization) { | 83 const std::string& serialization) { |
| 84 return FormatType(base::SysUTF8ToNSString(serialization)); | 84 return FormatType(base::SysUTF8ToNSString(serialization)); |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool Clipboard::FormatType::operator<(const FormatType& other) const { |
| 88 return [data_ compare:other.data_] == NSOrderedAscending; |
| 89 } |
| 90 |
| 87 Clipboard::Clipboard() { | 91 Clipboard::Clipboard() { |
| 88 DCHECK(CalledOnValidThread()); | 92 DCHECK(CalledOnValidThread()); |
| 89 } | 93 } |
| 90 | 94 |
| 91 Clipboard::~Clipboard() { | 95 Clipboard::~Clipboard() { |
| 92 DCHECK(CalledOnValidThread()); | 96 DCHECK(CalledOnValidThread()); |
| 93 } | 97 } |
| 94 | 98 |
| 95 void Clipboard::WriteObjects(ClipboardType type, const ObjectMap& objects) { | 99 void Clipboard::WriteObjects(ClipboardType type, const ObjectMap& objects) { |
| 96 DCHECK(CalledOnValidThread()); | 100 DCHECK(CalledOnValidThread()); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 360 |
| 357 void Clipboard::ReadData(const FormatType& format, std::string* result) const { | 361 void Clipboard::ReadData(const FormatType& format, std::string* result) const { |
| 358 DCHECK(CalledOnValidThread()); | 362 DCHECK(CalledOnValidThread()); |
| 359 NSPasteboard* pb = GetPasteboard(); | 363 NSPasteboard* pb = GetPasteboard(); |
| 360 NSData* data = [pb dataForType:format.ToNSString()]; | 364 NSData* data = [pb dataForType:format.ToNSString()]; |
| 361 if ([data length]) | 365 if ([data length]) |
| 362 result->assign(static_cast<const char*>([data bytes]), [data length]); | 366 result->assign(static_cast<const char*>([data bytes]), [data length]); |
| 363 } | 367 } |
| 364 | 368 |
| 365 // static | 369 // static |
| 366 Clipboard::FormatType Clipboard::GetFormatType( | 370 Clipboard::FormatType Clipboard::GetFormatTypeInternal( |
| 367 const std::string& format_string) { | 371 const std::string& format_string) { |
| 368 return FormatType::Deserialize(format_string); | 372 return FormatType::Deserialize(format_string); |
| 369 } | 373 } |
| 370 | 374 |
| 371 // static | 375 // static |
| 372 const Clipboard::FormatType& Clipboard::GetUrlFormatType() { | 376 const Clipboard::FormatType& Clipboard::GetUrlFormatType() { |
| 373 CR_DEFINE_STATIC_LOCAL(FormatType, type, (NSURLPboardType)); | 377 CR_DEFINE_STATIC_LOCAL(FormatType, type, (NSURLPboardType)); |
| 374 return type; | 378 return type; |
| 375 } | 379 } |
| 376 | 380 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 } | 424 } |
| 421 | 425 |
| 422 // static | 426 // static |
| 423 const Clipboard::FormatType& Clipboard::GetWebKitSmartPasteFormatType() { | 427 const Clipboard::FormatType& Clipboard::GetWebKitSmartPasteFormatType() { |
| 424 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kWebSmartPastePboardType)); | 428 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kWebSmartPastePboardType)); |
| 425 return type; | 429 return type; |
| 426 } | 430 } |
| 427 | 431 |
| 428 // static | 432 // static |
| 429 const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { | 433 const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { |
| 430 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kWebCustomDataPboardType)); | 434 CR_DEFINE_STATIC_LOCAL( |
| 435 FormatType, type, (GetFormatType([kWebCustomDataPboardType UTF8String]))); |
| 431 return type; | 436 return type; |
| 432 } | 437 } |
| 433 | 438 |
| 434 // static | 439 // static |
| 435 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { | 440 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { |
| 436 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPepperCustomDataPboardType)); | 441 CR_DEFINE_STATIC_LOCAL( |
| 442 FormatType, |
| 443 type, |
| 444 (GetFormatType([kPepperCustomDataPboardType UTF8String]))); |
| 437 return type; | 445 return type; |
| 438 } | 446 } |
| 439 | 447 |
| 440 } // namespace ui | 448 } // namespace ui |
| OLD | NEW |