Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1147)

Side by Side Diff: chrome/browser/gtk/custom_button.cc

Issue 149432: Add button tinting to the toolbar buttons. (Closed)
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/gtk/custom_button.h ('k') | chrome/browser/gtk/go_button_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/gtk/custom_button.h" 5 #include "chrome/browser/gtk/custom_button.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "app/theme_provider.h"
9 #include "base/basictypes.h" 10 #include "base/basictypes.h"
10 #include "base/gfx/gtk_util.h" 11 #include "base/gfx/gtk_util.h"
11 12 #include "chrome/common/notification_service.h"
12 #include "grit/theme_resources.h" 13 #include "grit/theme_resources.h"
13 14
14 CustomDrawButtonBase::CustomDrawButtonBase( 15 CustomDrawButtonBase::CustomDrawButtonBase(ThemeProvider* theme_provider,
15 int normal_id, 16 int normal_id, int active_id, int highlight_id, int depressed_id)
16 int active_id, 17 : paint_override_(-1),
17 int highlight_id, 18 normal_id_(normal_id),
18 int depressed_id) 19 active_id_(active_id),
19 : paint_override_(-1) { 20 highlight_id_(highlight_id),
20 // Load the button images from the resource bundle. 21 depressed_id_(depressed_id),
21 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 22 theme_provider_(theme_provider) {
22 pixbufs_[GTK_STATE_NORMAL] = 23 if (theme_provider) {
23 normal_id ? rb.GetRTLEnabledPixbufNamed(normal_id) : NULL; 24 // Load images by pretending that we got a BROWSER_THEME_CHANGED
24 pixbufs_[GTK_STATE_ACTIVE] = 25 // notification.
25 active_id ? rb.GetRTLEnabledPixbufNamed(active_id) : NULL; 26 Observe(NotificationType::BROWSER_THEME_CHANGED,
26 pixbufs_[GTK_STATE_PRELIGHT] = 27 NotificationService::AllSources(),
27 highlight_id ? rb.GetRTLEnabledPixbufNamed(highlight_id) : NULL; 28 NotificationService::NoDetails());
28 pixbufs_[GTK_STATE_SELECTED] = NULL; 29
29 pixbufs_[GTK_STATE_INSENSITIVE] = 30 registrar_.Add(this,
30 depressed_id ? rb.GetRTLEnabledPixbufNamed(depressed_id) : NULL; 31 NotificationType::BROWSER_THEME_CHANGED,
32 NotificationService::AllSources());
33 } else {
34 // Load the button images from the resource bundle.
35 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
36 pixbufs_[GTK_STATE_NORMAL] =
37 normal_id ? rb.GetRTLEnabledPixbufNamed(normal_id) : NULL;
38 pixbufs_[GTK_STATE_ACTIVE] =
39 active_id ? rb.GetRTLEnabledPixbufNamed(active_id) : NULL;
40 pixbufs_[GTK_STATE_PRELIGHT] =
41 highlight_id ? rb.GetRTLEnabledPixbufNamed(highlight_id) : NULL;
42 pixbufs_[GTK_STATE_SELECTED] = NULL;
43 pixbufs_[GTK_STATE_INSENSITIVE] =
44 depressed_id ? rb.GetRTLEnabledPixbufNamed(depressed_id) : NULL;
45 }
31 } 46 }
32 47
33 CustomDrawButtonBase::~CustomDrawButtonBase() { 48 CustomDrawButtonBase::~CustomDrawButtonBase() {
34 } 49 }
35 50
36 gboolean CustomDrawButtonBase::OnExpose(GtkWidget* widget, GdkEventExpose* e) { 51 gboolean CustomDrawButtonBase::OnExpose(GtkWidget* widget, GdkEventExpose* e) {
37 GdkPixbuf* pixbuf = pixbufs_[paint_override_ >= 0 ? 52 GdkPixbuf* pixbuf = pixbufs_[paint_override_ >= 0 ?
38 paint_override_ : GTK_WIDGET_STATE(widget)]; 53 paint_override_ : GTK_WIDGET_STATE(widget)];
39 54
40 // Fall back to the default image if we don't have one for this state. 55 // Fall back to the default image if we don't have one for this state.
(...skipping 13 matching lines...) Expand all
54 int x = gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL ? 69 int x = gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL ?
55 widget_width - pixbuf_width : 0; 70 widget_width - pixbuf_width : 0;
56 71
57 gdk_cairo_set_source_pixbuf(cairo_context, pixbuf, x, 0); 72 gdk_cairo_set_source_pixbuf(cairo_context, pixbuf, x, 0);
58 cairo_paint(cairo_context); 73 cairo_paint(cairo_context);
59 cairo_destroy(cairo_context); 74 cairo_destroy(cairo_context);
60 75
61 return TRUE; 76 return TRUE;
62 } 77 }
63 78
64 CustomDrawButton::CustomDrawButton( 79 void CustomDrawButtonBase::Observe(NotificationType type,
65 int normal_id, 80 const NotificationSource& source, const NotificationDetails& details) {
66 int active_id, 81 DCHECK(theme_provider_);
67 int highlight_id, 82 DCHECK(NotificationType::BROWSER_THEME_CHANGED == type);
68 int depressed_id, 83
69 const char* stock_id) 84 // TODO(tc): Add GetRTLEnabledPixbufNamed to ThemeProviderGtk.
70 : button_base_(normal_id, active_id, highlight_id, depressed_id), 85 pixbufs_[GTK_STATE_NORMAL] =
86 normal_id_ ? theme_provider_->GetPixbufNamed(normal_id_) : NULL;
87 pixbufs_[GTK_STATE_ACTIVE] =
88 active_id_ ? theme_provider_->GetPixbufNamed(active_id_) : NULL;
89 pixbufs_[GTK_STATE_PRELIGHT] =
90 highlight_id_ ? theme_provider_->GetPixbufNamed(highlight_id_) : NULL;
91 pixbufs_[GTK_STATE_SELECTED] = NULL;
92 pixbufs_[GTK_STATE_INSENSITIVE] =
93 depressed_id_ ? theme_provider_->GetPixbufNamed(depressed_id_) : NULL;
94 }
95
96 CustomDrawButton::CustomDrawButton(int normal_id, int active_id,
97 int highlight_id, int depressed_id, const char* stock_id)
98 : button_base_(NULL, normal_id, active_id, highlight_id, depressed_id),
71 gtk_stock_name_(stock_id), 99 gtk_stock_name_(stock_id),
72 has_expose_signal_handler_(false) { 100 has_expose_signal_handler_(false) {
73 widget_.Own(gtk_button_new()); 101 Init();
74 GTK_WIDGET_UNSET_FLAGS(widget_.get(), GTK_CAN_FOCUS); 102 }
75 SetUseSystemTheme(false); 103
104 CustomDrawButton::CustomDrawButton(ThemeProvider* theme_provider,
105 int normal_id, int active_id, int highlight_id, int depressed_id,
106 const char* stock_id)
107 : button_base_(theme_provider, normal_id, active_id, highlight_id,
108 depressed_id),
109 gtk_stock_name_(stock_id),
110 has_expose_signal_handler_(false) {
111 Init();
76 } 112 }
77 113
78 CustomDrawButton::~CustomDrawButton() { 114 CustomDrawButton::~CustomDrawButton() {
79 widget_.Destroy(); 115 widget_.Destroy();
80 } 116 }
81 117
118 void CustomDrawButton::Init() {
119 widget_.Own(gtk_button_new());
120 GTK_WIDGET_UNSET_FLAGS(widget_.get(), GTK_CAN_FOCUS);
121 SetUseSystemTheme(false);
122 }
123
82 void CustomDrawButton::SetUseSystemTheme(bool use_gtk) { 124 void CustomDrawButton::SetUseSystemTheme(bool use_gtk) {
83 if (use_gtk && gtk_stock_name_) { 125 if (use_gtk && gtk_stock_name_) {
84 gtk_button_set_image( 126 gtk_button_set_image(
85 GTK_BUTTON(widget_.get()), 127 GTK_BUTTON(widget_.get()),
86 gtk_image_new_from_stock(gtk_stock_name_, GTK_ICON_SIZE_BUTTON)); 128 gtk_image_new_from_stock(gtk_stock_name_, GTK_ICON_SIZE_BUTTON));
87 gtk_widget_set_size_request(widget_.get(), -1, -1); 129 gtk_widget_set_size_request(widget_.get(), -1, -1);
88 gtk_widget_set_app_paintable(widget_.get(), FALSE); 130 gtk_widget_set_app_paintable(widget_.get(), FALSE);
89 gtk_widget_set_double_buffered(widget_.get(), TRUE); 131 gtk_widget_set_double_buffered(widget_.get(), TRUE);
90 132
91 if (has_expose_signal_handler_) 133 if (has_expose_signal_handler_)
(...skipping 30 matching lines...) Expand all
122 return button->button_base_.OnExpose(widget, e); 164 return button->button_base_.OnExpose(widget, e);
123 } 165 }
124 166
125 // static 167 // static
126 CustomDrawButton* CustomDrawButton::CloseButton() { 168 CustomDrawButton* CustomDrawButton::CloseButton() {
127 CustomDrawButton* button = 169 CustomDrawButton* button =
128 new CustomDrawButton(IDR_CLOSE_BAR, IDR_CLOSE_BAR_P, 170 new CustomDrawButton(IDR_CLOSE_BAR, IDR_CLOSE_BAR_P,
129 IDR_CLOSE_BAR_H, 0, NULL); 171 IDR_CLOSE_BAR_H, 0, NULL);
130 return button; 172 return button;
131 } 173 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/custom_button.h ('k') | chrome/browser/gtk/go_button_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698