| OLD | NEW |
| 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_menu_controller_gtk.h" | 5 #include "chrome/browser/gtk/bookmark_menu_controller_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include "app/gtk_dnd_util.h" | 9 #include "app/gtk_dnd_util.h" |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| 11 #include "app/resource_bundle.h" | 11 #include "app/resource_bundle.h" |
| 12 #include "base/gfx/gtk_util.h" | 12 #include "base/gfx/gtk_util.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "chrome/browser/bookmarks/bookmark_model.h" | 14 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 15 #include "chrome/browser/gtk/bookmark_context_menu.h" | 15 #include "chrome/browser/gtk/bookmark_context_menu.h" |
| 16 #include "chrome/browser/gtk/bookmark_utils_gtk.h" | 16 #include "chrome/browser/gtk/bookmark_utils_gtk.h" |
| 17 #include "chrome/browser/gtk/gtk_chrome_button.h" | 17 #include "chrome/browser/gtk/gtk_chrome_button.h" |
| 18 #include "chrome/browser/gtk/gtk_theme_provider.h" | 18 #include "chrome/browser/gtk/gtk_theme_provider.h" |
| 19 #include "chrome/browser/gtk/menu_gtk.h" | 19 #include "chrome/browser/gtk/menu_gtk.h" |
| 20 #include "chrome/browser/profile.h" | 20 #include "chrome/browser/profile.h" |
| 21 #include "chrome/browser/tab_contents/page_navigator.h" | 21 #include "chrome/browser/tab_contents/page_navigator.h" |
| 22 #include "chrome/common/gtk_util.h" | 22 #include "chrome/common/gtk_util.h" |
| 23 #include "grit/app_resources.h" | 23 #include "grit/app_resources.h" |
| 24 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| 25 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
| 26 #include "webkit/glue/window_open_disposition.h" | 26 #include "webkit/glue/window_open_disposition.h" |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // TODO(estade): It might be a good idea to vary this by locale. |
| 31 const int kMaxChars = 50; |
| 32 |
| 30 void SetImageMenuItem(GtkWidget* menu_item, const SkBitmap& bitmap) { | 33 void SetImageMenuItem(GtkWidget* menu_item, const SkBitmap& bitmap) { |
| 31 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&bitmap); | 34 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&bitmap); |
| 32 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), | 35 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), |
| 33 gtk_image_new_from_pixbuf(pixbuf)); | 36 gtk_image_new_from_pixbuf(pixbuf)); |
| 34 g_object_unref(pixbuf); | 37 g_object_unref(pixbuf); |
| 35 } | 38 } |
| 36 | 39 |
| 37 const BookmarkNode* GetNodeFromMenuItem(GtkWidget* menu_item) { | 40 const BookmarkNode* GetNodeFromMenuItem(GtkWidget* menu_item) { |
| 38 return static_cast<const BookmarkNode*>( | 41 return static_cast<const BookmarkNode*>( |
| 39 g_object_get_data(G_OBJECT(menu_item), "bookmark-node")); | 42 g_object_get_data(G_OBJECT(menu_item), "bookmark-node")); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 GtkWidget* menu) { | 146 GtkWidget* menu) { |
| 144 DCHECK(!parent->GetChildCount() || | 147 DCHECK(!parent->GetChildCount() || |
| 145 start_child_index < parent->GetChildCount()); | 148 start_child_index < parent->GetChildCount()); |
| 146 | 149 |
| 147 g_signal_connect(G_OBJECT(menu), "button-press-event", | 150 g_signal_connect(G_OBJECT(menu), "button-press-event", |
| 148 G_CALLBACK(OnButtonPressed), this); | 151 G_CALLBACK(OnButtonPressed), this); |
| 149 | 152 |
| 150 for (int i = start_child_index; i < parent->GetChildCount(); ++i) { | 153 for (int i = start_child_index; i < parent->GetChildCount(); ++i) { |
| 151 const BookmarkNode* node = parent->GetChild(i); | 154 const BookmarkNode* node = parent->GetChild(i); |
| 152 | 155 |
| 153 GtkWidget* menu_item = gtk_image_menu_item_new_with_label( | 156 // This breaks on word boundaries. Ideally we would break on character |
| 154 WideToUTF8(node->GetTitle()).c_str()); | 157 // boundaries. |
| 158 std::wstring elided_name = |
| 159 l10n_util::TruncateString(node->GetTitle(), kMaxChars); |
| 160 GtkWidget* menu_item = |
| 161 gtk_image_menu_item_new_with_label(WideToUTF8(elided_name).c_str()); |
| 155 g_object_set_data(G_OBJECT(menu_item), "bookmark-node", AsVoid(node)); | 162 g_object_set_data(G_OBJECT(menu_item), "bookmark-node", AsVoid(node)); |
| 156 | 163 |
| 157 if (node->is_url()) { | 164 if (node->is_url()) { |
| 158 SkBitmap icon = profile_->GetBookmarkModel()->GetFavIcon(node); | 165 SkBitmap icon = profile_->GetBookmarkModel()->GetFavIcon(node); |
| 159 if (icon.width() == 0) { | 166 if (icon.width() == 0) { |
| 160 icon = *ResourceBundle::GetSharedInstance(). | 167 icon = *ResourceBundle::GetSharedInstance(). |
| 161 GetBitmapNamed(IDR_DEFAULT_FAVICON); | 168 GetBitmapNamed(IDR_DEFAULT_FAVICON); |
| 162 } | 169 } |
| 163 SetImageMenuItem(menu_item, icon); | 170 SetImageMenuItem(menu_item, icon); |
| 164 g_signal_connect(G_OBJECT(menu_item), "activate", | 171 g_signal_connect(G_OBJECT(menu_item), "activate", |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 // static | 345 // static |
| 339 void BookmarkMenuController::OnMenuItemDragGet( | 346 void BookmarkMenuController::OnMenuItemDragGet( |
| 340 GtkWidget* widget, GdkDragContext* context, | 347 GtkWidget* widget, GdkDragContext* context, |
| 341 GtkSelectionData* selection_data, | 348 GtkSelectionData* selection_data, |
| 342 guint target_type, guint time, | 349 guint target_type, guint time, |
| 343 BookmarkMenuController* controller) { | 350 BookmarkMenuController* controller) { |
| 344 const BookmarkNode* node = bookmark_utils::BookmarkNodeForWidget(widget); | 351 const BookmarkNode* node = bookmark_utils::BookmarkNodeForWidget(widget); |
| 345 bookmark_utils::WriteBookmarkToSelection(node, selection_data, target_type, | 352 bookmark_utils::WriteBookmarkToSelection(node, selection_data, target_type, |
| 346 controller->profile_); | 353 controller->profile_); |
| 347 } | 354 } |
| OLD | NEW |