summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-18 21:39:35 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-18 21:39:35 +0000
commit7fcb792736cc10cc20a84cce7fe6f7c5d2470bf9 (patch)
treebb805d888ba9bde1aa9c51674db0fceea6e5655a
parent2f4514d606aa6cb299517998438d4d93122986bd (diff)
downloadchromium_src-7fcb792736cc10cc20a84cce7fe6f7c5d2470bf9.zip
chromium_src-7fcb792736cc10cc20a84cce7fe6f7c5d2470bf9.tar.gz
chromium_src-7fcb792736cc10cc20a84cce7fe6f7c5d2470bf9.tar.bz2
GTK: Download item as drag source.
BUG=21656 TEST=Drag a completed download onto the desktop, or into the tabstrip, or wherever Review URL: http://codereview.chromium.org/215002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26624 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/gtk/download_item_gtk.cc23
-rw-r--r--chrome/browser/gtk/download_item_gtk.h5
2 files changed, 28 insertions, 0 deletions
diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc
index d8132f5..c273f1d 100644
--- a/chrome/browser/gtk/download_item_gtk.cc
+++ b/chrome/browser/gtk/download_item_gtk.cc
@@ -8,6 +8,7 @@
#include "app/gfx/canvas_paint.h"
#include "app/gfx/font.h"
#include "app/gfx/text_elider.h"
+#include "app/gtk_dnd_util.h"
#include "app/resource_bundle.h"
#include "app/slide_animation.h"
#include "base/basictypes.h"
@@ -26,6 +27,7 @@
#include "chrome/browser/gtk/standard_menus.h"
#include "chrome/common/gtk_util.h"
#include "chrome/common/notification_service.h"
+#include "net/base/net_util.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -389,6 +391,16 @@ void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) {
break;
case DownloadItem::COMPLETE:
StopDownloadProgress();
+
+ // Set up the widget as a drag source.
+ gtk_drag_source_set(body_.get(), GDK_BUTTON1_MASK, NULL, 0,
+ GDK_ACTION_COPY);
+ GtkDndUtil::SetSourceTargetListFromCodeMask(body_.get(),
+ GtkDndUtil::TEXT_URI_LIST |
+ GtkDndUtil::CHROME_NAMED_URL);
+ g_signal_connect(body_.get(), "drag-data-get",
+ G_CALLBACK(OnDragDataGet), this);
+
complete_animation_.reset(new SlideAnimation(this));
complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs);
complete_animation_->SetTweenType(SlideAnimation::NONE);
@@ -852,6 +864,17 @@ void DownloadItemGtk::OnShelfResized(GtkWidget *widget,
}
// static
+void DownloadItemGtk::OnDragDataGet(GtkWidget* widget, GdkDragContext* context,
+ GtkSelectionData* selection_data,
+ guint target_type, guint time,
+ DownloadItemGtk* item) {
+ GURL url = net::FilePathToFileURL(item->get_download()->full_path());
+
+ GtkDndUtil::WriteURLWithName(selection_data, url,
+ UTF8ToUTF16(item->get_download()->GetFileName().value()), target_type);
+}
+
+// static
gboolean DownloadItemGtk::OnDangerousPromptExpose(GtkWidget* widget,
GdkEventExpose* event, DownloadItemGtk* item) {
if (!item->theme_provider_->UseGtkTheme()) {
diff --git a/chrome/browser/gtk/download_item_gtk.h b/chrome/browser/gtk/download_item_gtk.h
index c490c94..36889a8 100644
--- a/chrome/browser/gtk/download_item_gtk.h
+++ b/chrome/browser/gtk/download_item_gtk.h
@@ -111,6 +111,11 @@ class DownloadItemGtk : public DownloadItem::Observer,
GtkAllocation *allocation,
DownloadItemGtk* item);
+ static void OnDragDataGet(GtkWidget* widget, GdkDragContext* context,
+ GtkSelectionData* selection_data,
+ guint target_type, guint time,
+ DownloadItemGtk* item);
+
// Dangerous download related. -----------------------------------------------
static gboolean OnDangerousPromptExpose(GtkWidget* widget,
GdkEventExpose* event,