summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk
diff options
context:
space:
mode:
authorcraig.schlenter@chromium.org <craig.schlenter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-01 04:40:39 +0000
committercraig.schlenter@chromium.org <craig.schlenter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-01 04:40:39 +0000
commitbe61bb5c487f1020756c31a39fbe23535e4d425b (patch)
tree3e29ec953ed5e45193b8f4f08790b5eeb471a8d1 /chrome/browser/gtk
parentbdb72360b89de3fd7fbcfe6d14b38e3c230dcd84 (diff)
downloadchromium_src-be61bb5c487f1020756c31a39fbe23535e4d425b.zip
chromium_src-be61bb5c487f1020756c31a39fbe23535e4d425b.tar.gz
chromium_src-be61bb5c487f1020756c31a39fbe23535e4d425b.tar.bz2
Ensure bookmark title truncation always produces a valid UTF-8 string.
We also add ellipses to the bookmark title. TEST = A bookmark with a title that has a UTF-8 character that spans the 15 character truncation point should not cause "Gtk: Invalid input string" errors. See http://dev.chromium.org/developers/coding-style for an example of the problem. The title in that case is as follows: "Coding Style \u200E(Chromium Developer Documentation)\u200E" Review URL: http://codereview.chromium.org/147207 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19706 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r--chrome/browser/gtk/bookmark_utils_gtk.cc17
1 files changed, 11 insertions, 6 deletions
diff --git a/chrome/browser/gtk/bookmark_utils_gtk.cc b/chrome/browser/gtk/bookmark_utils_gtk.cc
index e66adff..982e044 100644
--- a/chrome/browser/gtk/bookmark_utils_gtk.cc
+++ b/chrome/browser/gtk/bookmark_utils_gtk.cc
@@ -129,18 +129,23 @@ void ConfigureButtonForNode(const BookmarkNode* node, BookmarkModel* model,
if (!tooltip.empty())
gtk_widget_set_tooltip_text(button, tooltip.c_str());
+ GdkPixbuf* pixbuf = bookmark_utils::GetPixbufForNode(node, model);
+ gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_pixbuf(pixbuf));
+ g_object_unref(pixbuf);
+
// TODO(erg): Consider a soft maximum instead of this hard 15.
std::wstring title = node->GetTitle();
// Don't treat underscores as mnemonics.
// O, that we could just use gtk_button_set_use_underline()!
// See http://bugzilla.gnome.org/show_bug.cgi?id=586330
std::string text = DoubleUnderscores(WideToUTF8(title));
- text = text.substr(0, std::min(text.size(), kMaxCharsOnAButton));
gtk_button_set_label(GTK_BUTTON(button), text.c_str());
-
- GdkPixbuf* pixbuf = bookmark_utils::GetPixbufForNode(node, model);
- gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_pixbuf(pixbuf));
- g_object_unref(pixbuf);
+ GtkWidget* label = NULL;
+ gtk_container_foreach(GTK_CONTAINER(button), SearchForLabel, &label);
+ if (label) {
+ gtk_label_set_max_width_chars(GTK_LABEL(label), kMaxCharsOnAButton);
+ gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END);
+ }
SetButtonTextColors(button);
g_object_set_data(G_OBJECT(button), bookmark_utils::kBookmarkNode,
@@ -159,7 +164,7 @@ const BookmarkNode* BookmarkNodeForWidget(GtkWidget* widget) {
}
void SetButtonTextColors(GtkWidget* button) {
- GtkWidget* label;
+ GtkWidget* label = NULL;
gtk_container_foreach(GTK_CONTAINER(button), SearchForLabel, &label);
if (label) {
gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &kEnabledColor);