| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // Spacing between the favicon and the text. | 27 // Spacing between the favicon and the text. |
| 28 const int kBarButtonPadding = 4; | 28 const int kBarButtonPadding = 4; |
| 29 | 29 |
| 30 // Used in gtk_selection_data_set(). (I assume from this parameter that gtk has | 30 // Used in gtk_selection_data_set(). (I assume from this parameter that gtk has |
| 31 // to some really exotic hardware...) | 31 // to some really exotic hardware...) |
| 32 const int kBitsInAByte = 8; | 32 const int kBitsInAByte = 8; |
| 33 | 33 |
| 34 // Maximum number of characters on a bookmark button. | 34 // Maximum number of characters on a bookmark button. |
| 35 const size_t kMaxCharsOnAButton = 15; | 35 const size_t kMaxCharsOnAButton = 15; |
| 36 | 36 |
| 37 // Max size of each component of the button tooltips. | |
| 38 const size_t kMaxTooltipTitleLength = 100; | |
| 39 const size_t kMaxTooltipURLLength = 400; | |
| 40 | |
| 41 // Padding between the chrome button highlight border and the contents (favicon, | 37 // Padding between the chrome button highlight border and the contents (favicon, |
| 42 // text). | 38 // text). |
| 43 const int kButtonPaddingTop = 0; | 39 const int kButtonPaddingTop = 0; |
| 44 const int kButtonPaddingBottom = 0; | 40 const int kButtonPaddingBottom = 0; |
| 45 const int kButtonPaddingLeft = 5; | 41 const int kButtonPaddingLeft = 5; |
| 46 const int kButtonPaddingRight = 0; | 42 const int kButtonPaddingRight = 0; |
| 47 | 43 |
| 48 void* AsVoid(const BookmarkNode* node) { | 44 void* AsVoid(const BookmarkNode* node) { |
| 49 return const_cast<BookmarkNode*>(node); | 45 return const_cast<BookmarkNode*>(node); |
| 50 } | 46 } |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 gtk_widget_set_tooltip_markup(button, tooltip.c_str()); | 234 gtk_widget_set_tooltip_markup(button, tooltip.c_str()); |
| 239 | 235 |
| 240 g_object_set_data(G_OBJECT(button), bookmark_utils::kBookmarkNode, | 236 g_object_set_data(G_OBJECT(button), bookmark_utils::kBookmarkNode, |
| 241 AsVoid(node)); | 237 AsVoid(node)); |
| 242 } | 238 } |
| 243 | 239 |
| 244 std::string BuildTooltipFor(const BookmarkNode* node) { | 240 std::string BuildTooltipFor(const BookmarkNode* node) { |
| 245 if (node->is_folder()) | 241 if (node->is_folder()) |
| 246 return std::string(); | 242 return std::string(); |
| 247 | 243 |
| 248 const std::string& url = node->GetURL().possibly_invalid_spec(); | 244 return gtk_util::BuildTooltipTitleFor(node->GetTitle(), node->GetURL()); |
| 249 const std::string& title = UTF16ToUTF8(node->GetTitle()); | |
| 250 | |
| 251 std::string truncated_url = UTF16ToUTF8(l10n_util::TruncateString( | |
| 252 UTF8ToUTF16(url), kMaxTooltipURLLength)); | |
| 253 gchar* escaped_url_cstr = g_markup_escape_text(truncated_url.c_str(), | |
| 254 truncated_url.size()); | |
| 255 std::string escaped_url(escaped_url_cstr); | |
| 256 g_free(escaped_url_cstr); | |
| 257 | |
| 258 std::string tooltip; | |
| 259 if (url == title || title.empty()) { | |
| 260 return escaped_url; | |
| 261 } else { | |
| 262 std::string truncated_title = UTF16ToUTF8(l10n_util::TruncateString( | |
| 263 node->GetTitle(), kMaxTooltipTitleLength)); | |
| 264 gchar* escaped_title_cstr = g_markup_escape_text(truncated_title.c_str(), | |
| 265 truncated_title.size()); | |
| 266 std::string escaped_title(escaped_title_cstr); | |
| 267 g_free(escaped_title_cstr); | |
| 268 | |
| 269 if (!escaped_url.empty()) | |
| 270 return std::string("<b>") + escaped_title + "</b>\n" + escaped_url; | |
| 271 else | |
| 272 return std::string("<b>") + escaped_title + "</b>"; | |
| 273 } | |
| 274 } | 245 } |
| 275 | 246 |
| 276 const BookmarkNode* BookmarkNodeForWidget(GtkWidget* widget) { | 247 const BookmarkNode* BookmarkNodeForWidget(GtkWidget* widget) { |
| 277 return reinterpret_cast<const BookmarkNode*>( | 248 return reinterpret_cast<const BookmarkNode*>( |
| 278 g_object_get_data(G_OBJECT(widget), bookmark_utils::kBookmarkNode)); | 249 g_object_get_data(G_OBJECT(widget), bookmark_utils::kBookmarkNode)); |
| 279 } | 250 } |
| 280 | 251 |
| 281 void SetButtonTextColors(GtkWidget* label, GtkThemeService* provider) { | 252 void SetButtonTextColors(GtkWidget* label, GtkThemeService* provider) { |
| 282 if (provider->UseGtkTheme()) { | 253 if (provider->UseGtkTheme()) { |
| 283 gtk_util::SetLabelColor(label, NULL); | 254 gtk_util::SetLabelColor(label, NULL); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 GURL url; | 405 GURL url; |
| 435 string16 title; | 406 string16 title; |
| 436 if (!ui::ExtractNetscapeURL(selection_data, &url, &title)) | 407 if (!ui::ExtractNetscapeURL(selection_data, &url, &title)) |
| 437 return false; | 408 return false; |
| 438 | 409 |
| 439 model->AddURL(parent, idx, title, url); | 410 model->AddURL(parent, idx, title, url); |
| 440 return true; | 411 return true; |
| 441 } | 412 } |
| 442 | 413 |
| 443 } // namespace bookmark_utils | 414 } // namespace bookmark_utils |
| OLD | NEW |