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

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

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/ui/gtk/custom_button.h" 5 #include "chrome/browser/ui/gtk/custom_button.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "chrome/browser/ui/gtk/cairo_cached_surface.h" 8 #include "chrome/browser/ui/gtk/cairo_cached_surface.h"
9 #include "chrome/browser/ui/gtk/gtk_chrome_button.h" 9 #include "chrome/browser/ui/gtk/gtk_chrome_button.h"
10 #include "chrome/browser/ui/gtk/gtk_theme_service.h" 10 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
(...skipping 21 matching lines...) Expand all
32 for (int i = 0; i < (GTK_STATE_INSENSITIVE + 1); ++i) 32 for (int i = 0; i < (GTK_STATE_INSENSITIVE + 1); ++i)
33 surfaces_[i].reset(new CairoCachedSurface); 33 surfaces_[i].reset(new CairoCachedSurface);
34 background_image_.reset(new CairoCachedSurface); 34 background_image_.reset(new CairoCachedSurface);
35 35
36 if (theme_provider) { 36 if (theme_provider) {
37 // Load images by pretending that we got a BROWSER_THEME_CHANGED 37 // Load images by pretending that we got a BROWSER_THEME_CHANGED
38 // notification. 38 // notification.
39 theme_provider->InitThemesFor(this); 39 theme_provider->InitThemesFor(this);
40 40
41 registrar_.Add(this, 41 registrar_.Add(this,
42 NotificationType::BROWSER_THEME_CHANGED, 42 chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
43 NotificationService::AllSources()); 43 NotificationService::AllSources());
44 } else { 44 } else {
45 // Load the button images from the resource bundle. 45 // Load the button images from the resource bundle.
46 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 46 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
47 surfaces_[GTK_STATE_NORMAL]->UsePixbuf( 47 surfaces_[GTK_STATE_NORMAL]->UsePixbuf(
48 normal_id_ ? rb.GetRTLEnabledPixbufNamed(normal_id_) : NULL); 48 normal_id_ ? rb.GetRTLEnabledPixbufNamed(normal_id_) : NULL);
49 surfaces_[GTK_STATE_ACTIVE]->UsePixbuf( 49 surfaces_[GTK_STATE_ACTIVE]->UsePixbuf(
50 pressed_id_ ? rb.GetRTLEnabledPixbufNamed(pressed_id_) : NULL); 50 pressed_id_ ? rb.GetRTLEnabledPixbufNamed(pressed_id_) : NULL);
51 surfaces_[GTK_STATE_PRELIGHT]->UsePixbuf( 51 surfaces_[GTK_STATE_PRELIGHT]->UsePixbuf(
52 hover_id_ ? rb.GetRTLEnabledPixbufNamed(hover_id_) : NULL); 52 hover_id_ ? rb.GetRTLEnabledPixbufNamed(hover_id_) : NULL);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } else { 133 } else {
134 SkBitmap img = 134 SkBitmap img =
135 SkBitmapOperations::CreateButtonBackground(color, *image, *mask); 135 SkBitmapOperations::CreateButtonBackground(color, *image, *mask);
136 136
137 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&img); 137 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&img);
138 background_image_->UsePixbuf(pixbuf); 138 background_image_->UsePixbuf(pixbuf);
139 g_object_unref(pixbuf); 139 g_object_unref(pixbuf);
140 } 140 }
141 } 141 }
142 142
143 void CustomDrawButtonBase::Observe(NotificationType type, 143 void CustomDrawButtonBase::Observe(int type,
144 const NotificationSource& source, const NotificationDetails& details) { 144 const NotificationSource& source, const NotificationDetails& details) {
145 DCHECK(theme_service_); 145 DCHECK(theme_service_);
146 DCHECK(NotificationType::BROWSER_THEME_CHANGED == type); 146 DCHECK(chrome::NOTIFICATION_BROWSER_THEME_CHANGED == type);
147 147
148 surfaces_[GTK_STATE_NORMAL]->UsePixbuf(normal_id_ ? 148 surfaces_[GTK_STATE_NORMAL]->UsePixbuf(normal_id_ ?
149 theme_service_->GetRTLEnabledPixbufNamed(normal_id_) : NULL); 149 theme_service_->GetRTLEnabledPixbufNamed(normal_id_) : NULL);
150 surfaces_[GTK_STATE_ACTIVE]->UsePixbuf(pressed_id_ ? 150 surfaces_[GTK_STATE_ACTIVE]->UsePixbuf(pressed_id_ ?
151 theme_service_->GetRTLEnabledPixbufNamed(pressed_id_) : NULL); 151 theme_service_->GetRTLEnabledPixbufNamed(pressed_id_) : NULL);
152 surfaces_[GTK_STATE_PRELIGHT]->UsePixbuf(hover_id_ ? 152 surfaces_[GTK_STATE_PRELIGHT]->UsePixbuf(hover_id_ ?
153 theme_service_->GetRTLEnabledPixbufNamed(hover_id_) : NULL); 153 theme_service_->GetRTLEnabledPixbufNamed(hover_id_) : NULL);
154 surfaces_[GTK_STATE_SELECTED]->UsePixbuf(NULL); 154 surfaces_[GTK_STATE_SELECTED]->UsePixbuf(NULL);
155 surfaces_[GTK_STATE_INSENSITIVE]->UsePixbuf(disabled_id_ ? 155 surfaces_[GTK_STATE_INSENSITIVE]->UsePixbuf(disabled_id_ ?
156 theme_service_->GetRTLEnabledPixbufNamed(disabled_id_) : NULL); 156 theme_service_->GetRTLEnabledPixbufNamed(disabled_id_) : NULL);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 GtkIconSize stock_size) 237 GtkIconSize stock_size)
238 : button_base_(theme_provider, normal_id, pressed_id, hover_id, 238 : button_base_(theme_provider, normal_id, pressed_id, hover_id,
239 disabled_id), 239 disabled_id),
240 theme_service_(theme_provider) { 240 theme_service_(theme_provider) {
241 native_widget_.Own(gtk_image_new_from_stock(stock_id, stock_size)); 241 native_widget_.Own(gtk_image_new_from_stock(stock_id, stock_size));
242 242
243 Init(); 243 Init();
244 244
245 theme_service_->InitThemesFor(this); 245 theme_service_->InitThemesFor(this);
246 registrar_.Add(this, 246 registrar_.Add(this,
247 NotificationType::BROWSER_THEME_CHANGED, 247 chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
248 NotificationService::AllSources()); 248 NotificationService::AllSources());
249 } 249 }
250 250
251 CustomDrawButton::CustomDrawButton(GtkThemeService* theme_provider, 251 CustomDrawButton::CustomDrawButton(GtkThemeService* theme_provider,
252 int normal_id, 252 int normal_id,
253 int pressed_id, 253 int pressed_id,
254 int hover_id, 254 int hover_id,
255 int disabled_id, 255 int disabled_id,
256 GtkWidget* native_widget) 256 GtkWidget* native_widget)
257 : button_base_(theme_provider, normal_id, pressed_id, hover_id, 257 : button_base_(theme_provider, normal_id, pressed_id, hover_id,
258 disabled_id), 258 disabled_id),
259 native_widget_(native_widget), 259 native_widget_(native_widget),
260 theme_service_(theme_provider) { 260 theme_service_(theme_provider) {
261 Init(); 261 Init();
262 262
263 theme_service_->InitThemesFor(this); 263 theme_service_->InitThemesFor(this);
264 registrar_.Add(this, 264 registrar_.Add(this,
265 NotificationType::BROWSER_THEME_CHANGED, 265 chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
266 NotificationService::AllSources()); 266 NotificationService::AllSources());
267 } 267 }
268 268
269 CustomDrawButton::~CustomDrawButton() { 269 CustomDrawButton::~CustomDrawButton() {
270 widget_.Destroy(); 270 widget_.Destroy();
271 native_widget_.Destroy(); 271 native_widget_.Destroy();
272 } 272 }
273 273
274 void CustomDrawButton::Init() { 274 void CustomDrawButton::Init() {
275 widget_.Own(gtk_chrome_button_new()); 275 widget_.Own(gtk_chrome_button_new());
276 GTK_WIDGET_UNSET_FLAGS(widget(), GTK_CAN_FOCUS); 276 GTK_WIDGET_UNSET_FLAGS(widget(), GTK_CAN_FOCUS);
277 g_signal_connect(widget(), "expose-event", 277 g_signal_connect(widget(), "expose-event",
278 G_CALLBACK(OnCustomExposeThunk), this); 278 G_CALLBACK(OnCustomExposeThunk), this);
279 hover_controller_.Init(widget()); 279 hover_controller_.Init(widget());
280 } 280 }
281 281
282 void CustomDrawButton::Observe(NotificationType type, 282 void CustomDrawButton::Observe(int type,
283 const NotificationSource& source, const NotificationDetails& details) { 283 const NotificationSource& source, const NotificationDetails& details) {
284 DCHECK(NotificationType::BROWSER_THEME_CHANGED == type); 284 DCHECK(chrome::NOTIFICATION_BROWSER_THEME_CHANGED == type);
285 SetBrowserTheme(); 285 SetBrowserTheme();
286 } 286 }
287 287
288 void CustomDrawButton::SetPaintOverride(GtkStateType state) { 288 void CustomDrawButton::SetPaintOverride(GtkStateType state) {
289 button_base_.set_paint_override(state); 289 button_base_.set_paint_override(state);
290 gtk_chrome_button_set_paint_state(GTK_CHROME_BUTTON(widget()), state); 290 gtk_chrome_button_set_paint_state(GTK_CHROME_BUTTON(widget()), state);
291 gtk_widget_queue_draw(widget()); 291 gtk_widget_queue_draw(widget());
292 } 292 }
293 293
294 void CustomDrawButton::UnsetPaintOverride() { 294 void CustomDrawButton::UnsetPaintOverride() {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 gtk_widget_set_app_paintable(widget(), TRUE); 336 gtk_widget_set_app_paintable(widget(), TRUE);
337 } 337 }
338 338
339 gtk_chrome_button_set_use_gtk_rendering( 339 gtk_chrome_button_set_use_gtk_rendering(
340 GTK_CHROME_BUTTON(widget()), UseGtkTheme()); 340 GTK_CHROME_BUTTON(widget()), UseGtkTheme());
341 } 341 }
342 342
343 bool CustomDrawButton::UseGtkTheme() { 343 bool CustomDrawButton::UseGtkTheme() {
344 return theme_service_ && theme_service_->UsingNativeTheme(); 344 return theme_service_ && theme_service_->UsingNativeTheme();
345 } 345 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698