Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Side by Side Diff: chrome/browser/ui/gtk/custom_button.cc

Issue 10337010: Revert r123782. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "chrome/browser/ui/gtk/gtk_util.h" 12 #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/image/image.h" 20 #include "ui/gfx/image/image.h"
21 #include "ui/gfx/skbitmap_operations.h" 21 #include "ui/gfx/skbitmap_operations.h"
22 22
23 namespace { 23 namespace {
24 24
25 GdkPixbuf* GetImage(int resource_id) { 25 GdkPixbuf* GetImage(int resource_id) {
26 if (!resource_id) 26 if (!resource_id)
27 return NULL; 27 return NULL;
28 return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( 28 return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
29 resource_id, ui::ResourceBundle::RTL_ENABLED).ToGdkPixbuf(); 29 resource_id, ui::ResourceBundle::RTL_ENABLED).ToGdkPixbuf();
30 } 30 }
31 31
32 } // namespace 32 } // namespace
33 33
34 CustomDrawButtonBase::CustomDrawButtonBase(ThemeServiceGtk* theme_provider, 34 CustomDrawButtonBase::CustomDrawButtonBase(GtkThemeService* theme_provider,
35 int normal_id, 35 int normal_id,
36 int pressed_id, 36 int pressed_id,
37 int hover_id, 37 int hover_id,
38 int disabled_id) 38 int disabled_id)
39 : background_image_(NULL), 39 : background_image_(NULL),
40 paint_override_(-1), 40 paint_override_(-1),
41 normal_id_(normal_id), 41 normal_id_(normal_id),
42 pressed_id_(pressed_id), 42 pressed_id_(pressed_id),
43 hover_id_(hover_id), 43 hover_id_(hover_id),
44 disabled_id_(disabled_id), 44 disabled_id_(disabled_id),
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 int disabled_id) 237 int disabled_id)
238 : button_base_(NULL, normal_id, pressed_id, hover_id, disabled_id), 238 : button_base_(NULL, normal_id, pressed_id, hover_id, disabled_id),
239 theme_service_(NULL), 239 theme_service_(NULL),
240 forcing_chrome_theme_(false) { 240 forcing_chrome_theme_(false) {
241 Init(); 241 Init();
242 242
243 // Initialize the theme stuff with no theme_provider. 243 // Initialize the theme stuff with no theme_provider.
244 SetBrowserTheme(); 244 SetBrowserTheme();
245 } 245 }
246 246
247 CustomDrawButton::CustomDrawButton(ThemeServiceGtk* theme_provider, 247 CustomDrawButton::CustomDrawButton(GtkThemeService* theme_provider,
248 int normal_id, 248 int normal_id,
249 int pressed_id, 249 int pressed_id,
250 int hover_id, 250 int hover_id,
251 int disabled_id, 251 int disabled_id,
252 const char* stock_id, 252 const char* stock_id,
253 GtkIconSize stock_size) 253 GtkIconSize stock_size)
254 : button_base_(theme_provider, normal_id, pressed_id, hover_id, 254 : button_base_(theme_provider, normal_id, pressed_id, hover_id,
255 disabled_id), 255 disabled_id),
256 theme_service_(theme_provider), 256 theme_service_(theme_provider),
257 forcing_chrome_theme_(false) { 257 forcing_chrome_theme_(false) {
258 native_widget_.Own(gtk_image_new_from_stock(stock_id, stock_size)); 258 native_widget_.Own(gtk_image_new_from_stock(stock_id, stock_size));
259 259
260 Init(); 260 Init();
261 261
262 theme_service_->InitThemesFor(this); 262 theme_service_->InitThemesFor(this);
263 registrar_.Add(this, 263 registrar_.Add(this,
264 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 264 chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
265 content::Source<ThemeService>(theme_provider)); 265 content::Source<ThemeService>(theme_provider));
266 } 266 }
267 267
268 CustomDrawButton::CustomDrawButton(ThemeServiceGtk* theme_provider, 268 CustomDrawButton::CustomDrawButton(GtkThemeService* theme_provider,
269 int normal_id, 269 int normal_id,
270 int pressed_id, 270 int pressed_id,
271 int hover_id, 271 int hover_id,
272 int disabled_id, 272 int disabled_id,
273 GtkWidget* native_widget) 273 GtkWidget* native_widget)
274 : button_base_(theme_provider, normal_id, pressed_id, hover_id, 274 : button_base_(theme_provider, normal_id, pressed_id, hover_id,
275 disabled_id), 275 disabled_id),
276 native_widget_(native_widget), 276 native_widget_(native_widget),
277 theme_service_(theme_provider), 277 theme_service_(theme_provider),
278 forcing_chrome_theme_(false) { 278 forcing_chrome_theme_(false) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 // Continue processing this expose event. 347 // Continue processing this expose event.
348 return FALSE; 348 return FALSE;
349 } else { 349 } else {
350 double hover_state = hover_controller_.GetCurrentValue(); 350 double hover_state = hover_controller_.GetCurrentValue();
351 return button_base_.OnExpose(sender, e, hover_state); 351 return button_base_.OnExpose(sender, e, hover_state);
352 } 352 }
353 } 353 }
354 354
355 // static 355 // static
356 CustomDrawButton* CustomDrawButton::CloseButton( 356 CustomDrawButton* CustomDrawButton::CloseButton(
357 ThemeServiceGtk* theme_provider) { 357 GtkThemeService* theme_provider) {
358 CustomDrawButton* button = new CustomDrawButton(theme_provider, IDR_CLOSE_BAR, 358 CustomDrawButton* button = new CustomDrawButton(theme_provider, IDR_CLOSE_BAR,
359 IDR_CLOSE_BAR_P, IDR_CLOSE_BAR_H, 0, GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU); 359 IDR_CLOSE_BAR_P, IDR_CLOSE_BAR_H, 0, GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
360 return button; 360 return button;
361 } 361 }
362 362
363 void CustomDrawButton::SetBrowserTheme() { 363 void CustomDrawButton::SetBrowserTheme() {
364 if (UseGtkTheme()) { 364 if (UseGtkTheme()) {
365 if (native_widget_.get()) 365 if (native_widget_.get())
366 gtk_button_set_image(GTK_BUTTON(widget()), native_widget_.get()); 366 gtk_button_set_image(GTK_BUTTON(widget()), native_widget_.get());
367 gtk_widget_set_size_request(widget(), -1, -1); 367 gtk_widget_set_size_request(widget(), -1, -1);
368 gtk_widget_set_app_paintable(widget(), FALSE); 368 gtk_widget_set_app_paintable(widget(), FALSE);
369 } else { 369 } else {
370 if (native_widget_.get()) 370 if (native_widget_.get())
371 gtk_button_set_image(GTK_BUTTON(widget()), NULL); 371 gtk_button_set_image(GTK_BUTTON(widget()), NULL);
372 gtk_widget_set_size_request(widget(), button_base_.Width(), 372 gtk_widget_set_size_request(widget(), button_base_.Width(),
373 button_base_.Height()); 373 button_base_.Height());
374 374
375 gtk_widget_set_app_paintable(widget(), TRUE); 375 gtk_widget_set_app_paintable(widget(), TRUE);
376 } 376 }
377 377
378 gtk_chrome_button_set_use_gtk_rendering( 378 gtk_chrome_button_set_use_gtk_rendering(
379 GTK_CHROME_BUTTON(widget()), UseGtkTheme()); 379 GTK_CHROME_BUTTON(widget()), UseGtkTheme());
380 } 380 }
381 381
382 bool CustomDrawButton::UseGtkTheme() { 382 bool CustomDrawButton::UseGtkTheme() {
383 return !forcing_chrome_theme_ && theme_service_ && 383 return !forcing_chrome_theme_ && theme_service_ &&
384 theme_service_->UsingNativeTheme(); 384 theme_service_->UsingNativeTheme();
385 } 385 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/custom_button.h ('k') | chrome/browser/ui/gtk/download/download_item_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698