| 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 <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 #include <X11/extensions/Xfixes.h> | 8 #include <X11/extensions/Xfixes.h> |
| 9 #include <X11/Xatom.h> | 9 #include <X11/Xatom.h> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 std::string Clipboard::FormatType::Serialize() const { | 195 std::string Clipboard::FormatType::Serialize() const { |
| 196 return GdkAtomToString(data_); | 196 return GdkAtomToString(data_); |
| 197 } | 197 } |
| 198 | 198 |
| 199 // static | 199 // static |
| 200 Clipboard::FormatType Clipboard::FormatType::Deserialize( | 200 Clipboard::FormatType Clipboard::FormatType::Deserialize( |
| 201 const std::string& serialization) { | 201 const std::string& serialization) { |
| 202 return FormatType(serialization); | 202 return FormatType(serialization); |
| 203 } | 203 } |
| 204 | 204 |
| 205 bool Clipboard::FormatType::operator<(const FormatType& other) const { |
| 206 return GdkAtomToString(data_) < GdkAtomToString(other.data_); |
| 207 } |
| 208 |
| 205 bool Clipboard::FormatType::Equals(const FormatType& other) const { | 209 bool Clipboard::FormatType::Equals(const FormatType& other) const { |
| 206 return data_ == other.data_; | 210 return data_ == other.data_; |
| 207 } | 211 } |
| 208 | 212 |
| 209 Clipboard::Clipboard() : clipboard_data_(NULL) { | 213 Clipboard::Clipboard() : clipboard_data_(NULL) { |
| 210 DCHECK(CalledOnValidThread()); | 214 DCHECK(CalledOnValidThread()); |
| 211 clipboard_ = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); | 215 clipboard_ = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); |
| 212 primary_selection_ = gtk_clipboard_get(GDK_SELECTION_PRIMARY); | 216 primary_selection_ = gtk_clipboard_get(GDK_SELECTION_PRIMARY); |
| 213 } | 217 } |
| 214 | 218 |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 | 589 |
| 586 uint64 Clipboard::GetSequenceNumber(ClipboardType type) { | 590 uint64 Clipboard::GetSequenceNumber(ClipboardType type) { |
| 587 DCHECK(CalledOnValidThread()); | 591 DCHECK(CalledOnValidThread()); |
| 588 if (type == CLIPBOARD_TYPE_COPY_PASTE) | 592 if (type == CLIPBOARD_TYPE_COPY_PASTE) |
| 589 return SelectionChangeObserver::GetInstance()->clipboard_sequence_number(); | 593 return SelectionChangeObserver::GetInstance()->clipboard_sequence_number(); |
| 590 else | 594 else |
| 591 return SelectionChangeObserver::GetInstance()->primary_sequence_number(); | 595 return SelectionChangeObserver::GetInstance()->primary_sequence_number(); |
| 592 } | 596 } |
| 593 | 597 |
| 594 //static | 598 //static |
| 595 Clipboard::FormatType Clipboard::GetFormatType( | 599 Clipboard::FormatType Clipboard::GetFormatTypeInternal( |
| 596 const std::string& format_string) { | 600 const std::string& format_string) { |
| 597 return FormatType::Deserialize(format_string); | 601 return FormatType::Deserialize(format_string); |
| 598 } | 602 } |
| 599 | 603 |
| 600 // static | 604 // static |
| 601 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { | 605 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { |
| 602 CR_DEFINE_STATIC_LOCAL( | 606 CR_DEFINE_STATIC_LOCAL( |
| 603 FormatType, type, (GDK_TARGET_STRING)); | 607 FormatType, type, (GDK_TARGET_STRING)); |
| 604 return type; | 608 return type; |
| 605 } | 609 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 } | 642 } |
| 639 | 643 |
| 640 // static | 644 // static |
| 641 const Clipboard::FormatType& Clipboard::GetWebKitSmartPasteFormatType() { | 645 const Clipboard::FormatType& Clipboard::GetWebKitSmartPasteFormatType() { |
| 642 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebkitSmartPaste)); | 646 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebkitSmartPaste)); |
| 643 return type; | 647 return type; |
| 644 } | 648 } |
| 645 | 649 |
| 646 // static | 650 // static |
| 647 const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { | 651 const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { |
| 648 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData)); | 652 CR_DEFINE_STATIC_LOCAL( |
| 653 FormatType, type, (GetFormatType(kMimeTypeWebCustomData))); |
| 649 return type; | 654 return type; |
| 650 } | 655 } |
| 651 | 656 |
| 652 // static | 657 // static |
| 653 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { | 658 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { |
| 654 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); | 659 CR_DEFINE_STATIC_LOCAL( |
| 660 FormatType, type, (GetFormatType(kMimeTypePepperCustomData))); |
| 655 return type; | 661 return type; |
| 656 } | 662 } |
| 657 | 663 |
| 658 void Clipboard::InsertMapping(const char* key, | 664 void Clipboard::InsertMapping(const char* key, |
| 659 char* data, | 665 char* data, |
| 660 size_t data_len) { | 666 size_t data_len) { |
| 661 DCHECK(clipboard_data_->find(key) == clipboard_data_->end()); | 667 DCHECK(clipboard_data_->find(key) == clipboard_data_->end()); |
| 662 (*clipboard_data_)[key] = std::make_pair(data, data_len); | 668 (*clipboard_data_)[key] = std::make_pair(data, data_len); |
| 663 } | 669 } |
| 664 | 670 |
| 665 GtkClipboard* Clipboard::LookupBackingClipboard(ClipboardType type) const { | 671 GtkClipboard* Clipboard::LookupBackingClipboard(ClipboardType type) const { |
| 666 switch (type) { | 672 switch (type) { |
| 667 case CLIPBOARD_TYPE_COPY_PASTE: | 673 case CLIPBOARD_TYPE_COPY_PASTE: |
| 668 return clipboard_; | 674 return clipboard_; |
| 669 case CLIPBOARD_TYPE_SELECTION: | 675 case CLIPBOARD_TYPE_SELECTION: |
| 670 return primary_selection_; | 676 return primary_selection_; |
| 671 default: | 677 default: |
| 672 NOTREACHED(); | 678 NOTREACHED(); |
| 673 return NULL; | 679 return NULL; |
| 674 } | 680 } |
| 675 } | 681 } |
| 676 | 682 |
| 677 } // namespace ui | 683 } // namespace ui |
| OLD | NEW |