diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-09 06:40:57 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-09 06:40:57 +0000 |
commit | 64f001a8a74f5d861d9948155c92419f53928e50 (patch) | |
tree | 4f215495257c68c34f8f1bbc4724e35a73be1788 /chrome/browser/gtk/custom_button.cc | |
parent | 253071feeaf010115a8fbe498d1ebd634c2d1626 (diff) | |
download | chromium_src-64f001a8a74f5d861d9948155c92419f53928e50.zip chromium_src-64f001a8a74f5d861d9948155c92419f53928e50.tar.gz chromium_src-64f001a8a74f5d861d9948155c92419f53928e50.tar.bz2 |
Implement stop/go button for Linux.
Refactored code out of CustomDrawButton into CustomDrawButtonBase to be shared with GoButtonGtk.
Replaced the existing non-togglable go button with GoButtonGtk.
Note that tooltip support isn't done yet, as it changes based on the state of the location bar and the go/stop state.
Add a simple test.
Fix some minor lint errors.
BUG=9381
Review URL: http://codereview.chromium.org/62154
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13409 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/custom_button.cc')
-rw-r--r-- | chrome/browser/gtk/custom_button.cc | 63 |
1 files changed, 40 insertions, 23 deletions
diff --git a/chrome/browser/gtk/custom_button.cc b/chrome/browser/gtk/custom_button.cc index 150d29f..4ff475c 100644 --- a/chrome/browser/gtk/custom_button.cc +++ b/chrome/browser/gtk/custom_button.cc @@ -10,10 +10,11 @@ #include "grit/theme_resources.h" -CustomDrawButton::CustomDrawButton(int normal_id, - int active_id, int highlight_id, int depressed_id) { - widget_.Own(gtk_button_new()); - +CustomDrawButtonBase::CustomDrawButtonBase( + int normal_id, + int active_id, + int highlight_id, + int depressed_id) { // Load the button images from the resource bundle. ResourceBundle& rb = ResourceBundle::GetSharedInstance(); pixbufs_[GTK_STATE_NORMAL] = normal_id ? rb.LoadPixbuf(normal_id) : NULL; @@ -23,35 +24,21 @@ CustomDrawButton::CustomDrawButton(int normal_id, pixbufs_[GTK_STATE_SELECTED] = NULL; pixbufs_[GTK_STATE_INSENSITIVE] = depressed_id ? rb.LoadPixbuf(depressed_id) : NULL; - - gtk_widget_set_size_request(widget_.get(), - gdk_pixbuf_get_width(pixbufs_[0]), - gdk_pixbuf_get_height(pixbufs_[0])); - - gtk_widget_set_app_paintable(widget_.get(), TRUE); - // We effectively double-buffer by virtue of having only one image... - gtk_widget_set_double_buffered(widget_.get(), FALSE); - g_signal_connect(G_OBJECT(widget_.get()), "expose-event", - G_CALLBACK(OnExpose), this); } -CustomDrawButton::~CustomDrawButton() { +CustomDrawButtonBase::~CustomDrawButtonBase() { for (size_t i = 0; i < arraysize(pixbufs_); ++i) { if (pixbufs_[i]) - gdk_pixbuf_unref(pixbufs_[i]); + g_object_unref(pixbufs_[i]); } - - widget_.Destroy(); } -// static -gboolean CustomDrawButton::OnExpose(GtkWidget* widget, GdkEventExpose* e, - CustomDrawButton* button) { - GdkPixbuf* pixbuf = button->pixbufs_[GTK_WIDGET_STATE(widget)]; +gboolean CustomDrawButtonBase::OnExpose(GtkWidget* widget, GdkEventExpose* e) { + GdkPixbuf* pixbuf = pixbufs(GTK_WIDGET_STATE(widget)); // Fall back to the default image if we don't have one for this state. if (!pixbuf) - pixbuf = button->pixbufs_[GTK_STATE_NORMAL]; + pixbuf = pixbufs(GTK_STATE_NORMAL); if (!pixbuf) return FALSE; @@ -66,6 +53,36 @@ gboolean CustomDrawButton::OnExpose(GtkWidget* widget, GdkEventExpose* e, return TRUE; } +CustomDrawButton::CustomDrawButton( + int normal_id, + int active_id, + int highlight_id, + int depressed_id) + : button_base_(normal_id, active_id, highlight_id, depressed_id) { + widget_.Own(gtk_button_new()); + + gtk_widget_set_size_request(widget_.get(), + gdk_pixbuf_get_width(button_base_.pixbufs(0)), + gdk_pixbuf_get_height(button_base_.pixbufs(0))); + + gtk_widget_set_app_paintable(widget_.get(), TRUE); + // We effectively double-buffer by virtue of having only one image... + gtk_widget_set_double_buffered(widget_.get(), FALSE); + g_signal_connect(G_OBJECT(widget_.get()), "expose-event", + G_CALLBACK(OnExpose), this); +} + +CustomDrawButton::~CustomDrawButton() { + widget_.Destroy(); +} + +// static +gboolean CustomDrawButton::OnExpose(GtkWidget* widget, + GdkEventExpose* e, + CustomDrawButton* button) { + return button->button_base_.OnExpose(widget, e); +} + // static CustomDrawButton* CustomDrawButton::AddBarCloseButton(GtkWidget* hbox) { CustomDrawButton* rv = new CustomDrawButton(IDR_CLOSE_BAR, IDR_CLOSE_BAR_P, |