Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / gtk / custom_drag.cc
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.
4
5 #include "chrome/browser/ui/gtk/custom_drag.h"
6
7 #include "ui/base/dragdrop/gtk_dnd_util.h"
8 #include "ui/gfx/image/image.h"
9
10 CustomDrag::CustomDrag(gfx::Image* icon, int code_mask, GdkDragAction action)
11     : drag_widget_(gtk_invisible_new()),
12       image_(icon) {
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);
19
20   GtkTargetList* list = ui::GetTargetListFromCodeMask(code_mask);
21   GdkEvent* event = gtk_get_current_event();
22   gtk_drag_begin(drag_widget_, list, action, 1, event);
23   if (event)
24     gdk_event_free(event);
25   gtk_target_list_unref(list);
26 }
27
28 CustomDrag::~CustomDrag() {
29   gtk_widget_destroy(drag_widget_);
30 }
31
32 void CustomDrag::OnDragBegin(GtkWidget* widget, GdkDragContext* drag_context) {
33   if (image_)
34     gtk_drag_set_icon_pixbuf(drag_context, image_->ToGdkPixbuf(), 0, 0);
35 }
36
37 void CustomDrag::OnDragEnd(GtkWidget* widget, GdkDragContext* drag_context) {
38   delete this;
39 }