summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorskrul@google.com <skrul@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-21 20:01:08 +0000
committerskrul@google.com <skrul@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-21 20:01:08 +0000
commit6806d48ab1ce1f7dc3104033467581959368c28e (patch)
tree7875e66662af55969be0b3e668525c5a6b336b84 /views
parente08d7b463a5c82d253def91b20c8ed1756e8d337 (diff)
downloadchromium_src-6806d48ab1ce1f7dc3104033467581959368c28e.zip
chromium_src-6806d48ab1ce1f7dc3104033467581959368c28e.tar.gz
chromium_src-6806d48ab1ce1f7dc3104033467581959368c28e.tar.bz2
Implement dragging icon for dragging bookmarks in views/gtk.
Review URL: http://codereview.chromium.org/270068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29692 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/button/text_button.cc8
-rw-r--r--views/drag_utils_gtk.cc25
-rw-r--r--views/widget/widget_gtk.cc21
3 files changed, 49 insertions, 5 deletions
diff --git a/views/controls/button/text_button.cc b/views/controls/button/text_button.cc
index a64648f..068b323 100644
--- a/views/controls/button/text_button.cc
+++ b/views/controls/button/text_button.cc
@@ -277,6 +277,14 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) {
text_bounds.width(),
text_bounds.height(),
l10n_util::DefaultCanvasTextAlignment());
+#else
+ canvas->DrawStringInt(text_,
+ font_,
+ color_,
+ text_bounds.x(),
+ text_bounds.y(),
+ text_bounds.width(),
+ text_bounds.height());
#endif
} else {
canvas->DrawStringInt(text_,
diff --git a/views/drag_utils_gtk.cc b/views/drag_utils_gtk.cc
index 8a40b85..1a47aa4 100644
--- a/views/drag_utils_gtk.cc
+++ b/views/drag_utils_gtk.cc
@@ -4,9 +4,13 @@
#include "views/drag_utils.h"
+#include <gtk/gtk.h>
+
#include "app/gfx/canvas.h"
+#include "app/gfx/gtk_util.h"
#include "base/logging.h"
#include "app/os_exchange_data.h"
+#include "app/os_exchange_data_provider_gtk.h"
namespace drag_utils {
@@ -16,7 +20,26 @@ void SetDragImageOnDataObject(const gfx::Canvas& canvas,
int cursor_x_offset,
int cursor_y_offset,
OSExchangeData* data_object) {
- NOTIMPLEMENTED();
+ OSExchangeDataProviderGtk& provider(
+ static_cast<OSExchangeDataProviderGtk&>(data_object->provider()));
+
+ // Convert the canvas into a GdkPixbuf.
+ SkBitmap bitmap = canvas.ExtractBitmap();
+ GdkPixbuf* canvas_pixbuf = gfx::GdkPixbufFromSkBitmap(&bitmap);
+
+ // Make a new pixbuf of the requested size and copy it over.
+ GdkPixbuf* pixbuf = gdk_pixbuf_new(
+ gdk_pixbuf_get_colorspace(canvas_pixbuf),
+ gdk_pixbuf_get_has_alpha(canvas_pixbuf),
+ gdk_pixbuf_get_bits_per_sample(canvas_pixbuf),
+ width,
+ height);
+ gdk_pixbuf_copy_area(canvas_pixbuf, 0, 0, width, height, pixbuf, 0, 0);
+ g_object_unref(canvas_pixbuf);
+
+ // Set the drag data on to the provider.
+ provider.SetDragImage(pixbuf, cursor_x_offset, cursor_y_offset);
+ g_object_unref(pixbuf);
}
} // namespace drag_utils
diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc
index cfd9a44..de5b43e 100644
--- a/views/widget/widget_gtk.cc
+++ b/views/widget/widget_gtk.cc
@@ -184,10 +184,23 @@ void WidgetGtk::DoDrag(const OSExchangeData& data, int operation) {
GtkTargetList* targets = data_provider.GetTargetList();
GdkEvent* current_event = gtk_get_current_event();
DCHECK(current_event);
- gtk_drag_begin(window_contents_, targets,
- static_cast<GdkDragAction>(
- DragDropTypes::DragOperationToGdkDragAction(operation)),
- 1, current_event);
+ const OSExchangeDataProviderGtk& provider(
+ static_cast<const OSExchangeDataProviderGtk&>(data.provider()));
+
+ GdkDragContext* context = gtk_drag_begin(
+ window_contents_,
+ targets,
+ static_cast<GdkDragAction>(
+ DragDropTypes::DragOperationToGdkDragAction(operation)),
+ 1,
+ current_event);
+
+ // Set the drag image if one was supplied.
+ if (provider.drag_image())
+ gtk_drag_set_icon_pixbuf(context,
+ provider.drag_image(),
+ provider.cursor_offset_x(),
+ provider.cursor_offset_y());
gdk_event_free(current_event);
gtk_target_list_unref(targets);