diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-01 18:56:35 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-01 18:56:35 +0000 |
commit | 84c88aa65b45234668caa6b4a7205e534a7b8973 (patch) | |
tree | 23d54dea38749e169a832a29a52845faf4ecfadc /app/gtk_dnd_util.cc | |
parent | 0f215e0c0e92474342c3003414d1e0f7ee5e8eba (diff) | |
download | chromium_src-84c88aa65b45234668caa6b4a7205e534a7b8973.zip chromium_src-84c88aa65b45234668caa6b4a7205e534a7b8973.tar.gz chromium_src-84c88aa65b45234668caa6b4a7205e534a7b8973.tar.bz2 |
GTK: Make the toolbar star button a drag source.
Also refactor URI list/named url packing code.
BUG=19008
Review URL: http://codereview.chromium.org/175036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25067 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/gtk_dnd_util.cc')
-rw-r--r-- | app/gtk_dnd_util.cc | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/app/gtk_dnd_util.cc b/app/gtk_dnd_util.cc index e8ca0af..3e87f32 100644 --- a/app/gtk_dnd_util.cc +++ b/app/gtk_dnd_util.cc @@ -9,6 +9,8 @@ #include "base/pickle.h" #include "googleurl/src/gurl.h" +static const int kBitsPerByte = 8; + // static GdkAtom GtkDndUtil::GetAtomForTarget(int target) { switch (target) { @@ -112,6 +114,44 @@ void GtkDndUtil::AddTargetToList(GtkTargetList* targets, int target_code) { } // static +void GtkDndUtil::WriteURLWithName(GtkSelectionData* selection_data, + const GURL& url, + const string16& title, + int type) { + switch (type) { + case TEXT_PLAIN: { + gtk_selection_data_set_text(selection_data, url.spec().c_str(), + url.spec().length()); + break; + } + case TEXT_URI_LIST: { + gchar* uri_array[2]; + uri_array[0] = strdup(url.spec().c_str()); + uri_array[1] = NULL; + gtk_selection_data_set_uris(selection_data, uri_array); + free(uri_array[0]); + break; + } + case CHROME_NAMED_URL: { + Pickle pickle; + pickle.WriteString(UTF16ToUTF8(title)); + pickle.WriteString(url.spec()); + gtk_selection_data_set( + selection_data, + GetAtomForTarget(GtkDndUtil::CHROME_NAMED_URL), + kBitsPerByte, + reinterpret_cast<const guchar*>(pickle.data()), + pickle.size()); + break; + } + default: { + NOTREACHED(); + break; + } + } +} + +// static bool GtkDndUtil::ExtractNamedURL(GtkSelectionData* selection_data, GURL* url, string16* title) { @@ -133,7 +173,7 @@ bool GtkDndUtil::ExtractNamedURL(GtkSelectionData* selection_data, return true; } -// static void +// static bool GtkDndUtil::ExtractURIList(GtkSelectionData* selection_data, std::vector<GURL>* urls) { gchar** uris = gtk_selection_data_get_uris(selection_data); |