| Index: chrome/browser/gtk/gtk_chrome_link_button.cc
|
| ===================================================================
|
| --- chrome/browser/gtk/gtk_chrome_link_button.cc (revision 22168)
|
| +++ chrome/browser/gtk/gtk_chrome_link_button.cc (working copy)
|
| @@ -37,16 +37,71 @@
|
| 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->blue_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);
|
| + } 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);
|
| + }
|
| +
|
| + // Get the current GTK theme's link button text color.
|
| + GdkColor* native_color = NULL;
|
| + gtk_widget_style_get(GTK_WIDGET(button), "link-color", &native_color, NULL);
|
| +
|
| + if (native_color) {
|
| + gchar color_spec[9];
|
| + sprintf(color_spec, "#%02X%02X%02X", native_color->red / 257,
|
| + native_color->green / 257, native_color->blue / 257);
|
| + gdk_color_free(native_color);
|
| +
|
| + if (!uses_markup) {
|
| + button->native_markup = g_markup_printf_escaped(kLinkMarkup,
|
| + color_spec, text);
|
| + } else {
|
| + button->native_markup = static_cast<gchar*>(
|
| + g_malloc(strlen(kLinkMarkup) + strlen(color_spec) + strlen(text) +
|
| + 1));
|
| + sprintf(button->native_markup, kLinkMarkup, color_spec, text);
|
| + }
|
| + } 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;
|
| + }
|
| +
|
| + gtk_label_set_markup(GTK_LABEL(button->label),
|
| + button->using_native_theme ? button->native_markup : button->blue_markup);
|
| +}
|
| +
|
| static gboolean gtk_chrome_link_button_expose(GtkWidget* widget,
|
| GdkEventExpose* event) {
|
| GtkChromeLinkButton* button = GTK_CHROME_LINK_BUTTON(widget);
|
| GtkWidget* label = button->label;
|
|
|
| + 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) {
|
| - gtk_label_set_markup(GTK_LABEL(label), button->blue_markup);
|
| + gtk_label_set_markup(GTK_LABEL(label),
|
| + button->using_native_theme ? button->native_markup : button->blue_markup);
|
| button->is_blue = TRUE;
|
| }
|
|
|
| @@ -114,6 +169,10 @@
|
|
|
| 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)) {
|
| + g_free(button->native_markup);
|
| + button->native_markup = NULL;
|
| + }
|
| if (button->blue_markup) {
|
| g_free(button->blue_markup);
|
| button->blue_markup = NULL;
|
| @@ -126,9 +185,13 @@
|
| gdk_cursor_unref(button->hand_cursor);
|
| button->hand_cursor = NULL;
|
| }
|
| +
|
| free(button->click_button_event);
|
| button->click_button_event = NULL;
|
|
|
| + free(button->text);
|
| + button->text = NULL;
|
| +
|
| GTK_OBJECT_CLASS(gtk_chrome_link_button_parent_class)->destroy(object);
|
| }
|
|
|
| @@ -158,49 +221,40 @@
|
| button->blue_markup = NULL;
|
| button->red_markup = NULL;
|
| button->is_blue = TRUE;
|
| + button->native_markup = NULL;
|
| + button->using_native_theme = TRUE;
|
| button->hand_cursor = gdk_cursor_new(GDK_HAND2);
|
| button->click_button_event = NULL;
|
| + button->text = NULL;
|
|
|
| gtk_container_add(GTK_CONTAINER(button), button->label);
|
| gtk_widget_set_name(GTK_WIDGET(button), "chrome-link-button");
|
| gtk_widget_set_app_paintable(GTK_WIDGET(button), TRUE);
|
| }
|
|
|
| -static void gtk_chrome_link_button_set_text(GtkChromeLinkButton* button,
|
| - const char* text,
|
| - bool contains_markup) {
|
| - // We should have only been called once or we'd leak the markups.
|
| - DCHECK(!button->blue_markup && !button->red_markup);
|
| -
|
| - if (!contains_markup) {
|
| - button->blue_markup = g_markup_printf_escaped(kLinkMarkup, "blue", text);
|
| - button->red_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);
|
| - }
|
| -
|
| - gtk_label_set_markup(GTK_LABEL(button->label), button->blue_markup);
|
| - button->is_blue = TRUE;
|
| -}
|
| -
|
| GtkWidget* gtk_chrome_link_button_new(const char* text) {
|
| GtkWidget* lb = GTK_WIDGET(g_object_new(GTK_TYPE_CHROME_LINK_BUTTON, NULL));
|
| - gtk_chrome_link_button_set_text(GTK_CHROME_LINK_BUTTON(lb), text, false);
|
| + GTK_CHROME_LINK_BUTTON(lb)->text = strdup(text);
|
| + GTK_CHROME_LINK_BUTTON(lb)->uses_markup = FALSE;
|
| return lb;
|
| }
|
|
|
| GtkWidget* gtk_chrome_link_button_new_with_markup(const char* markup) {
|
| GtkWidget* lb = GTK_WIDGET(g_object_new(GTK_TYPE_CHROME_LINK_BUTTON, NULL));
|
| - gtk_chrome_link_button_set_text(GTK_CHROME_LINK_BUTTON(lb), markup, true);
|
| + GTK_CHROME_LINK_BUTTON(lb)->text = strdup(markup);
|
| + GTK_CHROME_LINK_BUTTON(lb)->uses_markup = TRUE;
|
| return lb;
|
| }
|
|
|
| +void gtk_chrome_link_button_set_use_gtk_theme(GtkChromeLinkButton* button,
|
| + gboolean use_gtk) {
|
| + if (use_gtk != button->using_native_theme) {
|
| + button->using_native_theme = use_gtk;
|
| + if (GTK_WIDGET_VISIBLE(button))
|
| + gtk_widget_queue_draw(GTK_WIDGET(button));
|
| + }
|
| +}
|
| +
|
| const GdkEventButton* gtk_chrome_link_button_get_event_for_click(
|
| GtkChromeLinkButton* button) {
|
| return button->click_button_event;
|
|
|