| OLD | NEW |
| 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 231 |
| 232 CustomDrawButton::CustomDrawButton(GtkThemeService* theme_provider, | 232 CustomDrawButton::CustomDrawButton(GtkThemeService* theme_provider, |
| 233 int normal_id, | 233 int normal_id, |
| 234 int pressed_id, | 234 int pressed_id, |
| 235 int hover_id, | 235 int hover_id, |
| 236 int disabled_id, | 236 int disabled_id, |
| 237 const char* stock_id, | 237 const char* stock_id, |
| 238 GtkIconSize stock_size) | 238 GtkIconSize stock_size) |
| 239 : button_base_(theme_provider, normal_id, pressed_id, hover_id, | 239 : button_base_(theme_provider, normal_id, pressed_id, hover_id, |
| 240 disabled_id), | 240 disabled_id), |
| 241 theme_service_(theme_provider) { | 241 theme_service_(theme_provider), |
| 242 forcing_browser_theme_(false) { |
| 242 native_widget_.Own(gtk_image_new_from_stock(stock_id, stock_size)); | 243 native_widget_.Own(gtk_image_new_from_stock(stock_id, stock_size)); |
| 243 | 244 |
| 244 Init(); | 245 Init(); |
| 245 | 246 |
| 246 theme_service_->InitThemesFor(this); | 247 theme_service_->InitThemesFor(this); |
| 247 registrar_.Add(this, | 248 registrar_.Add(this, |
| 248 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 249 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 249 Source<ThemeService>(theme_provider)); | 250 Source<ThemeService>(theme_provider)); |
| 250 } | 251 } |
| 251 | 252 |
| 252 CustomDrawButton::CustomDrawButton(GtkThemeService* theme_provider, | 253 CustomDrawButton::CustomDrawButton(GtkThemeService* theme_provider, |
| 253 int normal_id, | 254 int normal_id, |
| 254 int pressed_id, | 255 int pressed_id, |
| 255 int hover_id, | 256 int hover_id, |
| 256 int disabled_id, | 257 int disabled_id, |
| 257 GtkWidget* native_widget) | 258 GtkWidget* native_widget) |
| 258 : button_base_(theme_provider, normal_id, pressed_id, hover_id, | 259 : button_base_(theme_provider, normal_id, pressed_id, hover_id, |
| 259 disabled_id), | 260 disabled_id), |
| 260 native_widget_(native_widget), | 261 native_widget_(native_widget), |
| 261 theme_service_(theme_provider) { | 262 theme_service_(theme_provider), |
| 263 forcing_browser_theme_(false) { |
| 262 Init(); | 264 Init(); |
| 263 | 265 |
| 264 theme_service_->InitThemesFor(this); | 266 theme_service_->InitThemesFor(this); |
| 265 registrar_.Add(this, | 267 registrar_.Add(this, |
| 266 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 268 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 267 Source<ThemeService>(theme_provider)); | 269 Source<ThemeService>(theme_provider)); |
| 268 } | 270 } |
| 269 | 271 |
| 270 CustomDrawButton::~CustomDrawButton() { | 272 CustomDrawButton::~CustomDrawButton() { |
| 271 widget_.Destroy(); | 273 widget_.Destroy(); |
| 272 native_widget_.Destroy(); | 274 native_widget_.Destroy(); |
| 273 } | 275 } |
| 274 | 276 |
| 275 void CustomDrawButton::Init() { | 277 void CustomDrawButton::Init() { |
| 276 widget_.Own(gtk_chrome_button_new()); | 278 widget_.Own(gtk_chrome_button_new()); |
| 277 gtk_widget_set_can_focus(widget(), FALSE); | 279 gtk_widget_set_can_focus(widget(), FALSE); |
| 278 g_signal_connect(widget(), "expose-event", | 280 g_signal_connect(widget(), "expose-event", |
| 279 G_CALLBACK(OnCustomExposeThunk), this); | 281 G_CALLBACK(OnCustomExposeThunk), this); |
| 280 hover_controller_.Init(widget()); | 282 hover_controller_.Init(widget()); |
| 281 } | 283 } |
| 282 | 284 |
| 285 void CustomDrawButton::ForceBrowserTheme() { |
| 286 forcing_browser_theme_ = true; |
| 287 SetBrowserTheme(); |
| 288 } |
| 289 |
| 283 void CustomDrawButton::Observe(int type, | 290 void CustomDrawButton::Observe(int type, |
| 284 const NotificationSource& source, const NotificationDetails& details) { | 291 const NotificationSource& source, const NotificationDetails& details) { |
| 285 DCHECK(chrome::NOTIFICATION_BROWSER_THEME_CHANGED == type); | 292 DCHECK(chrome::NOTIFICATION_BROWSER_THEME_CHANGED == type); |
| 286 SetBrowserTheme(); | 293 SetBrowserTheme(); |
| 287 } | 294 } |
| 288 | 295 |
| 289 int CustomDrawButton::SurfaceWidth() const { | 296 int CustomDrawButton::SurfaceWidth() const { |
| 290 return button_base_.Width(); | 297 return button_base_.Width(); |
| 291 } | 298 } |
| 292 | 299 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 button_base_.Height()); | 350 button_base_.Height()); |
| 344 | 351 |
| 345 gtk_widget_set_app_paintable(widget(), TRUE); | 352 gtk_widget_set_app_paintable(widget(), TRUE); |
| 346 } | 353 } |
| 347 | 354 |
| 348 gtk_chrome_button_set_use_gtk_rendering( | 355 gtk_chrome_button_set_use_gtk_rendering( |
| 349 GTK_CHROME_BUTTON(widget()), UseGtkTheme()); | 356 GTK_CHROME_BUTTON(widget()), UseGtkTheme()); |
| 350 } | 357 } |
| 351 | 358 |
| 352 bool CustomDrawButton::UseGtkTheme() { | 359 bool CustomDrawButton::UseGtkTheme() { |
| 353 return theme_service_ && theme_service_->UsingNativeTheme(); | 360 return !forcing_browser_theme_ && theme_service_ && |
| 361 theme_service_->UsingNativeTheme(); |
| 354 } | 362 } |
| OLD | NEW |