diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-20 20:30:44 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-20 20:30:44 +0000 |
commit | 55f773b1a8a98dd59d73071f7294e928712d64a7 (patch) | |
tree | f772527ec996d8865bc0030137f232e66be1e778 /chrome/browser/gtk | |
parent | c74d7c570eccadf7be968a4767ea67c14ca08009 (diff) | |
download | chromium_src-55f773b1a8a98dd59d73071f7294e928712d64a7.zip chromium_src-55f773b1a8a98dd59d73071f7294e928712d64a7.tar.gz chromium_src-55f773b1a8a98dd59d73071f7294e928712d64a7.tar.bz2 |
Linux: add background image theming to bookmark bar.
I got rid of the border padding in an attempt to more closely match windows, where the bookmark bar is very compact.
BUG=http://crbug.com/12216
Review URL: http://codereview.chromium.org/115551
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16524 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.cc | 61 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.h | 19 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 2 |
3 files changed, 57 insertions, 25 deletions
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc index b86d7e2..301a8d5 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_gtk.cc @@ -18,6 +18,7 @@ #include "chrome/browser/gtk/custom_button.h" #include "chrome/browser/gtk/dnd_registry.h" #include "chrome/browser/gtk/gtk_chrome_button.h" +#include "chrome/browser/gtk/nine_box.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/profile.h" #include "chrome/common/gtk_util.h" @@ -28,11 +29,6 @@ namespace { -const GdkColor kBackgroundColor = GDK_COLOR_RGB(0xe6, 0xed, 0xf4); - -// Padding around the container. -const int kBarPadding = 2; - // Maximum number of characters on a bookmark button. const size_t kMaxCharsOnAButton = 15; @@ -74,7 +70,7 @@ BookmarkBarGtk::~BookmarkBarGtk() { RemoveAllBookmarkButtons(); bookmark_toolbar_.Destroy(); - container_.Destroy(); + bookmark_hbox_.Destroy(); } void BookmarkBarGtk::SetProfile(Profile* profile) { @@ -111,20 +107,21 @@ void BookmarkBarGtk::Init(Profile* profile) { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); static GdkPixbuf* folder_icon = rb.GetPixbufNamed(IDR_BOOKMARK_BAR_FOLDER); - bookmark_hbox_ = gtk_hbox_new(FALSE, 0); - container_.Own(gtk_util::CreateGtkBorderBin(bookmark_hbox_, &kBackgroundColor, - kBarPadding, kBarPadding, kBarPadding, kBarPadding)); + bookmark_hbox_.Own(gtk_hbox_new(FALSE, 0)); - instructions_ = - gtk_label_new( - l10n_util::GetStringUTF8(IDS_BOOKMARKS_NO_ITEMS).c_str()); - gtk_box_pack_start(GTK_BOX(bookmark_hbox_), instructions_, + instructions_ = gtk_label_new( + l10n_util::GetStringUTF8(IDS_BOOKMARKS_NO_ITEMS).c_str()); + gtk_box_pack_start(GTK_BOX(bookmark_hbox_.get()), instructions_, FALSE, FALSE, 0); + gtk_widget_set_app_paintable(bookmark_hbox_.get(), TRUE); + g_signal_connect(G_OBJECT(bookmark_hbox_.get()), "expose-event", + G_CALLBACK(&OnHBoxExpose), this); bookmark_toolbar_.Own(gtk_toolbar_new()); + gtk_widget_set_app_paintable(bookmark_toolbar_.get(), TRUE); g_signal_connect(G_OBJECT(bookmark_toolbar_.get()), "expose-event", G_CALLBACK(&OnToolbarExpose), this); - gtk_box_pack_start(GTK_BOX(bookmark_hbox_), bookmark_toolbar_.get(), + gtk_box_pack_start(GTK_BOX(bookmark_hbox_.get()), bookmark_toolbar_.get(), TRUE, TRUE, 0); gtk_drag_dest_set(bookmark_toolbar_.get(), GTK_DEST_DEFAULT_DROP, @@ -141,7 +138,7 @@ void BookmarkBarGtk::Init(Profile* profile) { g_signal_connect(bookmark_toolbar_.get(), "button-press-event", G_CALLBACK(&OnButtonPressed), this); - gtk_box_pack_start(GTK_BOX(bookmark_hbox_), gtk_vseparator_new(), + gtk_box_pack_start(GTK_BOX(bookmark_hbox_.get()), gtk_vseparator_new(), FALSE, FALSE, 0); other_bookmarks_button_ = gtk_chrome_button_new(); @@ -152,16 +149,16 @@ void BookmarkBarGtk::Init(Profile* profile) { gtk_button_set_image(GTK_BUTTON(other_bookmarks_button_), gtk_image_new_from_pixbuf(folder_icon)); - gtk_box_pack_start(GTK_BOX(bookmark_hbox_), other_bookmarks_button_, + gtk_box_pack_start(GTK_BOX(bookmark_hbox_.get()), other_bookmarks_button_, FALSE, FALSE, 0); } void BookmarkBarGtk::AddBookmarkbarToBox(GtkWidget* box) { - gtk_box_pack_start(GTK_BOX(box), container_.get(), FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(box), bookmark_hbox_.get(), FALSE, FALSE, 0); } void BookmarkBarGtk::Show() { - gtk_widget_show_all(container_.get()); + gtk_widget_show_all(bookmark_hbox_.get()); // Maybe show the instructions if (show_instructions_) { @@ -172,7 +169,7 @@ void BookmarkBarGtk::Show() { } void BookmarkBarGtk::Hide() { - gtk_widget_hide_all(container_.get()); + gtk_widget_hide_all(bookmark_hbox_.get()); } bool BookmarkBarGtk::OnNewTabPage() { @@ -436,6 +433,15 @@ BookmarkNode* BookmarkBarGtk::GetNodeForToolButton(GtkWidget* widget) { return NULL; } +void BookmarkBarGtk::InitBackground() { + if (background_ninebox_.get()) + return; + + background_ninebox_.reset(new NineBox( + browser_->profile()->GetThemeProvider(), + 0, IDR_THEME_TOOLBAR, 0, 0, 0, 0, 0, 0, 0)); +} + void BookmarkBarGtk::PopupMenuForNode(GtkWidget* sender, BookmarkNode* node, GdkEventButton* event) { if (!model_->IsLoaded()) { @@ -739,3 +745,20 @@ void BookmarkBarGtk::OnToolbarDragReceived(GtkWidget* widget, gtk_drag_finish(context, dnd_success, delete_selection_data, time); } + +// static +gboolean BookmarkBarGtk::OnHBoxExpose(GtkWidget* widget, + GdkEventExpose* event, + BookmarkBarGtk* bar) { + // Paint the background theme image. + cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); + cairo_rectangle(cr, event->area.x, event->area.y, + event->area.width, event->area.height); + cairo_clip(cr); + bar->InitBackground(); + bar->background_ninebox_->RenderTopCenterStrip(cr, event->area.x, + 0, event->area.width); + cairo_destroy(cr); + + return FALSE; // Propagate expose to children. +} diff --git a/chrome/browser/gtk/bookmark_bar_gtk.h b/chrome/browser/gtk/bookmark_bar_gtk.h index 72f42c6..3395df1 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.h +++ b/chrome/browser/gtk/bookmark_bar_gtk.h @@ -17,6 +17,7 @@ class BookmarkContextMenu; class BookmarkMenuController; class Browser; class CustomContainerButton; +class NineBox; class PageNavigator; class Profile; @@ -118,6 +119,9 @@ class BookmarkBarGtk : public BookmarkModelObserver { // Finds the BookmarkNode from the model associated with |button|. BookmarkNode* GetNodeForToolButton(GtkWidget* button); + // Loads the background image into memory, or does nothing if already loaded. + void InitBackground(); + // Creates and displays a popup menu for BookmarkNode |node|. void PopupMenuForNode(GtkWidget* sender, BookmarkNode* node, GdkEventButton* event); @@ -129,8 +133,6 @@ class BookmarkBarGtk : public BookmarkModelObserver { static gboolean OnButtonReleased(GtkWidget* sender, GdkEventButton* event, BookmarkBarGtk* bar); - static gboolean OnButtonExpose(GtkWidget* widget, GdkEventExpose* e, - BookmarkBarGtk* button); static void OnButtonDragBegin(GtkWidget* widget, GdkDragContext* drag_context, BookmarkBarGtk* bar); @@ -170,6 +172,11 @@ class BookmarkBarGtk : public BookmarkModelObserver { guint target_type, guint time, BookmarkBarGtk* bar); + // GtkHBox callbacks. + static gboolean OnHBoxExpose(GtkWidget* widget, GdkEventExpose* event, + BookmarkBarGtk* window); + + Profile* profile_; // Used for opening urls. @@ -181,12 +188,9 @@ class BookmarkBarGtk : public BookmarkModelObserver { // shown. This is owned by the Profile. BookmarkModel* model_; - // Top level container that contains |bookmark_hbox_| and spacers. - OwnedWidgetGtk container_; - // Container that has all the individual members of // |current_bookmark_buttons_| as children. - GtkWidget* bookmark_hbox_; + OwnedWidgetGtk bookmark_hbox_; // A GtkLabel to display when there are no bookmark buttons to display. GtkWidget* instructions_; @@ -218,6 +222,9 @@ class BookmarkBarGtk : public BookmarkModelObserver { // The last displayed left click menu, or NULL if no menus have been // displayed yet. scoped_ptr<BookmarkMenuController> current_menu_; + + // Paints the background for our bookmark bar. + scoped_ptr<NineBox> background_ninebox_; }; #endif // CHROME_BROWSER_GTK_BOOKMARK_BAR_GTK_H_ diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index 36b2478..1d16a2f 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -320,6 +320,8 @@ gboolean BrowserToolbarGtk::OnToolbarExpose(GtkWidget* widget, GdkEventExpose* e, BrowserToolbarGtk* toolbar) { cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); + cairo_rectangle(cr, e->area.x, e->area.y, e->area.width, e->area.height); + cairo_clip(cr); // It would be more intuitive to pass |e->area.y| rather than 0, but the // toolbar is supposed to blend in with the active tab, so we have to pass // coordinates for the IDR_THEME_TOOLBAR bitmap relative to the top of the |