diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-22 22:46:42 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-22 22:46:42 +0000 |
commit | d0aa2034a240084c5a5d4ae53de838ce5e09d211 (patch) | |
tree | 538b5060dab38f5dc0a82906e230b41504983f44 /chrome/browser | |
parent | fbf90315b8420502dbad77b9741f7547b3f2187e (diff) | |
download | chromium_src-d0aa2034a240084c5a5d4ae53de838ce5e09d211.zip chromium_src-d0aa2034a240084c5a5d4ae53de838ce5e09d211.tar.gz chromium_src-d0aa2034a240084c5a5d4ae53de838ce5e09d211.tar.bz2 |
GTK: make download shelf drags use the download icon.
This matches drags originating in the tabbed download manager.
BUG=42147
TEST=manual
Review URL: http://codereview.chromium.org/1690002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45368 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/gtk/custom_drag.cc | 17 | ||||
-rw-r--r-- | chrome/browser/gtk/custom_drag.h | 3 | ||||
-rw-r--r-- | chrome/browser/gtk/download_item_gtk.cc | 32 | ||||
-rw-r--r-- | chrome/browser/gtk/download_item_gtk.h | 11 |
4 files changed, 47 insertions, 16 deletions
diff --git a/chrome/browser/gtk/custom_drag.cc b/chrome/browser/gtk/custom_drag.cc index 5ae7206..282e316 100644 --- a/chrome/browser/gtk/custom_drag.cc +++ b/chrome/browser/gtk/custom_drag.cc @@ -93,12 +93,27 @@ void DownloadItemDrag::OnDragDataGet( } // static -void DownloadItemDrag::SetSource(GtkWidget* widget, DownloadItem* item) { +void DownloadItemDrag::SetSource(GtkWidget* widget, + DownloadItem* item, + SkBitmap* icon) { gtk_drag_source_set(widget, GDK_BUTTON1_MASK, NULL, 0, kDownloadItemDragAction); gtk_dnd_util::SetSourceTargetListFromCodeMask(widget, kDownloadItemCodeMask); + + // Disconnect previous signal handlers, if any. + g_signal_handlers_disconnect_by_func( + widget, + reinterpret_cast<gpointer>(OnDragDataGetStandalone), + item); + // Connect new signal handlers. g_signal_connect(widget, "drag-data-get", G_CALLBACK(OnDragDataGetStandalone), item); + + GdkPixbuf* pixbuf = icon ? gfx::GdkPixbufFromSkBitmap(icon) : NULL; + if (pixbuf) { + gtk_drag_source_set_icon_pixbuf(widget, pixbuf); + g_object_unref(pixbuf); + } } // static diff --git a/chrome/browser/gtk/custom_drag.h b/chrome/browser/gtk/custom_drag.h index a43b0da..1b7753e 100644 --- a/chrome/browser/gtk/custom_drag.h +++ b/chrome/browser/gtk/custom_drag.h @@ -50,7 +50,8 @@ class DownloadItemDrag : public CustomDrag { public: // Sets |widget| as a source for drags pertaining to |item|. No // DownloadItemDrag object is created. - static void SetSource(GtkWidget* widget, DownloadItem* item); + // It is safe to call this multiple times with different values of |icon|. + static void SetSource(GtkWidget* widget, DownloadItem* item, SkBitmap* icon); // Creates a new DownloadItemDrag, the lifetime of which is tied to the // system drag. diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc index 254561d..fd17beb 100644 --- a/chrome/browser/gtk/download_item_gtk.cc +++ b/chrome/browser/gtk/download_item_gtk.cc @@ -150,7 +150,8 @@ DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf, download_model_(download_model), dangerous_prompt_(NULL), dangerous_label_(NULL), - icon_(NULL), + icon_small_(NULL), + icon_large_(NULL), creation_time_(base::Time::Now()) { LoadIcon(); @@ -356,7 +357,7 @@ void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) { StopDownloadProgress(); // Set up the widget as a drag source. - DownloadItemDrag::SetSource(body_.get(), get_download()); + DownloadItemDrag::SetSource(body_.get(), get_download(), icon_large_); complete_animation_.reset(new SlideAnimation(this)); complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs); @@ -472,19 +473,28 @@ void DownloadItemGtk::StopDownloadProgress() { // Icon loading functions. -void DownloadItemGtk::OnLoadIconComplete(IconManager::Handle handle, - SkBitmap* icon_bitmap) { - icon_ = icon_bitmap; +void DownloadItemGtk::OnLoadSmallIconComplete(IconManager::Handle handle, + SkBitmap* icon_bitmap) { + icon_small_ = icon_bitmap; gtk_widget_queue_draw(progress_area_.get()); } +void DownloadItemGtk::OnLoadLargeIconComplete(IconManager::Handle handle, + SkBitmap* icon_bitmap) { + icon_large_ = icon_bitmap; + DownloadItemDrag::SetSource(body_.get(), get_download(), icon_large_); +} + void DownloadItemGtk::LoadIcon() { icon_consumer_.CancelAllRequests(); IconManager* im = g_browser_process->icon_manager(); icon_filepath_ = get_download()->full_path(); im->LoadIcon(icon_filepath_, IconLoader::SMALL, &icon_consumer_, - NewCallback(this, &DownloadItemGtk::OnLoadIconComplete)); + NewCallback(this, &DownloadItemGtk::OnLoadSmallIconComplete)); + im->LoadIcon(icon_filepath_, + IconLoader::LARGE, &icon_consumer_, + NewCallback(this, &DownloadItemGtk::OnLoadLargeIconComplete)); } void DownloadItemGtk::UpdateTooltip() { @@ -806,12 +816,12 @@ gboolean DownloadItemGtk::OnProgressAreaExpose(GtkWidget* widget, download_util::SMALL); } - // |icon_| may be NULL if it is still loading. If the file is an unrecognized - // type then we will get back a generic system icon. Hence there is no need to - // use the chromium-specific default download item icon. - if (download_item->icon_) { + // |icon_small_| may be NULL if it is still loading. If the file is an + // unrecognized type then we will get back a generic system icon. Hence + // there is no need to use the chromium-specific default download item icon. + if (download_item->icon_small_) { const int offset = download_util::kSmallProgressIconOffset; - canvas.DrawBitmapInt(*download_item->icon_, + canvas.DrawBitmapInt(*download_item->icon_small_, widget->allocation.x + offset, widget->allocation.y + offset); } diff --git a/chrome/browser/gtk/download_item_gtk.h b/chrome/browser/gtk/download_item_gtk.h index fbe2ec5..9cf6dc2 100644 --- a/chrome/browser/gtk/download_item_gtk.h +++ b/chrome/browser/gtk/download_item_gtk.h @@ -52,7 +52,10 @@ class DownloadItemGtk : public DownloadItem::Observer, // Called when the icon manager has finished loading the icon. We take // ownership of |icon_bitmap|. - void OnLoadIconComplete(IconManager::Handle handle, SkBitmap* icon_bitmap); + void OnLoadSmallIconComplete(IconManager::Handle handle, + SkBitmap* icon_bitmap); + void OnLoadLargeIconComplete(IconManager::Handle handle, + SkBitmap* icon_bitmap); // Returns the DownloadItem model object belonging to this item. DownloadItem* get_download(); @@ -198,8 +201,10 @@ class DownloadItemGtk : public DownloadItem::Observer, // Animation for download complete. scoped_ptr<SlideAnimation> complete_animation_; - // The file icon for the download. May be null. - SkBitmap* icon_; + // The file icon for the download. May be null. The small version is used + // for display in the shelf; the large version is for use as a drag icon. + SkBitmap* icon_small_; + SkBitmap* icon_large_; // The last download file path for which we requested an icon. FilePath icon_filepath_; |