Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(738)

Side by Side Diff: chrome/browser/gtk/bookmark_utils_gtk.cc

Issue 164101: Don't pack an empty label into bookmarks with empty titles. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/gtk/bookmark_utils_gtk.h" 5 #include "chrome/browser/gtk/bookmark_utils_gtk.h"
6 6
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "base/gfx/gtk_util.h" 8 #include "base/gfx/gtk_util.h"
9 #include "base/pickle.h" 9 #include "base/pickle.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 std::string tooltip = BuildTooltipFor(node); 121 std::string tooltip = BuildTooltipFor(node);
122 if (!tooltip.empty()) 122 if (!tooltip.empty())
123 gtk_widget_set_tooltip_text(button, tooltip.c_str()); 123 gtk_widget_set_tooltip_text(button, tooltip.c_str());
124 124
125 // We pack the button manually (rather than using gtk_button_set_*) so that 125 // We pack the button manually (rather than using gtk_button_set_*) so that
126 // we can have finer control over its label. 126 // we can have finer control over its label.
127 GdkPixbuf* pixbuf = bookmark_utils::GetPixbufForNode(node, model); 127 GdkPixbuf* pixbuf = bookmark_utils::GetPixbufForNode(node, model);
128 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); 128 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf);
129 g_object_unref(pixbuf); 129 g_object_unref(pixbuf);
130 130
131 GtkWidget* label = gtk_label_new(WideToUTF8(node->GetTitle()).c_str());
132 gtk_label_set_max_width_chars(GTK_LABEL(label), kMaxCharsOnAButton);
133 gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END);
134
135 GtkWidget* box = gtk_hbox_new(FALSE, kBarButtonPadding); 131 GtkWidget* box = gtk_hbox_new(FALSE, kBarButtonPadding);
136 gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0); 132 gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0);
137 gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0); 133
134 std::string label_string = WideToUTF8(node->GetTitle());
135 if (!label_string.empty()) {
136 GtkWidget* label = gtk_label_new(label_string.c_str());
137 gtk_label_set_max_width_chars(GTK_LABEL(label), kMaxCharsOnAButton);
138 gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END);
139 gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
140 SetButtonTextColors(label, provider);
141 }
138 142
139 GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); 143 GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
140 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 144 // If we are not showing the label, don't set any padding, so that the icon
141 kButtonPaddingTop, kButtonPaddingBottom, 145 // will just be centered.
142 kButtonPaddingLeft, kButtonPaddingRight); 146 if (label_string.c_str()) {
147 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
148 kButtonPaddingTop, kButtonPaddingBottom,
149 kButtonPaddingLeft, kButtonPaddingRight);
150 }
143 gtk_container_add(GTK_CONTAINER(alignment), box); 151 gtk_container_add(GTK_CONTAINER(alignment), box);
144 gtk_container_add(GTK_CONTAINER(button), alignment); 152 gtk_container_add(GTK_CONTAINER(button), alignment);
145 153
146 SetButtonTextColors(label, provider);
147 g_object_set_data(G_OBJECT(button), bookmark_utils::kBookmarkNode, 154 g_object_set_data(G_OBJECT(button), bookmark_utils::kBookmarkNode,
148 AsVoid(node)); 155 AsVoid(node));
149 156
150 gtk_widget_show_all(alignment); 157 gtk_widget_show_all(alignment);
151 } 158 }
152 159
153 std::string BuildTooltipFor(const BookmarkNode* node) { 160 std::string BuildTooltipFor(const BookmarkNode* node) {
154 // TODO(erg): Actually build the tooltip. For now, we punt and just return 161 // TODO(erg): Actually build the tooltip. For now, we punt and just return
155 // the URL. 162 // the URL.
156 return node->GetURL().possibly_invalid_spec(); 163 return node->GetURL().possibly_invalid_spec();
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 GURL url(uris[i]); 292 GURL url(uris[i]);
286 std::string title = GetNameForURL(url); 293 std::string title = GetNameForURL(url);
287 model->AddURL(parent, idx++, UTF8ToWide(title), url); 294 model->AddURL(parent, idx++, UTF8ToWide(title), url);
288 } 295 }
289 296
290 g_strfreev(uris); 297 g_strfreev(uris);
291 return true; 298 return true;
292 } 299 }
293 300
294 } // namespace bookmark_utils 301 } // namespace bookmark_utils
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698