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 /chrome/browser | |
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 'chrome/browser')
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.h | 5 | ||||
-rw-r--r-- | chrome/browser/gtk/tab_contents_drag_source.cc | 21 | ||||
-rw-r--r-- | chrome/browser/gtk/toolbar_star_toggle_gtk.cc | 24 | ||||
-rw-r--r-- | chrome/browser/gtk/toolbar_star_toggle_gtk.h | 8 |
5 files changed, 39 insertions, 21 deletions
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index 89d23d9..a667a32 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -496,8 +496,6 @@ GtkWidget* BrowserToolbarGtk::BuildToolbarMenuButton( } void BrowserToolbarGtk::SetUpDragForHomeButton() { - // TODO(estade): we should use a custom drag-drop handler so that we can - // prefer URIs over plain text when both are available. gtk_drag_dest_set(home_->widget(), GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_COPY); static const int targets[] = { GtkDndUtil::TEXT_PLAIN, diff --git a/chrome/browser/gtk/browser_toolbar_gtk.h b/chrome/browser/gtk/browser_toolbar_gtk.h index 58dd44a..ebf6528 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.h +++ b/chrome/browser/gtk/browser_toolbar_gtk.h @@ -57,6 +57,11 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver, return event_box_; } + // Getter for associated browser object. + Browser* browser() { + return browser_; + } + virtual LocationBar* GetLocationBar() const; GoButtonGtk* GetGoButton() { return go_.get(); } diff --git a/chrome/browser/gtk/tab_contents_drag_source.cc b/chrome/browser/gtk/tab_contents_drag_source.cc index b27ef57..780c6ca 100644 --- a/chrome/browser/gtk/tab_contents_drag_source.cc +++ b/chrome/browser/gtk/tab_contents_drag_source.cc @@ -129,15 +129,6 @@ void TabContentsDragSource::OnDragDataGet( break; } - case GtkDndUtil::TEXT_URI_LIST: { - gchar* uri_array[2]; - uri_array[0] = strdup(drop_data_->url.spec().c_str()); - uri_array[1] = NULL; - gtk_selection_data_set_uris(selection_data, uri_array); - free(uri_array[0]); - break; - } - case GtkDndUtil::TEXT_HTML: { // TODO(estade): change relative links to be absolute using // |html_base_url|. @@ -151,16 +142,10 @@ void TabContentsDragSource::OnDragDataGet( break; } + case GtkDndUtil::TEXT_URI_LIST: case GtkDndUtil::CHROME_NAMED_URL: { - Pickle pickle; - pickle.WriteString(UTF16ToUTF8(drop_data_->url_title)); - pickle.WriteString(drop_data_->url.spec()); - gtk_selection_data_set( - selection_data, - GtkDndUtil::GetAtomForTarget(GtkDndUtil::CHROME_NAMED_URL), - bits_per_byte, - reinterpret_cast<const guchar*>(pickle.data()), - pickle.size()); + GtkDndUtil::WriteURLWithName(selection_data, drop_data_->url, + drop_data_->url_title, target_type); break; } diff --git a/chrome/browser/gtk/toolbar_star_toggle_gtk.cc b/chrome/browser/gtk/toolbar_star_toggle_gtk.cc index ed4f524c..8723a48 100644 --- a/chrome/browser/gtk/toolbar_star_toggle_gtk.cc +++ b/chrome/browser/gtk/toolbar_star_toggle_gtk.cc @@ -4,13 +4,16 @@ #include "chrome/browser/gtk/toolbar_star_toggle_gtk.h" +#include "app/gtk_dnd_util.h" #include "app/resource_bundle.h" #include "base/gfx/rect.h" +#include "chrome/browser/browser.h" #include "chrome/browser/gtk/bookmark_bubble_gtk.h" #include "chrome/browser/gtk/browser_toolbar_gtk.h" #include "chrome/browser/gtk/gtk_chrome_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" #include "chrome/browser/profile.h" +#include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/notification_service.h" #include "grit/theme_resources.h" @@ -29,10 +32,18 @@ ToolbarStarToggleGtk::ToolbarStarToggleGtk(BrowserToolbarGtk* host) // We effectively double-buffer by virtue of having only one image... gtk_widget_set_double_buffered(widget_.get(), FALSE); - g_signal_connect(G_OBJECT(widget_.get()), "expose-event", + g_signal_connect(widget(), "expose-event", G_CALLBACK(OnExpose), this); GTK_WIDGET_UNSET_FLAGS(widget_.get(), GTK_CAN_FOCUS); + gtk_drag_source_set(widget(), GDK_BUTTON1_MASK, + NULL, 0, GDK_ACTION_COPY); + GtkDndUtil::SetSourceTargetListFromCodeMask(widget(), + GtkDndUtil::TEXT_PLAIN | + GtkDndUtil::TEXT_URI_LIST | + GtkDndUtil::CHROME_NAMED_URL); + g_signal_connect(widget(), "drag-data-get", G_CALLBACK(OnDragDataGet), this); + theme_provider_->InitThemesFor(this); registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, @@ -90,6 +101,17 @@ gboolean ToolbarStarToggleGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e, } } +// static +void ToolbarStarToggleGtk::OnDragDataGet(GtkWidget* widget, + GdkDragContext* drag_context, GtkSelectionData* data, guint info, + guint time, ToolbarStarToggleGtk* star) { + const TabContents* tab = star->host_->browser()->tabstrip_model()-> + GetSelectedTabContents(); + if (!tab) + return; + GtkDndUtil::WriteURLWithName(data, tab->GetURL(), tab->GetTitle(), info); +} + void ToolbarStarToggleGtk::UpdateGTKButton() { bool use_gtk = theme_provider_ && theme_provider_->UseGtkTheme(); diff --git a/chrome/browser/gtk/toolbar_star_toggle_gtk.h b/chrome/browser/gtk/toolbar_star_toggle_gtk.h index 2284415..66aa167 100644 --- a/chrome/browser/gtk/toolbar_star_toggle_gtk.h +++ b/chrome/browser/gtk/toolbar_star_toggle_gtk.h @@ -44,6 +44,14 @@ class ToolbarStarToggleGtk : public NotificationObserver { static gboolean OnExpose(GtkWidget* widget, GdkEventExpose* e, ToolbarStarToggleGtk* obj); + // Callback to get the data associated with a drag. + static void OnDragDataGet(GtkWidget* widget, + GdkDragContext* drag_context, + GtkSelectionData* data, + guint info, + guint time, + ToolbarStarToggleGtk* star); + // Used to listen for theme change notifications. NotificationRegistrar registrar_; |