summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-04 23:24:47 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-04 23:24:47 +0000
commit5043b9832a86dcbe10b0eec99efafd8e304a9502 (patch)
treefd9ffc524e804a94f6ce7e6465f3adf92a7825e9 /chrome/browser
parente078d3267684d1c8649cc717401d5c0e4df7526f (diff)
downloadchromium_src-5043b9832a86dcbe10b0eec99efafd8e304a9502.zip
chromium_src-5043b9832a86dcbe10b0eec99efafd8e304a9502.tar.gz
chromium_src-5043b9832a86dcbe10b0eec99efafd8e304a9502.tar.bz2
Add download items to the download shelf in linux.
Review URL: http://codereview.chromium.org/40136 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10935 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/browser.scons1
-rw-r--r--chrome/browser/gtk/download_item_gtk.cc120
-rw-r--r--chrome/browser/gtk/download_item_gtk.h45
-rw-r--r--chrome/browser/gtk/download_shelf_gtk.cc8
-rw-r--r--chrome/browser/gtk/download_shelf_gtk.h7
-rw-r--r--chrome/browser/gtk/nine_box.cc6
6 files changed, 182 insertions, 5 deletions
diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons
index 951ebce..b18808c 100644
--- a/chrome/browser/browser.scons
+++ b/chrome/browser/browser.scons
@@ -740,6 +740,7 @@ if env.Bit('linux'):
'gtk/browser_window_factory_gtk.cc',
'gtk/browser_window_gtk.cc',
'gtk/custom_button.cc',
+ 'gtk/download_item_gtk.cc',
'gtk/download_shelf_gtk.cc',
'gtk/menu_gtk.cc',
'gtk/nine_box.cc',
diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc
new file mode 100644
index 0000000..e14f592
--- /dev/null
+++ b/chrome/browser/gtk/download_item_gtk.cc
@@ -0,0 +1,120 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/gtk/download_item_gtk.h"
+
+#include "base/basictypes.h"
+#include "chrome/browser/download/download_item_model.h"
+#include "chrome/browser/download/download_manager.h"
+#include "chrome/browser/gtk/nine_box.h"
+#include "chrome/common/resource_bundle.h"
+
+#include "grit/theme_resources.h"
+
+NineBox* DownloadItemGtk::nine_box_normal_ = NULL;
+NineBox* DownloadItemGtk::nine_box_prelight_ = NULL;
+NineBox* DownloadItemGtk::nine_box_active_ = NULL;
+
+DownloadItemGtk::DownloadItemGtk(BaseDownloadItemModel* download_model,
+ GtkWidget* parent_shelf)
+ : download_model_(download_model),
+ parent_shelf_(parent_shelf) {
+ InitNineBoxes();
+
+ body_ = gtk_button_new();
+ gtk_widget_set_app_paintable(body_, TRUE);
+ g_signal_connect(G_OBJECT(body_), "expose-event",
+ G_CALLBACK(OnBodyExpose), this);
+
+ GtkWidget* label = gtk_label_new(download_model->download()->file_name()
+ .value().c_str());
+ gtk_container_add(GTK_CONTAINER(body_), label);
+
+ hbox_ = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(hbox_), body_, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(parent_shelf), hbox_, FALSE, FALSE, 0);
+ gtk_widget_show_all(hbox_);
+}
+
+// static
+void DownloadItemGtk::InitNineBoxes() {
+ if (nine_box_normal_)
+ return;
+
+ GdkPixbuf* images[9];
+ ResourceBundle &rb = ResourceBundle::GetSharedInstance();
+
+ int i = 0;
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_LEFT_TOP);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_CENTER_TOP);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_RIGHT_TOP);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM);
+ nine_box_normal_ = new NineBox(images);
+
+ i = 0;
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_LEFT_TOP_H);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_CENTER_TOP_H);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_RIGHT_TOP_H);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE_H);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE_H);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_H);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM_H);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM_H);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_H);
+ nine_box_prelight_ = new NineBox(images);
+
+ i = 0;
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_LEFT_TOP_P);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_CENTER_TOP_P);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_RIGHT_TOP_P);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE_P);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE_P);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_P);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM_P);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM_P);
+ images[i++] = rb.LoadPixbuf(IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_P);
+ nine_box_active_ = new NineBox(images);
+}
+
+// static
+gboolean DownloadItemGtk::OnBodyExpose(GtkWidget* widget, GdkEventExpose* e,
+ DownloadItemGtk* download_item) {
+ NineBox* nine_box = NULL;
+ if (GTK_WIDGET_STATE(widget) == GTK_STATE_PRELIGHT)
+ nine_box = nine_box_prelight_;
+ else if (GTK_WIDGET_STATE(widget) == GTK_STATE_ACTIVE)
+ nine_box = nine_box_active_;
+ else
+ nine_box = nine_box_normal_;
+
+ GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
+ true, // alpha
+ 8, // bits per channel
+ widget->allocation.width,
+ widget->allocation.height);
+
+ nine_box->RenderToPixbuf(pixbuf);
+
+ gdk_draw_pixbuf(widget->window,
+ widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
+ pixbuf,
+ 0, 0,
+ widget->allocation.x, widget->allocation.y, -1, -1,
+ GDK_RGB_DITHER_NONE, 0, 0);
+
+ gdk_pixbuf_unref(pixbuf);
+
+ gtk_container_propagate_expose(GTK_CONTAINER(widget),
+ gtk_bin_get_child(GTK_BIN(widget)),
+ e);
+
+ return TRUE;
+}
+
+
diff --git a/chrome/browser/gtk/download_item_gtk.h b/chrome/browser/gtk/download_item_gtk.h
new file mode 100644
index 0000000..f9b15e8
--- /dev/null
+++ b/chrome/browser/gtk/download_item_gtk.h
@@ -0,0 +1,45 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_GTK_DOWNLOAD_ITEM_GTK_H_
+#define CHROME_BROWSER_GTK_DOWNLOAD_ITEM_GTK_H_
+
+#include <gtk/gtk.h>
+
+#include "base/scoped_ptr.h"
+
+class BaseDownloadItemModel;
+class NineBox;
+
+class DownloadItemGtk {
+ public:
+ // DownloadItemGtk takes ownership of |download_item_model|;
+ DownloadItemGtk(BaseDownloadItemModel* download_item_model,
+ GtkWidget* parent_shelf);
+
+ private:
+ static void InitNineBoxes();
+
+ static gboolean OnBodyExpose(GtkWidget* widget, GdkEventExpose* e,
+ DownloadItemGtk* download_item);
+
+ static NineBox* nine_box_normal_;
+ static NineBox* nine_box_prelight_;
+ static NineBox* nine_box_active_;
+
+ // The widget that contains the body and menu dropdown.
+ GtkWidget* hbox_;
+
+ // The widget that contains the name of the download and the progress
+ // animation.
+ GtkWidget* body_;
+
+ // 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_;
+};
+
+#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 86a51b2..d583529 100644
--- a/chrome/browser/gtk/download_shelf_gtk.cc
+++ b/chrome/browser/gtk/download_shelf_gtk.cc
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "chrome/browser/download/download_item_model.h"
+#include "chrome/browser/gtk/download_item_gtk.h"
#include "chrome/common/l10n_util.h"
#include "chrome/common/resource_bundle.h"
#include "grit/generated_resources.h"
@@ -17,7 +18,7 @@
namespace {
// Total height of the shelf.
-const int kShelfHeight = 30;
+const int kShelfHeight = 42;
// Padding between the download widgets.
const int kDownloadItemPadding = 10;
@@ -41,6 +42,7 @@ DownloadShelfGtk::DownloadShelfGtk(TabContents* tab_contents)
is_showing_(false) {
shelf_ = gtk_hbox_new(FALSE, 0);
gtk_widget_set_size_request(shelf_, -1, kShelfHeight);
+ gtk_container_set_border_width(GTK_CONTAINER(shelf_), kTopBottomPadding);
// Create and pack the close button.
close_button_.reset(new CustomDrawButton(IDR_CLOSE_BAR,
@@ -59,7 +61,9 @@ DownloadShelfGtk::DownloadShelfGtk(TabContents* tab_contents)
}
void DownloadShelfGtk::AddDownload(BaseDownloadItemModel* download_model_) {
- NOTIMPLEMENTED();
+ // 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_, shelf_));
Show();
}
diff --git a/chrome/browser/gtk/download_shelf_gtk.h b/chrome/browser/gtk/download_shelf_gtk.h
index 9cbf5bc..28b64ad 100644
--- a/chrome/browser/gtk/download_shelf_gtk.h
+++ b/chrome/browser/gtk/download_shelf_gtk.h
@@ -7,11 +7,14 @@
#include <gtk/gtk.h>
+#include <vector>
+
#include "base/scoped_ptr.h"
#include "chrome/browser/download/download_shelf.h"
#include "chrome/browser/gtk/custom_button.h"
class BaseDownloadItemModel;
+class DownloadItemGtk;
class DownloadShelfGtk : public DownloadShelf {
public:
@@ -39,7 +42,9 @@ class DownloadShelfGtk : public DownloadShelf {
// Keeps track of our current hide/show state.
bool is_showing_;
+
+ // The download items we have added to our shelf.
+ std::vector<DownloadItemGtk*> download_items_;
};
#endif // CHROME_BROWSER_VIEWS_DOWNLOAD_SHELF_VIEW_H_
-
diff --git a/chrome/browser/gtk/nine_box.cc b/chrome/browser/gtk/nine_box.cc
index 0e1305b..eefa8c8 100644
--- a/chrome/browser/gtk/nine_box.cc
+++ b/chrome/browser/gtk/nine_box.cc
@@ -49,8 +49,10 @@ void NineBox::RenderToPixbuf(GdkPixbuf* dst) {
// rendering of the ninebox.
const int x1 = gdk_pixbuf_get_width(images[0]);
const int y1 = gdk_pixbuf_get_height(images[0]);
- const int x2 = gdk_pixbuf_get_width(dst) - gdk_pixbuf_get_width(images[2]);
- const int y2 = gdk_pixbuf_get_height(dst) - gdk_pixbuf_get_height(images[2]);
+ const int x2 = gdk_pixbuf_get_width(dst) - gdk_pixbuf_get_width(images[8]);
+ const int y2 = gdk_pixbuf_get_height(dst) - gdk_pixbuf_get_height(images[8]);
+ DCHECK(x2 >= x1);
+ DCHECK(y2 >= y1);
DrawPixbuf(images[0], dst, 0, 0);
RenderTopCenterStrip(dst, x1, x2);