diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-24 00:16:43 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-24 00:16:43 +0000 |
commit | 18597e6c4c13dba7da60255912572a6c133c455d (patch) | |
tree | cb646a77066b09be7970d43450c8545d5aae982e /chrome/browser/gtk/download_item_drag.cc | |
parent | c627aff9917462dda693aa8a57c1155235ca4ff3 (diff) | |
download | chromium_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
Diffstat (limited to 'chrome/browser/gtk/download_item_drag.cc')
-rw-r--r-- | chrome/browser/gtk/download_item_drag.cc | 80 |
1 files changed, 80 insertions, 0 deletions
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; +} |