diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-01 00:41:52 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-01 00:41:52 +0000 |
commit | 86fda681791b475fb4da0a16a29c44b69f5ec9bf (patch) | |
tree | 4084d0e20aceab587b1307215abeee3abdb369cd /chrome/browser/gtk/gtk_chrome_link_button.cc | |
parent | ec136c7195d187dabf64e1be5c18bb0aaede9794 (diff) | |
download | chromium_src-86fda681791b475fb4da0a16a29c44b69f5ec9bf.zip chromium_src-86fda681791b475fb4da0a16a29c44b69f5ec9bf.tar.gz chromium_src-86fda681791b475fb4da0a16a29c44b69f5ec9bf.tar.bz2 |
revert 22226 as it caused some ui test crashes
TBR=nsylvain
Review URL: http://codereview.chromium.org/160491
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22235 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/gtk_chrome_link_button.cc')
-rw-r--r-- | chrome/browser/gtk/gtk_chrome_link_button.cc | 106 |
1 files changed, 26 insertions, 80 deletions
diff --git a/chrome/browser/gtk/gtk_chrome_link_button.cc b/chrome/browser/gtk/gtk_chrome_link_button.cc index c2a7f28..bb35010 100644 --- a/chrome/browser/gtk/gtk_chrome_link_button.cc +++ b/chrome/browser/gtk/gtk_chrome_link_button.cc @@ -37,71 +37,16 @@ void SetLinkButtonStyle() { 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->using_native_theme ? button->native_markup : button->blue_markup); + gtk_label_set_markup(GTK_LABEL(label), button->blue_markup); button->is_blue = TRUE; } @@ -169,10 +114,6 @@ 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)) { - g_free(button->native_markup); - button->native_markup = NULL; - } if (button->blue_markup) { g_free(button->blue_markup); button->blue_markup = NULL; @@ -185,13 +126,9 @@ static void gtk_chrome_link_button_destroy(GtkObject* object) { 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); } @@ -221,40 +158,49 @@ static void gtk_chrome_link_button_init(GtkChromeLinkButton* button) { 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(lb)->text = strdup(text); - GTK_CHROME_LINK_BUTTON(lb)->uses_markup = FALSE; + gtk_chrome_link_button_set_text(GTK_CHROME_LINK_BUTTON(lb), text, 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(lb)->text = strdup(markup); - GTK_CHROME_LINK_BUTTON(lb)->uses_markup = TRUE; + gtk_chrome_link_button_set_text(GTK_CHROME_LINK_BUTTON(lb), 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; |