Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: chrome/browser/gtk/download_item_drag.cc

Issue 1029004: GTK: implement extension bookmark manager drag api.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/gtk/download_item_drag.h ('k') | chrome/browser/gtk/download_item_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/gtk/download_item_drag.h"
6
7 #include "app/gtk_dnd_util.h"
8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/download/download_manager.h"
10 #include "gfx/gtk_util.h"
11 #include "googleurl/src/gurl.h"
12 #include "net/base/net_util.h"
13 #include "third_party/skia/include/core/SkBitmap.h"
14
15 namespace {
16
17 const int kCodeMask = gtk_dnd_util::TEXT_URI_LIST |
18 gtk_dnd_util::CHROME_NAMED_URL;
19 const GdkDragAction kDragAction = GDK_ACTION_COPY;
20
21 void OnDragDataGet(GtkWidget* widget, GdkDragContext* context,
22 GtkSelectionData* selection_data,
23 guint target_type, guint time,
24 DownloadItem* download_item) {
25 GURL url = net::FilePathToFileURL(download_item->full_path());
26 gtk_dnd_util::WriteURLWithName(selection_data, url,
27 UTF8ToUTF16(download_item->GetFileName().value()), target_type);
28 }
29
30 } // namespace
31
32 // static
33 void DownloadItemDrag::SetSource(GtkWidget* widget, DownloadItem* item) {
34 gtk_drag_source_set(widget, GDK_BUTTON1_MASK, NULL, 0,
35 kDragAction);
36 gtk_dnd_util::SetSourceTargetListFromCodeMask(widget, kCodeMask);
37 g_signal_connect(widget, "drag-data-get",
38 G_CALLBACK(OnDragDataGet), item);
39 }
40
41 // static
42 void DownloadItemDrag::BeginDrag(const DownloadItem* item, SkBitmap* icon) {
43 new DownloadItemDrag(item, icon);
44 }
45
46 DownloadItemDrag::DownloadItemDrag(const DownloadItem* item,
47 SkBitmap* icon)
48 : drag_widget_(gtk_invisible_new()),
49 pixbuf_(gfx::GdkPixbufFromSkBitmap(icon)) {
50 g_object_ref_sink(drag_widget_);
51 g_signal_connect(drag_widget_, "drag-data-get",
52 G_CALLBACK(OnDragDataGet), const_cast<DownloadItem*>(item));
53 g_signal_connect(drag_widget_, "drag-begin",
54 G_CALLBACK(OnDragBegin), this);
55 g_signal_connect(drag_widget_, "drag-end",
56 G_CALLBACK(OnDragEnd), this);
57
58 GtkTargetList* list = gtk_dnd_util::GetTargetListFromCodeMask(kCodeMask);
59 GdkEvent* event = gtk_get_current_event();
60 gtk_drag_begin(drag_widget_, list, kDragAction, 1, event);
61 if (event)
62 gdk_event_free(event);
63 gtk_target_list_unref(list);
64 }
65
66 DownloadItemDrag::~DownloadItemDrag() {
67 g_object_unref(pixbuf_);
68 g_object_unref(drag_widget_);
69 }
70
71 // static
72 void DownloadItemDrag::OnDragBegin(GtkWidget* widget,
73 GdkDragContext* drag_context,
74 DownloadItemDrag* drag) {
75 gtk_drag_set_icon_pixbuf(drag_context, drag->pixbuf_, 0, 0);
76 }
77
78 // static
79 void DownloadItemDrag::OnDragEnd(GtkWidget* widget,
80 GdkDragContext* drag_context,
81 DownloadItemDrag* drag) {
82 delete drag;
83 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/download_item_drag.h ('k') | chrome/browser/gtk/download_item_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698