| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/browser/ui/gtk/gtk_chrome_button.h" | 10 #include "chrome/browser/ui/gtk/gtk_chrome_button.h" |
| 11 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | |
| 12 #include "chrome/browser/ui/gtk/gtk_util.h" | 11 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 12 #include "chrome/browser/ui/gtk/theme_service_gtk.h" |
| 13 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
| 14 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
| 15 #include "grit/ui_resources_standard.h" | 15 #include "grit/ui_resources_standard.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/gfx/gtk_util.h" | 18 #include "ui/gfx/gtk_util.h" |
| 19 #include "ui/gfx/image/cairo_cached_surface.h" | 19 #include "ui/gfx/image/cairo_cached_surface.h" |
| 20 #include "ui/gfx/skbitmap_operations.h" | 20 #include "ui/gfx/skbitmap_operations.h" |
| 21 | 21 |
| 22 CustomDrawButtonBase::CustomDrawButtonBase(GtkThemeService* theme_provider, | 22 CustomDrawButtonBase::CustomDrawButtonBase(ThemeServiceGtk* theme_provider, |
| 23 int normal_id, | 23 int normal_id, |
| 24 int pressed_id, | 24 int pressed_id, |
| 25 int hover_id, | 25 int hover_id, |
| 26 int disabled_id) | 26 int disabled_id) |
| 27 : background_image_(NULL), | 27 : background_image_(NULL), |
| 28 paint_override_(-1), | 28 paint_override_(-1), |
| 29 normal_id_(normal_id), | 29 normal_id_(normal_id), |
| 30 pressed_id_(pressed_id), | 30 pressed_id_(pressed_id), |
| 31 hover_id_(hover_id), | 31 hover_id_(hover_id), |
| 32 disabled_id_(disabled_id), | 32 disabled_id_(disabled_id), |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 int disabled_id) | 230 int disabled_id) |
| 231 : button_base_(NULL, normal_id, pressed_id, hover_id, disabled_id), | 231 : button_base_(NULL, normal_id, pressed_id, hover_id, disabled_id), |
| 232 theme_service_(NULL), | 232 theme_service_(NULL), |
| 233 forcing_chrome_theme_(false) { | 233 forcing_chrome_theme_(false) { |
| 234 Init(); | 234 Init(); |
| 235 | 235 |
| 236 // Initialize the theme stuff with no theme_provider. | 236 // Initialize the theme stuff with no theme_provider. |
| 237 SetBrowserTheme(); | 237 SetBrowserTheme(); |
| 238 } | 238 } |
| 239 | 239 |
| 240 CustomDrawButton::CustomDrawButton(GtkThemeService* theme_provider, | 240 CustomDrawButton::CustomDrawButton(ThemeServiceGtk* theme_provider, |
| 241 int normal_id, | 241 int normal_id, |
| 242 int pressed_id, | 242 int pressed_id, |
| 243 int hover_id, | 243 int hover_id, |
| 244 int disabled_id, | 244 int disabled_id, |
| 245 const char* stock_id, | 245 const char* stock_id, |
| 246 GtkIconSize stock_size) | 246 GtkIconSize stock_size) |
| 247 : button_base_(theme_provider, normal_id, pressed_id, hover_id, | 247 : button_base_(theme_provider, normal_id, pressed_id, hover_id, |
| 248 disabled_id), | 248 disabled_id), |
| 249 theme_service_(theme_provider), | 249 theme_service_(theme_provider), |
| 250 forcing_chrome_theme_(false) { | 250 forcing_chrome_theme_(false) { |
| 251 native_widget_.Own(gtk_image_new_from_stock(stock_id, stock_size)); | 251 native_widget_.Own(gtk_image_new_from_stock(stock_id, stock_size)); |
| 252 | 252 |
| 253 Init(); | 253 Init(); |
| 254 | 254 |
| 255 theme_service_->InitThemesFor(this); | 255 theme_service_->InitThemesFor(this); |
| 256 registrar_.Add(this, | 256 registrar_.Add(this, |
| 257 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 257 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 258 content::Source<ThemeService>(theme_provider)); | 258 content::Source<ThemeService>(theme_provider)); |
| 259 } | 259 } |
| 260 | 260 |
| 261 CustomDrawButton::CustomDrawButton(GtkThemeService* theme_provider, | 261 CustomDrawButton::CustomDrawButton(ThemeServiceGtk* theme_provider, |
| 262 int normal_id, | 262 int normal_id, |
| 263 int pressed_id, | 263 int pressed_id, |
| 264 int hover_id, | 264 int hover_id, |
| 265 int disabled_id, | 265 int disabled_id, |
| 266 GtkWidget* native_widget) | 266 GtkWidget* native_widget) |
| 267 : button_base_(theme_provider, normal_id, pressed_id, hover_id, | 267 : button_base_(theme_provider, normal_id, pressed_id, hover_id, |
| 268 disabled_id), | 268 disabled_id), |
| 269 native_widget_(native_widget), | 269 native_widget_(native_widget), |
| 270 theme_service_(theme_provider), | 270 theme_service_(theme_provider), |
| 271 forcing_chrome_theme_(false) { | 271 forcing_chrome_theme_(false) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 // Continue processing this expose event. | 340 // Continue processing this expose event. |
| 341 return FALSE; | 341 return FALSE; |
| 342 } else { | 342 } else { |
| 343 double hover_state = hover_controller_.GetCurrentValue(); | 343 double hover_state = hover_controller_.GetCurrentValue(); |
| 344 return button_base_.OnExpose(sender, e, hover_state); | 344 return button_base_.OnExpose(sender, e, hover_state); |
| 345 } | 345 } |
| 346 } | 346 } |
| 347 | 347 |
| 348 // static | 348 // static |
| 349 CustomDrawButton* CustomDrawButton::CloseButton( | 349 CustomDrawButton* CustomDrawButton::CloseButton( |
| 350 GtkThemeService* theme_provider) { | 350 ThemeServiceGtk* theme_provider) { |
| 351 CustomDrawButton* button = new CustomDrawButton(theme_provider, IDR_CLOSE_BAR, | 351 CustomDrawButton* button = new CustomDrawButton(theme_provider, IDR_CLOSE_BAR, |
| 352 IDR_CLOSE_BAR_P, IDR_CLOSE_BAR_H, 0, GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU); | 352 IDR_CLOSE_BAR_P, IDR_CLOSE_BAR_H, 0, GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU); |
| 353 return button; | 353 return button; |
| 354 } | 354 } |
| 355 | 355 |
| 356 void CustomDrawButton::SetBrowserTheme() { | 356 void CustomDrawButton::SetBrowserTheme() { |
| 357 if (UseGtkTheme()) { | 357 if (UseGtkTheme()) { |
| 358 if (native_widget_.get()) | 358 if (native_widget_.get()) |
| 359 gtk_button_set_image(GTK_BUTTON(widget()), native_widget_.get()); | 359 gtk_button_set_image(GTK_BUTTON(widget()), native_widget_.get()); |
| 360 gtk_widget_set_size_request(widget(), -1, -1); | 360 gtk_widget_set_size_request(widget(), -1, -1); |
| 361 gtk_widget_set_app_paintable(widget(), FALSE); | 361 gtk_widget_set_app_paintable(widget(), FALSE); |
| 362 } else { | 362 } else { |
| 363 if (native_widget_.get()) | 363 if (native_widget_.get()) |
| 364 gtk_button_set_image(GTK_BUTTON(widget()), NULL); | 364 gtk_button_set_image(GTK_BUTTON(widget()), NULL); |
| 365 gtk_widget_set_size_request(widget(), button_base_.Width(), | 365 gtk_widget_set_size_request(widget(), button_base_.Width(), |
| 366 button_base_.Height()); | 366 button_base_.Height()); |
| 367 | 367 |
| 368 gtk_widget_set_app_paintable(widget(), TRUE); | 368 gtk_widget_set_app_paintable(widget(), TRUE); |
| 369 } | 369 } |
| 370 | 370 |
| 371 gtk_chrome_button_set_use_gtk_rendering( | 371 gtk_chrome_button_set_use_gtk_rendering( |
| 372 GTK_CHROME_BUTTON(widget()), UseGtkTheme()); | 372 GTK_CHROME_BUTTON(widget()), UseGtkTheme()); |
| 373 } | 373 } |
| 374 | 374 |
| 375 bool CustomDrawButton::UseGtkTheme() { | 375 bool CustomDrawButton::UseGtkTheme() { |
| 376 return !forcing_chrome_theme_ && theme_service_ && | 376 return !forcing_chrome_theme_ && theme_service_ && |
| 377 theme_service_->UsingNativeTheme(); | 377 theme_service_->UsingNativeTheme(); |
| 378 } | 378 } |
| OLD | NEW |