| OLD | NEW |
| 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_sub_menu_model_gtk.h" | 5 #include "chrome/browser/ui/gtk/bookmarks/bookmark_sub_menu_model_gtk.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_model.h" | 11 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h" | 15 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h" |
| 16 #include "chrome/browser/ui/gtk/menu_gtk.h" | 16 #include "chrome/browser/ui/gtk/menu_gtk.h" |
| 17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 18 #include "grit/theme_resources.h" |
| 18 #include "ui/base/gtk/menu_label_accelerator_util.h" | 19 #include "ui/base/gtk/menu_label_accelerator_util.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/base/window_open_disposition.h" | 22 #include "ui/base/window_open_disposition.h" |
| 21 | 23 |
| 22 using content::OpenURLParams; | 24 using content::OpenURLParams; |
| 23 using content::PageNavigator; | 25 using content::PageNavigator; |
| 24 | 26 |
| 25 // Per chrome/app/chrome_command_ids.h, values < 4000 are for "dynamic menu | 27 // Per chrome/app/chrome_command_ids.h, values < 4000 are for "dynamic menu |
| 26 // items". We only use one command id for all the bookmarks, because we handle | 28 // items". We only use one command id for all the bookmarks, because we handle |
| 27 // bookmark item activations directly. So we pick a suitably large random value | 29 // bookmark item activations directly. So we pick a suitably large random value |
| 28 // and use that to avoid accidental conflicts with other dynamic items. | 30 // and use that to avoid accidental conflicts with other dynamic items. |
| 29 static const int kBookmarkItemCommandId = 1759; | 31 static const int kBookmarkItemCommandId = 1759; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // Ironically the label will end up getting converted back to UTF8 later. | 96 // Ironically the label will end up getting converted back to UTF8 later. |
| 95 // We need to escape any Windows-style "&" characters since they will be | 97 // We need to escape any Windows-style "&" characters since they will be |
| 96 // converted in MenuGtk outside of our control here. | 98 // converted in MenuGtk outside of our control here. |
| 97 const string16 label = UTF8ToUTF16(ui::EscapeWindowsStyleAccelerators( | 99 const string16 label = UTF8ToUTF16(ui::EscapeWindowsStyleAccelerators( |
| 98 bookmark_utils::BuildMenuLabelFor(node))); | 100 bookmark_utils::BuildMenuLabelFor(node))); |
| 99 // Don't pass in the delegate, if any. Bookmark submenus don't need one. | 101 // Don't pass in the delegate, if any. Bookmark submenus don't need one. |
| 100 BookmarkNodeMenuModel* submenu = | 102 BookmarkNodeMenuModel* submenu = |
| 101 new BookmarkNodeMenuModel(NULL, model_, node, page_navigator_); | 103 new BookmarkNodeMenuModel(NULL, model_, node, page_navigator_); |
| 102 // No command id. Nothing happens if you click on the submenu itself. | 104 // No command id. Nothing happens if you click on the submenu itself. |
| 103 AddSubMenu(kBookmarkItemCommandId, label, submenu); | 105 AddSubMenu(kBookmarkItemCommandId, label, submenu); |
| 106 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 107 const gfx::Image& folder_icon = rb.GetImageNamed(IDR_BOOKMARK_BAR_FOLDER); |
| 108 SetIcon(GetItemCount() - 1, folder_icon); |
| 104 submenus_.push_back(submenu); | 109 submenus_.push_back(submenu); |
| 105 } | 110 } |
| 106 | 111 |
| 107 void BookmarkNodeMenuModel::NavigateToMenuItem( | 112 void BookmarkNodeMenuModel::NavigateToMenuItem( |
| 108 int index, | 113 int index, |
| 109 WindowOpenDisposition disposition) { | 114 WindowOpenDisposition disposition) { |
| 110 const BookmarkNode* node = node_->GetChild(index); | 115 const BookmarkNode* node = node_->GetChild(index); |
| 111 DCHECK(node); | 116 DCHECK(node); |
| 112 page_navigator_->OpenURL(OpenURLParams( | 117 page_navigator_->OpenURL(OpenURLParams( |
| 113 node->url(), content::Referrer(), disposition, | 118 node->url(), content::Referrer(), disposition, |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 224 |
| 220 bool BookmarkSubMenuModel::IsVisibleAt(int index) const { | 225 bool BookmarkSubMenuModel::IsVisibleAt(int index) const { |
| 221 // We don't want the delegate interfering with bookmark items. | 226 // We don't want the delegate interfering with bookmark items. |
| 222 return index >= fixed_items_ || SimpleMenuModel::IsVisibleAt(index); | 227 return index >= fixed_items_ || SimpleMenuModel::IsVisibleAt(index); |
| 223 } | 228 } |
| 224 | 229 |
| 225 // static | 230 // static |
| 226 bool BookmarkSubMenuModel::IsBookmarkItemCommandId(int command_id) { | 231 bool BookmarkSubMenuModel::IsBookmarkItemCommandId(int command_id) { |
| 227 return command_id == kBookmarkItemCommandId; | 232 return command_id == kBookmarkItemCommandId; |
| 228 } | 233 } |
| OLD | NEW |