summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/gtk/download_item_gtk.cc59
-rw-r--r--chrome/browser/gtk/download_item_gtk.h8
-rw-r--r--chrome/browser/gtk/download_shelf_gtk.cc41
-rw-r--r--chrome/browser/gtk/download_shelf_gtk.h16
4 files changed, 59 insertions, 65 deletions
diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc
index d1eb597..d2c940c 100644
--- a/chrome/browser/gtk/download_item_gtk.cc
+++ b/chrome/browser/gtk/download_item_gtk.cc
@@ -144,7 +144,6 @@ DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf,
parent_shelf->browser()->profile())),
progress_angle_(download_util::kStartAngleDegrees),
download_model_(download_model),
- bounding_widget_(parent_shelf->GetRightBoundingWidget()),
dangerous_prompt_(NULL),
dangerous_label_(NULL),
icon_(NULL),
@@ -217,9 +216,7 @@ DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf,
gtk_box_pack_start(GTK_BOX(hbox_.get()), menu_button_, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(shelf_hbox), hbox_.get(), FALSE, FALSE, 0);
// Insert as the leftmost item.
- gtk_box_reorder_child(GTK_BOX(shelf_hbox), hbox_.get(), 1);
- g_signal_connect(shelf_hbox, "size-allocate",
- G_CALLBACK(OnShelfResized), this);
+ gtk_box_reorder_child(GTK_BOX(shelf_hbox), hbox_.get(), 0);
get_download()->AddObserver(this);
@@ -290,6 +287,14 @@ DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf,
NotificationService::AllSources());
theme_provider_->InitThemesFor(this);
+ // Set the initial width of the widget to be animated.
+ if (IsDangerous()) {
+ gtk_widget_set_size_request(dangerous_hbox_,
+ dangerous_hbox_start_width_, -1);
+ } else {
+ gtk_widget_set_size_request(body_.get(), kMinDownloadItemWidth, -1);
+ }
+
new_item_animation_->Show();
}
@@ -297,9 +302,9 @@ DownloadItemGtk::~DownloadItemGtk() {
icon_consumer_.CancelAllRequests();
StopDownloadProgress();
get_download()->RemoveObserver(this);
- g_signal_handlers_disconnect_by_func(parent_shelf_->GetHBox(),
- reinterpret_cast<gpointer>(OnShelfResized), this);
- gtk_widget_show_all(parent_shelf_->GetHBox());
+
+ // We may free some shelf space for showing more download items.
+ parent_shelf_->MaybeShowMoreDownloadItems();
hbox_.Destroy();
progress_area_.Destroy();
@@ -316,6 +321,9 @@ void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) {
gtk_widget_destroy(dangerous_prompt_);
gtk_widget_set_size_request(body_.get(), kBodyWidth, -1);
dangerous_prompt_ = NULL;
+
+ // We may free some shelf space for showing more download items.
+ parent_shelf_->MaybeShowMoreDownloadItems();
}
if (download->full_path() != icon_filepath_) {
@@ -557,21 +565,24 @@ void DownloadItemGtk::UpdateDangerWarning() {
// Until we switch to vector graphics, force the font size.
gtk_util::ForceFontSizePixels(dangerous_label_, kTextSize);
- gtk_label_set_line_wrap(GTK_LABEL(dangerous_label_), TRUE);
- double width_chars = 0.6 * dangerous_warning.size();
- gint dangerous_width;
- gtk_util::GetWidgetSizeFromCharacters(dangerous_label_, width_chars, 0,
- &dangerous_width, NULL);
- gtk_widget_set_size_request(dangerous_label_, dangerous_width, -1);
+ // Get the label width when displaying in one line, and reduce it to 60% to
+ // wrap the label into two lines.
+ gtk_widget_set_size_request(dangerous_label_, -1, -1);
+ gtk_label_set_line_wrap(GTK_LABEL(dangerous_label_), FALSE);
+
+ GtkRequisition req;
+ gtk_widget_size_request(dangerous_label_, &req);
+
+ gint label_width = req.width * 6 / 10;
+ gtk_label_set_line_wrap(GTK_LABEL(dangerous_label_), TRUE);
+ gtk_widget_set_size_request(dangerous_label_, label_width, -1);
// The width will depend on the text. We must do this each time we possibly
// change the label above.
- GtkRequisition req;
gtk_widget_size_request(dangerous_hbox_, &req);
dangerous_hbox_full_width_ = req.width;
- gtk_widget_size_request(dangerous_label_, &req);
- dangerous_hbox_start_width_ = dangerous_hbox_full_width_ - req.width;
+ dangerous_hbox_start_width_ = dangerous_hbox_full_width_ - label_width;
}
}
@@ -820,22 +831,6 @@ gboolean DownloadItemGtk::OnMenuButtonPressEvent(GtkWidget* button,
}
// static
-void DownloadItemGtk::OnShelfResized(GtkWidget *widget,
- GtkAllocation *allocation,
- DownloadItemGtk* item) {
- bool out_of_bounds =
- item->hbox_->allocation.x + item->hbox_->allocation.width >
- item->bounding_widget_->allocation.x;
- if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
- out_of_bounds = !out_of_bounds;
-
- if (out_of_bounds)
- gtk_widget_hide(item->hbox_.get());
- else
- gtk_widget_show(item->hbox_.get());
-}
-
-// static
gboolean DownloadItemGtk::OnDangerousPromptExpose(GtkWidget* widget,
GdkEventExpose* event, DownloadItemGtk* item) {
if (!item->theme_provider_->UseGtkTheme()) {
diff --git a/chrome/browser/gtk/download_item_gtk.h b/chrome/browser/gtk/download_item_gtk.h
index e19688f..e2abcb9 100644
--- a/chrome/browser/gtk/download_item_gtk.h
+++ b/chrome/browser/gtk/download_item_gtk.h
@@ -108,10 +108,6 @@ class DownloadItemGtk : public DownloadItem::Observer,
GdkEvent* event,
DownloadItemGtk* item);
- static void OnShelfResized(GtkWidget *widget,
- GtkAllocation *allocation,
- DownloadItemGtk* item);
-
// Dangerous download related. -----------------------------------------------
static gboolean OnDangerousPromptExpose(GtkWidget* widget,
GdkEventExpose* event,
@@ -180,10 +176,6 @@ class DownloadItemGtk : public DownloadItem::Observer,
// The download item model we represent.
scoped_ptr<BaseDownloadItemModel> download_model_;
- // 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 dangerous download dialog. This will be null for safe downloads.
GtkWidget* dangerous_prompt_;
GtkWidget* dangerous_image_;
diff --git a/chrome/browser/gtk/download_shelf_gtk.cc b/chrome/browser/gtk/download_shelf_gtk.cc
index 19ea3c8d..6d82d86 100644
--- a/chrome/browser/gtk/download_shelf_gtk.cc
+++ b/chrome/browser/gtk/download_shelf_gtk.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/gtk/custom_button.h"
#include "chrome/browser/gtk/download_item_gtk.h"
#include "chrome/browser/gtk/gtk_chrome_link_button.h"
+#include "chrome/browser/gtk/gtk_chrome_shrinkable_hbox.h"
#include "chrome/browser/gtk/gtk_theme_provider.h"
#include "chrome/browser/gtk/gtk_util.h"
#include "chrome/browser/tab_contents/tab_contents.h"
@@ -60,20 +61,28 @@ DownloadShelfGtk::DownloadShelfGtk(Browser* browser, GtkWidget* parent)
top_border_ = gtk_event_box_new();
gtk_widget_set_size_request(GTK_WIDGET(top_border_), 0, 1);
- // Create |hbox_|.
- hbox_.Own(gtk_hbox_new(FALSE, kDownloadItemPadding));
+ // Create |items_hbox_|. We use GtkChromeShrinkableHBox, so that download
+ // items can be hid automatically when there is no enough space to show them.
+ items_hbox_.Own(gtk_chrome_shrinkable_hbox_new(
+ TRUE, FALSE, kDownloadItemPadding));
// We want the download shelf to be horizontally shrinkable, so that the
// Chrome window can be resized freely even with many download items.
- gtk_widget_set_size_request(hbox_.get(), 0, kDownloadItemHeight);
+ gtk_widget_set_size_request(items_hbox_.get(), 0, kDownloadItemHeight);
- // Get the padding and background color for |hbox_| right.
+ // Create a hbox that holds |items_hbox_| and other shelf widgets.
+ GtkWidget* outer_hbox = gtk_hbox_new(FALSE, kDownloadItemPadding);
+
+ // Pack the |items_hbox_| in the outer hbox.
+ gtk_box_pack_start(GTK_BOX(outer_hbox), items_hbox_.get(), TRUE, TRUE, 0);
+
+ // Get the padding and background color for |outer_hbox| right.
GtkWidget* padding = gtk_alignment_new(0, 0, 1, 1);
// Subtract 1 from top spacing to account for top border.
gtk_alignment_set_padding(GTK_ALIGNMENT(padding),
kTopBottomPadding - 1, kTopBottomPadding, kLeftPadding, kRightPadding);
padding_bg_ = gtk_event_box_new();
gtk_container_add(GTK_CONTAINER(padding_bg_), padding);
- gtk_container_add(GTK_CONTAINER(padding), hbox_.get());
+ gtk_container_add(GTK_CONTAINER(padding), outer_hbox);
GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), top_border_, FALSE, FALSE, 0);
@@ -86,7 +95,7 @@ DownloadShelfGtk::DownloadShelfGtk(Browser* browser, GtkWidget* parent)
// Create and pack the close button.
close_button_.reset(CustomDrawButton::CloseButton(theme_provider_));
- gtk_util::CenterWidgetInHBox(hbox_.get(), close_button_->widget(), true, 0);
+ gtk_util::CenterWidgetInHBox(outer_hbox, close_button_->widget(), true, 0);
g_signal_connect(close_button_->widget(), "clicked",
G_CALLBACK(OnButtonClick), this);
@@ -107,11 +116,9 @@ DownloadShelfGtk::DownloadShelfGtk(Browser* browser, GtkWidget* parent)
GdkPixbuf* download_pixbuf = rb.GetPixbufNamed(IDR_DOWNLOADS_FAVICON);
GtkWidget* download_image = gtk_image_new_from_pixbuf(download_pixbuf);
- // Pack the link and the icon in an hbox.
- link_hbox_ = gtk_hbox_new(FALSE, 5);
- gtk_util::CenterWidgetInHBox(link_hbox_, download_image, false, 0);
- gtk_util::CenterWidgetInHBox(link_hbox_, link_button_, false, 0);
- gtk_box_pack_end(GTK_BOX(hbox_.get()), link_hbox_, FALSE, FALSE, 0);
+ // Pack the link and the icon in outer hbox.
+ gtk_util::CenterWidgetInHBox(outer_hbox, link_button_, true, 0);
+ gtk_util::CenterWidgetInHBox(outer_hbox, download_image, true, 0);
slide_widget_.reset(new SlideAnimatorGtk(shelf_.get(),
SlideAnimatorGtk::UP,
@@ -139,7 +146,7 @@ DownloadShelfGtk::~DownloadShelfGtk() {
}
shelf_.Destroy();
- hbox_.Destroy();
+ items_hbox_.Destroy();
}
void DownloadShelfGtk::AddDownload(BaseDownloadItemModel* download_model_) {
@@ -236,12 +243,14 @@ void DownloadShelfGtk::RemoveDownloadItem(DownloadItemGtk* download_item) {
}
}
-GtkWidget* DownloadShelfGtk::GetRightBoundingWidget() const {
- return link_hbox_;
+GtkWidget* DownloadShelfGtk::GetHBox() const {
+ return items_hbox_.get();
}
-GtkWidget* DownloadShelfGtk::GetHBox() const {
- return hbox_.get();
+void DownloadShelfGtk::MaybeShowMoreDownloadItems() {
+ // Show all existing download items. It'll trigger "size-allocate" signal,
+ // which will hide download items that don't have enough space to show.
+ gtk_widget_show_all(items_hbox_.get());
}
// static
diff --git a/chrome/browser/gtk/download_shelf_gtk.h b/chrome/browser/gtk/download_shelf_gtk.h
index 8530a2b..df2c4b0 100644
--- a/chrome/browser/gtk/download_shelf_gtk.h
+++ b/chrome/browser/gtk/download_shelf_gtk.h
@@ -55,12 +55,14 @@ class DownloadShelfGtk : public DownloadShelf,
// 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;
+ // Show more hidden download items if there is enough space in the shelf.
+ // It's called when a download item is removed from the shelf or an item's
+ // size is changed.
+ void MaybeShowMoreDownloadItems();
+
static void OnButtonClick(GtkWidget* button, DownloadShelfGtk* toolbar);
// The browser that owns this download shelf.
@@ -69,8 +71,8 @@ class DownloadShelfGtk : public DownloadShelf,
// The top level widget of the shelf.
scoped_ptr<SlideAnimatorGtk> slide_widget_;
- // |hbox_| holds the download items and buttons of the shelf.
- OwnedWidgetGtk hbox_;
+ // |items_hbox_| holds the download items.
+ OwnedWidgetGtk items_hbox_;
// |shelf_| is the second highest level widget. See the constructor
// for an explanation of the widget layout.
@@ -82,10 +84,6 @@ class DownloadShelfGtk : public DownloadShelf,
// A GtkEventBox which we color.
GtkWidget* padding_bg_;
- // This hbox holds the link text and download icon. It also holds the
- // distinction of being the leftmost non-download item widget on the shelf.
- GtkWidget* link_hbox_;
-
// The "Show all downloads..." link.
GtkWidget* link_button_;