summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-05 20:50:44 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-05 20:50:44 +0000
commitb2cc43523f7bb309cecd6071de51a1677e5d15cf (patch)
treef35c93b5d7cdd95877f86f30cca96738856b7236
parentbef76ead355bfb64d93336a548b8b16602a853c1 (diff)
downloadchromium_src-b2cc43523f7bb309cecd6071de51a1677e5d15cf.zip
chromium_src-b2cc43523f7bb309cecd6071de51a1677e5d15cf.tar.gz
chromium_src-b2cc43523f7bb309cecd6071de51a1677e5d15cf.tar.bz2
Linux download shelf: remove download items when the associated download is removed.
BUG=11381 TEST=in opt mode: download something, go to downloads tab, clear all, go back to tab with downloaded item. The shelf should be gone. Review URL: http://codereview.chromium.org/100366 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15335 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/gtk/download_item_gtk.cc41
-rw-r--r--chrome/browser/gtk/download_item_gtk.h15
-rw-r--r--chrome/browser/gtk/download_shelf_gtk.cc24
-rw-r--r--chrome/browser/gtk/download_shelf_gtk.h11
4 files changed, 74 insertions, 17 deletions
diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc
index b3f4238..5697e50c 100644
--- a/chrome/browser/gtk/download_item_gtk.cc
+++ b/chrome/browser/gtk/download_item_gtk.cc
@@ -10,6 +10,7 @@
#include "chrome/browser/download/download_item_model.h"
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/download/download_shelf.h"
+#include "chrome/browser/gtk/download_shelf_gtk.h"
#include "chrome/browser/gtk/menu_gtk.h"
#include "chrome/browser/gtk/nine_box.h"
#include "chrome/common/gfx/chrome_font.h"
@@ -135,12 +136,11 @@ NineBox* DownloadItemGtk::menu_nine_box_normal_ = NULL;
NineBox* DownloadItemGtk::menu_nine_box_prelight_ = NULL;
NineBox* DownloadItemGtk::menu_nine_box_active_ = NULL;
-DownloadItemGtk::DownloadItemGtk(BaseDownloadItemModel* download_model,
- GtkWidget* parent_shelf,
- GtkWidget* bounding_widget)
- : download_model_(download_model),
- parent_shelf_(parent_shelf),
- bounding_widget_(bounding_widget) {
+DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf,
+ BaseDownloadItemModel* download_model)
+ : parent_shelf_(parent_shelf),
+ download_model_(download_model),
+ bounding_widget_(parent_shelf->GetRightBoundingWidget()) {
InitNineBoxes();
body_ = gtk_button_new();
@@ -185,15 +185,16 @@ DownloadItemGtk::DownloadItemGtk(BaseDownloadItemModel* download_model,
reinterpret_cast<void*>(true));
gtk_widget_set_size_request(menu_button_, kMenuButtonWidth, 0);
+ GtkWidget* shelf_hbox = parent_shelf->GetHBox();
hbox_ = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox_), body_, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox_), menu_button_, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(parent_shelf), hbox_, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(shelf_hbox), hbox_, FALSE, FALSE, 0);
// Insert as the leftmost item.
- gtk_box_reorder_child(GTK_BOX(parent_shelf), hbox_, 1);
+ gtk_box_reorder_child(GTK_BOX(shelf_hbox), hbox_, 1);
- g_signal_connect(G_OBJECT(parent_shelf_), "size-allocate",
- G_CALLBACK(OnShelfResized), this);
+ resize_handler_id_ = g_signal_connect(G_OBJECT(shelf_hbox), "size-allocate",
+ G_CALLBACK(OnShelfResized), this);
download_model_->download()->AddObserver(this);
@@ -204,11 +205,31 @@ DownloadItemGtk::DownloadItemGtk(BaseDownloadItemModel* download_model,
}
DownloadItemGtk::~DownloadItemGtk() {
+ g_signal_handler_disconnect(parent_shelf_->GetHBox(), resize_handler_id_);
+ gtk_widget_destroy(hbox_);
download_model_->download()->RemoveObserver(this);
}
void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) {
DCHECK_EQ(download, download_model_->download());
+
+ switch (download->state()) {
+ case DownloadItem::REMOVING:
+ parent_shelf_->RemoveDownloadItem(this); // This will delete us!
+ return;
+ case DownloadItem::CANCELLED:
+ case DownloadItem::COMPLETE:
+ case DownloadItem::IN_PROGRESS:
+ // TODO(estade): adjust download progress animation appropriately, once
+ // we have download progress animations.
+ NOTIMPLEMENTED();
+ break;
+ default:
+ NOTREACHED();
+ }
+
+ // Now update the status label. We may have already removed it; if so, we
+ // do nothing.
if (!status_label_) {
return;
}
diff --git a/chrome/browser/gtk/download_item_gtk.h b/chrome/browser/gtk/download_item_gtk.h
index e3cabb2..b7cde2d 100644
--- a/chrome/browser/gtk/download_item_gtk.h
+++ b/chrome/browser/gtk/download_item_gtk.h
@@ -13,6 +13,7 @@
class BaseDownloadItemModel;
class DownloadShelfContextMenuGtk;
+class DownloadShelfGtk;
class NineBox;
class SlideAnimation;
@@ -20,8 +21,8 @@ class DownloadItemGtk : public DownloadItem::Observer,
public AnimationDelegate {
public:
// DownloadItemGtk takes ownership of |download_item_model|.
- DownloadItemGtk(BaseDownloadItemModel* download_item_model,
- GtkWidget* parent_shelf, GtkWidget* bounding_widget);
+ DownloadItemGtk(DownloadShelfGtk* parent_shelf,
+ BaseDownloadItemModel* download_item_model);
// We put |hbox_| in |parent_shelf| and rely on |parent_shelf| recursively
// destroying its children. Hence we do nothing in the destructor.
@@ -58,6 +59,9 @@ class DownloadItemGtk : public DownloadItem::Observer,
static NineBox* menu_nine_box_prelight_;
static NineBox* menu_nine_box_active_;
+ // The shelf on which we are displayed.
+ DownloadShelfGtk* parent_shelf_;
+
// The widget that contains the body and menu dropdown.
GtkWidget* hbox_;
@@ -81,13 +85,14 @@ class DownloadItemGtk : public DownloadItem::Observer,
// The download item model we represent.
scoped_ptr<BaseDownloadItemModel> download_model_;
- // The shelf we show ourselves on. We do not own this widget.
- GtkWidget* parent_shelf_;
-
// This is the leftmost widget on |parent_shelf_| that is not a download item.
// We do not want to overlap it.
GtkWidget* bounding_widget_;
+ // The ID of the handler for the parent shelf's "size-allocate" event. We save
+ // it so we can disconnect when we are destroyed.
+ gulong resize_handler_id_;
+
// The animation when this item is first added to the shelf.
scoped_ptr<SlideAnimation> new_item_animation_;
};
diff --git a/chrome/browser/gtk/download_shelf_gtk.cc b/chrome/browser/gtk/download_shelf_gtk.cc
index b476508..31d99dd 100644
--- a/chrome/browser/gtk/download_shelf_gtk.cc
+++ b/chrome/browser/gtk/download_shelf_gtk.cc
@@ -130,8 +130,7 @@ DownloadShelfGtk::~DownloadShelfGtk() {
}
void DownloadShelfGtk::AddDownload(BaseDownloadItemModel* download_model_) {
- download_items_.push_back(new DownloadItemGtk(download_model_, hbox_,
- link_hbox_));
+ download_items_.push_back(new DownloadItemGtk(this, download_model_));
slide_widget_->Open();
}
@@ -139,6 +138,27 @@ bool DownloadShelfGtk::IsShowing() const {
return slide_widget_->IsShowing();
}
+void DownloadShelfGtk::RemoveDownloadItem(DownloadItemGtk* download_item) {
+ DCHECK(download_item);
+ std::vector<DownloadItemGtk*>::iterator i =
+ find(download_items_.begin(), download_items_.end(), download_item);
+ DCHECK(i != download_items_.end());
+ download_items_.erase(i);
+ delete download_item;
+ if (download_items_.empty()) {
+ slide_widget_->CloseWithoutAnimation();
+ tab_contents_->SetDownloadShelfVisible(false);
+ }
+}
+
+GtkWidget* DownloadShelfGtk::GetRightBoundingWidget() const {
+ return link_hbox_;
+}
+
+GtkWidget* DownloadShelfGtk::GetHBox() const {
+ return hbox_;
+}
+
// static
void DownloadShelfGtk::OnButtonClick(GtkWidget* button,
DownloadShelfGtk* shelf) {
diff --git a/chrome/browser/gtk/download_shelf_gtk.h b/chrome/browser/gtk/download_shelf_gtk.h
index 76ff640..e2819a0 100644
--- a/chrome/browser/gtk/download_shelf_gtk.h
+++ b/chrome/browser/gtk/download_shelf_gtk.h
@@ -30,6 +30,15 @@ class DownloadShelfGtk : public DownloadShelf {
virtual bool IsShowing() const;
private:
+ // Remove |download_item| from the download shelf and delete it.
+ void RemoveDownloadItem(DownloadItemGtk* download_item);
+
+ // Get the leftmost non-download item widget on the shelf.
+ GtkWidget* GetRightBoundingWidget() const;
+
+ // Get the hbox download items ought to pack themselves into.
+ GtkWidget* GetHBox() const;
+
static void OnButtonClick(GtkWidget* button, DownloadShelfGtk* toolbar);
// The top level widget of the shelf.
@@ -57,6 +66,8 @@ class DownloadShelfGtk : public DownloadShelf {
// The download items we have added to our shelf.
std::vector<DownloadItemGtk*> download_items_;
+
+ friend class DownloadItemGtk;
};
#endif // CHROME_BROWSER_GTK_DOWNLOAD_SHELF_GTK_H_