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

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

Issue 62154: Implement stop/go button for Linux (Closed)
Patch Set: Add a small DCHECK => DCHECK_NE change. 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
« no previous file with comments | « chrome/browser/gtk/custom_button.h ('k') | chrome/browser/gtk/go_button_gtk.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 CustomDrawButton::CustomDrawButton(int normal_id, 13 CustomDrawButtonBase::CustomDrawButtonBase(
14 int active_id, int highlight_id, int depressed_id) { 14 int normal_id,
15 widget_.Own(gtk_button_new()); 15 int active_id,
16 16 int highlight_id,
17 int depressed_id) {
17 // Load the button images from the resource bundle. 18 // Load the button images from the resource bundle.
18 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 19 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
19 pixbufs_[GTK_STATE_NORMAL] = normal_id ? rb.LoadPixbuf(normal_id) : NULL; 20 pixbufs_[GTK_STATE_NORMAL] = normal_id ? rb.LoadPixbuf(normal_id) : NULL;
20 pixbufs_[GTK_STATE_ACTIVE] = active_id ? rb.LoadPixbuf(active_id) : NULL; 21 pixbufs_[GTK_STATE_ACTIVE] = active_id ? rb.LoadPixbuf(active_id) : NULL;
21 pixbufs_[GTK_STATE_PRELIGHT] = 22 pixbufs_[GTK_STATE_PRELIGHT] =
22 highlight_id ? rb.LoadPixbuf(highlight_id) : NULL; 23 highlight_id ? rb.LoadPixbuf(highlight_id) : NULL;
23 pixbufs_[GTK_STATE_SELECTED] = NULL; 24 pixbufs_[GTK_STATE_SELECTED] = NULL;
24 pixbufs_[GTK_STATE_INSENSITIVE] = 25 pixbufs_[GTK_STATE_INSENSITIVE] =
25 depressed_id ? rb.LoadPixbuf(depressed_id) : NULL; 26 depressed_id ? rb.LoadPixbuf(depressed_id) : NULL;
26
27 gtk_widget_set_size_request(widget_.get(),
28 gdk_pixbuf_get_width(pixbufs_[0]),
29 gdk_pixbuf_get_height(pixbufs_[0]));
30
31 gtk_widget_set_app_paintable(widget_.get(), TRUE);
32 // We effectively double-buffer by virtue of having only one image...
33 gtk_widget_set_double_buffered(widget_.get(), FALSE);
34 g_signal_connect(G_OBJECT(widget_.get()), "expose-event",
35 G_CALLBACK(OnExpose), this);
36 } 27 }
37 28
38 CustomDrawButton::~CustomDrawButton() { 29 CustomDrawButtonBase::~CustomDrawButtonBase() {
39 for (size_t i = 0; i < arraysize(pixbufs_); ++i) { 30 for (size_t i = 0; i < arraysize(pixbufs_); ++i) {
40 if (pixbufs_[i]) 31 if (pixbufs_[i])
41 gdk_pixbuf_unref(pixbufs_[i]); 32 g_object_unref(pixbufs_[i]);
42 } 33 }
43
44 widget_.Destroy();
45 } 34 }
46 35
47 // static 36 gboolean CustomDrawButtonBase::OnExpose(GtkWidget* widget, GdkEventExpose* e) {
48 gboolean CustomDrawButton::OnExpose(GtkWidget* widget, GdkEventExpose* e, 37 GdkPixbuf* pixbuf = pixbufs(GTK_WIDGET_STATE(widget));
49 CustomDrawButton* button) {
50 GdkPixbuf* pixbuf = button->pixbufs_[GTK_WIDGET_STATE(widget)];
51 38
52 // Fall back to the default image if we don't have one for this state. 39 // Fall back to the default image if we don't have one for this state.
53 if (!pixbuf) 40 if (!pixbuf)
54 pixbuf = button->pixbufs_[GTK_STATE_NORMAL]; 41 pixbuf = pixbufs(GTK_STATE_NORMAL);
55 42
56 if (!pixbuf) 43 if (!pixbuf)
57 return FALSE; 44 return FALSE;
58 45
59 gdk_draw_pixbuf(widget->window, 46 gdk_draw_pixbuf(widget->window,
60 widget->style->fg_gc[GTK_WIDGET_STATE(widget)], 47 widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
61 pixbuf, 48 pixbuf,
62 0, 0, 49 0, 0,
63 widget->allocation.x, widget->allocation.y, -1, -1, 50 widget->allocation.x, widget->allocation.y, -1, -1,
64 GDK_RGB_DITHER_NONE, 0, 0); 51 GDK_RGB_DITHER_NONE, 0, 0);
65 52
66 return TRUE; 53 return TRUE;
67 } 54 }
68 55
56 CustomDrawButton::CustomDrawButton(
57 int normal_id,
58 int active_id,
59 int highlight_id,
60 int depressed_id)
61 : button_base_(normal_id, active_id, highlight_id, depressed_id) {
62 widget_.Own(gtk_button_new());
63
64 gtk_widget_set_size_request(widget_.get(),
65 gdk_pixbuf_get_width(button_base_.pixbufs(0)),
66 gdk_pixbuf_get_height(button_base_.pixbufs(0)));
67
68 gtk_widget_set_app_paintable(widget_.get(), TRUE);
69 // We effectively double-buffer by virtue of having only one image...
70 gtk_widget_set_double_buffered(widget_.get(), FALSE);
71 g_signal_connect(G_OBJECT(widget_.get()), "expose-event",
72 G_CALLBACK(OnExpose), this);
73 }
74
75 CustomDrawButton::~CustomDrawButton() {
76 widget_.Destroy();
77 }
78
79 // static
80 gboolean CustomDrawButton::OnExpose(GtkWidget* widget,
81 GdkEventExpose* e,
82 CustomDrawButton* button) {
83 return button->button_base_.OnExpose(widget, e);
84 }
85
69 // static 86 // static
70 CustomDrawButton* CustomDrawButton::AddBarCloseButton(GtkWidget* hbox) { 87 CustomDrawButton* CustomDrawButton::AddBarCloseButton(GtkWidget* hbox) {
71 CustomDrawButton* rv = new CustomDrawButton(IDR_CLOSE_BAR, IDR_CLOSE_BAR_P, 88 CustomDrawButton* rv = new CustomDrawButton(IDR_CLOSE_BAR, IDR_CLOSE_BAR_P,
72 IDR_CLOSE_BAR_H, 0); 89 IDR_CLOSE_BAR_H, 0);
73 GTK_WIDGET_UNSET_FLAGS(rv->widget(), GTK_CAN_FOCUS); 90 GTK_WIDGET_UNSET_FLAGS(rv->widget(), GTK_CAN_FOCUS);
74 GtkWidget* centering_vbox = gtk_vbox_new(FALSE, 0); 91 GtkWidget* centering_vbox = gtk_vbox_new(FALSE, 0);
75 gtk_box_pack_start(GTK_BOX(centering_vbox), rv->widget(), TRUE, FALSE, 0); 92 gtk_box_pack_start(GTK_BOX(centering_vbox), rv->widget(), TRUE, FALSE, 0);
76 gtk_box_pack_end(GTK_BOX(hbox), centering_vbox, FALSE, FALSE, 0); 93 gtk_box_pack_end(GTK_BOX(hbox), centering_vbox, FALSE, FALSE, 0);
77 return rv; 94 return rv;
78 } 95 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 147
131 // If we return FALSE from the function, the button paints itself. 148 // If we return FALSE from the function, the button paints itself.
132 // If we return TRUE, no children are painted. 149 // If we return TRUE, no children are painted.
133 // So we return TRUE and send the expose along directly to the child. 150 // So we return TRUE and send the expose along directly to the child.
134 gtk_container_propagate_expose(GTK_CONTAINER(widget), 151 gtk_container_propagate_expose(GTK_CONTAINER(widget),
135 gtk_bin_get_child(GTK_BIN(widget)), 152 gtk_bin_get_child(GTK_BIN(widget)),
136 e); 153 e);
137 154
138 return TRUE; // Prevent normal painting. 155 return TRUE; // Prevent normal painting.
139 } 156 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/custom_button.h ('k') | chrome/browser/gtk/go_button_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698