| 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 #import <AppKit/AppKit.h> | 5 #import <AppKit/AppKit.h> |
| 6 | 6 |
| 7 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
| 8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #import "chrome/browser/app_controller_mac.h" | 9 #import "chrome/browser/app_controller_mac.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 ClearBookmarkMenu(bookmark_menu); | 76 ClearBookmarkMenu(bookmark_menu); |
| 77 | 77 |
| 78 // Add at most one separator for the bookmark bar and the managed bookmarks | 78 // Add at most one separator for the bookmark bar and the managed bookmarks |
| 79 // folder. | 79 // folder. |
| 80 ChromeBookmarkClient* client = | 80 ChromeBookmarkClient* client = |
| 81 ChromeBookmarkClientFactory::GetForProfile(profile_); | 81 ChromeBookmarkClientFactory::GetForProfile(profile_); |
| 82 const BookmarkNode* barNode = model->bookmark_bar_node(); | 82 const BookmarkNode* barNode = model->bookmark_bar_node(); |
| 83 const BookmarkNode* managedNode = client->managed_node(); | 83 const BookmarkNode* managedNode = client->managed_node(); |
| 84 if (!barNode->empty() || !managedNode->empty()) | 84 if (!barNode->empty() || !managedNode->empty()) |
| 85 [bookmark_menu addItem:[NSMenuItem separatorItem]]; | 85 [bookmark_menu addItem:[NSMenuItem separatorItem]]; |
| 86 // TODO(joaodasilva): use the 'Managed Bookmarks' icon for the managedNode. | 86 if (!managedNode->empty()) { |
| 87 if (!managedNode->empty()) | 87 // Most users never see this node, so the image is only loaded if needed. |
| 88 AddNodeAsSubmenu(bookmark_menu, managedNode, !is_submenu); | 88 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 89 NSImage* image = |
| 90 rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER_MANAGED).ToNSImage(); |
| 91 AddNodeAsSubmenu(bookmark_menu, managedNode, image, !is_submenu); |
| 92 } |
| 89 if (!barNode->empty()) | 93 if (!barNode->empty()) |
| 90 AddNodeToMenu(barNode, bookmark_menu, !is_submenu); | 94 AddNodeToMenu(barNode, bookmark_menu, !is_submenu); |
| 91 | 95 |
| 92 // If the "Other Bookmarks" folder has any content, make a submenu for it and | 96 // If the "Other Bookmarks" folder has any content, make a submenu for it and |
| 93 // fill it in. | 97 // fill it in. |
| 94 if (!model->other_node()->empty()) { | 98 if (!model->other_node()->empty()) { |
| 95 [bookmark_menu addItem:[NSMenuItem separatorItem]]; | 99 [bookmark_menu addItem:[NSMenuItem separatorItem]]; |
| 96 AddNodeAsSubmenu(bookmark_menu, | 100 AddNodeAsSubmenu(bookmark_menu, |
| 97 model->other_node(), | 101 model->other_node(), |
| 102 folder_image_, |
| 98 !is_submenu); | 103 !is_submenu); |
| 99 } | 104 } |
| 100 | 105 |
| 101 // If the "Mobile Bookmarks" folder has any content, make a submenu for it and | 106 // If the "Mobile Bookmarks" folder has any content, make a submenu for it and |
| 102 // fill it in. | 107 // fill it in. |
| 103 if (!model->mobile_node()->empty()) { | 108 if (!model->mobile_node()->empty()) { |
| 104 // Add a separator if we did not already add one due to a non-empty | 109 // Add a separator if we did not already add one due to a non-empty |
| 105 // "Other Bookmarks" folder. | 110 // "Other Bookmarks" folder. |
| 106 if (model->other_node()->empty()) | 111 if (model->other_node()->empty()) |
| 107 [bookmark_menu addItem:[NSMenuItem separatorItem]]; | 112 [bookmark_menu addItem:[NSMenuItem separatorItem]]; |
| 108 | 113 |
| 109 AddNodeAsSubmenu(bookmark_menu, | 114 AddNodeAsSubmenu(bookmark_menu, |
| 110 model->mobile_node(), | 115 model->mobile_node(), |
| 116 folder_image_, |
| 111 !is_submenu); | 117 !is_submenu); |
| 112 } | 118 } |
| 113 | 119 |
| 114 menuIsValid_ = true; | 120 menuIsValid_ = true; |
| 115 } | 121 } |
| 116 | 122 |
| 117 void BookmarkMenuBridge::BookmarkModelBeingDeleted(BookmarkModel* model) { | 123 void BookmarkMenuBridge::BookmarkModelBeingDeleted(BookmarkModel* model) { |
| 118 NSMenu* bookmark_menu = BookmarkMenu(); | 124 NSMenu* bookmark_menu = BookmarkMenu(); |
| 119 if (bookmark_menu == nil) | 125 if (bookmark_menu == nil) |
| 120 return; | 126 return; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 // any. | 222 // any. |
| 217 [menu removeItem:item]; | 223 [menu removeItem:item]; |
| 218 } else { | 224 } else { |
| 219 // Leave it alone. | 225 // Leave it alone. |
| 220 } | 226 } |
| 221 } | 227 } |
| 222 } | 228 } |
| 223 | 229 |
| 224 void BookmarkMenuBridge::AddNodeAsSubmenu(NSMenu* menu, | 230 void BookmarkMenuBridge::AddNodeAsSubmenu(NSMenu* menu, |
| 225 const BookmarkNode* node, | 231 const BookmarkNode* node, |
| 232 NSImage* image, |
| 226 bool add_extra_items) { | 233 bool add_extra_items) { |
| 227 NSString* title = SysUTF16ToNSString(node->GetTitle()); | 234 NSString* title = SysUTF16ToNSString(node->GetTitle()); |
| 228 NSMenuItem* items = [[[NSMenuItem alloc] | 235 NSMenuItem* items = [[[NSMenuItem alloc] |
| 229 initWithTitle:title | 236 initWithTitle:title |
| 230 action:nil | 237 action:nil |
| 231 keyEquivalent:@""] autorelease]; | 238 keyEquivalent:@""] autorelease]; |
| 232 [items setImage:folder_image_]; | 239 [items setImage:image]; |
| 233 [menu addItem:items]; | 240 [menu addItem:items]; |
| 234 NSMenu* submenu = [[[NSMenu alloc] initWithTitle:title] autorelease]; | 241 NSMenu* submenu = [[[NSMenu alloc] initWithTitle:title] autorelease]; |
| 235 [menu setSubmenu:submenu forItem:items]; | 242 [menu setSubmenu:submenu forItem:items]; |
| 236 AddNodeToMenu(node, submenu, add_extra_items); | 243 AddNodeToMenu(node, submenu, add_extra_items); |
| 237 } | 244 } |
| 238 | 245 |
| 239 // TODO(jrg): limit the number of bookmarks in the menubar? | 246 // TODO(jrg): limit the number of bookmarks in the menubar? |
| 240 void BookmarkMenuBridge::AddNodeToMenu(const BookmarkNode* node, NSMenu* menu, | 247 void BookmarkMenuBridge::AddNodeToMenu(const BookmarkNode* node, NSMenu* menu, |
| 241 bool add_extra_items) { | 248 bool add_extra_items) { |
| 242 int child_count = node->child_count(); | 249 int child_count = node->child_count(); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 | 350 |
| 344 NSMenuItem* BookmarkMenuBridge::MenuItemForNode(const BookmarkNode* node) { | 351 NSMenuItem* BookmarkMenuBridge::MenuItemForNode(const BookmarkNode* node) { |
| 345 if (!node) | 352 if (!node) |
| 346 return nil; | 353 return nil; |
| 347 std::map<const BookmarkNode*, NSMenuItem*>::iterator it = | 354 std::map<const BookmarkNode*, NSMenuItem*>::iterator it = |
| 348 bookmark_nodes_.find(node); | 355 bookmark_nodes_.find(node); |
| 349 if (it == bookmark_nodes_.end()) | 356 if (it == bookmark_nodes_.end()) |
| 350 return nil; | 357 return nil; |
| 351 return it->second; | 358 return it->second; |
| 352 } | 359 } |
| OLD | NEW |