diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-03 00:42:29 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-03 00:42:29 +0000 |
commit | a5166af69628552e4bcf746a38f3710cc895eac3 (patch) | |
tree | 0d6e0ab20143724111855ac501aad3fd469e6b8d /chrome/browser/gtk/gtk_chrome_button.cc | |
parent | 08f91cc8431cc6dea19e3c3ff3a229c71a7fc71f (diff) | |
download | chromium_src-a5166af69628552e4bcf746a38f3710cc895eac3.zip chromium_src-a5166af69628552e4bcf746a38f3710cc895eac3.tar.gz chromium_src-a5166af69628552e4bcf746a38f3710cc895eac3.tar.bz2 |
GTK: Initial implementation of using GTK themes, partially based on evan's CL 118358.
A lot of stuff works:
- Colors are picked out of the GTK theme.
- Buttons use the current GTK button theme.
- We use the user's icon theme.
A lot of stuff doesn't:
- We could do a better job of picking colors for the skylines.
- The omnibox hasn't been touched.
- UI that's not part of the toolbar hasn't been touched.
- We currently fail on themes like HighContrastInverse.
TEST=Under Options>Personal Stuff, click GTK Theme. Colors and widgets should be rendered with the current GTK theme stuff.
TEST=With chrome open and in GTK Theme mode, change your GTK theme or icon theme. chrome should pick up on the change immediately and reimport the colors and images.
http://crbug.com/13967
Review URL: http://codereview.chromium.org/150176
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19868 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/gtk_chrome_button.cc')
-rw-r--r-- | chrome/browser/gtk/gtk_chrome_button.cc | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/chrome/browser/gtk/gtk_chrome_button.cc b/chrome/browser/gtk/gtk_chrome_button.cc index 558e610..6b35716 100644 --- a/chrome/browser/gtk/gtk_chrome_button.cc +++ b/chrome/browser/gtk/gtk_chrome_button.cc @@ -5,6 +5,7 @@ #include "chrome/browser/gtk/gtk_chrome_button.h" #include "base/basictypes.h" +#include "base/gfx/gtk_util.h" #include "chrome/browser/gtk/nine_box.h" #include "grit/app_resources.h" @@ -27,6 +28,10 @@ typedef struct _GtkChromeButtonPrivate GtkChromeButtonPrivate; struct _GtkChromeButtonPrivate { int paint_state; + + // If true, we use images provided by the theme instead of GTK's default + // button rendering. + gboolean use_gtk_rendering; }; G_DEFINE_TYPE(GtkChromeButton, gtk_chrome_button, GTK_TYPE_BUTTON) @@ -66,6 +71,7 @@ static void gtk_chrome_button_class_init(GtkChromeButtonClass* button_class) { static void gtk_chrome_button_init(GtkChromeButton* button) { GtkChromeButtonPrivate* priv = GTK_CHROME_BUTTON_GET_PRIVATE(button); priv->paint_state = -1; + priv->use_gtk_rendering = FALSE; gtk_widget_set_app_paintable(GTK_WIDGET(button), TRUE); @@ -78,19 +84,34 @@ static gboolean gtk_chrome_button_expose(GtkWidget* widget, int paint_state = priv->paint_state < 0 ? GTK_WIDGET_STATE(widget) : priv->paint_state; - NineBox* nine_box = NULL; - if (paint_state == GTK_STATE_PRELIGHT) - nine_box = g_nine_box_prelight; - else if (paint_state == GTK_STATE_ACTIVE) - nine_box = g_nine_box_active; - - // Only draw theme graphics if we have some. - if (nine_box) - nine_box->RenderToWidget(widget); - - gtk_container_propagate_expose(GTK_CONTAINER(widget), - gtk_bin_get_child(GTK_BIN(widget)), - event); + if (priv->use_gtk_rendering) { + // We have the superclass handle this expose when we aren't using custom + // rendering AND we're in either the prelight or active state so that we + // get the button border for the current GTK theme drawn. + if (paint_state == GTK_STATE_PRELIGHT || paint_state == GTK_STATE_ACTIVE) { + (*GTK_WIDGET_CLASS(gtk_chrome_button_parent_class)->expose_event) + (widget, event); + } else { + // Otherwise, we're still responsible for rendering our children. + gtk_container_propagate_expose(GTK_CONTAINER(widget), + gtk_bin_get_child(GTK_BIN(widget)), + event); + } + } else { + NineBox* nine_box = NULL; + if (paint_state == GTK_STATE_PRELIGHT) + nine_box = g_nine_box_prelight; + else if (paint_state == GTK_STATE_ACTIVE) + nine_box = g_nine_box_active; + + // Only draw theme graphics if we have some. + if (nine_box) + nine_box->RenderToWidget(widget); + + gtk_container_propagate_expose(GTK_CONTAINER(widget), + gtk_bin_get_child(GTK_BIN(widget)), + event); + } return TRUE; // Don't propagate, we are the default handler. } @@ -118,4 +139,11 @@ void gtk_chrome_button_unset_paint_state(GtkChromeButton* button) { gtk_widget_queue_draw(GTK_WIDGET(button)); } +void gtk_chrome_button_set_use_gtk_rendering(GtkChromeButton* button, + gboolean value) { + g_return_if_fail(GTK_IS_CHROME_BUTTON(button)); + GtkChromeButtonPrivate *priv = GTK_CHROME_BUTTON_GET_PRIVATE(button); + priv->use_gtk_rendering = value; +} + G_END_DECLS |