summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-23 22:27:32 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-23 22:27:32 +0000
commite83a7f61f212487d7da91206583feff16f8637a0 (patch)
treee0f63c838bb7aa5349168b7028e4b45002731952
parentc53add011c152049587f9d3f78158b87b93692ad (diff)
downloadchromium_src-e83a7f61f212487d7da91206583feff16f8637a0.zip
chromium_src-e83a7f61f212487d7da91206583feff16f8637a0.tar.gz
chromium_src-e83a7f61f212487d7da91206583feff16f8637a0.tar.bz2
GTK: Support transparent web image drags.
This depends on a webkit side change before it has any effect. This only works on compositing WMs; non-compositing WMs will just not get a transparent image (it actually will appear slightly darkened). BUG=11457 TEST=manul Review URL: http://codereview.chromium.org/1756008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45503 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/gtk/tab_contents_drag_source.cc39
-rw-r--r--chrome/browser/gtk/tab_contents_drag_source.h4
2 files changed, 35 insertions, 8 deletions
diff --git a/chrome/browser/gtk/tab_contents_drag_source.cc b/chrome/browser/gtk/tab_contents_drag_source.cc
index 8e285d1..c3d94c0 100644
--- a/chrome/browser/gtk/tab_contents_drag_source.cc
+++ b/chrome/browser/gtk/tab_contents_drag_source.cc
@@ -30,6 +30,7 @@ using WebKit::WebDragOperationNone;
TabContentsDragSource::TabContentsDragSource(
TabContentsView* tab_contents_view)
: tab_contents_view_(tab_contents_view),
+ drag_pixbuf_(NULL),
drag_failed_(false),
drag_widget_(NULL),
drag_icon_(NULL) {
@@ -104,7 +105,9 @@ void TabContentsDragSource::StartDragging(const WebDropData& drop_data,
}
drop_data_.reset(new WebDropData(drop_data));
- drag_image_ = image;
+
+ if (!image.isNull())
+ drag_pixbuf_ = gfx::GdkPixbufFromSkBitmap(&image);
image_offset_ = image_offset;
GtkTargetList* list = gtk_dnd_util::GetTargetListFromCodeMask(targets_mask);
@@ -315,14 +318,19 @@ void TabContentsDragSource::OnDragBegin(GtkWidget* sender,
generated_download_file_name.value().length());
}
- if (!drag_image_.isNull()) {
- GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&drag_image_);
- GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf);
- gtk_widget_show(image);
- g_object_unref(pixbuf);
+ if (drag_pixbuf_) {
drag_icon_ = gtk_window_new(GTK_WINDOW_POPUP);
g_object_ref_sink(drag_icon_);
- gtk_container_add(GTK_CONTAINER(drag_icon_), image);
+ g_signal_connect(drag_icon_, "expose-event",
+ G_CALLBACK(OnDragIconExposeThunk), this);
+ gtk_widget_set_size_request(drag_icon_,
+ gdk_pixbuf_get_width(drag_pixbuf_),
+ gdk_pixbuf_get_height(drag_pixbuf_));
+
+ GdkScreen* screen = gtk_widget_get_screen(GTK_WIDGET(drag_icon_));
+ GdkColormap* rgba = gdk_screen_get_rgba_colormap(screen);
+ if (rgba)
+ gtk_widget_set_colormap(GTK_WIDGET(drag_icon_), rgba);
gtk_drag_set_icon_widget(drag_context, drag_icon_,
image_offset_.x(), image_offset_.y());
@@ -335,6 +343,10 @@ void TabContentsDragSource::OnDragEnd(GtkWidget* sender,
g_object_unref(drag_icon_);
drag_icon_ = NULL;
}
+ if (drag_pixbuf_) {
+ g_object_unref(drag_pixbuf_);
+ drag_pixbuf_ = NULL;
+ }
MessageLoopForUI::current()->RemoveObserver(this);
@@ -364,3 +376,16 @@ void TabContentsDragSource::OnDragEnd(GtkWidget* sender,
gfx::NativeView TabContentsDragSource::GetContentNativeView() const {
return tab_contents_view_->GetContentNativeView();
}
+
+gboolean TabContentsDragSource::OnDragIconExpose(GtkWidget* sender,
+ GdkEventExpose* event) {
+ cairo_t* cr = gdk_cairo_create(event->window);
+ gdk_cairo_rectangle(cr, &event->area);
+ cairo_clip(cr);
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+ gdk_cairo_set_source_pixbuf(cr, drag_pixbuf_, 0, 0);
+ cairo_paint(cr);
+ cairo_destroy(cr);
+
+ return TRUE;
+}
diff --git a/chrome/browser/gtk/tab_contents_drag_source.h b/chrome/browser/gtk/tab_contents_drag_source.h
index fbfaeee..f43629f 100644
--- a/chrome/browser/gtk/tab_contents_drag_source.h
+++ b/chrome/browser/gtk/tab_contents_drag_source.h
@@ -52,6 +52,8 @@ class TabContentsDragSource : public MessageLoopForUI::Observer {
GdkDragContext*);
CHROMEGTK_CALLBACK_4(TabContentsDragSource, void, OnDragDataGet,
GdkDragContext*, GtkSelectionData*, guint, guint);
+ CHROMEGTK_CALLBACK_1(TabContentsDragSource, gboolean, OnDragIconExpose,
+ GdkEventExpose*);
gfx::NativeView GetContentNativeView() const;
@@ -64,7 +66,7 @@ class TabContentsDragSource : public MessageLoopForUI::Observer {
// The image used for depicting the drag, and the offset between the cursor
// and the top left pixel.
- SkBitmap drag_image_;
+ GdkPixbuf* drag_pixbuf_;
gfx::Point image_offset_;
// The mime type for the file contents of the current drag (if any).