diff options
author | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-07 23:28:29 +0000 |
---|---|---|
committer | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-07 23:28:29 +0000 |
commit | ff53be65f85e67b06d05f91c7c69a47ac7517625 (patch) | |
tree | 3116ab4bcbdcb08b8e04c0fef6a0909a2a906481 /ui/base/clipboard/clipboard.h | |
parent | 83ce153a1498beadb8415fac34d1465d160a4521 (diff) | |
download | chromium_src-ff53be65f85e67b06d05f91c7c69a47ac7517625.zip chromium_src-ff53be65f85e67b06d05f91c7c69a47ac7517625.tar.gz chromium_src-ff53be65f85e67b06d05f91c7c69a47ac7517625.tar.bz2 |
Make Clipboard::FormatType an opaque handle type.
BUG=106523
TEST=ui_unittests --gtest_filter=ClipboardTest.* and manual testing
Review URL: http://codereview.chromium.org/8801038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113502 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base/clipboard/clipboard.h')
-rw-r--r-- | ui/base/clipboard/clipboard.h | 105 |
1 files changed, 75 insertions, 30 deletions
diff --git a/ui/base/clipboard/clipboard.h b/ui/base/clipboard/clipboard.h index 39cb5d4..be8d460 100644 --- a/ui/base/clipboard/clipboard.h +++ b/ui/base/clipboard/clipboard.h @@ -16,6 +16,10 @@ #include "base/string16.h" #include "ui/base/ui_export.h" +#if defined(TOOLKIT_USES_GTK) +#include <gdk/gdk.h> +#endif + namespace gfx { class Size; } @@ -27,11 +31,54 @@ class SkBitmap; typedef struct _GtkClipboard GtkClipboard; #endif +#ifdef __OBJC__ +@class NSString; +#else +class NSString; +#endif + namespace ui { class UI_EXPORT Clipboard { public: - typedef std::string FormatType; + // Platform neutral holder for native data representation of a clipboard type. + struct UI_EXPORT FormatType { + FormatType(); + ~FormatType(); + + std::string Serialize() const; + static FormatType Deserialize(const std::string& serialization); + + private: + friend class Clipboard; + + bool Equals(const FormatType& other) const; + +#if defined(OS_WIN) + explicit FormatType(UINT native_format); + UINT ToUINT() const { return data_; } + UINT data_; +#elif defined(USE_AURA) + explicit FormatType(const std::string& native_format); + const std::string& ToString() const { return data_; } + std::string data_; +#elif defined(TOOLKIT_USES_GTK) + explicit FormatType(const std::string& native_format); + explicit FormatType(const GdkAtom& native_format); + const GdkAtom& ToGdkAtom() const { return data_; } + GdkAtom data_; +#elif defined(OS_MACOSX) + public: + FormatType(const FormatType& other); + FormatType& operator=(const FormatType& other); + private: + explicit FormatType(NSString* native_format); + NSString* ToNSString() const { return data_; } + NSString* data_; +#else +#error No FormatType definition. +#endif + }; // ObjectType designates the type of data to be stored in the clipboard. This // designation is shared across all OSes. The system-specific designation @@ -132,11 +179,6 @@ class UI_EXPORT Clipboard { // Tests whether the clipboard contains a certain format bool IsFormatAvailable(const FormatType& format, Buffer buffer) const; - // As above, but instead of interpreting |format| by some platform-specific - // definition, interpret it as a literal MIME type. - bool IsFormatAvailableByString(const std::string& format, - Buffer buffer) const; - void ReadAvailableTypes(Buffer buffer, std::vector<string16>* types, bool* contains_filenames) const; @@ -170,23 +212,26 @@ class UI_EXPORT Clipboard { // Reads raw data from the clipboard with the given format type. Stores result // as a byte vector. - // TODO(dcheng): Due to platform limitations on Windows, we should make sure - // format is never controlled by the user. - void ReadData(const std::string& format, std::string* result) const; - - // Get format Identifiers for various types. - static FormatType GetUrlFormatType(); - static FormatType GetUrlWFormatType(); - static FormatType GetMozUrlFormatType(); - static FormatType GetPlainTextFormatType(); - static FormatType GetPlainTextWFormatType(); - static FormatType GetFilenameFormatType(); - static FormatType GetFilenameWFormatType(); - static FormatType GetWebKitSmartPasteFormatType(); + void ReadData(const FormatType& format, std::string* result) const; + + // Gets the FormatType corresponding to an arbitrary format string, + // registering it with the system if needed. Due to Windows/Linux + // limitiations, |format_string| must never be controlled by the user. + static FormatType GetFormatType(const std::string& format_string); + + // Get format identifiers for various types. + static const FormatType& GetUrlFormatType(); + static const FormatType& GetUrlWFormatType(); + static const FormatType& GetMozUrlFormatType(); + static const FormatType& GetPlainTextFormatType(); + static const FormatType& GetPlainTextWFormatType(); + static const FormatType& GetFilenameFormatType(); + static const FormatType& GetFilenameWFormatType(); + static const FormatType& GetWebKitSmartPasteFormatType(); // Win: MS HTML Format, Other: Generic HTML format - static FormatType GetHtmlFormatType(); - static FormatType GetBitmapFormatType(); - static FormatType GetWebCustomDataFormatType(); + static const FormatType& GetHtmlFormatType(); + static const FormatType& GetBitmapFormatType(); + static const FormatType& GetWebCustomDataFormatType(); // Embeds a pointer to a SharedMemory object pointed to by |bitmap_handle| // belonging to |process| into a shared bitmap [CBF_SMBITMAP] slot in @@ -198,10 +243,10 @@ class UI_EXPORT Clipboard { base::ProcessHandle process); #if defined(OS_WIN) // Firefox text/html - static FormatType GetTextHtmlFormatType(); - static FormatType GetCFHDropFormatType(); - static FormatType GetFileDescriptorFormatType(); - static FormatType GetFileContentFormatZeroType(); + static const FormatType& GetTextHtmlFormatType(); + static const FormatType& GetCFHDropFormatType(); + static const FormatType& GetFileDescriptorFormatType(); + static const FormatType& GetFileContentFormatZeroType(); #endif private: @@ -226,9 +271,9 @@ class UI_EXPORT Clipboard { void WriteBitmap(const char* pixel_data, const char* size_data); - // |format_name| is an ASCII string and should be NULL-terminated. - void WriteData(const char* format_name, size_t format_len, - const char* data_data, size_t data_len); + void WriteData(const FormatType& format, + const char* data_data, + size_t data_len); #if defined(OS_WIN) void WriteBitmapFromHandle(HBITMAP source_hbitmap, const gfx::Size& size); @@ -262,7 +307,7 @@ class UI_EXPORT Clipboard { // contents of clipboard_data_. public: - typedef std::map<FormatType, std::pair<char*, size_t> > TargetMap; + typedef std::map<std::string, std::pair<char*, size_t> > TargetMap; private: // Write changes to gtk clipboard. |