OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 "ui/views/drag_utils.h" | |
6 | |
7 #include <gtk/gtk.h> | |
8 | |
9 #include "base/logging.h" | |
10 #include "third_party/skia/include/core/SkBitmap.h" | |
11 #include "ui/base/dragdrop/os_exchange_data.h" | |
12 #include "ui/base/dragdrop/os_exchange_data_provider_gtk.h" | |
13 #include "ui/gfx/canvas.h" | |
14 #include "ui/gfx/gtk_util.h" | |
15 #include "ui/gfx/point.h" | |
16 #include "ui/gfx/size.h" | |
17 | |
18 namespace drag_utils { | |
19 | |
20 void SetDragImageOnDataObject(const SkBitmap& bitmap, | |
21 const gfx::Size& size, | |
22 const gfx::Point& cursor_offset, | |
23 ui::OSExchangeData* data_object) { | |
24 ui::OSExchangeDataProviderGtk& provider( | |
25 static_cast<ui::OSExchangeDataProviderGtk&>(data_object->provider())); | |
26 | |
27 // Convert the bitmap into a GdkPixbuf. | |
28 GdkPixbuf* canvas_pixbuf = gfx::GdkPixbufFromSkBitmap(&bitmap); | |
29 | |
30 // Make a new pixbuf of the requested size and copy it over. | |
31 GdkPixbuf* pixbuf = gdk_pixbuf_new( | |
32 gdk_pixbuf_get_colorspace(canvas_pixbuf), | |
33 gdk_pixbuf_get_has_alpha(canvas_pixbuf), | |
34 gdk_pixbuf_get_bits_per_sample(canvas_pixbuf), | |
35 size.width(), | |
36 size.height()); | |
37 gdk_pixbuf_copy_area(canvas_pixbuf, 0, 0, size.width(), size.height(), pixbuf, | |
38 0, 0); | |
39 g_object_unref(canvas_pixbuf); | |
40 | |
41 // Set the drag data on to the provider. | |
42 provider.SetDragImage(pixbuf, cursor_offset); | |
43 g_object_unref(pixbuf); | |
44 } | |
45 | |
46 } // namespace drag_utils | |
OLD | NEW |