1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/gtk/custom_drag.h"
7 #include "ui/base/dragdrop/gtk_dnd_util.h"
8 #include "ui/gfx/image/image.h"
10 CustomDrag::CustomDrag(gfx::Image
* icon
, int code_mask
, GdkDragAction action
)
11 : drag_widget_(gtk_invisible_new()),
13 g_signal_connect(drag_widget_
, "drag-data-get",
14 G_CALLBACK(OnDragDataGetThunk
), this);
15 g_signal_connect(drag_widget_
, "drag-begin",
16 G_CALLBACK(OnDragBeginThunk
), this);
17 g_signal_connect(drag_widget_
, "drag-end",
18 G_CALLBACK(OnDragEndThunk
), this);
20 GtkTargetList
* list
= ui::GetTargetListFromCodeMask(code_mask
);
21 GdkEvent
* event
= gtk_get_current_event();
22 gtk_drag_begin(drag_widget_
, list
, action
, 1, event
);
24 gdk_event_free(event
);
25 gtk_target_list_unref(list
);
28 CustomDrag::~CustomDrag() {
29 gtk_widget_destroy(drag_widget_
);
32 void CustomDrag::OnDragBegin(GtkWidget
* widget
, GdkDragContext
* drag_context
) {
34 gtk_drag_set_icon_pixbuf(drag_context
, image_
->ToGdkPixbuf(), 0, 0);
37 void CustomDrag::OnDragEnd(GtkWidget
* widget
, GdkDragContext
* drag_context
) {