summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorerg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-14 19:08:55 +0000
committererg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-14 19:08:55 +0000
commit6c8bece66bb899bd9395a5d23d4442a344e74cc0 (patch)
treea497281cfb4248a7cd5311bbf1afd4f560ba3a35
parent77dee9a13600fa16c5b5da67e8c8ec927f3563dc (diff)
downloadchromium_src-6c8bece66bb899bd9395a5d23d4442a344e74cc0.zip
chromium_src-6c8bece66bb899bd9395a5d23d4442a344e74cc0.tar.gz
chromium_src-6c8bece66bb899bd9395a5d23d4442a344e74cc0.tar.bz2
GTK: Match link colors.
- Realize our fake window in the GtkThemeProvider so we can access the style properties. - Make sure we don't generate the markup for a GtkChromeLinkButton until after it is realized. - Make sure GtkChromeLinkButton responds to system wide style theme changes. BUG=43850 TEST=Open up chrome to the NTP with an empty bookmark bar in GTK+ theme mode. The links on the NTP should match the GTK+ link color, and so should the import bookmark link in the bookmark bar. Change your GTK+ theme to one with a different link color. The NTP and import bookmark link should change to the new color. Review URL: http://codereview.chromium.org/2067007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47293 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/gtk/gtk_chrome_link_button.cc41
-rw-r--r--chrome/browser/gtk/gtk_theme_provider.cc4
2 files changed, 27 insertions, 18 deletions
diff --git a/chrome/browser/gtk/gtk_chrome_link_button.cc b/chrome/browser/gtk/gtk_chrome_link_button.cc
index a3b08ef..fea5822 100644
--- a/chrome/browser/gtk/gtk_chrome_link_button.cc
+++ b/chrome/browser/gtk/gtk_chrome_link_button.cc
@@ -51,13 +51,19 @@ static void gtk_chrome_link_button_destroy_text_resources(
G_BEGIN_DECLS
G_DEFINE_TYPE(GtkChromeLinkButton, gtk_chrome_link_button, GTK_TYPE_BUTTON)
-// Should be called after we are realized so that the "link-color" property
-// can be read.
static void gtk_chrome_link_button_set_text(GtkChromeLinkButton* button) {
- // We only set the markup once.
- if (button->normal_markup)
+ // If we were called before we were realized, abort. We'll be called for
+ // real when |button| is realized.
+ if (!GTK_WIDGET_REALIZED(button))
return;
+ g_free(button->native_markup);
+ button->native_markup = NULL;
+ g_free(button->normal_markup);
+ button->normal_markup = NULL;
+ g_free(button->pressed_markup);
+ button->pressed_markup = NULL;
+
gchar* text = button->text;
gboolean uses_markup = button->uses_markup;
@@ -100,6 +106,15 @@ static void gtk_chrome_link_button_set_text(GtkChromeLinkButton* button) {
button->normal_markup);
}
+static void gtk_chrome_link_button_style_changed(GtkChromeLinkButton* button) {
+ // Regenerate the link with the possibly new colors after the user has
+ // changed his GTK style.
+ gtk_chrome_link_button_set_text(button);
+
+ if (GTK_WIDGET_VISIBLE(button))
+ gtk_widget_queue_draw(GTK_WIDGET(button));
+}
+
static gboolean gtk_chrome_link_button_expose(GtkWidget* widget,
GdkEventExpose* event) {
GtkChromeLinkButton* button = GTK_CHROME_LINK_BUTTON(widget);
@@ -187,6 +202,10 @@ static void gtk_chrome_link_button_init(GtkChromeLinkButton* button) {
gtk_container_add(GTK_CONTAINER(button), button->label);
gtk_widget_set_app_paintable(GTK_WIDGET(button), TRUE);
+ g_signal_connect(button, "realize",
+ G_CALLBACK(gtk_chrome_link_button_set_text), NULL);
+ g_signal_connect(button, "style-set",
+ G_CALLBACK(gtk_chrome_link_button_style_changed), NULL);
}
GtkWidget* gtk_chrome_link_button_new(const char* text) {
@@ -194,8 +213,6 @@ GtkWidget* gtk_chrome_link_button_new(const char* text) {
GTK_CHROME_LINK_BUTTON(lb)->text = g_strdup(text);
GTK_CHROME_LINK_BUTTON(lb)->uses_markup = FALSE;
- gtk_chrome_link_button_set_text(GTK_CHROME_LINK_BUTTON(lb));
-
return lb;
}
@@ -204,8 +221,6 @@ GtkWidget* gtk_chrome_link_button_new_with_markup(const char* markup) {
GTK_CHROME_LINK_BUTTON(lb)->text = g_strdup(markup);
GTK_CHROME_LINK_BUTTON(lb)->uses_markup = TRUE;
- gtk_chrome_link_button_set_text(GTK_CHROME_LINK_BUTTON(lb));
-
return lb;
}
@@ -220,8 +235,7 @@ void gtk_chrome_link_button_set_use_gtk_theme(GtkChromeLinkButton* button,
void gtk_chrome_link_button_set_label(GtkChromeLinkButton* button,
const char* text) {
- // Clear the markup so we can redraw.
- gtk_chrome_link_button_destroy_text_resources(button);
+ g_free(button->text);
button->text = g_strdup(text);
gtk_chrome_link_button_set_text(button);
@@ -232,13 +246,6 @@ void gtk_chrome_link_button_set_label(GtkChromeLinkButton* button,
void gtk_chrome_link_button_set_normal_color(GtkChromeLinkButton* button,
const GdkColor* color) {
- g_free(button->native_markup);
- button->native_markup = NULL;
- g_free(button->normal_markup);
- button->normal_markup = NULL;
- g_free(button->pressed_markup);
- button->pressed_markup = NULL;
-
if (color) {
snprintf(button->normal_color, 9, "#%02X%02X%02X", color->red / 257,
color->green / 257, color->blue / 257);
diff --git a/chrome/browser/gtk/gtk_theme_provider.cc b/chrome/browser/gtk/gtk_theme_provider.cc
index 66fa0e5..d7d4b6b 100644
--- a/chrome/browser/gtk/gtk_theme_provider.cc
+++ b/chrome/browser/gtk/gtk_theme_provider.cc
@@ -143,8 +143,10 @@ GtkThemeProvider::GtkThemeProvider()
fake_entry_.Own(gtk_entry_new());
// Only realized widgets receive style-set notifications, which we need to
- // broadcast new theme images and colors.
+ // broadcast new theme images and colors. Only realized widgets have style
+ // properties, too, which we query for some colors.
gtk_widget_realize(fake_frame_);
+ gtk_widget_realize(fake_window_);
signals_.Connect(fake_frame_, "style-set", G_CALLBACK(&OnStyleSet), this);
}