| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/theme_provider.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "chrome/browser/gtk/cairo_cached_surface.h" | 11 #include "chrome/browser/gtk/cairo_cached_surface.h" |
| 12 #include "chrome/browser/gtk/gtk_chrome_button.h" | 12 #include "chrome/browser/gtk/gtk_chrome_button.h" |
| 13 #include "chrome/browser/gtk/gtk_theme_provider.h" | 13 #include "chrome/browser/gtk/gtk_theme_provider.h" |
| 14 #include "chrome/browser/gtk/gtk_util.h" | 14 #include "chrome/browser/gtk/gtk_util.h" |
| 15 #include "chrome/common/notification_service.h" | 15 #include "chrome/common/notification_service.h" |
| 16 #include "gfx/gtk_util.h" | 16 #include "gfx/gtk_util.h" |
| 17 #include "gfx/skbitmap_operations.h" | 17 #include "gfx/skbitmap_operations.h" |
| 18 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 19 #include "third_party/skia/include/core/SkBitmap.h" | 19 #include "third_party/skia/include/core/SkBitmap.h" |
| 20 | 20 |
| 21 CustomDrawButtonBase::CustomDrawButtonBase(GtkThemeProvider* theme_provider, | 21 CustomDrawButtonBase::CustomDrawButtonBase(GtkThemeProvider* theme_provider, |
| 22 int normal_id, int active_id, int highlight_id, int depressed_id, | 22 int normal_id, |
| 23 int background_id) | 23 int pressed_id, |
| 24 int hover_id, |
| 25 int disabled_id, |
| 26 int background_id) |
| 24 : background_image_(NULL), | 27 : background_image_(NULL), |
| 25 paint_override_(-1), | 28 paint_override_(-1), |
| 26 normal_id_(normal_id), | 29 normal_id_(normal_id), |
| 27 active_id_(active_id), | 30 pressed_id_(pressed_id), |
| 28 highlight_id_(highlight_id), | 31 hover_id_(hover_id), |
| 29 depressed_id_(depressed_id), | 32 disabled_id_(disabled_id), |
| 30 button_background_id_(background_id), | 33 button_background_id_(background_id), |
| 31 theme_provider_(theme_provider), | 34 theme_provider_(theme_provider), |
| 32 flipped_(false) { | 35 flipped_(false) { |
| 33 for (int i = 0; i < (GTK_STATE_INSENSITIVE + 1); ++i) | 36 for (int i = 0; i < (GTK_STATE_INSENSITIVE + 1); ++i) |
| 34 surfaces_[i].reset(new CairoCachedSurface); | 37 surfaces_[i].reset(new CairoCachedSurface); |
| 35 background_image_.reset(new CairoCachedSurface); | 38 background_image_.reset(new CairoCachedSurface); |
| 36 | 39 |
| 37 if (theme_provider) { | 40 if (theme_provider) { |
| 38 // Load images by pretending that we got a BROWSER_THEME_CHANGED | 41 // Load images by pretending that we got a BROWSER_THEME_CHANGED |
| 39 // notification. | 42 // notification. |
| 40 theme_provider->InitThemesFor(this); | 43 theme_provider->InitThemesFor(this); |
| 41 | 44 |
| 42 registrar_.Add(this, | 45 registrar_.Add(this, |
| 43 NotificationType::BROWSER_THEME_CHANGED, | 46 NotificationType::BROWSER_THEME_CHANGED, |
| 44 NotificationService::AllSources()); | 47 NotificationService::AllSources()); |
| 45 } else { | 48 } else { |
| 46 // Load the button images from the resource bundle. | 49 // Load the button images from the resource bundle. |
| 47 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 50 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 48 surfaces_[GTK_STATE_NORMAL]->UsePixbuf( | 51 surfaces_[GTK_STATE_NORMAL]->UsePixbuf( |
| 49 normal_id ? rb.GetRTLEnabledPixbufNamed(normal_id) : NULL); | 52 normal_id_ ? rb.GetRTLEnabledPixbufNamed(normal_id_) : NULL); |
| 50 surfaces_[GTK_STATE_ACTIVE]->UsePixbuf( | 53 surfaces_[GTK_STATE_ACTIVE]->UsePixbuf( |
| 51 active_id ? rb.GetRTLEnabledPixbufNamed(active_id) : NULL); | 54 pressed_id_ ? rb.GetRTLEnabledPixbufNamed(pressed_id_) : NULL); |
| 52 surfaces_[GTK_STATE_PRELIGHT]->UsePixbuf( | 55 surfaces_[GTK_STATE_PRELIGHT]->UsePixbuf( |
| 53 highlight_id ? rb.GetRTLEnabledPixbufNamed(highlight_id) : NULL); | 56 hover_id_ ? rb.GetRTLEnabledPixbufNamed(hover_id_) : NULL); |
| 54 surfaces_[GTK_STATE_SELECTED]->UsePixbuf(NULL); | 57 surfaces_[GTK_STATE_SELECTED]->UsePixbuf(NULL); |
| 55 surfaces_[GTK_STATE_INSENSITIVE]->UsePixbuf( | 58 surfaces_[GTK_STATE_INSENSITIVE]->UsePixbuf( |
| 56 depressed_id ? rb.GetRTLEnabledPixbufNamed(depressed_id) : NULL); | 59 disabled_id_ ? rb.GetRTLEnabledPixbufNamed(disabled_id_) : NULL); |
| 57 } | 60 } |
| 58 } | 61 } |
| 59 | 62 |
| 60 CustomDrawButtonBase::~CustomDrawButtonBase() { | 63 CustomDrawButtonBase::~CustomDrawButtonBase() { |
| 61 } | 64 } |
| 62 | 65 |
| 63 int CustomDrawButtonBase::Width() const { | 66 int CustomDrawButtonBase::Width() const { |
| 64 return surfaces_[0]->Width(); | 67 return surfaces_[0]->Width(); |
| 65 } | 68 } |
| 66 | 69 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 } | 140 } |
| 138 } | 141 } |
| 139 | 142 |
| 140 void CustomDrawButtonBase::Observe(NotificationType type, | 143 void CustomDrawButtonBase::Observe(NotificationType type, |
| 141 const NotificationSource& source, const NotificationDetails& details) { | 144 const NotificationSource& source, const NotificationDetails& details) { |
| 142 DCHECK(theme_provider_); | 145 DCHECK(theme_provider_); |
| 143 DCHECK(NotificationType::BROWSER_THEME_CHANGED == type); | 146 DCHECK(NotificationType::BROWSER_THEME_CHANGED == type); |
| 144 | 147 |
| 145 surfaces_[GTK_STATE_NORMAL]->UsePixbuf(normal_id_ ? | 148 surfaces_[GTK_STATE_NORMAL]->UsePixbuf(normal_id_ ? |
| 146 theme_provider_->GetRTLEnabledPixbufNamed(normal_id_) : NULL); | 149 theme_provider_->GetRTLEnabledPixbufNamed(normal_id_) : NULL); |
| 147 surfaces_[GTK_STATE_ACTIVE]->UsePixbuf(active_id_ ? | 150 surfaces_[GTK_STATE_ACTIVE]->UsePixbuf(pressed_id_ ? |
| 148 theme_provider_->GetRTLEnabledPixbufNamed(active_id_) : NULL); | 151 theme_provider_->GetRTLEnabledPixbufNamed(pressed_id_) : NULL); |
| 149 surfaces_[GTK_STATE_PRELIGHT]->UsePixbuf(highlight_id_ ? | 152 surfaces_[GTK_STATE_PRELIGHT]->UsePixbuf(hover_id_ ? |
| 150 theme_provider_->GetRTLEnabledPixbufNamed(highlight_id_) : NULL); | 153 theme_provider_->GetRTLEnabledPixbufNamed(hover_id_) : NULL); |
| 151 surfaces_[GTK_STATE_SELECTED]->UsePixbuf(NULL); | 154 surfaces_[GTK_STATE_SELECTED]->UsePixbuf(NULL); |
| 152 surfaces_[GTK_STATE_INSENSITIVE]->UsePixbuf(depressed_id_ ? | 155 surfaces_[GTK_STATE_INSENSITIVE]->UsePixbuf(disabled_id_ ? |
| 153 theme_provider_->GetRTLEnabledPixbufNamed(depressed_id_) : NULL); | 156 theme_provider_->GetRTLEnabledPixbufNamed(disabled_id_) : NULL); |
| 154 | 157 |
| 155 // Use the tinted background in some themes. | 158 // Use the tinted background in some themes. |
| 156 if (button_background_id_) { | 159 if (button_background_id_) { |
| 157 SkColor color = theme_provider_->GetColor( | 160 SkColor color = theme_provider_->GetColor( |
| 158 BrowserThemeProvider::COLOR_BUTTON_BACKGROUND); | 161 BrowserThemeProvider::COLOR_BUTTON_BACKGROUND); |
| 159 SkBitmap* background = theme_provider_->GetBitmapNamed( | 162 SkBitmap* background = theme_provider_->GetBitmapNamed( |
| 160 IDR_THEME_BUTTON_BACKGROUND); | 163 IDR_THEME_BUTTON_BACKGROUND); |
| 161 SkBitmap* mask = theme_provider_->GetBitmapNamed(button_background_id_); | 164 SkBitmap* mask = theme_provider_->GetBitmapNamed(button_background_id_); |
| 162 | 165 |
| 163 SetBackground(color, background, mask); | 166 SetBackground(color, background, mask); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 // When the user is holding a mouse button, we don't want to animate. | 224 // When the user is holding a mouse button, we don't want to animate. |
| 222 if (event->state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)) | 225 if (event->state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)) |
| 223 controller->slide_animation_.Reset(); | 226 controller->slide_animation_.Reset(); |
| 224 else | 227 else |
| 225 controller->slide_animation_.Hide(); | 228 controller->slide_animation_.Hide(); |
| 226 return FALSE; | 229 return FALSE; |
| 227 } | 230 } |
| 228 | 231 |
| 229 // CustomDrawButton ------------------------------------------------------------ | 232 // CustomDrawButton ------------------------------------------------------------ |
| 230 | 233 |
| 231 CustomDrawButton::CustomDrawButton(int normal_id, int active_id, | 234 CustomDrawButton::CustomDrawButton(int normal_id, |
| 232 int highlight_id, int depressed_id) | 235 int pressed_id, |
| 233 : button_base_(NULL, normal_id, active_id, highlight_id, depressed_id, 0), | 236 int hover_id, |
| 237 int disabled_id) |
| 238 : button_base_(NULL, normal_id, pressed_id, hover_id, disabled_id, 0), |
| 234 theme_provider_(NULL), | 239 theme_provider_(NULL), |
| 235 gtk_stock_name_(NULL), | 240 gtk_stock_name_(NULL), |
| 236 icon_size_(GTK_ICON_SIZE_INVALID) { | 241 icon_size_(GTK_ICON_SIZE_INVALID) { |
| 237 Init(); | 242 Init(); |
| 238 | 243 |
| 239 // Initialize the theme stuff with no theme_provider. | 244 // Initialize the theme stuff with no theme_provider. |
| 240 SetBrowserTheme(); | 245 SetBrowserTheme(); |
| 241 } | 246 } |
| 242 | 247 |
| 243 CustomDrawButton::CustomDrawButton(GtkThemeProvider* theme_provider, | 248 CustomDrawButton::CustomDrawButton(GtkThemeProvider* theme_provider, |
| 244 int normal_id, int active_id, int highlight_id, int depressed_id, | 249 int normal_id, |
| 245 int background_id, const char* stock_id, GtkIconSize stock_size) | 250 int pressed_id, |
| 246 : button_base_(theme_provider, normal_id, active_id, highlight_id, | 251 int hover_id, |
| 247 depressed_id, background_id), | 252 int disabled_id, |
| 253 int background_id, |
| 254 const char* stock_id, |
| 255 GtkIconSize stock_size) |
| 256 : button_base_(theme_provider, normal_id, pressed_id, hover_id, |
| 257 disabled_id, background_id), |
| 248 theme_provider_(theme_provider), | 258 theme_provider_(theme_provider), |
| 249 gtk_stock_name_(stock_id), | 259 gtk_stock_name_(stock_id), |
| 250 icon_size_(stock_size) { | 260 icon_size_(stock_size) { |
| 251 Init(); | 261 Init(); |
| 252 | 262 |
| 253 theme_provider_->InitThemesFor(this); | 263 theme_provider_->InitThemesFor(this); |
| 254 registrar_.Add(this, | 264 registrar_.Add(this, |
| 255 NotificationType::BROWSER_THEME_CHANGED, | 265 NotificationType::BROWSER_THEME_CHANGED, |
| 256 NotificationService::AllSources()); | 266 NotificationService::AllSources()); |
| 257 } | 267 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 } else { | 335 } else { |
| 326 gtk_widget_set_size_request(widget(), button_base_.Width(), | 336 gtk_widget_set_size_request(widget(), button_base_.Width(), |
| 327 button_base_.Height()); | 337 button_base_.Height()); |
| 328 | 338 |
| 329 gtk_widget_set_app_paintable(widget(), TRUE); | 339 gtk_widget_set_app_paintable(widget(), TRUE); |
| 330 } | 340 } |
| 331 | 341 |
| 332 gtk_chrome_button_set_use_gtk_rendering( | 342 gtk_chrome_button_set_use_gtk_rendering( |
| 333 GTK_CHROME_BUTTON(widget()), use_gtk); | 343 GTK_CHROME_BUTTON(widget()), use_gtk); |
| 334 } | 344 } |
| OLD | NEW |