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

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

Issue 67179: Have ResourceBundle own GdkPixbufs. (Closed)
Patch Set: null Created 11 years, 8 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "chrome/common/resource_bundle.h" 8 #include "chrome/common/resource_bundle.h"
9 #include "chrome/browser/gtk/nine_box.h" 9 #include "chrome/browser/gtk/nine_box.h"
10 10
11 #include "grit/theme_resources.h" 11 #include "grit/theme_resources.h"
12 12
13 CustomDrawButtonBase::CustomDrawButtonBase( 13 CustomDrawButtonBase::CustomDrawButtonBase(
14 int normal_id, 14 int normal_id,
15 int active_id, 15 int active_id,
16 int highlight_id, 16 int highlight_id,
17 int depressed_id) { 17 int depressed_id) {
18 // Load the button images from the resource bundle. 18 // Load the button images from the resource bundle.
19 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 19 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
20 pixbufs_[GTK_STATE_NORMAL] = normal_id ? rb.LoadPixbuf(normal_id) : NULL; 20 pixbufs_[GTK_STATE_NORMAL] = normal_id ? rb.GetPixbufNamed(normal_id) : NULL;
21 pixbufs_[GTK_STATE_ACTIVE] = active_id ? rb.LoadPixbuf(active_id) : NULL; 21 pixbufs_[GTK_STATE_ACTIVE] = active_id ? rb.GetPixbufNamed(active_id) : NULL;
22 pixbufs_[GTK_STATE_PRELIGHT] = 22 pixbufs_[GTK_STATE_PRELIGHT] =
23 highlight_id ? rb.LoadPixbuf(highlight_id) : NULL; 23 highlight_id ? rb.GetPixbufNamed(highlight_id) : NULL;
24 pixbufs_[GTK_STATE_SELECTED] = NULL; 24 pixbufs_[GTK_STATE_SELECTED] = NULL;
25 pixbufs_[GTK_STATE_INSENSITIVE] = 25 pixbufs_[GTK_STATE_INSENSITIVE] =
26 depressed_id ? rb.LoadPixbuf(depressed_id) : NULL; 26 depressed_id ? rb.GetPixbufNamed(depressed_id) : NULL;
27 } 27 }
28 28
29 CustomDrawButtonBase::~CustomDrawButtonBase() { 29 CustomDrawButtonBase::~CustomDrawButtonBase() {
30 for (size_t i = 0; i < arraysize(pixbufs_); ++i) {
31 if (pixbufs_[i])
32 g_object_unref(pixbufs_[i]);
33 }
34 } 30 }
35 31
36 gboolean CustomDrawButtonBase::OnExpose(GtkWidget* widget, GdkEventExpose* e) { 32 gboolean CustomDrawButtonBase::OnExpose(GtkWidget* widget, GdkEventExpose* e) {
37 GdkPixbuf* pixbuf = pixbufs(GTK_WIDGET_STATE(widget)); 33 GdkPixbuf* pixbuf = pixbufs(GTK_WIDGET_STATE(widget));
38 34
39 // Fall back to the default image if we don't have one for this state. 35 // Fall back to the default image if we don't have one for this state.
40 if (!pixbuf) 36 if (!pixbuf)
41 pixbuf = pixbufs(GTK_STATE_NORMAL); 37 pixbuf = pixbufs(GTK_STATE_NORMAL);
42 38
43 if (!pixbuf) 39 if (!pixbuf)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // static 82 // static
87 CustomDrawButton* CustomDrawButton::AddBarCloseButton(GtkWidget* hbox) { 83 CustomDrawButton* CustomDrawButton::AddBarCloseButton(GtkWidget* hbox) {
88 CustomDrawButton* rv = new CustomDrawButton(IDR_CLOSE_BAR, IDR_CLOSE_BAR_P, 84 CustomDrawButton* rv = new CustomDrawButton(IDR_CLOSE_BAR, IDR_CLOSE_BAR_P,
89 IDR_CLOSE_BAR_H, 0); 85 IDR_CLOSE_BAR_H, 0);
90 GTK_WIDGET_UNSET_FLAGS(rv->widget(), GTK_CAN_FOCUS); 86 GTK_WIDGET_UNSET_FLAGS(rv->widget(), GTK_CAN_FOCUS);
91 GtkWidget* centering_vbox = gtk_vbox_new(FALSE, 0); 87 GtkWidget* centering_vbox = gtk_vbox_new(FALSE, 0);
92 gtk_box_pack_start(GTK_BOX(centering_vbox), rv->widget(), TRUE, FALSE, 0); 88 gtk_box_pack_start(GTK_BOX(centering_vbox), rv->widget(), TRUE, FALSE, 0);
93 gtk_box_pack_end(GTK_BOX(hbox), centering_vbox, FALSE, FALSE, 0); 89 gtk_box_pack_end(GTK_BOX(hbox), centering_vbox, FALSE, FALSE, 0);
94 return rv; 90 return rv;
95 } 91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698