summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--app/gfx/canvas.cc2
-rw-r--r--app/gfx/canvas.h2
-rw-r--r--app/os_exchange_data_provider_gtk.cc23
-rw-r--r--app/os_exchange_data_provider_gtk.h14
-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
7 files changed, 86 insertions, 9 deletions
diff --git a/app/gfx/canvas.cc b/app/gfx/canvas.cc
index 2cef3de..306531c4 100644
--- a/app/gfx/canvas.cc
+++ b/app/gfx/canvas.cc
@@ -248,7 +248,7 @@ void Canvas::TileImageInt(const SkBitmap& bitmap, int src_x, int src_y,
restore();
}
-SkBitmap Canvas::ExtractBitmap() {
+SkBitmap Canvas::ExtractBitmap() const {
const SkBitmap& device_bitmap = getDevice()->accessBitmap(false);
// Make a bitmap to return, and a canvas to draw into it. We don't just want
diff --git a/app/gfx/canvas.h b/app/gfx/canvas.h
index 553ec94..90cfad8 100644
--- a/app/gfx/canvas.h
+++ b/app/gfx/canvas.h
@@ -180,7 +180,7 @@ class Canvas : public skia::PlatformCanvas {
int dest_x, int dest_y, int w, int h);
// Extracts a bitmap from the contents of this canvas.
- SkBitmap ExtractBitmap();
+ SkBitmap ExtractBitmap() const;
#if defined(OS_LINUX)
// Applies current matrix on the canvas to the cairo context. This should be
diff --git a/app/os_exchange_data_provider_gtk.cc b/app/os_exchange_data_provider_gtk.cc
index 597a5ae..dbae20e 100644
--- a/app/os_exchange_data_provider_gtk.cc
+++ b/app/os_exchange_data_provider_gtk.cc
@@ -16,15 +16,23 @@ OSExchangeDataProviderGtk::OSExchangeDataProviderGtk(
const std::set<GdkAtom>& known_custom_formats)
: known_formats_(known_formats),
known_custom_formats_(known_custom_formats),
- formats_(0) {
+ formats_(0),
+ drag_image_(NULL),
+ cursor_offset_x_(0),
+ cursor_offset_y_(0) {
}
OSExchangeDataProviderGtk::OSExchangeDataProviderGtk()
: known_formats_(0),
- formats_(0) {
+ formats_(0),
+ drag_image_(NULL),
+ cursor_offset_x_(0),
+ cursor_offset_y_(0) {
}
OSExchangeDataProviderGtk::~OSExchangeDataProviderGtk() {
+ if (drag_image_)
+ g_object_unref(drag_image_);
}
bool OSExchangeDataProviderGtk::HasDataForAllFormats(
@@ -218,6 +226,17 @@ bool OSExchangeDataProviderGtk::GetPlainTextURL(GURL* url) const {
return true;
}
+void OSExchangeDataProviderGtk::SetDragImage(GdkPixbuf* drag_image,
+ int cursor_offset_x,
+ int cursor_offset_y) {
+ if (drag_image_)
+ g_object_unref(drag_image_);
+ g_object_ref(drag_image);
+ drag_image_ = drag_image;
+ cursor_offset_x_ = cursor_offset_x;
+ cursor_offset_y_ = cursor_offset_y;
+}
+
///////////////////////////////////////////////////////////////////////////////
// OSExchangeData, public:
diff --git a/app/os_exchange_data_provider_gtk.h b/app/os_exchange_data_provider_gtk.h
index ffbb182..9a56a2d 100644
--- a/app/os_exchange_data_provider_gtk.h
+++ b/app/os_exchange_data_provider_gtk.h
@@ -69,6 +69,15 @@ class OSExchangeDataProviderGtk : public OSExchangeData::Provider {
virtual bool HasFile() const;
virtual bool HasCustomFormat(OSExchangeData::CustomFormat format) const;
+ // Set the image and cursor offset data for this drag. Will
+ // increment the ref count of pixbuf.
+ void SetDragImage(GdkPixbuf* pixbuf,
+ int cursor_offset_x,
+ int cursor_offset_y);
+ GdkPixbuf* drag_image() const { return drag_image_; }
+ int cursor_offset_x() const { return cursor_offset_x_; }
+ int cursor_offset_y() const { return cursor_offset_y_; }
+
private:
typedef std::map<OSExchangeData::CustomFormat, Pickle> PickleData;
@@ -99,6 +108,11 @@ class OSExchangeDataProviderGtk : public OSExchangeData::Provider {
// PICKLED_DATA contents.
PickleData pickle_data_;
+ // Drag image and offset data.
+ GdkPixbuf* drag_image_;
+ int cursor_offset_x_;
+ int cursor_offset_y_;
+
DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderGtk);
};
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);