summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-26 23:51:20 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-26 23:51:20 +0000
commit488bf5acd6459d69fcaead5769125e3c371098f8 (patch)
treea1fe15a9ebc16725ca17fe151dd7d468c8d1a0df /chrome
parent92b0417bd59b83f6a4908a6bb19ef833852faf08 (diff)
downloadchromium_src-488bf5acd6459d69fcaead5769125e3c371098f8.zip
chromium_src-488bf5acd6459d69fcaead5769125e3c371098f8.tar.gz
chromium_src-488bf5acd6459d69fcaead5769125e3c371098f8.tar.bz2
Gtk download shelf:
- show status text (when appropriate) - set text colors - limit the size of the download item view and elide text to fit - don't let download items spill over on the right (hide and show them as shelf grows and shrinks) Review URL: http://codereview.chromium.org/42672 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12624 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/gtk/download_item_gtk.cc78
-rw-r--r--chrome/browser/gtk/download_item_gtk.h10
-rw-r--r--chrome/browser/gtk/download_shelf_gtk.cc11
-rw-r--r--chrome/browser/gtk/download_shelf_gtk.h4
4 files changed, 84 insertions, 19 deletions
diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc
index 88c73cc..4e2fab8 100644
--- a/chrome/browser/gtk/download_item_gtk.cc
+++ b/chrome/browser/gtk/download_item_gtk.cc
@@ -11,6 +11,8 @@
#include "chrome/browser/download/download_shelf.h"
#include "chrome/browser/gtk/menu_gtk.h"
#include "chrome/browser/gtk/nine_box.h"
+#include "chrome/common/gfx/chrome_font.h"
+#include "chrome/common/gfx/text_elider.h"
#include "chrome/common/resource_bundle.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
@@ -21,6 +23,14 @@ namespace {
// bitmap that we use to draw it, i.e. 16, but can be more.
const int kMenuButtonWidth = 16;
+// Amount of space we allot to showing the filename. If the filename is too wide
+// it will be elided.
+const int kTextWidth = 140;
+
+const char* kLabelColorMarkup = "<span color='#%s'>%s</span>";
+const char* kFilenameColor = "576C95"; // 87, 108, 149
+const char* kStatusColor = "7B8DAE"; // 123, 141, 174
+
} // namespace
// DownloadShelfContextMenuGtk -------------------------------------------------
@@ -118,28 +128,42 @@ NineBox* DownloadItemGtk::menu_nine_box_prelight_ = NULL;
NineBox* DownloadItemGtk::menu_nine_box_active_ = NULL;
DownloadItemGtk::DownloadItemGtk(BaseDownloadItemModel* download_model,
- GtkWidget* parent_shelf)
+ GtkWidget* parent_shelf,
+ GtkWidget* bounding_widget)
: download_model_(download_model),
- parent_shelf_(parent_shelf) {
+ parent_shelf_(parent_shelf),
+ bounding_widget_(bounding_widget) {
InitNineBoxes();
body_ = gtk_button_new();
+ // Eventually we will show an icon and graphical download progress, but for
+ // now the only contents of body_ is text, so to make its size request the
+ // same as the width of the text (plus a little padding: see below).
+ gtk_widget_set_size_request(body_, kTextWidth + 50, -1);
gtk_widget_set_app_paintable(body_, TRUE);
g_signal_connect(G_OBJECT(body_), "expose-event",
G_CALLBACK(OnExpose), this);
GTK_WIDGET_UNSET_FLAGS(body_, GTK_CAN_FOCUS);
- // TODO(estade): gtk_label_new() expects UTF8, but FilePath may have a
- // different encoding on linux.
- GtkWidget* name_label = gtk_label_new(
- download_model->download()->GetFileName().value().c_str());
- gtk_misc_set_alignment(GTK_MISC(name_label), 0, 0);
- status_label_ =
- gtk_label_new(WideToUTF8(download_model->GetStatusText()).c_str());
- gtk_misc_set_alignment(GTK_MISC(status_label_), 0, 0);
+ GtkWidget* name_label = gtk_label_new(NULL);
+ // TODO(estade): This is at best an educated guess, since we don't actually
+ // use ChromeFont() to draw the text. This is why we need to add so
+ // much padding when we set the size request. We need to either use ChromeFont
+ // or somehow extend TextElider.
+ std::wstring elided_filename = gfx::ElideFilename(
+ download_model->download()->GetFileName().ToWStringHack(),
+ ChromeFont(), kTextWidth);
+ std::string label_markup =
+ StringPrintf(kLabelColorMarkup, kFilenameColor,
+ WideToUTF8(elided_filename).c_str());
+ gtk_label_set_markup(GTK_LABEL(name_label), label_markup.c_str());
+ status_label_ = gtk_label_new(NULL);
+ // Left align and vertically center the labels.
+ gtk_misc_set_alignment(GTK_MISC(name_label), 0, 0.5);
+ gtk_misc_set_alignment(GTK_MISC(status_label_), 0, 0.5);
// Stack the labels on top of one another.
GtkWidget* text_stack = gtk_vbox_new(FALSE, 0);
- gtk_box_pack_start(GTK_BOX(text_stack), name_label, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(text_stack), name_label, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(text_stack), status_label_, FALSE, FALSE, 0);
gtk_container_add(GTK_CONTAINER(body_), text_stack);
@@ -162,17 +186,35 @@ DownloadItemGtk::DownloadItemGtk(BaseDownloadItemModel* download_model,
gtk_box_reorder_child(GTK_BOX(parent_shelf), hbox_, 1);
gtk_widget_show_all(hbox_);
+ g_signal_connect(G_OBJECT(parent_shelf_), "size-allocate",
+ G_CALLBACK(OnShelfResized), this);
+
download_model_->download()->AddObserver(this);
}
DownloadItemGtk::~DownloadItemGtk() {
+ download_model_->download()->RemoveObserver(this);
}
void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) {
DCHECK_EQ(download, download_model_->download());
+ if (!status_label_) {
+ return;
+ }
+
+ std::wstring status_text = download_model_->GetStatusText();
+ // Remove the status text label.
+ if (status_text.empty()) {
+ gtk_widget_destroy(status_label_);
+ status_label_ = NULL;
+ return;
+ }
+
+ std::string label_markup =
+ StringPrintf(kLabelColorMarkup, kStatusColor,
+ WideToUTF8(status_text).c_str());
- gtk_label_set_text(GTK_LABEL(status_label_),
- WideToUTF8(download_model_->GetStatusText()).c_str());
+ gtk_label_set_markup(GTK_LABEL(status_label_), label_markup.c_str());
}
// static
@@ -296,3 +338,13 @@ gboolean DownloadItemGtk::OnMenuButtonPressEvent(GtkWidget* button,
return FALSE;
}
+
+void DownloadItemGtk::OnShelfResized(GtkWidget *widget,
+ GtkAllocation *allocation,
+ DownloadItemGtk* item) {
+ if (item->hbox_->allocation.x + item->hbox_->allocation.width >
+ item->bounding_widget_->allocation.x)
+ gtk_widget_hide(item->hbox_);
+ else
+ gtk_widget_show(item->hbox_);
+}
diff --git a/chrome/browser/gtk/download_item_gtk.h b/chrome/browser/gtk/download_item_gtk.h
index f0f04c6..9495a97 100644
--- a/chrome/browser/gtk/download_item_gtk.h
+++ b/chrome/browser/gtk/download_item_gtk.h
@@ -18,7 +18,7 @@ class DownloadItemGtk : DownloadItem::Observer {
public:
// DownloadItemGtk takes ownership of |download_item_model|.
DownloadItemGtk(BaseDownloadItemModel* download_item_model,
- GtkWidget* parent_shelf);
+ GtkWidget* parent_shelf, GtkWidget* bounding_widget);
// We put |hbox_| in |parent_shelf| and rely on |parent_shelf| recursively
// destroying its children. Hence we do nothing in the destructor.
@@ -37,6 +37,10 @@ class DownloadItemGtk : DownloadItem::Observer {
GdkEvent* event,
DownloadItemGtk* item);
+ static void OnShelfResized(GtkWidget *widget,
+ GtkAllocation *allocation,
+ DownloadItemGtk* item);
+
// Nineboxes for the body area.
static NineBox* body_nine_box_normal_;
static NineBox* body_nine_box_prelight_;
@@ -69,6 +73,10 @@ class DownloadItemGtk : DownloadItem::Observer {
// 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_;
};
#endif // CHROME_BROWSER_GTK_DOWNLOAD_ITEM_GTK_H_
diff --git a/chrome/browser/gtk/download_shelf_gtk.cc b/chrome/browser/gtk/download_shelf_gtk.cc
index 3d30e89..18ab1bc 100644
--- a/chrome/browser/gtk/download_shelf_gtk.cc
+++ b/chrome/browser/gtk/download_shelf_gtk.cc
@@ -159,10 +159,10 @@ DownloadShelfGtk::DownloadShelfGtk(TabContents* tab_contents)
gdk_pixbuf_unref(download_pixbuf);
// Pack the link and the icon in an hbox.
- GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0);
- gtk_box_pack_start(GTK_BOX(link_hbox), download_image, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(link_hbox), link_box, FALSE, FALSE, 0);
- gtk_box_pack_end(GTK_BOX(hbox_), link_hbox, FALSE, FALSE, 0);
+ link_hbox_ = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(link_hbox_), download_image, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(link_hbox_), link_box, FALSE, FALSE, 0);
+ gtk_box_pack_end(GTK_BOX(hbox_), link_hbox_, FALSE, FALSE, 0);
// Stick ourselves at the bottom of the parent tab contents.
GtkWidget* parent_contents = tab_contents->GetNativeView();
@@ -178,7 +178,8 @@ DownloadShelfGtk::~DownloadShelfGtk() {
void DownloadShelfGtk::AddDownload(BaseDownloadItemModel* download_model_) {
// TODO(estade): we need to delete these at some point. There's no explicit
// mass delete on windows, figure out where they do it.
- download_items_.push_back(new DownloadItemGtk(download_model_, hbox_));
+ download_items_.push_back(new DownloadItemGtk(download_model_, hbox_,
+ link_hbox_));
Show();
}
diff --git a/chrome/browser/gtk/download_shelf_gtk.h b/chrome/browser/gtk/download_shelf_gtk.h
index 98aeaa6..89f2fc9 100644
--- a/chrome/browser/gtk/download_shelf_gtk.h
+++ b/chrome/browser/gtk/download_shelf_gtk.h
@@ -42,6 +42,10 @@ class DownloadShelfGtk : public DownloadShelf {
// for an explanation of the widget layout.
GtkWidget* shelf_;
+ // 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 'x' that the user can press to hide the download shelf.
scoped_ptr<CustomDrawButton> close_button_;