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 #include <list> | 7 #include <list> |
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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 return current_data_; | 399 return current_data_; |
400 } | 400 } |
401 | 401 |
402 static ClipboardData* current_data_; | 402 static ClipboardData* current_data_; |
403 }; | 403 }; |
404 | 404 |
405 ClipboardData* ClipboardDataBuilder::current_data_ = NULL; | 405 ClipboardData* ClipboardDataBuilder::current_data_ = NULL; |
406 | 406 |
407 } // namespace | 407 } // namespace |
408 | 408 |
| 409 // Clipboard FormatType implementation. |
409 Clipboard::FormatType::FormatType() { | 410 Clipboard::FormatType::FormatType() { |
410 } | 411 } |
411 | 412 |
412 Clipboard::FormatType::FormatType(const std::string& native_format) | 413 Clipboard::FormatType::FormatType(const std::string& native_format) |
413 : data_(native_format) { | 414 : data_(native_format) { |
414 } | 415 } |
415 | 416 |
416 Clipboard::FormatType::~FormatType() { | 417 Clipboard::FormatType::~FormatType() { |
417 } | 418 } |
418 | 419 |
419 std::string Clipboard::FormatType::Serialize() const { | 420 std::string Clipboard::FormatType::Serialize() const { |
420 return data_; | 421 return data_; |
421 } | 422 } |
422 | 423 |
423 // static | 424 // static |
424 Clipboard::FormatType Clipboard::FormatType::Deserialize( | 425 Clipboard::FormatType Clipboard::FormatType::Deserialize( |
425 const std::string& serialization) { | 426 const std::string& serialization) { |
426 return FormatType(serialization); | 427 return FormatType(serialization); |
427 } | 428 } |
428 | 429 |
429 bool Clipboard::FormatType::operator<(const FormatType& other) const { | 430 bool Clipboard::FormatType::operator<(const FormatType& other) const { |
430 return data_ < other.data_; | 431 return data_ < other.data_; |
431 } | 432 } |
432 | 433 |
433 bool Clipboard::FormatType::Equals(const FormatType& other) const { | 434 bool Clipboard::FormatType::Equals(const FormatType& other) const { |
434 return data_ == other.data_; | 435 return data_ == other.data_; |
435 } | 436 } |
436 | 437 |
| 438 // Various predefined FormatTypes. |
| 439 // static |
| 440 Clipboard::FormatType Clipboard::GetFormatType( |
| 441 const std::string& format_string) { |
| 442 return FormatType::Deserialize(format_string); |
| 443 } |
| 444 |
| 445 // static |
| 446 const Clipboard::FormatType& Clipboard::GetUrlFormatType() { |
| 447 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeURIList)); |
| 448 return type; |
| 449 } |
| 450 |
| 451 // static |
| 452 const Clipboard::FormatType& Clipboard::GetUrlWFormatType() { |
| 453 return GetUrlFormatType(); |
| 454 } |
| 455 |
| 456 // static |
| 457 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { |
| 458 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeText)); |
| 459 return type; |
| 460 } |
| 461 |
| 462 // static |
| 463 const Clipboard::FormatType& Clipboard::GetPlainTextWFormatType() { |
| 464 return GetPlainTextFormatType(); |
| 465 } |
| 466 |
| 467 // static |
| 468 const Clipboard::FormatType& Clipboard::GetFilenameFormatType() { |
| 469 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeFilename)); |
| 470 return type; |
| 471 } |
| 472 |
| 473 // static |
| 474 const Clipboard::FormatType& Clipboard::GetFilenameWFormatType() { |
| 475 return Clipboard::GetFilenameFormatType(); |
| 476 } |
| 477 |
| 478 // static |
| 479 const Clipboard::FormatType& Clipboard::GetHtmlFormatType() { |
| 480 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeHTML)); |
| 481 return type; |
| 482 } |
| 483 |
| 484 // static |
| 485 const Clipboard::FormatType& Clipboard::GetRtfFormatType() { |
| 486 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeRTF)); |
| 487 return type; |
| 488 } |
| 489 |
| 490 // static |
| 491 const Clipboard::FormatType& Clipboard::GetBitmapFormatType() { |
| 492 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeBitmap)); |
| 493 return type; |
| 494 } |
| 495 |
| 496 // static |
| 497 const Clipboard::FormatType& Clipboard::GetWebKitSmartPasteFormatType() { |
| 498 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebkitSmartPaste)); |
| 499 return type; |
| 500 } |
| 501 |
| 502 // static |
| 503 const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { |
| 504 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData)); |
| 505 return type; |
| 506 } |
| 507 |
| 508 // static |
| 509 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { |
| 510 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); |
| 511 return type; |
| 512 } |
| 513 |
| 514 // Clipboard implementation. |
437 Clipboard::Clipboard() { | 515 Clipboard::Clipboard() { |
438 DCHECK(CalledOnValidThread()); | 516 DCHECK(CalledOnValidThread()); |
439 // Make sure clipboard is created. | 517 // Make sure clipboard is created. |
440 GetClipboard(); | 518 GetClipboard(); |
441 } | 519 } |
442 | 520 |
443 Clipboard::~Clipboard() { | 521 Clipboard::~Clipboard() { |
444 DCHECK(CalledOnValidThread()); | 522 DCHECK(CalledOnValidThread()); |
445 DeleteClipboard(); | 523 DeleteClipboard(); |
446 } | 524 } |
447 | 525 |
448 void Clipboard::WriteObjects(ClipboardType type, const ObjectMap& objects) { | 526 uint64 Clipboard::GetSequenceNumber(ClipboardType type) { |
449 DCHECK(CalledOnValidThread()); | 527 DCHECK(CalledOnValidThread()); |
450 DCHECK(IsSupportedClipboardType(type)); | 528 return GetClipboard()->sequence_number(); |
451 for (ObjectMap::const_iterator iter = objects.begin(); | |
452 iter != objects.end(); ++iter) { | |
453 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); | |
454 } | |
455 ClipboardDataBuilder::CommitToClipboard(); | |
456 } | 529 } |
457 | 530 |
458 bool Clipboard::IsFormatAvailable(const FormatType& format, | 531 bool Clipboard::IsFormatAvailable(const FormatType& format, |
459 ClipboardType type) const { | 532 ClipboardType type) const { |
460 DCHECK(CalledOnValidThread()); | 533 DCHECK(CalledOnValidThread()); |
461 DCHECK(IsSupportedClipboardType(type)); | 534 DCHECK(IsSupportedClipboardType(type)); |
462 AuraClipboard* clipboard = GetClipboard(); | 535 AuraClipboard* clipboard = GetClipboard(); |
463 if (GetPlainTextFormatType().Equals(format) || | 536 if (GetPlainTextFormatType().Equals(format) || |
464 GetUrlFormatType().Equals(format)) | 537 GetUrlFormatType().Equals(format)) |
465 return clipboard->IsFormatAvailable(TEXT); | 538 return clipboard->IsFormatAvailable(TEXT); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 void Clipboard::ReadBookmark(base::string16* title, std::string* url) const { | 625 void Clipboard::ReadBookmark(base::string16* title, std::string* url) const { |
553 DCHECK(CalledOnValidThread()); | 626 DCHECK(CalledOnValidThread()); |
554 GetClipboard()->ReadBookmark(title, url); | 627 GetClipboard()->ReadBookmark(title, url); |
555 } | 628 } |
556 | 629 |
557 void Clipboard::ReadData(const FormatType& format, std::string* result) const { | 630 void Clipboard::ReadData(const FormatType& format, std::string* result) const { |
558 DCHECK(CalledOnValidThread()); | 631 DCHECK(CalledOnValidThread()); |
559 GetClipboard()->ReadData(format.ToString(), result); | 632 GetClipboard()->ReadData(format.ToString(), result); |
560 } | 633 } |
561 | 634 |
562 uint64 Clipboard::GetSequenceNumber(ClipboardType type) { | 635 void Clipboard::WriteObjects(ClipboardType type, const ObjectMap& objects) { |
563 DCHECK(CalledOnValidThread()); | 636 DCHECK(CalledOnValidThread()); |
564 return GetClipboard()->sequence_number(); | 637 DCHECK(IsSupportedClipboardType(type)); |
| 638 for (ObjectMap::const_iterator iter = objects.begin(); |
| 639 iter != objects.end(); ++iter) { |
| 640 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); |
| 641 } |
| 642 ClipboardDataBuilder::CommitToClipboard(); |
565 } | 643 } |
566 | 644 |
567 void Clipboard::WriteText(const char* text_data, size_t text_len) { | 645 void Clipboard::WriteText(const char* text_data, size_t text_len) { |
568 ClipboardDataBuilder::WriteText(text_data, text_len); | 646 ClipboardDataBuilder::WriteText(text_data, text_len); |
569 } | 647 } |
570 | 648 |
571 void Clipboard::WriteHTML(const char* markup_data, | 649 void Clipboard::WriteHTML(const char* markup_data, |
572 size_t markup_len, | 650 size_t markup_len, |
573 const char* url_data, | 651 const char* url_data, |
574 size_t url_len) { | 652 size_t url_len) { |
(...skipping 18 matching lines...) Expand all Loading... |
593 void Clipboard::WriteBitmap(const SkBitmap& bitmap) { | 671 void Clipboard::WriteBitmap(const SkBitmap& bitmap) { |
594 ClipboardDataBuilder::WriteBitmap(bitmap); | 672 ClipboardDataBuilder::WriteBitmap(bitmap); |
595 } | 673 } |
596 | 674 |
597 void Clipboard::WriteData(const FormatType& format, | 675 void Clipboard::WriteData(const FormatType& format, |
598 const char* data_data, | 676 const char* data_data, |
599 size_t data_len) { | 677 size_t data_len) { |
600 ClipboardDataBuilder::WriteData(format.ToString(), data_data, data_len); | 678 ClipboardDataBuilder::WriteData(format.ToString(), data_data, data_len); |
601 } | 679 } |
602 | 680 |
603 // static | |
604 Clipboard::FormatType Clipboard::GetFormatType( | |
605 const std::string& format_string) { | |
606 return FormatType::Deserialize(format_string); | |
607 } | |
608 | |
609 // static | |
610 const Clipboard::FormatType& Clipboard::GetUrlFormatType() { | |
611 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeURIList)); | |
612 return type; | |
613 } | |
614 | |
615 // static | |
616 const Clipboard::FormatType& Clipboard::GetUrlWFormatType() { | |
617 return GetUrlFormatType(); | |
618 } | |
619 | |
620 // static | |
621 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { | |
622 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeText)); | |
623 return type; | |
624 } | |
625 | |
626 // static | |
627 const Clipboard::FormatType& Clipboard::GetPlainTextWFormatType() { | |
628 return GetPlainTextFormatType(); | |
629 } | |
630 | |
631 // static | |
632 const Clipboard::FormatType& Clipboard::GetFilenameFormatType() { | |
633 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeFilename)); | |
634 return type; | |
635 } | |
636 | |
637 // static | |
638 const Clipboard::FormatType& Clipboard::GetFilenameWFormatType() { | |
639 return Clipboard::GetFilenameFormatType(); | |
640 } | |
641 | |
642 // static | |
643 const Clipboard::FormatType& Clipboard::GetHtmlFormatType() { | |
644 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeHTML)); | |
645 return type; | |
646 } | |
647 | |
648 // static | |
649 const Clipboard::FormatType& Clipboard::GetRtfFormatType() { | |
650 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeRTF)); | |
651 return type; | |
652 } | |
653 | |
654 // static | |
655 const Clipboard::FormatType& Clipboard::GetBitmapFormatType() { | |
656 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeBitmap)); | |
657 return type; | |
658 } | |
659 | |
660 // static | |
661 const Clipboard::FormatType& Clipboard::GetWebKitSmartPasteFormatType() { | |
662 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebkitSmartPaste)); | |
663 return type; | |
664 } | |
665 | |
666 // static | |
667 const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { | |
668 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData)); | |
669 return type; | |
670 } | |
671 | |
672 // static | |
673 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { | |
674 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); | |
675 return type; | |
676 } | |
677 | |
678 } // namespace ui | 681 } // namespace ui |
OLD | NEW |