diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-10 18:32:14 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-10 18:32:14 +0000 |
commit | 6e64343accab0d5b5436645e40a36f5ff20d17ec (patch) | |
tree | cbf33d783e15f8fcd27bd1c27b79046fac0fb4be /app/gtk_dnd_util.h | |
parent | ede729d4d7a1e6a1dc07d58e0fff2ca5cc6e7131 (diff) | |
download | chromium_src-6e64343accab0d5b5436645e40a36f5ff20d17ec.zip chromium_src-6e64343accab0d5b5436645e40a36f5ff20d17ec.tar.gz chromium_src-6e64343accab0d5b5436645e40a36f5ff20d17ec.tar.bz2 |
Final removal of the bad dependency of chrome/common on chrome/browser
Also convert app/gtk_dnd_util.h from a class to a namespace for consistency
with added app/gtk_util.h.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/669268
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41177 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/gtk_dnd_util.h')
-rw-r--r-- | app/gtk_dnd_util.h | 133 |
1 files changed, 65 insertions, 68 deletions
diff --git a/app/gtk_dnd_util.h b/app/gtk_dnd_util.h index 2c323e9..4471174 100644 --- a/app/gtk_dnd_util.h +++ b/app/gtk_dnd_util.h @@ -6,80 +6,77 @@ #define APP_GTK_DND_UTIL_H_ #include <gtk/gtk.h> + #include <vector> #include "base/string16.h" class GURL; -class GtkDndUtil { - public: - // Registry of all internal int codes for drag and drop. - enum { - // Intra-application types. - CHROME_TAB = 1 << 0, - CHROME_BOOKMARK_ITEM = 1 << 1, - CHROME_WEBDROP_FILE_CONTENTS = 1 << 2, - CHROME_NAMED_URL = 1 << 3, - - // Standard types. - TEXT_PLAIN = 1 << 4, - TEXT_URI_LIST = 1 << 5, - TEXT_HTML = 1 << 6, - - // Other types. NETSCAPE_URL is provided for compatibility with other - // apps. - NETSCAPE_URL = 1 << 7, - - // Used for drag-out download. - TEXT_PLAIN_NO_CHARSET = 1 << 8, - DIRECT_SAVE_FILE = 1 << 9, - - INVALID_TARGET = 1 << 10, - }; - - // Get the atom for a given target (of the above enum type). Will return NULL - // for non-custom targets, such as CHROME_TEXT_PLAIN. - static GdkAtom GetAtomForTarget(int target); - - // Creates a target list from the given mask. The mask should be an OR of - // CHROME_* values. The target list is returned with ref count 1; the caller - // is responsible for calling gtk_target_list_unref() when it is no longer - // needed. - // Since the MIME type for WEBDROP_FILE_CONTENTS depends on the file's - // contents, that flag is ignored by this function. It is the responsibility - // of the client code to do the right thing. - static GtkTargetList* GetTargetListFromCodeMask(int code_mask); - - // Set the drag target list for |source| with the target list that - // corresponds to |code_mask|. - static void SetSourceTargetListFromCodeMask(GtkWidget* source, int code_mask); - - // Set the accepted targets list for |dest|. The |target_codes| array should - // be sorted in preference order and should be terminated with -1. - static void SetDestTargetList(GtkWidget* dest, const int* target_codes); - - // Write a URL to the selection in the given type. - static void WriteURLWithName(GtkSelectionData* selection_data, - const GURL& url, - const string16& title, - int type); - - // Extracts data of type CHROME_NAMED_URL from |selection_data| into - // |url| and |title|. Returns true if the url/title were safely extracted - // and the url is valid. - static bool ExtractNamedURL(GtkSelectionData* selection_data, - GURL* url, - string16* title); - - // Extracts data of type TEXT_URI_LIST from |selection_data| into |urls|. - static bool ExtractURIList(GtkSelectionData* selection_data, - std::vector<GURL>* urls); - - private: - GtkDndUtil(); - - static void AddTargetToList(GtkTargetList* targets, int target_code); +namespace gtk_dnd_util { + +// Registry of all internal int codes for drag and drop. +enum { + // Intra-application types. + CHROME_TAB = 1 << 0, + CHROME_BOOKMARK_ITEM = 1 << 1, + CHROME_WEBDROP_FILE_CONTENTS = 1 << 2, + CHROME_NAMED_URL = 1 << 3, + + // Standard types. + TEXT_PLAIN = 1 << 4, + TEXT_URI_LIST = 1 << 5, + TEXT_HTML = 1 << 6, + + // Other types. NETSCAPE_URL is provided for compatibility with other + // apps. + NETSCAPE_URL = 1 << 7, + + // Used for drag-out download. + TEXT_PLAIN_NO_CHARSET = 1 << 8, + DIRECT_SAVE_FILE = 1 << 9, + + INVALID_TARGET = 1 << 10, }; +// Get the atom for a given target (of the above enum type). Will return NULL +// for non-custom targets, such as CHROME_TEXT_PLAIN. +GdkAtom GetAtomForTarget(int target); + +// Creates a target list from the given mask. The mask should be an OR of +// CHROME_* values. The target list is returned with ref count 1; the caller +// is responsible for calling gtk_target_list_unref() when it is no longer +// needed. +// Since the MIME type for WEBDROP_FILE_CONTENTS depends on the file's +// contents, that flag is ignored by this function. It is the responsibility +// of the client code to do the right thing. +GtkTargetList* GetTargetListFromCodeMask(int code_mask); + +// Set the drag target list for |source| with the target list that +// corresponds to |code_mask|. +void SetSourceTargetListFromCodeMask(GtkWidget* source, int code_mask); + +// Set the accepted targets list for |dest|. The |target_codes| array should +// be sorted in preference order and should be terminated with -1. +void SetDestTargetList(GtkWidget* dest, const int* target_codes); + +// Write a URL to the selection in the given type. +void WriteURLWithName(GtkSelectionData* selection_data, + const GURL& url, + const string16& title, + int type); + +// Extracts data of type CHROME_NAMED_URL from |selection_data| into +// |url| and |title|. Returns true if the url/title were safely extracted +// and the url is valid. +bool ExtractNamedURL(GtkSelectionData* selection_data, + GURL* url, + string16* title); + +// Extracts data of type TEXT_URI_LIST from |selection_data| into |urls|. +bool ExtractURIList(GtkSelectionData* selection_data, + std::vector<GURL>* urls); + +} // namespace gtk_dnd_util + #endif // APP_GTK_DND_UTIL_H_ |