summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-08 01:34:55 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-08 01:34:55 +0000
commit71d96212c24b5104f6722d09ed2c6a64b0293114 (patch)
tree3833401da5ce3a34ecebc03381338c8d2ebd7099 /chrome/browser
parent3d7845d63164ac46d396f586bf041d7a4a70e435 (diff)
downloadchromium_src-71d96212c24b5104f6722d09ed2c6a64b0293114.zip
chromium_src-71d96212c24b5104f6722d09ed2c6a64b0293114.tar.gz
chromium_src-71d96212c24b5104f6722d09ed2c6a64b0293114.tar.bz2
More info bar implementation.
Review URL: http://codereview.chromium.org/62136 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13329 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/gtk/infobar_gtk.cc110
-rw-r--r--chrome/browser/gtk/infobar_gtk.h7
2 files changed, 101 insertions, 16 deletions
diff --git a/chrome/browser/gtk/infobar_gtk.cc b/chrome/browser/gtk/infobar_gtk.cc
index a8419c6..b1e0506 100644
--- a/chrome/browser/gtk/infobar_gtk.cc
+++ b/chrome/browser/gtk/infobar_gtk.cc
@@ -6,21 +6,56 @@
#include <gtk/gtk.h>
+#include "base/gfx/gtk_util.h"
+#include "base/string_util.h"
#include "chrome/browser/gtk/custom_button.h"
#include "chrome/browser/gtk/infobar_container_gtk.h"
+namespace {
+
+// TODO(estade): The background should be a gradient. For now we just use this
+// solid color.
+const GdkColor kBackgroundColor = GDK_COLOR_RGB(250, 230, 145);
+
+// Border color (the top pixel of the infobar).
+const GdkColor kBorderColor = GDK_COLOR_RGB(0xbe, 0xc8, 0xd4);
+
+// The total height of the info bar.
+const int kInfoBarHeight = 37;
+
+// Pixels between infobar elements.
+const int kElementPadding = 5;
+
+// Extra padding on either end of info bar.
+const int kLeftPadding = 5;
+const int kRightPadding = 5;
+
+}
+
InfoBar::InfoBar(InfoBarDelegate* delegate)
- : widget_(gtk_hbox_new(FALSE, 0)),
- container_(NULL),
+ : container_(NULL),
delegate_(delegate) {
- g_object_set_data(G_OBJECT(widget_.get()), "info-bar", this);
- close_button_.reset(CustomDrawButton::AddBarCloseButton(widget_.get()));
+ // Create |hbox_| and pad the sides.
+ hbox_ = gtk_hbox_new(FALSE, kElementPadding);
+ GtkWidget* padding = gtk_alignment_new(0, 0, 1, 1);
+ gtk_alignment_set_padding(GTK_ALIGNMENT(padding),
+ 0, 0, kLeftPadding, kRightPadding);
+
+ GtkWidget* bg_box = gtk_event_box_new();
+ gtk_container_add(GTK_CONTAINER(padding), hbox_);
+ gtk_container_add(GTK_CONTAINER(bg_box), padding);
+
+ // Set the top border and background color.
+ gtk_widget_modify_bg(bg_box, GTK_STATE_NORMAL, &kBackgroundColor);
+ widget_.Own(gfx::CreateGtkBorderBin(bg_box, &kBorderColor,
+ 1, 0, 0, 0));
+ gtk_widget_set_size_request(widget_.get(), -1, kInfoBarHeight);
+
+ close_button_.reset(CustomDrawButton::AddBarCloseButton(hbox_));
+ g_signal_connect(G_OBJECT(close_button_->widget()), "clicked",
+ G_CALLBACK(OnCloseButton), this);
- // TODO(estade): remove these lines.
- GtkWidget* label = gtk_label_new("Infobars not yet implemented. "
- "Check back later.");
- gtk_box_pack_start(GTK_BOX(widget_.get()), label, FALSE, FALSE, 10);
- gtk_widget_set_size_request(widget_.get(), -1, 40);
+ g_object_set_data(G_OBJECT(widget_.get()), "info-bar", this);
}
InfoBar::~InfoBar() {
@@ -51,23 +86,68 @@ void InfoBar::RemoveInfoBar() const {
container_->RemoveDelegate(delegate_);
}
+// static
+void InfoBar::OnCloseButton(GtkWidget* button, InfoBar* info_bar) {
+ info_bar->AnimateClose();
+}
+
+// AlertInfoBar ----------------------------------------------------------------
+
+class AlertInfoBar : public InfoBar {
+ public:
+ AlertInfoBar(AlertInfoBarDelegate* delegate)
+ : InfoBar(delegate) {
+ std::wstring text = delegate->GetMessageText();
+ GtkWidget* label = gtk_label_new(WideToUTF8(text).c_str());
+
+ SkBitmap* icon = delegate->GetIcon();
+ GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(icon);
+ GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf);
+ gdk_pixbuf_unref(pixbuf);
+
+ gtk_box_pack_start(GTK_BOX(hbox_), image, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(hbox_), label, FALSE, FALSE, 0);
+ }
+};
+
+// LinkInfoBar -----------------------------------------------------------------
+
+class LinkInfoBar : public InfoBar {
+ public:
+ LinkInfoBar(LinkInfoBarDelegate* delegate)
+ : InfoBar(delegate) {
+ // TODO(estade): remove these lines.
+ NOTIMPLEMENTED();
+ GtkWidget* label = gtk_label_new("LinkInfoBar not yet implemented. "
+ "Check back later.");
+ gtk_box_pack_start(GTK_BOX(hbox_), label, FALSE, FALSE, 10);
+ }
+};
+
+// ConfirmInfoBar --------------------------------------------------------------
+
+class ConfirmInfoBar : public AlertInfoBar {
+ public:
+ ConfirmInfoBar(ConfirmInfoBarDelegate* delegate)
+ : AlertInfoBar(delegate) {
+ NOTIMPLEMENTED();
+ }
+};
+
// AlertInfoBarDelegate, InfoBarDelegate overrides: ----------------------------
InfoBar* AlertInfoBarDelegate::CreateInfoBar() {
- NOTIMPLEMENTED();
- return new InfoBar(this);
+ return new AlertInfoBar(this);
}
// LinkInfoBarDelegate, InfoBarDelegate overrides: -----------------------------
InfoBar* LinkInfoBarDelegate::CreateInfoBar() {
- NOTIMPLEMENTED();
- return new InfoBar(this);
+ return new LinkInfoBar(this);
}
// ConfirmInfoBarDelegate, InfoBarDelegate overrides: --------------------------
InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() {
- NOTIMPLEMENTED();
- return new InfoBar(this);
+ return new ConfirmInfoBar(this);
}
diff --git a/chrome/browser/gtk/infobar_gtk.h b/chrome/browser/gtk/infobar_gtk.h
index 0dff963..684fa63 100644
--- a/chrome/browser/gtk/infobar_gtk.h
+++ b/chrome/browser/gtk/infobar_gtk.h
@@ -47,10 +47,12 @@ class InfoBar {
// (Will lead to this InfoBar being closed).
void RemoveInfoBar() const;
- private:
// The top level GTK widget.
OwnedWidgetGtk widget_;
+ // The hbox that holds infobar elements (button, text, icon, etc.).
+ GtkWidget* hbox_;
+
// The x that closes the bar.
scoped_ptr<CustomDrawButton> close_button_;
@@ -60,6 +62,9 @@ class InfoBar {
// The InfoBar's delegate.
InfoBarDelegate* delegate_;
+ private:
+ static void OnCloseButton(GtkWidget* button, InfoBar* info_bar);
+
DISALLOW_COPY_AND_ASSIGN(InfoBar);
};