summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-12 00:33:01 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-12 00:33:01 +0000
commit61260acded7964f6ec0e2e5ef6d834a7a7a42110 (patch)
tree5ea441066bc854c72bd34fa26f74f365e103b671 /chrome/browser/gtk
parent825eda1e093e2e16113ac6cf61e6607e1033f18e (diff)
downloadchromium_src-61260acded7964f6ec0e2e5ef6d834a7a7a42110.zip
chromium_src-61260acded7964f6ec0e2e5ef6d834a7a7a42110.tar.gz
chromium_src-61260acded7964f6ec0e2e5ef6d834a7a7a42110.tar.bz2
GTK: Use bookmark bar text color for show all downloads... link when not using GTK theme or Classic theme.
BUG=27075 Review URL: http://codereview.chromium.org/384060 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31743 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r--chrome/browser/gtk/download_shelf_gtk.cc27
-rw-r--r--chrome/browser/gtk/download_shelf_gtk.h3
-rw-r--r--chrome/browser/gtk/gtk_chrome_link_button.cc96
-rw-r--r--chrome/browser/gtk/gtk_chrome_link_button.h12
4 files changed, 92 insertions, 46 deletions
diff --git a/chrome/browser/gtk/download_shelf_gtk.cc b/chrome/browser/gtk/download_shelf_gtk.cc
index 7820097..336454f 100644
--- a/chrome/browser/gtk/download_shelf_gtk.cc
+++ b/chrome/browser/gtk/download_shelf_gtk.cc
@@ -91,15 +91,13 @@ DownloadShelfGtk::DownloadShelfGtk(Browser* browser, GtkWidget* parent)
// Create the "Show all downloads..." link and connect to the click event.
std::string link_text =
l10n_util::GetStringUTF8(IDS_SHOW_ALL_DOWNLOADS);
- GtkWidget* link_button = gtk_chrome_link_button_new(link_text.c_str());
- gtk_chrome_link_button_set_use_gtk_theme(
- GTK_CHROME_LINK_BUTTON(link_button), FALSE);
- g_signal_connect(link_button, "clicked",
+ link_button_ = gtk_chrome_link_button_new(link_text.c_str());
+ g_signal_connect(link_button_, "clicked",
G_CALLBACK(OnButtonClick), this);
- gtk_util::SetButtonTriggersNavigation(link_button);
+ gtk_util::SetButtonTriggersNavigation(link_button_);
// Until we switch to vector graphics, force the font size.
// 13.4px == 10pt @ 96dpi
- gtk_util::ForceFontSizePixels(GTK_CHROME_LINK_BUTTON(link_button)->label,
+ gtk_util::ForceFontSizePixels(GTK_CHROME_LINK_BUTTON(link_button_)->label,
13.4);
// Make the download arrow icon.
@@ -110,7 +108,7 @@ DownloadShelfGtk::DownloadShelfGtk(Browser* browser, GtkWidget* parent)
// Pack the link and the icon in an hbox.
link_hbox_ = gtk_hbox_new(FALSE, 5);
gtk_util::CenterWidgetInHBox(link_hbox_, download_image, false, 0);
- gtk_util::CenterWidgetInHBox(link_hbox_, link_button, false, 0);
+ gtk_util::CenterWidgetInHBox(link_hbox_, link_button_, false, 0);
gtk_box_pack_end(GTK_BOX(hbox_.get()), link_hbox_, FALSE, FALSE, 0);
slide_widget_.reset(new SlideAnimatorGtk(shelf_.get(),
@@ -195,6 +193,21 @@ void DownloadShelfGtk::Observe(NotificationType type,
color = theme_provider_->GetBorderColor();
gtk_widget_modify_bg(top_border_, GTK_STATE_NORMAL, &color);
+
+ gtk_chrome_link_button_set_use_gtk_theme(
+ GTK_CHROME_LINK_BUTTON(link_button_), theme_provider_->UseGtkTheme());
+
+ // When using a non-standard, non-gtk theme, we make the link color match
+ // the bookmark text color. Otherwise, standard link blue can look very
+ // bad for some dark themes.
+ bool use_default_color = theme_provider_->GetColor(
+ BrowserThemeProvider::COLOR_BOOKMARK_TEXT) ==
+ BrowserThemeProvider::kDefaultColorBookmarkText;
+ GdkColor bookmark_color = theme_provider_->GetGdkColor(
+ BrowserThemeProvider::COLOR_BOOKMARK_TEXT);
+ gtk_chrome_link_button_set_normal_color(
+ GTK_CHROME_LINK_BUTTON(link_button_),
+ use_default_color ? NULL : &bookmark_color);
}
}
diff --git a/chrome/browser/gtk/download_shelf_gtk.h b/chrome/browser/gtk/download_shelf_gtk.h
index 509109e..8530a2b 100644
--- a/chrome/browser/gtk/download_shelf_gtk.h
+++ b/chrome/browser/gtk/download_shelf_gtk.h
@@ -86,6 +86,9 @@ class DownloadShelfGtk : public DownloadShelf,
// distinction of being the leftmost non-download item widget on the shelf.
GtkWidget* link_hbox_;
+ // The "Show all downloads..." link.
+ GtkWidget* link_button_;
+
// The 'x' that the user can press to hide the download shelf.
scoped_ptr<CustomDrawButton> close_button_;
diff --git a/chrome/browser/gtk/gtk_chrome_link_button.cc b/chrome/browser/gtk/gtk_chrome_link_button.cc
index 0534a76..764c9c7 100644
--- a/chrome/browser/gtk/gtk_chrome_link_button.cc
+++ b/chrome/browser/gtk/gtk_chrome_link_button.cc
@@ -42,23 +42,26 @@ G_DEFINE_TYPE(GtkChromeLinkButton, gtk_chrome_link_button, GTK_TYPE_BUTTON)
// can be read.
static void gtk_chrome_link_button_set_text(GtkChromeLinkButton* button) {
// We only set the markup once.
- if (button->blue_markup)
+ if (button->normal_markup)
return;
gchar* text = button->text;
gboolean uses_markup = button->uses_markup;
if (!uses_markup) {
- button->blue_markup = g_markup_printf_escaped(kLinkMarkup, "blue", text);
- button->red_markup = g_markup_printf_escaped(kLinkMarkup, "red", text);
+ button->normal_markup = g_markup_printf_escaped(kLinkMarkup,
+ button->normal_color,
+ text);
+ button->pressed_markup = g_markup_printf_escaped(kLinkMarkup, "red", text);
} else {
- button->blue_markup = static_cast<gchar*>(
- g_malloc(strlen(kLinkMarkup) + strlen("blue") + strlen(text) + 1));
- sprintf(button->blue_markup, kLinkMarkup, "blue", text);
-
- button->red_markup = static_cast<gchar*>(
- g_malloc(strlen(kLinkMarkup) + strlen("red") + strlen(text) + 1));
- sprintf(button->red_markup, kLinkMarkup, "red", text);
+ int length = strlen(kLinkMarkup) + 9 + strlen(text) + 1;
+ button->normal_markup = static_cast<gchar*>(g_malloc(length));
+ snprintf(button->normal_markup, length, kLinkMarkup, button->normal_color,
+ text);
+
+ length = strlen(kLinkMarkup) + strlen("red") + strlen(text) + 1;
+ button->pressed_markup = static_cast<gchar*>(g_malloc(length));
+ snprintf(button->pressed_markup, length, kLinkMarkup, "red", text);
}
// Get the current GTK theme's link button text color.
@@ -67,7 +70,7 @@ static void gtk_chrome_link_button_set_text(GtkChromeLinkButton* button) {
if (native_color) {
gchar color_spec[9];
- sprintf(color_spec, "#%02X%02X%02X", native_color->red / 257,
+ sprintf(color_spec, 9, "#%02X%02X%02X", native_color->red / 257,
native_color->green / 257, native_color->blue / 257);
gdk_color_free(native_color);
@@ -83,11 +86,12 @@ static void gtk_chrome_link_button_set_text(GtkChromeLinkButton* button) {
} else {
// If the theme doesn't have a link color, just use blue. This matches the
// default for GtkLinkButton.
- button->native_markup = button->blue_markup;
+ button->native_markup = button->normal_markup;
}
gtk_label_set_markup(GTK_LABEL(button->label),
- button->using_native_theme ? button->native_markup : button->blue_markup);
+ button->using_native_theme ? button->native_markup :
+ button->normal_markup);
}
static gboolean gtk_chrome_link_button_expose(GtkWidget* widget,
@@ -97,14 +101,15 @@ static gboolean gtk_chrome_link_button_expose(GtkWidget* widget,
gtk_chrome_link_button_set_text(button);
- if (GTK_WIDGET_STATE(widget) == GTK_STATE_ACTIVE && button->is_blue) {
- gtk_label_set_markup(GTK_LABEL(label), button->red_markup);
- button->is_blue = FALSE;
- } else if (GTK_WIDGET_STATE(widget) != GTK_STATE_ACTIVE && !button->is_blue) {
+ if (GTK_WIDGET_STATE(widget) == GTK_STATE_ACTIVE && button->is_normal) {
+ gtk_label_set_markup(GTK_LABEL(label), button->pressed_markup);
+ button->is_normal = FALSE;
+ } else if (GTK_WIDGET_STATE(widget) != GTK_STATE_ACTIVE &&
+ !button->is_normal) {
gtk_label_set_markup(GTK_LABEL(label),
button->using_native_theme ? button->native_markup :
- button->blue_markup);
- button->is_blue = TRUE;
+ button->normal_markup);
+ button->is_normal = TRUE;
}
// Draw the link inside the button.
@@ -135,16 +140,16 @@ static void gtk_chrome_link_button_leave(GtkButton* button) {
static void gtk_chrome_link_button_destroy(GtkObject* object) {
GtkChromeLinkButton* button = GTK_CHROME_LINK_BUTTON(object);
- if (button->native_markup && (button->native_markup != button->blue_markup))
+ if (button->native_markup && (button->native_markup != button->normal_markup))
g_free(button->native_markup);
button->native_markup = NULL;
- if (button->blue_markup) {
- g_free(button->blue_markup);
- button->blue_markup = NULL;
+ if (button->normal_markup) {
+ g_free(button->normal_markup);
+ button->normal_markup = NULL;
}
- if (button->red_markup) {
- g_free(button->red_markup);
- button->red_markup = NULL;
+ if (button->pressed_markup) {
+ g_free(button->pressed_markup);
+ button->pressed_markup = NULL;
}
if (button->hand_cursor) {
gdk_cursor_unref(button->hand_cursor);
@@ -178,9 +183,10 @@ static void gtk_chrome_link_button_init(GtkChromeLinkButton* button) {
// let the button draw itself; catch all expose events to the button and pass
// them through to the label.
button->label = gtk_label_new(NULL);
- button->blue_markup = NULL;
- button->red_markup = NULL;
- button->is_blue = TRUE;
+ button->normal_markup = NULL;
+ button->pressed_markup = NULL;
+ button->is_normal = TRUE;
+ strncpy(button->normal_color, "blue", 9);
button->native_markup = NULL;
button->using_native_theme = TRUE;
button->hand_cursor = gtk_util::GetCursor(GDK_HAND2);
@@ -221,16 +227,34 @@ void gtk_chrome_link_button_set_label(GtkChromeLinkButton* button,
button->text = strdup(text);
// Clear the markup so we can redraw.
- if (button->native_markup && (button->native_markup != button->blue_markup))
+ if (button->native_markup && (button->native_markup != button->normal_markup))
g_free(button->native_markup);
button->native_markup = NULL;
- if (button->blue_markup) {
- g_free(button->blue_markup);
- button->blue_markup = NULL;
+ if (button->normal_markup) {
+ g_free(button->normal_markup);
+ button->normal_markup = NULL;
+ }
+ if (button->pressed_markup) {
+ g_free(button->pressed_markup);
+ button->pressed_markup = NULL;
+ }
+
+ if (GTK_WIDGET_VISIBLE(button))
+ gtk_widget_queue_draw(GTK_WIDGET(button));
+}
+
+void gtk_chrome_link_button_set_normal_color(GtkChromeLinkButton* button,
+ const GdkColor* color) {
+ if (button->normal_markup) {
+ g_free(button->normal_markup);
+ button->normal_markup = NULL;
}
- if (button->red_markup) {
- g_free(button->red_markup);
- button->red_markup = NULL;
+
+ if (color) {
+ snprintf(button->normal_color, 9, "#%02X%02X%02X", color->red / 257,
+ color->green / 257, color->blue / 257);
+ } else {
+ strncpy(button->normal_color, "blue", 9);
}
if (GTK_WIDGET_VISIBLE(button))
diff --git a/chrome/browser/gtk/gtk_chrome_link_button.h b/chrome/browser/gtk/gtk_chrome_link_button.h
index 565eae1..1021cba 100644
--- a/chrome/browser/gtk/gtk_chrome_link_button.h
+++ b/chrome/browser/gtk/gtk_chrome_link_button.h
@@ -37,9 +37,10 @@ typedef struct _GtkChromeLinkButtonClass GtkChromeLinkButtonClass;
struct _GtkChromeLinkButton {
GtkButton button;
GtkWidget* label;
- gchar* blue_markup;
- gchar* red_markup;
- gboolean is_blue;
+ gchar* normal_markup;
+ gchar* pressed_markup;
+ gboolean is_normal;
+ gchar normal_color[9];
gchar* native_markup;
gboolean using_native_theme;
GdkCursor* hand_cursor;
@@ -66,6 +67,11 @@ void gtk_chrome_link_button_set_use_gtk_theme(GtkChromeLinkButton* button,
void gtk_chrome_link_button_set_label(GtkChromeLinkButton* button,
const char* text);
+// Set the color when the link is in a normal state (i.e. not pressed).
+// If not set, or called NULL |color|, the color will be blue.
+void gtk_chrome_link_button_set_normal_color(GtkChromeLinkButton* button,
+ const GdkColor* color);
+
GType gtk_chrome_link_button_get_type();
G_END_DECLS