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 <X11/extensions/Xfixes.h> | 7 #include <X11/extensions/Xfixes.h> |
8 #include <X11/Xatom.h> | 8 #include <X11/Xatom.h> |
9 #include <list> | 9 #include <list> |
10 #include <set> | 10 #include <set> |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 break; | 562 break; |
563 } | 563 } |
564 default: | 564 default: |
565 break; | 565 break; |
566 } | 566 } |
567 | 567 |
568 return POST_DISPATCH_NONE; | 568 return POST_DISPATCH_NONE; |
569 } | 569 } |
570 | 570 |
571 /////////////////////////////////////////////////////////////////////////////// | 571 /////////////////////////////////////////////////////////////////////////////// |
| 572 // Various predefined FormatTypes. |
| 573 // static |
| 574 Clipboard::FormatType Clipboard::GetFormatType( |
| 575 const std::string& format_string) { |
| 576 return FormatType::Deserialize(format_string); |
| 577 } |
| 578 |
| 579 // static |
| 580 const Clipboard::FormatType& Clipboard::GetUrlFormatType() { |
| 581 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeURIList)); |
| 582 return type; |
| 583 } |
| 584 |
| 585 // static |
| 586 const Clipboard::FormatType& Clipboard::GetUrlWFormatType() { |
| 587 return GetUrlFormatType(); |
| 588 } |
| 589 |
| 590 // static |
| 591 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { |
| 592 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeText)); |
| 593 return type; |
| 594 } |
| 595 |
| 596 // static |
| 597 const Clipboard::FormatType& Clipboard::GetPlainTextWFormatType() { |
| 598 return GetPlainTextFormatType(); |
| 599 } |
| 600 |
| 601 // static |
| 602 const Clipboard::FormatType& Clipboard::GetFilenameFormatType() { |
| 603 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeFilename)); |
| 604 return type; |
| 605 } |
| 606 |
| 607 // static |
| 608 const Clipboard::FormatType& Clipboard::GetFilenameWFormatType() { |
| 609 return Clipboard::GetFilenameFormatType(); |
| 610 } |
| 611 |
| 612 // static |
| 613 const Clipboard::FormatType& Clipboard::GetHtmlFormatType() { |
| 614 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeHTML)); |
| 615 return type; |
| 616 } |
| 617 |
| 618 // static |
| 619 const Clipboard::FormatType& Clipboard::GetRtfFormatType() { |
| 620 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeRTF)); |
| 621 return type; |
| 622 } |
| 623 |
| 624 // static |
| 625 const Clipboard::FormatType& Clipboard::GetBitmapFormatType() { |
| 626 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePNG)); |
| 627 return type; |
| 628 } |
| 629 |
| 630 // static |
| 631 const Clipboard::FormatType& Clipboard::GetWebKitSmartPasteFormatType() { |
| 632 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebkitSmartPaste)); |
| 633 return type; |
| 634 } |
| 635 |
| 636 // static |
| 637 const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { |
| 638 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData)); |
| 639 return type; |
| 640 } |
| 641 |
| 642 // static |
| 643 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { |
| 644 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); |
| 645 return type; |
| 646 } |
| 647 |
| 648 /////////////////////////////////////////////////////////////////////////////// |
572 // Clipboard | 649 // Clipboard |
573 | 650 |
574 Clipboard::Clipboard() | 651 Clipboard::Clipboard() |
575 : aurax11_details_(new AuraX11Details) { | 652 : aurax11_details_(new AuraX11Details) { |
576 DCHECK(CalledOnValidThread()); | 653 DCHECK(CalledOnValidThread()); |
577 } | 654 } |
578 | 655 |
579 Clipboard::~Clipboard() { | 656 Clipboard::~Clipboard() { |
580 DCHECK(CalledOnValidThread()); | 657 DCHECK(CalledOnValidThread()); |
581 | 658 |
582 aurax11_details_->StoreCopyPasteDataAndWait(); | 659 aurax11_details_->StoreCopyPasteDataAndWait(); |
583 } | 660 } |
584 | 661 |
585 void Clipboard::WriteObjects(ClipboardType type, const ObjectMap& objects) { | 662 uint64 Clipboard::GetSequenceNumber(ClipboardType type) { |
586 DCHECK(CalledOnValidThread()); | 663 DCHECK(CalledOnValidThread()); |
587 DCHECK(IsSupportedClipboardType(type)); | 664 if (type == CLIPBOARD_TYPE_COPY_PASTE) |
588 | 665 return SelectionChangeObserver::GetInstance()->clipboard_sequence_number(); |
589 aurax11_details_->CreateNewClipboardData(); | 666 else |
590 for (ObjectMap::const_iterator iter = objects.begin(); | 667 return SelectionChangeObserver::GetInstance()->primary_sequence_number(); |
591 iter != objects.end(); ++iter) { | |
592 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); | |
593 } | |
594 aurax11_details_->TakeOwnershipOfSelection(type); | |
595 | |
596 if (type == CLIPBOARD_TYPE_COPY_PASTE) { | |
597 ObjectMap::const_iterator text_iter = objects.find(CBF_TEXT); | |
598 if (text_iter != objects.end()) { | |
599 aurax11_details_->CreateNewClipboardData(); | |
600 const ObjectMapParams& params_vector = text_iter->second; | |
601 if (params_vector.size()) { | |
602 const ObjectMapParam& char_vector = params_vector[0]; | |
603 if (char_vector.size()) | |
604 WriteText(&char_vector.front(), char_vector.size()); | |
605 } | |
606 aurax11_details_->TakeOwnershipOfSelection(CLIPBOARD_TYPE_SELECTION); | |
607 } | |
608 } | |
609 } | 668 } |
610 | 669 |
611 bool Clipboard::IsFormatAvailable(const FormatType& format, | 670 bool Clipboard::IsFormatAvailable(const FormatType& format, |
612 ClipboardType type) const { | 671 ClipboardType type) const { |
613 DCHECK(CalledOnValidThread()); | 672 DCHECK(CalledOnValidThread()); |
614 DCHECK(IsSupportedClipboardType(type)); | 673 DCHECK(IsSupportedClipboardType(type)); |
615 | 674 |
616 TargetList target_list = aurax11_details_->WaitAndGetTargetsList(type); | 675 TargetList target_list = aurax11_details_->WaitAndGetTargetsList(type); |
617 if (format.Equals(GetPlainTextFormatType()) || | 676 if (format.Equals(GetPlainTextFormatType()) || |
618 format.Equals(GetUrlFormatType())) { | 677 format.Equals(GetUrlFormatType())) { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 | 803 |
745 void Clipboard::ReadData(const FormatType& format, std::string* result) const { | 804 void Clipboard::ReadData(const FormatType& format, std::string* result) const { |
746 DCHECK(CalledOnValidThread()); | 805 DCHECK(CalledOnValidThread()); |
747 | 806 |
748 SelectionData data(aurax11_details_->RequestAndWaitForTypes( | 807 SelectionData data(aurax11_details_->RequestAndWaitForTypes( |
749 CLIPBOARD_TYPE_COPY_PASTE, aurax11_details_->GetAtomsForFormat(format))); | 808 CLIPBOARD_TYPE_COPY_PASTE, aurax11_details_->GetAtomsForFormat(format))); |
750 if (data.IsValid()) | 809 if (data.IsValid()) |
751 data.AssignTo(result); | 810 data.AssignTo(result); |
752 } | 811 } |
753 | 812 |
754 uint64 Clipboard::GetSequenceNumber(ClipboardType type) { | 813 void Clipboard::WriteObjects(ClipboardType type, const ObjectMap& objects) { |
755 DCHECK(CalledOnValidThread()); | 814 DCHECK(CalledOnValidThread()); |
756 if (type == CLIPBOARD_TYPE_COPY_PASTE) | 815 DCHECK(IsSupportedClipboardType(type)); |
757 return SelectionChangeObserver::GetInstance()->clipboard_sequence_number(); | 816 |
758 else | 817 aurax11_details_->CreateNewClipboardData(); |
759 return SelectionChangeObserver::GetInstance()->primary_sequence_number(); | 818 for (ObjectMap::const_iterator iter = objects.begin(); |
| 819 iter != objects.end(); ++iter) { |
| 820 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); |
| 821 } |
| 822 aurax11_details_->TakeOwnershipOfSelection(type); |
| 823 |
| 824 if (type == CLIPBOARD_TYPE_COPY_PASTE) { |
| 825 ObjectMap::const_iterator text_iter = objects.find(CBF_TEXT); |
| 826 if (text_iter != objects.end()) { |
| 827 aurax11_details_->CreateNewClipboardData(); |
| 828 const ObjectMapParams& params_vector = text_iter->second; |
| 829 if (params_vector.size()) { |
| 830 const ObjectMapParam& char_vector = params_vector[0]; |
| 831 if (char_vector.size()) |
| 832 WriteText(&char_vector.front(), char_vector.size()); |
| 833 } |
| 834 aurax11_details_->TakeOwnershipOfSelection(CLIPBOARD_TYPE_SELECTION); |
| 835 } |
| 836 } |
760 } | 837 } |
761 | 838 |
762 void Clipboard::WriteText(const char* text_data, size_t text_len) { | 839 void Clipboard::WriteText(const char* text_data, size_t text_len) { |
763 std::string str(text_data, text_len); | 840 std::string str(text_data, text_len); |
764 scoped_refptr<base::RefCountedMemory> mem( | 841 scoped_refptr<base::RefCountedMemory> mem( |
765 base::RefCountedString::TakeString(&str)); | 842 base::RefCountedString::TakeString(&str)); |
766 | 843 |
767 aurax11_details_->InsertMapping(kMimeTypeText, mem); | 844 aurax11_details_->InsertMapping(kMimeTypeText, mem); |
768 aurax11_details_->InsertMapping(kText, mem); | 845 aurax11_details_->InsertMapping(kText, mem); |
769 aurax11_details_->InsertMapping(kString, mem); | 846 aurax11_details_->InsertMapping(kString, mem); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 // Therefore we must upkeep their integrity. | 912 // Therefore we must upkeep their integrity. |
836 if (format.Equals(GetBitmapFormatType())) | 913 if (format.Equals(GetBitmapFormatType())) |
837 return; | 914 return; |
838 | 915 |
839 std::vector<unsigned char> bytes(data_data, data_data + data_len); | 916 std::vector<unsigned char> bytes(data_data, data_data + data_len); |
840 scoped_refptr<base::RefCountedMemory> mem( | 917 scoped_refptr<base::RefCountedMemory> mem( |
841 base::RefCountedBytes::TakeVector(&bytes)); | 918 base::RefCountedBytes::TakeVector(&bytes)); |
842 aurax11_details_->InsertMapping(format.ToString(), mem); | 919 aurax11_details_->InsertMapping(format.ToString(), mem); |
843 } | 920 } |
844 | 921 |
845 // static | |
846 Clipboard::FormatType Clipboard::GetFormatType( | |
847 const std::string& format_string) { | |
848 return FormatType::Deserialize(format_string); | |
849 } | |
850 | |
851 // static | |
852 const Clipboard::FormatType& Clipboard::GetUrlFormatType() { | |
853 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeURIList)); | |
854 return type; | |
855 } | |
856 | |
857 // static | |
858 const Clipboard::FormatType& Clipboard::GetUrlWFormatType() { | |
859 return GetUrlFormatType(); | |
860 } | |
861 | |
862 // static | |
863 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { | |
864 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeText)); | |
865 return type; | |
866 } | |
867 | |
868 // static | |
869 const Clipboard::FormatType& Clipboard::GetPlainTextWFormatType() { | |
870 return GetPlainTextFormatType(); | |
871 } | |
872 | |
873 // static | |
874 const Clipboard::FormatType& Clipboard::GetFilenameFormatType() { | |
875 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeFilename)); | |
876 return type; | |
877 } | |
878 | |
879 // static | |
880 const Clipboard::FormatType& Clipboard::GetFilenameWFormatType() { | |
881 return Clipboard::GetFilenameFormatType(); | |
882 } | |
883 | |
884 // static | |
885 const Clipboard::FormatType& Clipboard::GetHtmlFormatType() { | |
886 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeHTML)); | |
887 return type; | |
888 } | |
889 | |
890 // static | |
891 const Clipboard::FormatType& Clipboard::GetRtfFormatType() { | |
892 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeRTF)); | |
893 return type; | |
894 } | |
895 | |
896 // static | |
897 const Clipboard::FormatType& Clipboard::GetBitmapFormatType() { | |
898 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePNG)); | |
899 return type; | |
900 } | |
901 | |
902 // static | |
903 const Clipboard::FormatType& Clipboard::GetWebKitSmartPasteFormatType() { | |
904 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebkitSmartPaste)); | |
905 return type; | |
906 } | |
907 | |
908 // static | |
909 const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { | |
910 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData)); | |
911 return type; | |
912 } | |
913 | |
914 // static | |
915 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { | |
916 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); | |
917 return type; | |
918 } | |
919 | |
920 } // namespace ui | 922 } // namespace ui |
OLD | NEW |