diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-09 20:28:19 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-09 20:28:19 +0000 |
commit | edd32342189ef6329e894ff08456a2c565606355 (patch) | |
tree | e0762a103238b4a06714ffed53e6ca24f1c5b408 /chrome | |
parent | 8f24f0d6752f811905c182a85181f456c7656817 (diff) | |
download | chromium_src-edd32342189ef6329e894ff08456a2c565606355.zip chromium_src-edd32342189ef6329e894ff08456a2c565606355.tar.gz chromium_src-edd32342189ef6329e894ff08456a2c565606355.tar.bz2 |
Make CustomContainerButton a gtk widget.
Review URL: http://codereview.chromium.org/62171
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13452 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.cc | 66 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.h | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 44 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.h | 8 | ||||
-rw-r--r-- | chrome/browser/gtk/custom_button.cc | 61 | ||||
-rw-r--r-- | chrome/browser/gtk/custom_button.h | 23 | ||||
-rw-r--r-- | chrome/browser/gtk/gtk_chrome_button.cc | 88 | ||||
-rw-r--r-- | chrome/browser/gtk/gtk_chrome_button.h | 41 | ||||
-rw-r--r-- | chrome/chrome.gyp | 6 |
9 files changed, 167 insertions, 174 deletions
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc index 9496956..4e4402e 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_gtk.cc @@ -7,6 +7,7 @@ #include "base/gfx/gtk_util.h" #include "chrome/browser/browser.h" #include "chrome/browser/gtk/custom_button.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" @@ -44,7 +45,6 @@ BookmarkBarGtk::BookmarkBarGtk(Profile* profile, Browser* browser) instructions_(NULL), show_instructions_(true) { Init(profile); - LoadNineboxImages(); SetProfile(profile); } @@ -114,11 +114,11 @@ void BookmarkBarGtk::Init(Profile* profile) { gtk_box_pack_start(GTK_BOX(bookmark_hbox_), gtk_vseparator_new(), FALSE, FALSE, 0); - other_bookmarks_button_ = new CustomContainerButton(); - gtk_button_set_label(GTK_BUTTON(other_bookmarks_button_->widget()), + other_bookmarks_button_ = gtk_chrome_button_new(); + gtk_button_set_label(GTK_BUTTON(other_bookmarks_button_), "Other bookmarks"); // TODO(erg): Hook up a popup menu to |other_bookmarks_button_|. - gtk_box_pack_start(GTK_BOX(bookmark_hbox_), other_bookmarks_button_->widget(), + gtk_box_pack_start(GTK_BOX(bookmark_hbox_), other_bookmarks_button_, FALSE, FALSE, 0); } @@ -178,7 +178,7 @@ bool BookmarkBarGtk::IsAlwaysShown() { GtkWidget* BookmarkBarGtk::CreateBookmarkButton( BookmarkNode* node) { - GtkWidget* button = gtk_button_new(); + GtkWidget* button = gtk_chrome_button_new(); if (node->is_url()) { gtk_widget_set_tooltip_text(button, BuildTooltip(node).c_str()); @@ -189,10 +189,6 @@ GtkWidget* BookmarkBarGtk::CreateBookmarkButton( GTK_LABEL(gtk_bin_get_child(GTK_BIN(button))), kMaxCharsOnAButton); - gtk_widget_set_app_paintable(button, TRUE); - g_signal_connect(G_OBJECT(button), "expose-event", - G_CALLBACK(&OnButtonExpose), this); - // The tool item is also a source for dragging gtk_drag_source_set(button, GDK_BUTTON1_MASK, target_table, G_N_ELEMENTS(target_table), @@ -235,35 +231,6 @@ std::string BookmarkBarGtk::BuildTooltip(BookmarkNode* node) { return node->GetURL().possibly_invalid_spec(); } -void BookmarkBarGtk::LoadNineboxImages() { - GdkPixbuf* images[9]; - int i = 0; - - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_TOP_LEFT_H); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_TOP_H); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_TOP_RIGHT_H); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_LEFT_H); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_CENTER_H); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_RIGHT_H); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_LEFT_H); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_H); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_RIGHT_H); - nine_box_prelight_.reset(new NineBox(images)); - - i = 0; - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_TOP_LEFT_P); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_TOP_P); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_TOP_RIGHT_P); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_LEFT_P); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_CENTER_P); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_RIGHT_P); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_LEFT_P); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_P); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_RIGHT_P); - nine_box_active_.reset(new NineBox(images)); -} - gboolean BookmarkBarGtk::OnButtonPressed(GtkWidget* sender, GdkEventButton* event, BookmarkBarGtk* bar) { @@ -302,29 +269,6 @@ gboolean BookmarkBarGtk::OnButtonReleased(GtkWidget* sender, } // static -gboolean BookmarkBarGtk::OnButtonExpose(GtkWidget* widget, GdkEventExpose* e, - BookmarkBarGtk* button) { - NineBox* nine_box = NULL; - if (GTK_WIDGET_STATE(widget) == GTK_STATE_PRELIGHT) - nine_box = button->nine_box_prelight_.get(); - else if (GTK_WIDGET_STATE(widget) == GTK_STATE_ACTIVE) - nine_box = button->nine_box_active_.get(); - - // Only draw theme graphics if we have some. - if (nine_box) - nine_box->RenderToWidget(widget); - - // If we return FALSE from the function, the button paints itself. - // If we return TRUE, no children are painted. - // So we return TRUE and send the expose along directly to the child. - gtk_container_propagate_expose(GTK_CONTAINER(widget), - gtk_bin_get_child(GTK_BIN(widget)), - e); - - return TRUE; // Prevent normal painting. -} - -// static void BookmarkBarGtk::OnButtonDragBegin(GtkWidget* button, GdkDragContext* drag_context, BookmarkBarGtk* bar) { diff --git a/chrome/browser/gtk/bookmark_bar_gtk.h b/chrome/browser/gtk/bookmark_bar_gtk.h index 53f6beb..1c151f5 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.h +++ b/chrome/browser/gtk/bookmark_bar_gtk.h @@ -115,8 +115,6 @@ class BookmarkBarGtk : public BookmarkModelObserver { std::string BuildTooltip(BookmarkNode* node); - void LoadNineboxImages(); - // GtkButton callbacks static gboolean OnButtonPressed(GtkWidget* sender, GdkEventButton* event, @@ -171,7 +169,7 @@ class BookmarkBarGtk : public BookmarkModelObserver { OwnedWidgetGtk bookmark_toolbar_; // The other bookmarks button. - CustomContainerButton* other_bookmarks_button_; + GtkWidget* other_bookmarks_button_; // Whether we should ignore the next button release event (because we were // dragging). diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index 8455157..60eb7c1 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -14,6 +14,7 @@ #include "chrome/browser/gtk/back_forward_menu_model_gtk.h" #include "chrome/browser/gtk/custom_button.h" #include "chrome/browser/gtk/go_button_gtk.h" +#include "chrome/browser/gtk/gtk_chrome_button.h" #include "chrome/browser/gtk/location_bar_view_gtk.h" #include "chrome/browser/gtk/nine_box.h" #include "chrome/browser/gtk/standard_menus.h" @@ -62,6 +63,8 @@ BrowserToolbarGtk::~BrowserToolbarGtk() { // group. Make sure to tear them down before |accel_group_|. page_menu_.reset(); app_menu_.reset(); + page_menu_button_.Destroy(); + app_menu_button_.Destroy(); back_forward_menu_.reset(); g_object_unref(accel_group_); } @@ -127,13 +130,15 @@ void BrowserToolbarGtk::Init(Profile* profile, gtk_box_pack_start(GTK_BOX(toolbar_), gtk_label_new(" "), FALSE, FALSE, 0); - page_menu_button_.reset(BuildToolbarMenuButton(IDR_MENU_PAGE, - l10n_util::GetString(IDS_PAGEMENU_TOOLTIP))); + BuildToolbarMenuButton(IDR_MENU_PAGE, + l10n_util::GetString(IDS_PAGEMENU_TOOLTIP), + &page_menu_button_); page_menu_.reset(new MenuGtk(this, GetStandardPageMenu(), accel_group_)); - app_menu_button_.reset(BuildToolbarMenuButton(IDR_MENU_CHROME, + BuildToolbarMenuButton(IDR_MENU_CHROME, l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, - l10n_util::GetString(IDS_PRODUCT_NAME)))); + l10n_util::GetString(IDS_PRODUCT_NAME)), + &app_menu_button_); app_menu_.reset(new MenuGtk(this, GetStandardAppMenu(), accel_group_)); gtk_widget_show_all(toolbar_); @@ -246,25 +251,24 @@ ToolbarStarToggleGtk* BrowserToolbarGtk::BuildStarButton( return button; } -CustomContainerButton* BrowserToolbarGtk::BuildToolbarMenuButton( +void BrowserToolbarGtk::BuildToolbarMenuButton( int icon_id, - const std::wstring& localized_tooltip) { - CustomContainerButton* button = new CustomContainerButton; + const std::wstring& localized_tooltip, + OwnedWidgetGtk* owner) { + GtkWidget* button = gtk_chrome_button_new(); + owner->Own(button); ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - gtk_container_set_border_width(GTK_CONTAINER(button->widget()), 2); - gtk_container_add(GTK_CONTAINER(button->widget()), + gtk_container_set_border_width(GTK_CONTAINER(button), 2); + gtk_container_add(GTK_CONTAINER(button), gtk_image_new_from_pixbuf(rb.LoadPixbuf(icon_id))); - gtk_widget_set_tooltip_text(button->widget(), - WideToUTF8(localized_tooltip).c_str()); - g_signal_connect(G_OBJECT(button->widget()), "button-press-event", + gtk_widget_set_tooltip_text(button, WideToUTF8(localized_tooltip).c_str()); + g_signal_connect(G_OBJECT(button), "button-press-event", G_CALLBACK(OnMenuButtonPressEvent), this); - GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); - - gtk_box_pack_start(GTK_BOX(toolbar_), button->widget(), FALSE, FALSE, 0); + GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS); - return button; + gtk_box_pack_start(GTK_BOX(toolbar_), button, FALSE, FALSE, 0); } // static @@ -311,10 +315,10 @@ gboolean BrowserToolbarGtk::OnMenuButtonPressEvent(GtkWidget* button, GdkEventButton* event_button = reinterpret_cast<GdkEventButton*>(event); if (event_button->button == 1) { // We have a button press we should respond to. - if (button == toolbar->page_menu_button_->widget()) { + if (button == toolbar->page_menu_button_.get()) { toolbar->RunPageMenu(event); return TRUE; - } else if (button == toolbar->app_menu_button_->widget()) { + } else if (button == toolbar->app_menu_button_.get()) { toolbar->RunAppMenu(event); return TRUE; } @@ -384,11 +388,11 @@ void BrowserToolbarGtk::ShowBackForwardMenu(GtkWidget* widget, } void BrowserToolbarGtk::RunPageMenu(GdkEvent* button_press_event) { - page_menu_->Popup(page_menu_button_->widget(), button_press_event); + page_menu_->Popup(page_menu_button_.get(), button_press_event); } void BrowserToolbarGtk::RunAppMenu(GdkEvent* button_press_event) { - app_menu_->Popup(app_menu_button_->widget(), button_press_event); + app_menu_->Popup(app_menu_button_.get(), button_press_event); } CustomDrawButton* BrowserToolbarGtk::MakeHomeButton() { diff --git a/chrome/browser/gtk/browser_toolbar_gtk.h b/chrome/browser/gtk/browser_toolbar_gtk.h index 3f391a7..dc1b78b1 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.h +++ b/chrome/browser/gtk/browser_toolbar_gtk.h @@ -16,7 +16,6 @@ class BackForwardMenuModelGtk; class Browser; -class CustomContainerButton; class CustomDrawButton; class GoButtonGtk; class LocationBar; @@ -80,9 +79,10 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver, ToolbarStarToggleGtk* BuildStarButton(const std::wstring& localized_tooltip); - CustomContainerButton* BuildToolbarMenuButton( + void BuildToolbarMenuButton( int icon_id, - const std::wstring& localized_tooltip); + const std::wstring& localized_tooltip, + OwnedWidgetGtk* owner); // Adds a keyboard accelerator which trigers a button. (i.e., Ctrl+R is now // equivalent to a reload click). @@ -134,7 +134,7 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver, scoped_ptr<CustomDrawButton> home_; // May be NULL. scoped_ptr<ToolbarStarToggleGtk> star_; scoped_ptr<GoButtonGtk> go_; - scoped_ptr<CustomContainerButton> page_menu_button_, app_menu_button_; + OwnedWidgetGtk page_menu_button_, app_menu_button_; // The model that contains the security level, text, icon to display... ToolbarModel* model_; diff --git a/chrome/browser/gtk/custom_button.cc b/chrome/browser/gtk/custom_button.cc index 4ff475c..3110dea 100644 --- a/chrome/browser/gtk/custom_button.cc +++ b/chrome/browser/gtk/custom_button.cc @@ -93,64 +93,3 @@ CustomDrawButton* CustomDrawButton::AddBarCloseButton(GtkWidget* hbox) { gtk_box_pack_end(GTK_BOX(hbox), centering_vbox, FALSE, FALSE, 0); return rv; } - -CustomContainerButton::CustomContainerButton() { - GdkPixbuf* images[9]; - int i = 0; - - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_TOP_LEFT_H); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_TOP_H); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_TOP_RIGHT_H); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_LEFT_H); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_CENTER_H); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_RIGHT_H); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_LEFT_H); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_H); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_RIGHT_H); - nine_box_prelight_.reset(new NineBox(images)); - - i = 0; - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_TOP_LEFT_P); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_TOP_P); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_TOP_RIGHT_P); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_LEFT_P); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_CENTER_P); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_RIGHT_P); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_LEFT_P); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_P); - images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_RIGHT_P); - nine_box_active_.reset(new NineBox(images)); - - widget_.Own(gtk_button_new()); - gtk_widget_set_app_paintable(widget_.get(), TRUE); - g_signal_connect(G_OBJECT(widget_.get()), "expose-event", - G_CALLBACK(OnExpose), this); -} - -CustomContainerButton::~CustomContainerButton() { - widget_.Destroy(); -} - -// static -gboolean CustomContainerButton::OnExpose(GtkWidget* widget, GdkEventExpose* e, - CustomContainerButton* button) { - NineBox* nine_box = NULL; - if (GTK_WIDGET_STATE(widget) == GTK_STATE_PRELIGHT) - nine_box = button->nine_box_prelight_.get(); - else if (GTK_WIDGET_STATE(widget) == GTK_STATE_ACTIVE) - nine_box = button->nine_box_active_.get(); - - // Only draw theme graphics if we have some. - if (nine_box) - nine_box->RenderToWidget(widget); - - // If we return FALSE from the function, the button paints itself. - // If we return TRUE, no children are painted. - // So we return TRUE and send the expose along directly to the child. - gtk_container_propagate_expose(GTK_CONTAINER(widget), - gtk_bin_get_child(GTK_BIN(widget)), - e); - - return TRUE; // Prevent normal painting. -} diff --git a/chrome/browser/gtk/custom_button.h b/chrome/browser/gtk/custom_button.h index 96b4ad6..7a7a1a8 100644 --- a/chrome/browser/gtk/custom_button.h +++ b/chrome/browser/gtk/custom_button.h @@ -75,27 +75,4 @@ class CustomDrawButton { DISALLOW_COPY_AND_ASSIGN(CustomDrawButton); }; -// CustomContainerButton wraps another widget and uses a NineBox of -// images to draw a highlight around the edges when you mouse over it. -class CustomContainerButton { - public: - CustomContainerButton(); - ~CustomContainerButton(); - - GtkWidget* widget() const { return widget_.get(); } - - private: - // Callback for expose, used to draw the custom graphics. - static gboolean OnExpose(GtkWidget* widget, GdkEventExpose* e, - CustomContainerButton* obj); - - // The button widget. - OwnedWidgetGtk widget_; - - // The theme graphics for when the mouse is over the button. - scoped_ptr<NineBox> nine_box_prelight_; - // The theme graphics for when the button is clicked. - scoped_ptr<NineBox> nine_box_active_; -}; - #endif // CHROME_BROWSER_GTK_CUSTOM_BUTTON_H_ diff --git a/chrome/browser/gtk/gtk_chrome_button.cc b/chrome/browser/gtk/gtk_chrome_button.cc new file mode 100644 index 0000000..3e53a2e --- /dev/null +++ b/chrome/browser/gtk/gtk_chrome_button.cc @@ -0,0 +1,88 @@ +// 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/gtk_chrome_button.h" + +#include "base/basictypes.h" +#include "chrome/common/resource_bundle.h" +#include "chrome/browser/gtk/nine_box.h" + +#include "grit/theme_resources.h" + +namespace { + +// The theme graphics for when the mouse is over the button. +scoped_ptr<NineBox> nine_box_prelight; +// The theme graphics for when the button is clicked. +scoped_ptr<NineBox> nine_box_active; + +} + +G_BEGIN_DECLS + +G_DEFINE_TYPE (GtkChromeButton, gtk_chrome_button, GTK_TYPE_BUTTON) +static gboolean gtk_chrome_button_expose (GtkWidget *widget, + GdkEventExpose *event); + +static void gtk_chrome_button_class_init(GtkChromeButtonClass *button_class) { + GtkWidgetClass* widget_class = (GtkWidgetClass*)button_class; + widget_class->expose_event = gtk_chrome_button_expose; + + GdkPixbuf* images[9]; + int i = 0; + + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_TOP_LEFT_H); + images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_TOP_H); + images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_TOP_RIGHT_H); + images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_LEFT_H); + images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_CENTER_H); + images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_RIGHT_H); + images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_LEFT_H); + images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_H); + images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_RIGHT_H); + nine_box_prelight.reset(new NineBox(images)); + + i = 0; + images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_TOP_LEFT_P); + images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_TOP_P); + images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_TOP_RIGHT_P); + images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_LEFT_P); + images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_CENTER_P); + images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_RIGHT_P); + images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_LEFT_P); + images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_P); + images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_RIGHT_P); + nine_box_active.reset(new NineBox(images)); +} + +static void gtk_chrome_button_init(GtkChromeButton* button) { + gtk_widget_set_app_paintable(GTK_WIDGET(button), TRUE); +} + +static gboolean gtk_chrome_button_expose (GtkWidget *widget, + GdkEventExpose *event) { + NineBox* nine_box = NULL; + if (GTK_WIDGET_STATE(widget) == GTK_STATE_PRELIGHT) + nine_box = nine_box_prelight.get(); + else if (GTK_WIDGET_STATE(widget) == GTK_STATE_ACTIVE) + nine_box = nine_box_active.get(); + + // Only draw theme graphics if we have some. + if (nine_box) + nine_box->RenderToWidget(widget); + + gtk_container_propagate_expose(GTK_CONTAINER(widget), + gtk_bin_get_child(GTK_BIN(widget)), + event); + + return FALSE; +} + +GtkWidget* gtk_chrome_button_new(void) { + return GTK_WIDGET(g_object_new(GTK_TYPE_CHROME_BUTTON, NULL)); +} + +G_END_DECLS + diff --git a/chrome/browser/gtk/gtk_chrome_button.h b/chrome/browser/gtk/gtk_chrome_button.h new file mode 100644 index 0000000..84d1490 --- /dev/null +++ b/chrome/browser/gtk/gtk_chrome_button.h @@ -0,0 +1,41 @@ +// 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_GTK_CHROME_BUTTON_H_ +#define CHROME_BROWSER_GTK_GTK_CHROME_BUTTON_H_ + +#include <gdk/gdk.h> +#include <gtk/gtkbutton.h> + +G_BEGIN_DECLS + +#define GTK_TYPE_CHROME_BUTTON (gtk_chrome_button_get_type ()) +#define GTK_CHROME_BUTTON(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_CHROME_BUTTON, GtkChromeButton)) +#define GTK_CHROME_BUTTON_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_CHROME_BUTTON, \ + GtkChromeButtonClass)) +#define GTK_IS_CHROME_BUTTON(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CHROME_BUTTON)) +#define GTK_IS_CHROME_BUTTON_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CHROME_BUTTON)) +#define GTK_CHROME_BUTTON_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CHROME_BUTTON, GtkChromeButton)) + +typedef struct _GtkChromeButton GtkChromeButton; +typedef struct _GtkChromeButtonClass GtkChromeButtonClass; + +struct _GtkChromeButton { + GtkButton button; +}; + +struct _GtkChromeButtonClass { + GtkButtonClass parent_class; +}; + +GtkWidget* gtk_chrome_button_new(); + +G_END_DECLS + +#endif // CHROME_BROWSER_GTK_GTK_CHROME_BUTTON_H_ diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index b3c4afb..92dc21a 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -705,8 +705,10 @@ 'browser/gtk/download_item_gtk.h', 'browser/gtk/download_shelf_gtk.cc', 'browser/gtk/download_shelf_gtk.h', - 'browser/gtk/go_button_gtk.cc', - 'browser/gtk/go_button_gtk.h', + 'browser/gtk/go_button_gtk.cc', + 'browser/gtk/go_button_gtk.h', + 'browser/gtk/gtk_chrome_button.cc', + 'browser/gtk/gtk_chrome_button.h', 'browser/gtk/infobar_gtk.cc', 'browser/gtk/infobar_gtk.h', 'browser/gtk/infobar_container_gtk.cc', |