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

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

Issue 112913004: Update some uses of UTF conversions in chrome/browser to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 12 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/gtk/bookmarks/bookmark_utils_gtk.h" 5 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h"
6 6
7 #include "base/pickle.h" 7 #include "base/pickle.h"
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 if (former_child) 66 if (former_child)
67 gtk_container_remove(GTK_CONTAINER(button), former_child); 67 gtk_container_remove(GTK_CONTAINER(button), former_child);
68 68
69 // We pack the button manually (rather than using gtk_button_set_*) so that 69 // We pack the button manually (rather than using gtk_button_set_*) so that
70 // we can have finer control over its label. 70 // we can have finer control over its label.
71 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); 71 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf);
72 72
73 GtkWidget* box = gtk_hbox_new(FALSE, kBarButtonPadding); 73 GtkWidget* box = gtk_hbox_new(FALSE, kBarButtonPadding);
74 gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0); 74 gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0);
75 75
76 std::string label_string = UTF16ToUTF8(title); 76 std::string label_string = base::UTF16ToUTF8(title);
77 if (!label_string.empty()) { 77 if (!label_string.empty()) {
78 GtkWidget* label = gtk_label_new(label_string.c_str()); 78 GtkWidget* label = gtk_label_new(label_string.c_str());
79 // Until we switch to vector graphics, force the font size. 79 // Until we switch to vector graphics, force the font size.
80 if (!provider->UsingNativeTheme()) 80 if (!provider->UsingNativeTheme())
81 gtk_util::ForceFontSizePixels(label, 13.4); // 13.4px == 10pt @ 96dpi 81 gtk_util::ForceFontSizePixels(label, 13.4); // 13.4px == 10pt @ 96dpi
82 82
83 // Ellipsize long bookmark names. 83 // Ellipsize long bookmark names.
84 if (ellipsize) { 84 if (ellipsize) {
85 gtk_label_set_max_width_chars(GTK_LABEL(label), kMaxCharsOnAButton); 85 gtk_label_set_max_width_chars(GTK_LABEL(label), kMaxCharsOnAButton);
86 gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END); 86 gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 std::string BuildTooltipFor(const BookmarkNode* node) { 269 std::string BuildTooltipFor(const BookmarkNode* node) {
270 if (node->is_folder()) 270 if (node->is_folder())
271 return std::string(); 271 return std::string();
272 272
273 return gtk_util::BuildTooltipTitleFor(node->GetTitle(), node->url()); 273 return gtk_util::BuildTooltipTitleFor(node->GetTitle(), node->url());
274 } 274 }
275 275
276 std::string BuildMenuLabelFor(const BookmarkNode* node) { 276 std::string BuildMenuLabelFor(const BookmarkNode* node) {
277 // This breaks on word boundaries. Ideally we would break on character 277 // This breaks on word boundaries. Ideally we would break on character
278 // boundaries. 278 // boundaries.
279 std::string elided_name = UTF16ToUTF8( 279 std::string elided_name = base::UTF16ToUTF8(
280 gfx::TruncateString(node->GetTitle(), kMaxCharsOnAMenuLabel)); 280 gfx::TruncateString(node->GetTitle(), kMaxCharsOnAMenuLabel));
281 281
282 if (elided_name.empty()) { 282 if (elided_name.empty()) {
283 elided_name = UTF16ToUTF8(gfx::TruncateString( 283 elided_name = base::UTF16ToUTF8(gfx::TruncateString(
284 UTF8ToUTF16(node->url().possibly_invalid_spec()), 284 base::UTF8ToUTF16(node->url().possibly_invalid_spec()),
285 kMaxCharsOnAMenuLabel)); 285 kMaxCharsOnAMenuLabel));
286 } 286 }
287 287
288 return elided_name; 288 return elided_name;
289 } 289 }
290 290
291 const BookmarkNode* BookmarkNodeForWidget(GtkWidget* widget) { 291 const BookmarkNode* BookmarkNodeForWidget(GtkWidget* widget) {
292 return reinterpret_cast<const BookmarkNode*>( 292 return reinterpret_cast<const BookmarkNode*>(
293 g_object_get_data(G_OBJECT(widget), kBookmarkNode)); 293 g_object_get_data(G_OBJECT(widget), kBookmarkNode));
294 } 294 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 gtk_selection_data_set(selection_data, 345 gtk_selection_data_set(selection_data,
346 gtk_selection_data_get_target(selection_data), 346 gtk_selection_data_get_target(selection_data),
347 kBitsInAByte, 347 kBitsInAByte,
348 static_cast<const guchar*>(pickle.data()), 348 static_cast<const guchar*>(pickle.data()),
349 pickle.size()); 349 pickle.size());
350 break; 350 break;
351 } 351 }
352 case ui::NETSCAPE_URL: { 352 case ui::NETSCAPE_URL: {
353 // _NETSCAPE_URL format is URL + \n + title. 353 // _NETSCAPE_URL format is URL + \n + title.
354 std::string utf8_text = nodes[0]->url().spec() + "\n" + 354 std::string utf8_text = nodes[0]->url().spec() + "\n" +
355 UTF16ToUTF8(nodes[0]->GetTitle()); 355 base::UTF16ToUTF8(nodes[0]->GetTitle());
356 gtk_selection_data_set(selection_data, 356 gtk_selection_data_set(selection_data,
357 gtk_selection_data_get_target(selection_data), 357 gtk_selection_data_get_target(selection_data),
358 kBitsInAByte, 358 kBitsInAByte,
359 reinterpret_cast<const guchar*>(utf8_text.c_str()), 359 reinterpret_cast<const guchar*>(utf8_text.c_str()),
360 utf8_text.length()); 360 utf8_text.length());
361 break; 361 break;
362 } 362 }
363 case ui::TEXT_URI_LIST: { 363 case ui::TEXT_URI_LIST: {
364 gchar** uris = reinterpret_cast<gchar**>(malloc(sizeof(gchar*) * 364 gchar** uris = reinterpret_cast<gchar**>(malloc(sizeof(gchar*) *
365 (nodes.size() + 1))); 365 (nodes.size() + 1)));
366 for (size_t i = 0; i < nodes.size(); ++i) { 366 for (size_t i = 0; i < nodes.size(); ++i) {
367 // If the node is a folder, this will be empty. TODO(estade): figure out 367 // If the node is a folder, this will be empty. TODO(estade): figure out
368 // if there are any ramifications to passing an empty URI. After a 368 // if there are any ramifications to passing an empty URI. After a
369 // little testing, it seems fine. 369 // little testing, it seems fine.
370 const GURL& url = nodes[i]->url(); 370 const GURL& url = nodes[i]->url();
371 // This const cast should be safe as gtk_selection_data_set_uris() 371 // This const cast should be safe as gtk_selection_data_set_uris()
372 // makes copies. 372 // makes copies.
373 uris[i] = const_cast<gchar*>(url.spec().c_str()); 373 uris[i] = const_cast<gchar*>(url.spec().c_str());
374 } 374 }
375 uris[nodes.size()] = NULL; 375 uris[nodes.size()] = NULL;
376 376
377 gtk_selection_data_set_uris(selection_data, uris); 377 gtk_selection_data_set_uris(selection_data, uris);
378 free(uris); 378 free(uris);
379 break; 379 break;
380 } 380 }
381 case ui::TEXT_HTML: { 381 case ui::TEXT_HTML: {
382 std::string utf8_title = UTF16ToUTF8(nodes[0]->GetTitle()); 382 std::string utf8_title = base::UTF16ToUTF8(nodes[0]->GetTitle());
383 std::string utf8_html = base::StringPrintf("<a href=\"%s\">%s</a>", 383 std::string utf8_html = base::StringPrintf("<a href=\"%s\">%s</a>",
384 nodes[0]->url().spec().c_str(), 384 nodes[0]->url().spec().c_str(),
385 utf8_title.c_str()); 385 utf8_title.c_str());
386 gtk_selection_data_set(selection_data, 386 gtk_selection_data_set(selection_data,
387 GetAtomForTarget(ui::TEXT_HTML), 387 GetAtomForTarget(ui::TEXT_HTML),
388 kBitsInAByte, 388 kBitsInAByte,
389 reinterpret_cast<const guchar*>(utf8_html.data()), 389 reinterpret_cast<const guchar*>(utf8_html.data()),
390 utf8_html.size()); 390 utf8_html.size());
391 break; 391 break;
392 } 392 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 return net::GetSuggestedFilename(url, 484 return net::GetSuggestedFilename(url,
485 std::string(), 485 std::string(),
486 std::string(), 486 std::string(),
487 std::string(), 487 std::string(),
488 std::string(), 488 std::string(),
489 std::string()); 489 std::string());
490 } else { 490 } else {
491 return l10n_util::GetStringUTF16(IDS_APP_UNTITLED_SHORTCUT_FILE_NAME); 491 return l10n_util::GetStringUTF16(IDS_APP_UNTITLED_SHORTCUT_FILE_NAME);
492 } 492 }
493 } 493 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/bookmarks/bookmark_tree_model.cc ('k') | chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698