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

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

Issue 175004: Ellipsize long entries in bookmark menus and the back/forward menus.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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
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/gtk_dnd_util.h" 7 #include "app/gtk_dnd_util.h"
8 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 9 #include "app/resource_bundle.h"
9 #include "base/gfx/gtk_util.h" 10 #include "base/gfx/gtk_util.h"
10 #include "base/pickle.h" 11 #include "base/pickle.h"
11 #include "base/string_util.h" 12 #include "base/string_util.h"
12 #include "chrome/browser/bookmarks/bookmark_drag_data.h" 13 #include "chrome/browser/bookmarks/bookmark_drag_data.h"
13 #include "chrome/browser/bookmarks/bookmark_model.h" 14 #include "chrome/browser/bookmarks/bookmark_model.h"
14 #include "chrome/browser/bookmarks/bookmark_utils.h" 15 #include "chrome/browser/bookmarks/bookmark_utils.h"
15 #include "chrome/browser/gtk/gtk_chrome_button.h" 16 #include "chrome/browser/gtk/gtk_chrome_button.h"
16 #include "chrome/browser/gtk/gtk_theme_provider.h" 17 #include "chrome/browser/gtk/gtk_theme_provider.h"
17 #include "chrome/browser/profile.h" 18 #include "chrome/browser/profile.h"
18 #include "chrome/common/gtk_util.h" 19 #include "chrome/common/gtk_util.h"
19 #include "grit/app_resources.h" 20 #include "grit/app_resources.h"
20 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
21 #include "grit/theme_resources.h" 22 #include "grit/theme_resources.h"
22 23
23 namespace { 24 namespace {
24 25
25 // Used in gtk_selection_data_set(). (I assume from this parameter that gtk has 26 // Used in gtk_selection_data_set(). (I assume from this parameter that gtk has
26 // to some really exotic hardware...) 27 // to some really exotic hardware...)
27 const int kBitsInAByte = 8; 28 const int kBitsInAByte = 8;
28 29
29 // Maximum number of characters on a bookmark button. 30 // Maximum number of characters on a bookmark button.
30 const size_t kMaxCharsOnAButton = 15; 31 const size_t kMaxCharsOnAButton = 15;
31 32
33 // Max size of each component of the button tooltips.
34 const size_t kMaxTooltipTitleLength = 100;
35 const size_t kMaxTooltipURLLength = 400;
36
32 // Only used for the background of the drag widget. 37 // Only used for the background of the drag widget.
33 const GdkColor kBackgroundColor = GDK_COLOR_RGB(0xe6, 0xed, 0xf4); 38 const GdkColor kBackgroundColor = GDK_COLOR_RGB(0xe6, 0xed, 0xf4);
34 39
35 // Padding between the chrome button highlight border and the contents (favicon, 40 // Padding between the chrome button highlight border and the contents (favicon,
36 // text). 41 // text).
37 // TODO(estade): we need to adjust the top and bottom padding, but first we need 42 // TODO(estade): we need to adjust the top and bottom padding, but first we need
38 // to give the bookmark bar more space (at the expense of the toolbar). 43 // to give the bookmark bar more space (at the expense of the toolbar).
39 const int kButtonPaddingTop = 0; 44 const int kButtonPaddingTop = 0;
40 const int kButtonPaddingBottom = 0; 45 const int kButtonPaddingBottom = 0;
41 const int kButtonPaddingLeft = 2; 46 const int kButtonPaddingLeft = 2;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 145 }
141 146
142 void ConfigureButtonForNode(const BookmarkNode* node, BookmarkModel* model, 147 void ConfigureButtonForNode(const BookmarkNode* node, BookmarkModel* model,
143 GtkWidget* button, GtkThemeProvider* provider) { 148 GtkWidget* button, GtkThemeProvider* provider) {
144 GtkWidget* former_child = gtk_bin_get_child(GTK_BIN(button)); 149 GtkWidget* former_child = gtk_bin_get_child(GTK_BIN(button));
145 if (former_child) 150 if (former_child)
146 gtk_container_remove(GTK_CONTAINER(button), former_child); 151 gtk_container_remove(GTK_CONTAINER(button), former_child);
147 152
148 std::string tooltip = BuildTooltipFor(node); 153 std::string tooltip = BuildTooltipFor(node);
149 if (!tooltip.empty()) 154 if (!tooltip.empty())
150 gtk_widget_set_tooltip_text(button, tooltip.c_str()); 155 gtk_widget_set_tooltip_markup(button, tooltip.c_str());
151 156
152 // We pack the button manually (rather than using gtk_button_set_*) so that 157 // We pack the button manually (rather than using gtk_button_set_*) so that
153 // we can have finer control over its label. 158 // we can have finer control over its label.
154 GdkPixbuf* pixbuf = bookmark_utils::GetPixbufForNode(node, model, 159 GdkPixbuf* pixbuf = bookmark_utils::GetPixbufForNode(node, model,
155 provider->UseGtkTheme()); 160 provider->UseGtkTheme());
156 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); 161 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf);
157 g_object_unref(pixbuf); 162 g_object_unref(pixbuf);
158 163
159 GtkWidget* box = gtk_hbox_new(FALSE, kBarButtonPadding); 164 GtkWidget* box = gtk_hbox_new(FALSE, kBarButtonPadding);
160 gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0); 165 gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0);
(...skipping 18 matching lines...) Expand all
179 gtk_container_add(GTK_CONTAINER(alignment), box); 184 gtk_container_add(GTK_CONTAINER(alignment), box);
180 gtk_container_add(GTK_CONTAINER(button), alignment); 185 gtk_container_add(GTK_CONTAINER(button), alignment);
181 186
182 g_object_set_data(G_OBJECT(button), bookmark_utils::kBookmarkNode, 187 g_object_set_data(G_OBJECT(button), bookmark_utils::kBookmarkNode,
183 AsVoid(node)); 188 AsVoid(node));
184 189
185 gtk_widget_show_all(alignment); 190 gtk_widget_show_all(alignment);
186 } 191 }
187 192
188 std::string BuildTooltipFor(const BookmarkNode* node) { 193 std::string BuildTooltipFor(const BookmarkNode* node) {
189 // TODO(erg): Actually build the tooltip. For now, we punt and just return 194 const std::string& url = node->GetURL().possibly_invalid_spec();
190 // the URL. 195 const std::string& title = WideToUTF8(node->GetTitle());
191 return node->GetURL().possibly_invalid_spec(); 196
197 std::string truncated_url = WideToUTF8(l10n_util::TruncateString(
198 UTF8ToWide(url), kMaxTooltipURLLength));
199 gchar* escaped_url_cstr = g_markup_escape_text(truncated_url.c_str(),
200 truncated_url.size());
201 std::string escaped_url(escaped_url_cstr);
202 g_free(escaped_url_cstr);
203
204 std::string tooltip;
205 if (url == title) {
206 return escaped_url;
207 } else {
208 std::string truncated_title = WideToUTF8(l10n_util::TruncateString(
209 node->GetTitle(), kMaxTooltipTitleLength));
210 gchar* escaped_title_cstr = g_markup_escape_text(truncated_title.c_str(),
211 truncated_title.size());
212 std::string escaped_title(escaped_title_cstr);
213 g_free(escaped_title_cstr);
214
215 return std::string("<b>") + escaped_title + "</b>\n" + escaped_url;
216 }
192 } 217 }
193 218
194 const BookmarkNode* BookmarkNodeForWidget(GtkWidget* widget) { 219 const BookmarkNode* BookmarkNodeForWidget(GtkWidget* widget) {
195 return reinterpret_cast<const BookmarkNode*>( 220 return reinterpret_cast<const BookmarkNode*>(
196 g_object_get_data(G_OBJECT(widget), bookmark_utils::kBookmarkNode)); 221 g_object_get_data(G_OBJECT(widget), bookmark_utils::kBookmarkNode));
197 } 222 }
198 223
199 void SetButtonTextColors(GtkWidget* label, GtkThemeProvider* provider) { 224 void SetButtonTextColors(GtkWidget* label, GtkThemeProvider* provider) {
200 if (provider->UseGtkTheme()) { 225 if (provider->UseGtkTheme()) {
201 gtk_util::SetLabelColor(label, NULL); 226 gtk_util::SetLabelColor(label, NULL);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 std::vector<GURL> urls; 332 std::vector<GURL> urls;
308 GtkDndUtil::ExtractURIList(selection_data, &urls); 333 GtkDndUtil::ExtractURIList(selection_data, &urls);
309 for (size_t i = 0; i < urls.size(); ++i) { 334 for (size_t i = 0; i < urls.size(); ++i) {
310 std::string title = GetNameForURL(urls[i]); 335 std::string title = GetNameForURL(urls[i]);
311 model->AddURL(parent, idx++, UTF8ToWide(title), urls[i]); 336 model->AddURL(parent, idx++, UTF8ToWide(title), urls[i]);
312 } 337 }
313 return true; 338 return true;
314 } 339 }
315 340
316 } // namespace bookmark_utils 341 } // namespace bookmark_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698