OLD | NEW |
1 // Copyright (c) 2010 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, | 22 int normal_id, |
23 int pressed_id, | 23 int pressed_id, |
24 int hover_id, | 24 int hover_id, |
25 int disabled_id, | 25 int disabled_id) |
26 int background_id) | |
27 : background_image_(NULL), | 26 : background_image_(NULL), |
28 paint_override_(-1), | 27 paint_override_(-1), |
29 normal_id_(normal_id), | 28 normal_id_(normal_id), |
30 pressed_id_(pressed_id), | 29 pressed_id_(pressed_id), |
31 hover_id_(hover_id), | 30 hover_id_(hover_id), |
32 disabled_id_(disabled_id), | 31 disabled_id_(disabled_id), |
33 button_background_id_(background_id), | |
34 theme_provider_(theme_provider), | 32 theme_provider_(theme_provider), |
35 flipped_(false) { | 33 flipped_(false) { |
36 for (int i = 0; i < (GTK_STATE_INSENSITIVE + 1); ++i) | 34 for (int i = 0; i < (GTK_STATE_INSENSITIVE + 1); ++i) |
37 surfaces_[i].reset(new CairoCachedSurface); | 35 surfaces_[i].reset(new CairoCachedSurface); |
38 background_image_.reset(new CairoCachedSurface); | 36 background_image_.reset(new CairoCachedSurface); |
39 | 37 |
40 if (theme_provider) { | 38 if (theme_provider) { |
41 // Load images by pretending that we got a BROWSER_THEME_CHANGED | 39 // Load images by pretending that we got a BROWSER_THEME_CHANGED |
42 // notification. | 40 // notification. |
43 theme_provider->InitThemesFor(this); | 41 theme_provider->InitThemesFor(this); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 145 |
148 surfaces_[GTK_STATE_NORMAL]->UsePixbuf(normal_id_ ? | 146 surfaces_[GTK_STATE_NORMAL]->UsePixbuf(normal_id_ ? |
149 theme_provider_->GetRTLEnabledPixbufNamed(normal_id_) : NULL); | 147 theme_provider_->GetRTLEnabledPixbufNamed(normal_id_) : NULL); |
150 surfaces_[GTK_STATE_ACTIVE]->UsePixbuf(pressed_id_ ? | 148 surfaces_[GTK_STATE_ACTIVE]->UsePixbuf(pressed_id_ ? |
151 theme_provider_->GetRTLEnabledPixbufNamed(pressed_id_) : NULL); | 149 theme_provider_->GetRTLEnabledPixbufNamed(pressed_id_) : NULL); |
152 surfaces_[GTK_STATE_PRELIGHT]->UsePixbuf(hover_id_ ? | 150 surfaces_[GTK_STATE_PRELIGHT]->UsePixbuf(hover_id_ ? |
153 theme_provider_->GetRTLEnabledPixbufNamed(hover_id_) : NULL); | 151 theme_provider_->GetRTLEnabledPixbufNamed(hover_id_) : NULL); |
154 surfaces_[GTK_STATE_SELECTED]->UsePixbuf(NULL); | 152 surfaces_[GTK_STATE_SELECTED]->UsePixbuf(NULL); |
155 surfaces_[GTK_STATE_INSENSITIVE]->UsePixbuf(disabled_id_ ? | 153 surfaces_[GTK_STATE_INSENSITIVE]->UsePixbuf(disabled_id_ ? |
156 theme_provider_->GetRTLEnabledPixbufNamed(disabled_id_) : NULL); | 154 theme_provider_->GetRTLEnabledPixbufNamed(disabled_id_) : NULL); |
157 | |
158 // Use the tinted background in some themes. | |
159 if (button_background_id_) { | |
160 SkColor color = theme_provider_->GetColor( | |
161 BrowserThemeProvider::COLOR_BUTTON_BACKGROUND); | |
162 SkBitmap* background = theme_provider_->GetBitmapNamed( | |
163 IDR_THEME_BUTTON_BACKGROUND); | |
164 SkBitmap* mask = theme_provider_->GetBitmapNamed(button_background_id_); | |
165 | |
166 SetBackground(color, background, mask); | |
167 } | |
168 } | 155 } |
169 | 156 |
170 CairoCachedSurface* CustomDrawButtonBase::PixbufForState(int state) { | 157 CairoCachedSurface* CustomDrawButtonBase::PixbufForState(int state) { |
171 CairoCachedSurface* pixbuf = surfaces_[state].get(); | 158 CairoCachedSurface* pixbuf = surfaces_[state].get(); |
172 | 159 |
173 // Fall back to the default image if we don't have one for this state. | 160 // Fall back to the default image if we don't have one for this state. |
174 if (!pixbuf || !pixbuf->valid()) | 161 if (!pixbuf || !pixbuf->valid()) |
175 pixbuf = surfaces_[GTK_STATE_NORMAL].get(); | 162 pixbuf = surfaces_[GTK_STATE_NORMAL].get(); |
176 | 163 |
177 return pixbuf; | 164 return pixbuf; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 controller->slide_animation_.Hide(); | 215 controller->slide_animation_.Hide(); |
229 return FALSE; | 216 return FALSE; |
230 } | 217 } |
231 | 218 |
232 // CustomDrawButton ------------------------------------------------------------ | 219 // CustomDrawButton ------------------------------------------------------------ |
233 | 220 |
234 CustomDrawButton::CustomDrawButton(int normal_id, | 221 CustomDrawButton::CustomDrawButton(int normal_id, |
235 int pressed_id, | 222 int pressed_id, |
236 int hover_id, | 223 int hover_id, |
237 int disabled_id) | 224 int disabled_id) |
238 : button_base_(NULL, normal_id, pressed_id, hover_id, disabled_id, 0), | 225 : button_base_(NULL, normal_id, pressed_id, hover_id, disabled_id), |
239 theme_provider_(NULL), | 226 theme_provider_(NULL), |
240 gtk_stock_name_(NULL), | 227 gtk_stock_name_(NULL), |
241 icon_size_(GTK_ICON_SIZE_INVALID) { | 228 icon_size_(GTK_ICON_SIZE_INVALID) { |
242 Init(); | 229 Init(); |
243 | 230 |
244 // Initialize the theme stuff with no theme_provider. | 231 // Initialize the theme stuff with no theme_provider. |
245 SetBrowserTheme(); | 232 SetBrowserTheme(); |
246 } | 233 } |
247 | 234 |
248 CustomDrawButton::CustomDrawButton(GtkThemeProvider* theme_provider, | 235 CustomDrawButton::CustomDrawButton(GtkThemeProvider* theme_provider, |
249 int normal_id, | 236 int normal_id, |
250 int pressed_id, | 237 int pressed_id, |
251 int hover_id, | 238 int hover_id, |
252 int disabled_id, | 239 int disabled_id, |
253 int background_id, | |
254 const char* stock_id, | 240 const char* stock_id, |
255 GtkIconSize stock_size) | 241 GtkIconSize stock_size) |
256 : button_base_(theme_provider, normal_id, pressed_id, hover_id, | 242 : button_base_(theme_provider, normal_id, pressed_id, hover_id, |
257 disabled_id, background_id), | 243 disabled_id), |
258 theme_provider_(theme_provider), | 244 theme_provider_(theme_provider), |
259 gtk_stock_name_(stock_id), | 245 gtk_stock_name_(stock_id), |
260 icon_size_(stock_size) { | 246 icon_size_(stock_size) { |
261 Init(); | 247 Init(); |
262 | 248 |
263 theme_provider_->InitThemesFor(this); | 249 theme_provider_->InitThemesFor(this); |
264 registrar_.Add(this, | 250 registrar_.Add(this, |
265 NotificationType::BROWSER_THEME_CHANGED, | 251 NotificationType::BROWSER_THEME_CHANGED, |
266 NotificationService::AllSources()); | 252 NotificationService::AllSources()); |
267 } | 253 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 return FALSE; | 296 return FALSE; |
311 } else { | 297 } else { |
312 double hover_state = button->hover_controller_.GetCurrentValue(); | 298 double hover_state = button->hover_controller_.GetCurrentValue(); |
313 return button->button_base_.OnExpose(widget, e, hover_state); | 299 return button->button_base_.OnExpose(widget, e, hover_state); |
314 } | 300 } |
315 } | 301 } |
316 | 302 |
317 // static | 303 // static |
318 CustomDrawButton* CustomDrawButton::CloseButton( | 304 CustomDrawButton* CustomDrawButton::CloseButton( |
319 GtkThemeProvider* theme_provider) { | 305 GtkThemeProvider* theme_provider) { |
320 CustomDrawButton* button = new CustomDrawButton( | 306 CustomDrawButton* button = new CustomDrawButton(theme_provider, IDR_CLOSE_BAR, |
321 theme_provider, IDR_CLOSE_BAR, IDR_CLOSE_BAR_P, | 307 IDR_CLOSE_BAR_P, IDR_CLOSE_BAR_H, 0, GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU); |
322 IDR_CLOSE_BAR_H, 0, 0, GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU); | |
323 return button; | 308 return button; |
324 } | 309 } |
325 | 310 |
326 void CustomDrawButton::SetBrowserTheme() { | 311 void CustomDrawButton::SetBrowserTheme() { |
327 bool use_gtk = theme_provider_ && theme_provider_->UseGtkTheme(); | 312 bool use_gtk = theme_provider_ && theme_provider_->UseGtkTheme(); |
328 | 313 |
329 if (use_gtk && gtk_stock_name_) { | 314 if (use_gtk && gtk_stock_name_) { |
330 gtk_button_set_image( | 315 gtk_button_set_image( |
331 GTK_BUTTON(widget()), | 316 GTK_BUTTON(widget()), |
332 gtk_image_new_from_stock(gtk_stock_name_, icon_size_)); | 317 gtk_image_new_from_stock(gtk_stock_name_, icon_size_)); |
333 gtk_widget_set_size_request(widget(), -1, -1); | 318 gtk_widget_set_size_request(widget(), -1, -1); |
334 gtk_widget_set_app_paintable(widget(), FALSE); | 319 gtk_widget_set_app_paintable(widget(), FALSE); |
335 } else { | 320 } else { |
336 gtk_widget_set_size_request(widget(), button_base_.Width(), | 321 gtk_widget_set_size_request(widget(), button_base_.Width(), |
337 button_base_.Height()); | 322 button_base_.Height()); |
338 | 323 |
339 gtk_widget_set_app_paintable(widget(), TRUE); | 324 gtk_widget_set_app_paintable(widget(), TRUE); |
340 } | 325 } |
341 | 326 |
342 gtk_chrome_button_set_use_gtk_rendering( | 327 gtk_chrome_button_set_use_gtk_rendering( |
343 GTK_CHROME_BUTTON(widget()), use_gtk); | 328 GTK_CHROME_BUTTON(widget()), use_gtk); |
344 } | 329 } |
OLD | NEW |