summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/custom_button.cc
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-10 19:41:53 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-10 19:41:53 +0000
commitaf62bb4afd0dba5e607643f818a08a2aec642a80 (patch)
tree577687d6570ae15b9d23ccf2673eb669a31c4866 /chrome/browser/gtk/custom_button.cc
parentb8da78ad0ca066ada021b02bf4aaf1a686ef5af3 (diff)
downloadchromium_src-af62bb4afd0dba5e607643f818a08a2aec642a80.zip
chromium_src-af62bb4afd0dba5e607643f818a08a2aec642a80.tar.gz
chromium_src-af62bb4afd0dba5e607643f818a08a2aec642a80.tar.bz2
Revert "Revert "Add button tinting to the toolbar buttons.""
This reverts commit r20399 and re-applies the button tinting code. There's a fix for the go button gtk unittest by checking to see if the browser is non-NULL before getting the theme provider. TBR=erg Review URL: http://codereview.chromium.org/155369 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20402 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/custom_button.cc')
-rw-r--r--chrome/browser/gtk/custom_button.cc96
1 files changed, 69 insertions, 27 deletions
diff --git a/chrome/browser/gtk/custom_button.cc b/chrome/browser/gtk/custom_button.cc
index 6729ee6..cbe0f94 100644
--- a/chrome/browser/gtk/custom_button.cc
+++ b/chrome/browser/gtk/custom_button.cc
@@ -6,28 +6,43 @@
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
+#include "app/theme_provider.h"
#include "base/basictypes.h"
#include "base/gfx/gtk_util.h"
-
+#include "chrome/common/notification_service.h"
#include "grit/theme_resources.h"
-CustomDrawButtonBase::CustomDrawButtonBase(
- int normal_id,
- int active_id,
- int highlight_id,
- int depressed_id)
- : paint_override_(-1) {
- // Load the button images from the resource bundle.
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- pixbufs_[GTK_STATE_NORMAL] =
- normal_id ? rb.GetRTLEnabledPixbufNamed(normal_id) : NULL;
- pixbufs_[GTK_STATE_ACTIVE] =
- active_id ? rb.GetRTLEnabledPixbufNamed(active_id) : NULL;
- pixbufs_[GTK_STATE_PRELIGHT] =
- highlight_id ? rb.GetRTLEnabledPixbufNamed(highlight_id) : NULL;
- pixbufs_[GTK_STATE_SELECTED] = NULL;
- pixbufs_[GTK_STATE_INSENSITIVE] =
- depressed_id ? rb.GetRTLEnabledPixbufNamed(depressed_id) : NULL;
+CustomDrawButtonBase::CustomDrawButtonBase(ThemeProvider* theme_provider,
+ int normal_id, int active_id, int highlight_id, int depressed_id)
+ : paint_override_(-1),
+ normal_id_(normal_id),
+ active_id_(active_id),
+ highlight_id_(highlight_id),
+ depressed_id_(depressed_id),
+ theme_provider_(theme_provider) {
+ if (theme_provider) {
+ // Load images by pretending that we got a BROWSER_THEME_CHANGED
+ // notification.
+ Observe(NotificationType::BROWSER_THEME_CHANGED,
+ NotificationService::AllSources(),
+ NotificationService::NoDetails());
+
+ registrar_.Add(this,
+ NotificationType::BROWSER_THEME_CHANGED,
+ NotificationService::AllSources());
+ } else {
+ // Load the button images from the resource bundle.
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ pixbufs_[GTK_STATE_NORMAL] =
+ normal_id ? rb.GetRTLEnabledPixbufNamed(normal_id) : NULL;
+ pixbufs_[GTK_STATE_ACTIVE] =
+ active_id ? rb.GetRTLEnabledPixbufNamed(active_id) : NULL;
+ pixbufs_[GTK_STATE_PRELIGHT] =
+ highlight_id ? rb.GetRTLEnabledPixbufNamed(highlight_id) : NULL;
+ pixbufs_[GTK_STATE_SELECTED] = NULL;
+ pixbufs_[GTK_STATE_INSENSITIVE] =
+ depressed_id ? rb.GetRTLEnabledPixbufNamed(depressed_id) : NULL;
+ }
}
CustomDrawButtonBase::~CustomDrawButtonBase() {
@@ -61,24 +76,51 @@ gboolean CustomDrawButtonBase::OnExpose(GtkWidget* widget, GdkEventExpose* e) {
return TRUE;
}
-CustomDrawButton::CustomDrawButton(
- int normal_id,
- int active_id,
- int highlight_id,
- int depressed_id,
+void CustomDrawButtonBase::Observe(NotificationType type,
+ const NotificationSource& source, const NotificationDetails& details) {
+ DCHECK(theme_provider_);
+ DCHECK(NotificationType::BROWSER_THEME_CHANGED == type);
+
+ // TODO(tc): Add GetRTLEnabledPixbufNamed to ThemeProviderGtk.
+ pixbufs_[GTK_STATE_NORMAL] =
+ normal_id_ ? theme_provider_->GetPixbufNamed(normal_id_) : NULL;
+ pixbufs_[GTK_STATE_ACTIVE] =
+ active_id_ ? theme_provider_->GetPixbufNamed(active_id_) : NULL;
+ pixbufs_[GTK_STATE_PRELIGHT] =
+ highlight_id_ ? theme_provider_->GetPixbufNamed(highlight_id_) : NULL;
+ pixbufs_[GTK_STATE_SELECTED] = NULL;
+ pixbufs_[GTK_STATE_INSENSITIVE] =
+ depressed_id_ ? theme_provider_->GetPixbufNamed(depressed_id_) : NULL;
+}
+
+CustomDrawButton::CustomDrawButton(int normal_id, int active_id,
+ int highlight_id, int depressed_id, const char* stock_id)
+ : button_base_(NULL, normal_id, active_id, highlight_id, depressed_id),
+ gtk_stock_name_(stock_id),
+ has_expose_signal_handler_(false) {
+ Init();
+}
+
+CustomDrawButton::CustomDrawButton(ThemeProvider* theme_provider,
+ int normal_id, int active_id, int highlight_id, int depressed_id,
const char* stock_id)
- : button_base_(normal_id, active_id, highlight_id, depressed_id),
+ : button_base_(theme_provider, normal_id, active_id, highlight_id,
+ depressed_id),
gtk_stock_name_(stock_id),
has_expose_signal_handler_(false) {
- widget_.Own(gtk_button_new());
- GTK_WIDGET_UNSET_FLAGS(widget_.get(), GTK_CAN_FOCUS);
- SetUseSystemTheme(false);
+ Init();
}
CustomDrawButton::~CustomDrawButton() {
widget_.Destroy();
}
+void CustomDrawButton::Init() {
+ widget_.Own(gtk_button_new());
+ GTK_WIDGET_UNSET_FLAGS(widget_.get(), GTK_CAN_FOCUS);
+ SetUseSystemTheme(false);
+}
+
void CustomDrawButton::SetUseSystemTheme(bool use_gtk) {
if (use_gtk && gtk_stock_name_) {
gtk_button_set_image(