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

Unified Diff: chrome/browser/ui/gtk/download/download_item_drag.cc

Issue 23646006: gtk: Split CustomDrag into multiple pieces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/gtk/download/download_item_drag.cc
diff --git a/chrome/browser/ui/gtk/custom_drag.cc b/chrome/browser/ui/gtk/download/download_item_drag.cc
similarity index 53%
copy from chrome/browser/ui/gtk/custom_drag.cc
copy to chrome/browser/ui/gtk/download/download_item_drag.cc
index 027fcd7c3616eed9c29e805dd7446417d08e5f04..0128fe658feaccc6f131b13e4225fc3c62f93939 100644
--- a/chrome/browser/ui/gtk/custom_drag.cc
+++ b/chrome/browser/ui/gtk/download/download_item_drag.cc
@@ -1,17 +1,14 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2013 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/ui/gtk/custom_drag.h"
+#include "chrome/browser/ui/gtk/download/download_item_drag.h"
#include "base/files/file_path.h"
#include "base/strings/utf_string_conversions.h"
-#include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h"
#include "content/public/browser/download_item.h"
#include "net/base/net_util.h"
-#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/dragdrop/gtk_dnd_util.h"
-#include "ui/gfx/gtk_util.h"
#include "ui/gfx/image/image.h"
#include "url/gurl.h"
@@ -21,56 +18,15 @@ namespace {
const int kDownloadItemCodeMask = ui::TEXT_URI_LIST | ui::CHROME_NAMED_URL;
const GdkDragAction kDownloadItemDragAction = GDK_ACTION_COPY;
-const GdkDragAction kBookmarkDragAction =
- static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE);
} // namespace
-// CustomDrag ------------------------------------------------------------------
-
-CustomDrag::CustomDrag(gfx::Image* icon, int code_mask, GdkDragAction action)
- : drag_widget_(gtk_invisible_new()),
- image_(icon) {
- g_signal_connect(drag_widget_, "drag-data-get",
- G_CALLBACK(OnDragDataGetThunk), this);
- g_signal_connect(drag_widget_, "drag-begin",
- G_CALLBACK(OnDragBeginThunk), this);
- g_signal_connect(drag_widget_, "drag-end",
- G_CALLBACK(OnDragEndThunk), this);
-
- GtkTargetList* list = ui::GetTargetListFromCodeMask(code_mask);
- GdkEvent* event = gtk_get_current_event();
- gtk_drag_begin(drag_widget_, list, action, 1, event);
- if (event)
- gdk_event_free(event);
- gtk_target_list_unref(list);
-}
-
-CustomDrag::~CustomDrag() {
- gtk_widget_destroy(drag_widget_);
-}
-
-void CustomDrag::OnDragBegin(GtkWidget* widget, GdkDragContext* drag_context) {
- if (image_)
- gtk_drag_set_icon_pixbuf(drag_context, image_->ToGdkPixbuf(), 0, 0);
-}
-
-void CustomDrag::OnDragEnd(GtkWidget* widget, GdkDragContext* drag_context) {
- delete this;
-}
-
-// DownloadItemDrag ------------------------------------------------------------
-
// Stores metadata for a drag & drop operation.
class DownloadItemDrag::DragData {
public:
// Constructs a DragData object based on the current state of |item|.
explicit DragData(const DownloadItem* item);
- // 'drag-data-get' signal handler.
- CHROMEGTK_CALLBACK_4(DragData, void, OnDragDataGet, GdkDragContext*,
- GtkSelectionData*, guint, guint);
-
// Sets up a drag source and connects |drag_data| to 'drag-data-get' on
// |widget|. If |icon| is non-NULL it will be used as the drag icon. The
// object pointed to by |drag_data| will be deleted when the signal is
@@ -79,13 +35,17 @@ class DownloadItemDrag::DragData {
GtkWidget* widget,
gfx::Image* icon);
+ // 'drag-data-get' signal handler.
+ CHROMEGTK_CALLBACK_4(DragData, void, OnDragDataGet, GdkDragContext*,
+ GtkSelectionData*, guint, guint);
+
private:
// GClosureNotify handler for destroying a DragData object. |data| is assumed
// to be a DragData*.
static void OnDestroy(gpointer data, GClosure* closure);
GURL url_;
- string16 display_name_;
+ base::string16 display_name_;
};
DownloadItemDrag::DragData::DragData(const DownloadItem* item)
@@ -94,61 +54,51 @@ DownloadItemDrag::DragData::DragData(const DownloadItem* item)
DCHECK_EQ(DownloadItem::COMPLETE, item->GetState());
}
-void DownloadItemDrag::DragData::OnDragDataGet(GtkWidget* widget,
- GdkDragContext* context,
- GtkSelectionData* selection_data,
- guint target_type,
- guint time) {
- ui::WriteURLWithName(selection_data, url_, display_name_, target_type);
-}
-
// static
void DownloadItemDrag::DragData::AttachToWidget(scoped_ptr<DragData> drag_data,
GtkWidget* widget,
gfx::Image* icon) {
- gtk_drag_source_set(widget, GDK_BUTTON1_MASK, NULL, 0,
- kDownloadItemDragAction);
+ gtk_drag_source_set(
+ widget, GDK_BUTTON1_MASK, NULL, 0, kDownloadItemDragAction);
ui::SetSourceTargetListFromCodeMask(widget, kDownloadItemCodeMask);
// Disconnect previous signal handlers, if any.
g_signal_handlers_disconnect_matched(
- widget, G_SIGNAL_MATCH_FUNC, 0, 0, NULL,
+ widget,
+ G_SIGNAL_MATCH_FUNC,
+ 0,
+ 0,
+ NULL,
reinterpret_cast<gpointer>(&OnDragDataGetThunk),
NULL);
// Connect new signal handlers.
- g_signal_connect_data(
- widget, "drag-data-get",
- G_CALLBACK(&OnDragDataGetThunk),
- reinterpret_cast<gpointer>(drag_data.release()),
- &OnDestroy,
- static_cast<GConnectFlags>(0));
+ g_signal_connect_data(widget,
+ "drag-data-get",
+ G_CALLBACK(&OnDragDataGetThunk),
+ reinterpret_cast<gpointer>(drag_data.release()),
+ &OnDestroy,
+ static_cast<GConnectFlags>(0));
if (icon)
gtk_drag_source_set_icon_pixbuf(widget, icon->ToGdkPixbuf());
}
+void DownloadItemDrag::DragData::OnDragDataGet(GtkWidget* widget,
+ GdkDragContext* context,
+ GtkSelectionData* selection_data,
+ guint target_type,
+ guint time) {
+ ui::WriteURLWithName(selection_data, url_, display_name_, target_type);
+}
+
// static
void DownloadItemDrag::DragData::OnDestroy(gpointer data, GClosure* closure) {
DragData* drag_data = reinterpret_cast<DragData*>(data);
delete drag_data;
}
-DownloadItemDrag::DownloadItemDrag(const DownloadItem* item,
- gfx::Image* icon)
- : CustomDrag(icon, kDownloadItemCodeMask, kDownloadItemDragAction),
- drag_data_(new DragData(item)) {
-}
-
-DownloadItemDrag::~DownloadItemDrag() {
-}
-
-void DownloadItemDrag::OnDragDataGet(
- GtkWidget* widget, GdkDragContext* context,
- GtkSelectionData* selection_data,
- guint target_type, guint time) {
- drag_data_->OnDragDataGet(widget, context, selection_data, target_type, time);
-}
+// DownloadItemDrag ------------------------------------------------------------
// static
void DownloadItemDrag::SetSource(GtkWidget* widget,
@@ -163,27 +113,16 @@ void DownloadItemDrag::BeginDrag(const DownloadItem* item, gfx::Image* icon) {
new DownloadItemDrag(item, icon);
}
-// BookmarkDrag ----------------------------------------------------------------
-
-BookmarkDrag::BookmarkDrag(Profile* profile,
- const std::vector<const BookmarkNode*>& nodes)
- : CustomDrag(NULL, GetCodeMask(false), kBookmarkDragAction),
- profile_(profile),
- nodes_(nodes) {}
-
-BookmarkDrag::~BookmarkDrag() {
-}
+DownloadItemDrag::DownloadItemDrag(const DownloadItem* item, gfx::Image* icon)
+ : CustomDrag(icon, kDownloadItemCodeMask, kDownloadItemDragAction),
+ drag_data_(new DragData(item)) {}
-void BookmarkDrag::OnDragDataGet(GtkWidget* widget,
- GdkDragContext* context,
- GtkSelectionData* selection_data,
- guint target_type,
- guint time) {
- WriteBookmarksToSelection(nodes_, selection_data, target_type, profile_);
-}
+DownloadItemDrag::~DownloadItemDrag() {}
-// static
-void BookmarkDrag::BeginDrag(Profile* profile,
- const std::vector<const BookmarkNode*>& nodes) {
- new BookmarkDrag(profile, nodes);
+void DownloadItemDrag::OnDragDataGet(GtkWidget* widget,
+ GdkDragContext* context,
+ GtkSelectionData* selection_data,
+ guint target_type,
+ guint time) {
+ drag_data_->OnDragDataGet(widget, context, selection_data, target_type, time);
}
« no previous file with comments | « chrome/browser/ui/gtk/download/download_item_drag.h ('k') | chrome/browser/ui/gtk/download/download_item_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698