summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-24 00:16:43 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-24 00:16:43 +0000
commit18597e6c4c13dba7da60255912572a6c133c455d (patch)
treecb646a77066b09be7970d43450c8545d5aae982e
parentc627aff9917462dda693aa8a57c1155235ca4ff3 (diff)
downloadchromium_src-18597e6c4c13dba7da60255912572a6c133c455d.zip
chromium_src-18597e6c4c13dba7da60255912572a6c133c455d.tar.gz
chromium_src-18597e6c4c13dba7da60255912572a6c133c455d.tar.bz2
GTK: handle dom_ui-generated download drag events.
BUG=36512 TEST=drag a file out of the downloads page Review URL: http://codereview.chromium.org/657026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39815 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--app/gtk_dnd_util.h3
-rw-r--r--chrome/browser/download/download_util.cc10
-rw-r--r--chrome/browser/gtk/download_item_drag.cc80
-rw-r--r--chrome/browser/gtk/download_item_drag.h43
-rw-r--r--chrome/browser/gtk/download_item_gtk.cc24
-rw-r--r--chrome/browser/gtk/download_item_gtk.h5
-rwxr-xr-xchrome/chrome_browser.gypi2
7 files changed, 137 insertions, 30 deletions
diff --git a/app/gtk_dnd_util.h b/app/gtk_dnd_util.h
index efa249c..2c323e9 100644
--- a/app/gtk_dnd_util.h
+++ b/app/gtk_dnd_util.h
@@ -44,7 +44,8 @@ class GtkDndUtil {
// 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 unreffing it when it is no longer needed.
+ // 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.
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc
index 48cb86f..611b199 100644
--- a/chrome/browser/download/download_util.cc
+++ b/chrome/browser/download/download_util.cc
@@ -34,10 +34,14 @@
#include "views/drag_utils.h"
#endif
-#if defined(TOOLKIT_VIEWS) && defined(OS_LINUX)
+#if defined(OS_LINUX)
+#if defined(TOOLKIT_VIEWS)
#include "app/drag_drop_types.h"
#include "views/widget/widget_gtk.h"
-#endif
+#elif defined(TOOLKIT_GTK)
+#include "chrome/browser/gtk/download_item_drag.h"
+#endif // defined(TOOLKIT_GTK)
+#endif // defined(OS_LINUX)
#if defined(OS_WIN)
#include "app/os_exchange_data_provider_win.h"
@@ -294,7 +298,7 @@ void DragDownload(const DownloadItem* download,
void DragDownload(const DownloadItem* download,
SkBitmap* icon,
gfx::NativeView view) {
- NOTIMPLEMENTED();
+ DownloadItemDrag::BeginDrag(download, icon);
}
#endif // OS_LINUX
diff --git a/chrome/browser/gtk/download_item_drag.cc b/chrome/browser/gtk/download_item_drag.cc
new file mode 100644
index 0000000..4106a91
--- /dev/null
+++ b/chrome/browser/gtk/download_item_drag.cc
@@ -0,0 +1,80 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/gtk/download_item_drag.h"
+
+#include "app/gfx/gtk_util.h"
+#include "app/gtk_dnd_util.h"
+#include "base/string_util.h"
+#include "chrome/browser/download/download_manager.h"
+#include "googleurl/src/gurl.h"
+#include "net/base/net_util.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+
+namespace {
+
+const int kCodeMask = GtkDndUtil::TEXT_URI_LIST |
+ GtkDndUtil::CHROME_NAMED_URL;
+const GdkDragAction kDragAction = GDK_ACTION_COPY;
+
+void OnDragDataGet(GtkWidget* widget, GdkDragContext* context,
+ GtkSelectionData* selection_data,
+ guint target_type, guint time,
+ DownloadItem* download_item) {
+ GURL url = net::FilePathToFileURL(download_item->full_path());
+ GtkDndUtil::WriteURLWithName(selection_data, url,
+ UTF8ToUTF16(download_item->GetFileName().value()), target_type);
+}
+
+} // namespace
+
+// static
+void DownloadItemDrag::SetSource(GtkWidget* widget, DownloadItem* item) {
+ gtk_drag_source_set(widget, GDK_BUTTON1_MASK, NULL, 0,
+ kDragAction);
+ GtkDndUtil::SetSourceTargetListFromCodeMask(widget, kCodeMask);
+ g_signal_connect(widget, "drag-data-get",
+ G_CALLBACK(OnDragDataGet), item);
+}
+
+// static
+void DownloadItemDrag::BeginDrag(const DownloadItem* item, SkBitmap* icon) {
+ new DownloadItemDrag(item, icon);
+}
+
+DownloadItemDrag::DownloadItemDrag(const DownloadItem* item,
+ SkBitmap* icon)
+ : drag_widget_(gtk_invisible_new()),
+ pixbuf_(gfx::GdkPixbufFromSkBitmap(icon)) {
+ g_object_ref_sink(drag_widget_);
+ g_signal_connect(drag_widget_, "drag-data-get",
+ G_CALLBACK(OnDragDataGet), const_cast<DownloadItem*>(item));
+ g_signal_connect(drag_widget_, "drag-begin",
+ G_CALLBACK(OnDragBegin), this);
+ g_signal_connect(drag_widget_, "drag-end",
+ G_CALLBACK(OnDragEnd), this);
+
+ GtkTargetList* list = GtkDndUtil::GetTargetListFromCodeMask(kCodeMask);
+ gtk_drag_begin(drag_widget_, list, kDragAction, 1, gtk_get_current_event());
+ gtk_target_list_unref(list);
+}
+
+DownloadItemDrag::~DownloadItemDrag() {
+ g_object_unref(pixbuf_);
+ g_object_unref(drag_widget_);
+}
+
+// static
+void DownloadItemDrag::OnDragBegin(GtkWidget* widget,
+ GdkDragContext* drag_context,
+ DownloadItemDrag* drag) {
+ gtk_drag_set_icon_pixbuf(drag_context, drag->pixbuf_, 0, 0);
+}
+
+// static
+void DownloadItemDrag::OnDragEnd(GtkWidget* widget,
+ GdkDragContext* drag_context,
+ DownloadItemDrag* drag) {
+ delete drag;
+}
diff --git a/chrome/browser/gtk/download_item_drag.h b/chrome/browser/gtk/download_item_drag.h
new file mode 100644
index 0000000..1f8df44
--- /dev/null
+++ b/chrome/browser/gtk/download_item_drag.h
@@ -0,0 +1,43 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_GTK_DOWNLOAD_ITEM_DRAG_H_
+#define CHROME_BROWSER_GTK_DOWNLOAD_ITEM_DRAG_H_
+
+#include <gtk/gtk.h>
+
+#include "base/basictypes.h"
+
+class DownloadItem;
+class SkBitmap;
+
+class DownloadItemDrag {
+ public:
+ // Sets |widget| as a source for drags pertaining to |item|. No
+ // DownloadItemDrag object is created.
+ static void SetSource(GtkWidget* widget, DownloadItem* item);
+
+ // Creates a new DownloadItemDrag, the lifetime of which is tied to the
+ // system drag.
+ static void BeginDrag(const DownloadItem* item, SkBitmap* icon);
+
+ private:
+ explicit DownloadItemDrag(const DownloadItem* item, SkBitmap* icon);
+ ~DownloadItemDrag();
+
+ static void OnDragBegin(GtkWidget* widget,
+ GdkDragContext* drag_context,
+ DownloadItemDrag* drag);
+
+ static void OnDragEnd(GtkWidget* widget,
+ GdkDragContext* drag_context,
+ DownloadItemDrag* drag);
+
+ GtkWidget* drag_widget_;
+ GdkPixbuf* pixbuf_;
+
+ DISALLOW_COPY_AND_ASSIGN(DownloadItemDrag);
+};
+
+#endif // CHROME_BROWSER_GTK_DOWNLOAD_ITEM_DRAG_H_
diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc
index 9ea494c..47c8f86 100644
--- a/chrome/browser/gtk/download_item_gtk.cc
+++ b/chrome/browser/gtk/download_item_gtk.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,7 +9,6 @@
#include "app/gfx/color_utils.h"
#include "app/gfx/font.h"
#include "app/gfx/text_elider.h"
-#include "app/gtk_dnd_util.h"
#include "app/menus/simple_menu_model.h"
#include "app/resource_bundle.h"
#include "app/slide_animation.h"
@@ -23,6 +22,7 @@
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/download/download_shelf.h"
#include "chrome/browser/download/download_util.h"
+#include "chrome/browser/gtk/download_item_drag.h"
#include "chrome/browser/gtk/download_shelf_gtk.h"
#include "chrome/browser/gtk/gtk_theme_provider.h"
#include "chrome/browser/gtk/menu_gtk.h"
@@ -32,7 +32,6 @@
#include "chrome/common/notification_service.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
-#include "net/base/net_util.h"
#include "skia/ext/skia_utils_gtk.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -370,13 +369,7 @@ void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) {
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);
+ DownloadItemDrag::SetSource(body_.get(), get_download());
complete_animation_.reset(new SlideAnimation(this));
complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs);
@@ -871,17 +864,6 @@ 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 1976be8..e19688f 100644
--- a/chrome/browser/gtk/download_item_gtk.h
+++ b/chrome/browser/gtk/download_item_gtk.h
@@ -112,11 +112,6 @@ 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,
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 2a19c89..6d21f79 100755
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1048,6 +1048,8 @@
'browser/gtk/download_in_progress_dialog_gtk.h',
'browser/gtk/download_item_gtk.cc',
'browser/gtk/download_item_gtk.h',
+ 'browser/gtk/download_item_drag.cc',
+ 'browser/gtk/download_item_drag.h',
'browser/gtk/download_shelf_gtk.cc',
'browser/gtk/download_shelf_gtk.h',
'browser/gtk/download_started_animation_gtk.cc',