| 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 // Maximum number of characters on a menu label. |
| 38 const int kMaxCharsOnAMenuLabel = 50; |
| 39 |
| 37 // Padding between the chrome button highlight border and the contents (favicon, | 40 // Padding between the chrome button highlight border and the contents (favicon, |
| 38 // text). | 41 // text). |
| 39 const int kButtonPaddingTop = 0; | 42 const int kButtonPaddingTop = 0; |
| 40 const int kButtonPaddingBottom = 0; | 43 const int kButtonPaddingBottom = 0; |
| 41 const int kButtonPaddingLeft = 5; | 44 const int kButtonPaddingLeft = 5; |
| 42 const int kButtonPaddingRight = 0; | 45 const int kButtonPaddingRight = 0; |
| 43 | 46 |
| 44 void* AsVoid(const BookmarkNode* node) { | 47 void* AsVoid(const BookmarkNode* node) { |
| 45 return const_cast<BookmarkNode*>(node); | 48 return const_cast<BookmarkNode*>(node); |
| 46 } | 49 } |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 AsVoid(node)); | 241 AsVoid(node)); |
| 239 } | 242 } |
| 240 | 243 |
| 241 std::string BuildTooltipFor(const BookmarkNode* node) { | 244 std::string BuildTooltipFor(const BookmarkNode* node) { |
| 242 if (node->is_folder()) | 245 if (node->is_folder()) |
| 243 return std::string(); | 246 return std::string(); |
| 244 | 247 |
| 245 return gtk_util::BuildTooltipTitleFor(node->GetTitle(), node->GetURL()); | 248 return gtk_util::BuildTooltipTitleFor(node->GetTitle(), node->GetURL()); |
| 246 } | 249 } |
| 247 | 250 |
| 251 std::string BuildMenuLabelFor(const BookmarkNode* node) { |
| 252 // This breaks on word boundaries. Ideally we would break on character |
| 253 // boundaries. |
| 254 std::string elided_name = UTF16ToUTF8( |
| 255 l10n_util::TruncateString(node->GetTitle(), kMaxCharsOnAMenuLabel)); |
| 256 |
| 257 if (elided_name.empty()) { |
| 258 elided_name = UTF16ToUTF8(l10n_util::TruncateString( |
| 259 UTF8ToUTF16(node->GetURL().possibly_invalid_spec()), |
| 260 kMaxCharsOnAMenuLabel)); |
| 261 } |
| 262 |
| 263 return elided_name; |
| 264 } |
| 265 |
| 248 const BookmarkNode* BookmarkNodeForWidget(GtkWidget* widget) { | 266 const BookmarkNode* BookmarkNodeForWidget(GtkWidget* widget) { |
| 249 return reinterpret_cast<const BookmarkNode*>( | 267 return reinterpret_cast<const BookmarkNode*>( |
| 250 g_object_get_data(G_OBJECT(widget), bookmark_utils::kBookmarkNode)); | 268 g_object_get_data(G_OBJECT(widget), bookmark_utils::kBookmarkNode)); |
| 251 } | 269 } |
| 252 | 270 |
| 253 void SetButtonTextColors(GtkWidget* label, GtkThemeService* provider) { | 271 void SetButtonTextColors(GtkWidget* label, GtkThemeService* provider) { |
| 254 if (provider->UsingNativeTheme()) { | 272 if (provider->UsingNativeTheme()) { |
| 255 gtk_util::SetLabelColor(label, NULL); | 273 gtk_util::SetLabelColor(label, NULL); |
| 256 } else { | 274 } else { |
| 257 GdkColor color = provider->GetGdkColor( | 275 GdkColor color = provider->GetGdkColor( |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 GURL url; | 424 GURL url; |
| 407 string16 title; | 425 string16 title; |
| 408 if (!ui::ExtractNetscapeURL(selection_data, &url, &title)) | 426 if (!ui::ExtractNetscapeURL(selection_data, &url, &title)) |
| 409 return false; | 427 return false; |
| 410 | 428 |
| 411 model->AddURL(parent, idx, title, url); | 429 model->AddURL(parent, idx, title, url); |
| 412 return true; | 430 return true; |
| 413 } | 431 } |
| 414 | 432 |
| 415 } // namespace bookmark_utils | 433 } // namespace bookmark_utils |
| OLD | NEW |