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

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

Issue 150176: GTK: First draft of using native themes, partially based on evan's CL 118358. (Closed)
Patch Set: And the codereview tool is back. Created 11 years, 5 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/gtk_chrome_button.h" 5 #include "chrome/browser/gtk/gtk_chrome_button.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/gfx/gtk_util.h"
8 #include "chrome/browser/gtk/nine_box.h" 9 #include "chrome/browser/gtk/nine_box.h"
9 10
10 #include "grit/app_resources.h" 11 #include "grit/app_resources.h"
11 12
12 namespace { 13 namespace {
13 14
14 // The theme graphics for when the mouse is over the button. 15 // The theme graphics for when the mouse is over the button.
15 NineBox* g_nine_box_prelight; 16 NineBox* g_nine_box_prelight;
16 // The theme graphics for when the button is clicked. 17 // The theme graphics for when the button is clicked.
17 NineBox* g_nine_box_active; 18 NineBox* g_nine_box_active;
18 19
19 } // namespace 20 } // namespace
20 21
21 G_BEGIN_DECLS 22 G_BEGIN_DECLS
22 23
23 #define GTK_CHROME_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o),\ 24 #define GTK_CHROME_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o),\
24 GTK_TYPE_CHROME_BUTTON,\ 25 GTK_TYPE_CHROME_BUTTON,\
25 GtkChromeButtonPrivate)) 26 GtkChromeButtonPrivate))
26 typedef struct _GtkChromeButtonPrivate GtkChromeButtonPrivate; 27 typedef struct _GtkChromeButtonPrivate GtkChromeButtonPrivate;
27 28
28 struct _GtkChromeButtonPrivate { 29 struct _GtkChromeButtonPrivate {
29 int paint_state; 30 int paint_state;
31
32 // If true, we use images provided by the theme instead of GTK's default
33 // button rendering.
34 gboolean use_gtk_rendering;
30 }; 35 };
31 36
32 G_DEFINE_TYPE(GtkChromeButton, gtk_chrome_button, GTK_TYPE_BUTTON) 37 G_DEFINE_TYPE(GtkChromeButton, gtk_chrome_button, GTK_TYPE_BUTTON)
33 static gboolean gtk_chrome_button_expose(GtkWidget* widget, 38 static gboolean gtk_chrome_button_expose(GtkWidget* widget,
34 GdkEventExpose* event); 39 GdkEventExpose* event);
35 40
36 static void gtk_chrome_button_class_init(GtkChromeButtonClass* button_class) { 41 static void gtk_chrome_button_class_init(GtkChromeButtonClass* button_class) {
37 GObjectClass* gobject_class = G_OBJECT_CLASS(button_class); 42 GObjectClass* gobject_class = G_OBJECT_CLASS(button_class);
38 GtkWidgetClass* widget_class = reinterpret_cast<GtkWidgetClass*>(button_class) ; 43 GtkWidgetClass* widget_class = reinterpret_cast<GtkWidgetClass*>(button_class) ;
39 widget_class->expose_event = gtk_chrome_button_expose; 44 widget_class->expose_event = gtk_chrome_button_expose;
(...skipping 19 matching lines...) Expand all
59 IDR_TEXTBUTTON_BOTTOM_LEFT_P, 64 IDR_TEXTBUTTON_BOTTOM_LEFT_P,
60 IDR_TEXTBUTTON_BOTTOM_P, 65 IDR_TEXTBUTTON_BOTTOM_P,
61 IDR_TEXTBUTTON_BOTTOM_RIGHT_P); 66 IDR_TEXTBUTTON_BOTTOM_RIGHT_P);
62 67
63 g_type_class_add_private(gobject_class, sizeof(GtkChromeButtonPrivate)); 68 g_type_class_add_private(gobject_class, sizeof(GtkChromeButtonPrivate));
64 } 69 }
65 70
66 static void gtk_chrome_button_init(GtkChromeButton* button) { 71 static void gtk_chrome_button_init(GtkChromeButton* button) {
67 GtkChromeButtonPrivate* priv = GTK_CHROME_BUTTON_GET_PRIVATE(button); 72 GtkChromeButtonPrivate* priv = GTK_CHROME_BUTTON_GET_PRIVATE(button);
68 priv->paint_state = -1; 73 priv->paint_state = -1;
74 priv->use_gtk_rendering = FALSE;
69 75
70 gtk_widget_set_app_paintable(GTK_WIDGET(button), TRUE); 76 gtk_widget_set_app_paintable(GTK_WIDGET(button), TRUE);
71 77
72 GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS); 78 GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS);
73 } 79 }
74 80
75 static gboolean gtk_chrome_button_expose(GtkWidget* widget, 81 static gboolean gtk_chrome_button_expose(GtkWidget* widget,
76 GdkEventExpose* event) { 82 GdkEventExpose* event) {
77 GtkChromeButtonPrivate *priv = GTK_CHROME_BUTTON_GET_PRIVATE(widget); 83 GtkChromeButtonPrivate *priv = GTK_CHROME_BUTTON_GET_PRIVATE(widget);
78 int paint_state = priv->paint_state < 0 ? 84 int paint_state = priv->paint_state < 0 ?
79 GTK_WIDGET_STATE(widget) : priv->paint_state; 85 GTK_WIDGET_STATE(widget) : priv->paint_state;
80 86
81 NineBox* nine_box = NULL; 87 if (priv->use_gtk_rendering) {
82 if (paint_state == GTK_STATE_PRELIGHT) 88 // We have the superclass handle this expose when we aren't using custom
83 nine_box = g_nine_box_prelight; 89 // rendering AND we're in either the prelight or active state so that we
84 else if (paint_state == GTK_STATE_ACTIVE) 90 // get the button border for the current GTK theme drawn.
85 nine_box = g_nine_box_active; 91 if (paint_state == GTK_STATE_PRELIGHT || paint_state == GTK_STATE_ACTIVE) {
92 (*GTK_WIDGET_CLASS(gtk_chrome_button_parent_class)->expose_event)
93 (widget, event);
94 } else {
95 // Otherwise, we're still responsible for rendering our children.
96 gtk_container_propagate_expose(GTK_CONTAINER(widget),
97 gtk_bin_get_child(GTK_BIN(widget)),
98 event);
99 }
100 } else {
101 NineBox* nine_box = NULL;
102 if (paint_state == GTK_STATE_PRELIGHT)
103 nine_box = g_nine_box_prelight;
104 else if (paint_state == GTK_STATE_ACTIVE)
105 nine_box = g_nine_box_active;
86 106
87 // Only draw theme graphics if we have some. 107 // Only draw theme graphics if we have some.
88 if (nine_box) 108 if (nine_box)
89 nine_box->RenderToWidget(widget); 109 nine_box->RenderToWidget(widget);
90 110
91 gtk_container_propagate_expose(GTK_CONTAINER(widget), 111 gtk_container_propagate_expose(GTK_CONTAINER(widget),
92 gtk_bin_get_child(GTK_BIN(widget)), 112 gtk_bin_get_child(GTK_BIN(widget)),
93 event); 113 event);
114 }
94 115
95 return TRUE; // Don't propagate, we are the default handler. 116 return TRUE; // Don't propagate, we are the default handler.
96 } 117 }
97 118
98 GtkWidget* gtk_chrome_button_new(void) { 119 GtkWidget* gtk_chrome_button_new(void) {
99 return GTK_WIDGET(g_object_new(GTK_TYPE_CHROME_BUTTON, NULL)); 120 return GTK_WIDGET(g_object_new(GTK_TYPE_CHROME_BUTTON, NULL));
100 } 121 }
101 122
102 void gtk_chrome_button_set_paint_state(GtkChromeButton* button, 123 void gtk_chrome_button_set_paint_state(GtkChromeButton* button,
103 GtkStateType state) { 124 GtkStateType state) {
104 g_return_if_fail(GTK_IS_CHROME_BUTTON(button)); 125 g_return_if_fail(GTK_IS_CHROME_BUTTON(button));
105 126
106 GtkChromeButtonPrivate *priv = GTK_CHROME_BUTTON_GET_PRIVATE(button); 127 GtkChromeButtonPrivate *priv = GTK_CHROME_BUTTON_GET_PRIVATE(button);
107 priv->paint_state = state; 128 priv->paint_state = state;
108 129
109 gtk_widget_queue_draw(GTK_WIDGET(button)); 130 gtk_widget_queue_draw(GTK_WIDGET(button));
110 } 131 }
111 132
112 void gtk_chrome_button_unset_paint_state(GtkChromeButton* button) { 133 void gtk_chrome_button_unset_paint_state(GtkChromeButton* button) {
113 g_return_if_fail(GTK_IS_CHROME_BUTTON(button)); 134 g_return_if_fail(GTK_IS_CHROME_BUTTON(button));
114 135
115 GtkChromeButtonPrivate *priv = GTK_CHROME_BUTTON_GET_PRIVATE(button); 136 GtkChromeButtonPrivate *priv = GTK_CHROME_BUTTON_GET_PRIVATE(button);
116 priv->paint_state = -1; 137 priv->paint_state = -1;
117 138
118 gtk_widget_queue_draw(GTK_WIDGET(button)); 139 gtk_widget_queue_draw(GTK_WIDGET(button));
119 } 140 }
120 141
142 void gtk_chrome_button_set_use_gtk_rendering(GtkChromeButton* button,
143 gboolean value) {
144 g_return_if_fail(GTK_IS_CHROME_BUTTON(button));
145 GtkChromeButtonPrivate *priv = GTK_CHROME_BUTTON_GET_PRIVATE(button);
146 priv->use_gtk_rendering = value;
147 }
148
121 G_END_DECLS 149 G_END_DECLS
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698