| 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" |
| 11 #include "chrome/browser/ui/gtk/gtk_util.h" | 11 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 12 #include "chrome/common/chrome_notification_types.h" |
| 12 #include "content/common/notification_service.h" | 13 #include "content/common/notification_service.h" |
| 13 #include "grit/theme_resources_standard.h" | 14 #include "grit/theme_resources_standard.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 15 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/gfx/gtk_util.h" | 17 #include "ui/gfx/gtk_util.h" |
| 17 #include "ui/gfx/skbitmap_operations.h" | 18 #include "ui/gfx/skbitmap_operations.h" |
| 18 | 19 |
| 19 CustomDrawButtonBase::CustomDrawButtonBase(GtkThemeService* theme_provider, | 20 CustomDrawButtonBase::CustomDrawButtonBase(GtkThemeService* theme_provider, |
| 20 int normal_id, | 21 int normal_id, |
| 21 int pressed_id, | 22 int pressed_id, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 32 for (int i = 0; i < (GTK_STATE_INSENSITIVE + 1); ++i) | 33 for (int i = 0; i < (GTK_STATE_INSENSITIVE + 1); ++i) |
| 33 surfaces_[i].reset(new CairoCachedSurface); | 34 surfaces_[i].reset(new CairoCachedSurface); |
| 34 background_image_.reset(new CairoCachedSurface); | 35 background_image_.reset(new CairoCachedSurface); |
| 35 | 36 |
| 36 if (theme_provider) { | 37 if (theme_provider) { |
| 37 // Load images by pretending that we got a BROWSER_THEME_CHANGED | 38 // Load images by pretending that we got a BROWSER_THEME_CHANGED |
| 38 // notification. | 39 // notification. |
| 39 theme_provider->InitThemesFor(this); | 40 theme_provider->InitThemesFor(this); |
| 40 | 41 |
| 41 registrar_.Add(this, | 42 registrar_.Add(this, |
| 42 NotificationType::BROWSER_THEME_CHANGED, | 43 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 43 NotificationService::AllSources()); | 44 NotificationService::AllSources()); |
| 44 } else { | 45 } else { |
| 45 // Load the button images from the resource bundle. | 46 // Load the button images from the resource bundle. |
| 46 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 47 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 47 surfaces_[GTK_STATE_NORMAL]->UsePixbuf( | 48 surfaces_[GTK_STATE_NORMAL]->UsePixbuf( |
| 48 normal_id_ ? rb.GetRTLEnabledPixbufNamed(normal_id_) : NULL); | 49 normal_id_ ? rb.GetRTLEnabledPixbufNamed(normal_id_) : NULL); |
| 49 surfaces_[GTK_STATE_ACTIVE]->UsePixbuf( | 50 surfaces_[GTK_STATE_ACTIVE]->UsePixbuf( |
| 50 pressed_id_ ? rb.GetRTLEnabledPixbufNamed(pressed_id_) : NULL); | 51 pressed_id_ ? rb.GetRTLEnabledPixbufNamed(pressed_id_) : NULL); |
| 51 surfaces_[GTK_STATE_PRELIGHT]->UsePixbuf( | 52 surfaces_[GTK_STATE_PRELIGHT]->UsePixbuf( |
| 52 hover_id_ ? rb.GetRTLEnabledPixbufNamed(hover_id_) : NULL); | 53 hover_id_ ? rb.GetRTLEnabledPixbufNamed(hover_id_) : NULL); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } else { | 134 } else { |
| 134 SkBitmap img = | 135 SkBitmap img = |
| 135 SkBitmapOperations::CreateButtonBackground(color, *image, *mask); | 136 SkBitmapOperations::CreateButtonBackground(color, *image, *mask); |
| 136 | 137 |
| 137 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&img); | 138 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&img); |
| 138 background_image_->UsePixbuf(pixbuf); | 139 background_image_->UsePixbuf(pixbuf); |
| 139 g_object_unref(pixbuf); | 140 g_object_unref(pixbuf); |
| 140 } | 141 } |
| 141 } | 142 } |
| 142 | 143 |
| 143 void CustomDrawButtonBase::Observe(NotificationType type, | 144 void CustomDrawButtonBase::Observe(int type, |
| 144 const NotificationSource& source, const NotificationDetails& details) { | 145 const NotificationSource& source, const NotificationDetails& details) { |
| 145 DCHECK(theme_service_); | 146 DCHECK(theme_service_); |
| 146 DCHECK(NotificationType::BROWSER_THEME_CHANGED == type); | 147 DCHECK(chrome::NOTIFICATION_BROWSER_THEME_CHANGED == type); |
| 147 | 148 |
| 148 surfaces_[GTK_STATE_NORMAL]->UsePixbuf(normal_id_ ? | 149 surfaces_[GTK_STATE_NORMAL]->UsePixbuf(normal_id_ ? |
| 149 theme_service_->GetRTLEnabledPixbufNamed(normal_id_) : NULL); | 150 theme_service_->GetRTLEnabledPixbufNamed(normal_id_) : NULL); |
| 150 surfaces_[GTK_STATE_ACTIVE]->UsePixbuf(pressed_id_ ? | 151 surfaces_[GTK_STATE_ACTIVE]->UsePixbuf(pressed_id_ ? |
| 151 theme_service_->GetRTLEnabledPixbufNamed(pressed_id_) : NULL); | 152 theme_service_->GetRTLEnabledPixbufNamed(pressed_id_) : NULL); |
| 152 surfaces_[GTK_STATE_PRELIGHT]->UsePixbuf(hover_id_ ? | 153 surfaces_[GTK_STATE_PRELIGHT]->UsePixbuf(hover_id_ ? |
| 153 theme_service_->GetRTLEnabledPixbufNamed(hover_id_) : NULL); | 154 theme_service_->GetRTLEnabledPixbufNamed(hover_id_) : NULL); |
| 154 surfaces_[GTK_STATE_SELECTED]->UsePixbuf(NULL); | 155 surfaces_[GTK_STATE_SELECTED]->UsePixbuf(NULL); |
| 155 surfaces_[GTK_STATE_INSENSITIVE]->UsePixbuf(disabled_id_ ? | 156 surfaces_[GTK_STATE_INSENSITIVE]->UsePixbuf(disabled_id_ ? |
| 156 theme_service_->GetRTLEnabledPixbufNamed(disabled_id_) : NULL); | 157 theme_service_->GetRTLEnabledPixbufNamed(disabled_id_) : NULL); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 GtkIconSize stock_size) | 238 GtkIconSize stock_size) |
| 238 : button_base_(theme_provider, normal_id, pressed_id, hover_id, | 239 : button_base_(theme_provider, normal_id, pressed_id, hover_id, |
| 239 disabled_id), | 240 disabled_id), |
| 240 theme_service_(theme_provider) { | 241 theme_service_(theme_provider) { |
| 241 native_widget_.Own(gtk_image_new_from_stock(stock_id, stock_size)); | 242 native_widget_.Own(gtk_image_new_from_stock(stock_id, stock_size)); |
| 242 | 243 |
| 243 Init(); | 244 Init(); |
| 244 | 245 |
| 245 theme_service_->InitThemesFor(this); | 246 theme_service_->InitThemesFor(this); |
| 246 registrar_.Add(this, | 247 registrar_.Add(this, |
| 247 NotificationType::BROWSER_THEME_CHANGED, | 248 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 248 NotificationService::AllSources()); | 249 NotificationService::AllSources()); |
| 249 } | 250 } |
| 250 | 251 |
| 251 CustomDrawButton::CustomDrawButton(GtkThemeService* theme_provider, | 252 CustomDrawButton::CustomDrawButton(GtkThemeService* theme_provider, |
| 252 int normal_id, | 253 int normal_id, |
| 253 int pressed_id, | 254 int pressed_id, |
| 254 int hover_id, | 255 int hover_id, |
| 255 int disabled_id, | 256 int disabled_id, |
| 256 GtkWidget* native_widget) | 257 GtkWidget* native_widget) |
| 257 : button_base_(theme_provider, normal_id, pressed_id, hover_id, | 258 : button_base_(theme_provider, normal_id, pressed_id, hover_id, |
| 258 disabled_id), | 259 disabled_id), |
| 259 native_widget_(native_widget), | 260 native_widget_(native_widget), |
| 260 theme_service_(theme_provider) { | 261 theme_service_(theme_provider) { |
| 261 Init(); | 262 Init(); |
| 262 | 263 |
| 263 theme_service_->InitThemesFor(this); | 264 theme_service_->InitThemesFor(this); |
| 264 registrar_.Add(this, | 265 registrar_.Add(this, |
| 265 NotificationType::BROWSER_THEME_CHANGED, | 266 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 266 NotificationService::AllSources()); | 267 NotificationService::AllSources()); |
| 267 } | 268 } |
| 268 | 269 |
| 269 CustomDrawButton::~CustomDrawButton() { | 270 CustomDrawButton::~CustomDrawButton() { |
| 270 widget_.Destroy(); | 271 widget_.Destroy(); |
| 271 native_widget_.Destroy(); | 272 native_widget_.Destroy(); |
| 272 } | 273 } |
| 273 | 274 |
| 274 void CustomDrawButton::Init() { | 275 void CustomDrawButton::Init() { |
| 275 widget_.Own(gtk_chrome_button_new()); | 276 widget_.Own(gtk_chrome_button_new()); |
| 276 GTK_WIDGET_UNSET_FLAGS(widget(), GTK_CAN_FOCUS); | 277 GTK_WIDGET_UNSET_FLAGS(widget(), GTK_CAN_FOCUS); |
| 277 g_signal_connect(widget(), "expose-event", | 278 g_signal_connect(widget(), "expose-event", |
| 278 G_CALLBACK(OnCustomExposeThunk), this); | 279 G_CALLBACK(OnCustomExposeThunk), this); |
| 279 hover_controller_.Init(widget()); | 280 hover_controller_.Init(widget()); |
| 280 } | 281 } |
| 281 | 282 |
| 282 void CustomDrawButton::Observe(NotificationType type, | 283 void CustomDrawButton::Observe(int type, |
| 283 const NotificationSource& source, const NotificationDetails& details) { | 284 const NotificationSource& source, const NotificationDetails& details) { |
| 284 DCHECK(NotificationType::BROWSER_THEME_CHANGED == type); | 285 DCHECK(chrome::NOTIFICATION_BROWSER_THEME_CHANGED == type); |
| 285 SetBrowserTheme(); | 286 SetBrowserTheme(); |
| 286 } | 287 } |
| 287 | 288 |
| 288 void CustomDrawButton::SetPaintOverride(GtkStateType state) { | 289 void CustomDrawButton::SetPaintOverride(GtkStateType state) { |
| 289 button_base_.set_paint_override(state); | 290 button_base_.set_paint_override(state); |
| 290 gtk_chrome_button_set_paint_state(GTK_CHROME_BUTTON(widget()), state); | 291 gtk_chrome_button_set_paint_state(GTK_CHROME_BUTTON(widget()), state); |
| 291 gtk_widget_queue_draw(widget()); | 292 gtk_widget_queue_draw(widget()); |
| 292 } | 293 } |
| 293 | 294 |
| 294 void CustomDrawButton::UnsetPaintOverride() { | 295 void CustomDrawButton::UnsetPaintOverride() { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 gtk_widget_set_app_paintable(widget(), TRUE); | 337 gtk_widget_set_app_paintable(widget(), TRUE); |
| 337 } | 338 } |
| 338 | 339 |
| 339 gtk_chrome_button_set_use_gtk_rendering( | 340 gtk_chrome_button_set_use_gtk_rendering( |
| 340 GTK_CHROME_BUTTON(widget()), UseGtkTheme()); | 341 GTK_CHROME_BUTTON(widget()), UseGtkTheme()); |
| 341 } | 342 } |
| 342 | 343 |
| 343 bool CustomDrawButton::UseGtkTheme() { | 344 bool CustomDrawButton::UseGtkTheme() { |
| 344 return theme_service_ && theme_service_->UsingNativeTheme(); | 345 return theme_service_ && theme_service_->UsingNativeTheme(); |
| 345 } | 346 } |
| OLD | NEW |