| 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 // C++ controller for the bookmark menu; one per AppController (which | 5 // C++ controller for the bookmark menu; one per AppController (which |
| 6 // means there is only one). When bookmarks are changed, this class | 6 // means there is only one). When bookmarks are changed, this class |
| 7 // takes care of updating Cocoa bookmark menus. This is not named | 7 // takes care of updating Cocoa bookmark menus. This is not named |
| 8 // BookmarkMenuController to help avoid confusion between languages. | 8 // BookmarkMenuController to help avoid confusion between languages. |
| 9 // This class needs to be C++, not ObjC, since it derives from | 9 // This class needs to be C++, not ObjC, since it derives from |
| 10 // BookmarkModelObserver. | 10 // BookmarkModelObserver. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 NSString* title); | 71 NSString* title); |
| 72 | 72 |
| 73 // Helper for recursively adding items to our bookmark menu | 73 // Helper for recursively adding items to our bookmark menu |
| 74 // All children of |node| will be added to |menu|. | 74 // All children of |node| will be added to |menu|. |
| 75 // TODO(jrg): add a counter to enforce maximum nodes added | 75 // TODO(jrg): add a counter to enforce maximum nodes added |
| 76 void AddNodeToMenu(const BookmarkNode* node, NSMenu* menu); | 76 void AddNodeToMenu(const BookmarkNode* node, NSMenu* menu); |
| 77 | 77 |
| 78 // This configures an NSMenuItem with all the data from a BookmarkNode. This | 78 // This configures an NSMenuItem with all the data from a BookmarkNode. This |
| 79 // is used to update existing menu items, as well as to configure newly | 79 // is used to update existing menu items, as well as to configure newly |
| 80 // created ones, like in AddNodeToMenu(). | 80 // created ones, like in AddNodeToMenu(). |
| 81 void ConfigureMenuItem(const BookmarkNode* node, NSMenuItem* item); | 81 // |set_title| is optional since it is only needed when we get a |
| 82 // node changed notification. On initial build of the menu we set |
| 83 // the title as part of alloc/init. |
| 84 void ConfigureMenuItem(const BookmarkNode* node, NSMenuItem* item, |
| 85 bool set_title); |
| 82 | 86 |
| 83 // Returns the NSMenuItem for a given BookmarkNode. | 87 // Returns the NSMenuItem for a given BookmarkNode. |
| 84 NSMenuItem* MenuItemForNode(const BookmarkNode* node); | 88 NSMenuItem* MenuItemForNode(const BookmarkNode* node); |
| 85 | 89 |
| 86 // Return the Bookmark menu. | 90 // Return the Bookmark menu. |
| 87 virtual NSMenu* BookmarkMenu(); | 91 virtual NSMenu* BookmarkMenu(); |
| 88 | 92 |
| 89 // Start watching the bookmarks for changes. | 93 // Start watching the bookmarks for changes. |
| 90 void ObserveBookmarkModel(); | 94 void ObserveBookmarkModel(); |
| 91 | 95 |
| 92 private: | 96 private: |
| 93 friend class BookmarkMenuBridgeTest; | 97 friend class BookmarkMenuBridgeTest; |
| 94 | 98 |
| 95 Profile* profile_; // weak | 99 Profile* profile_; // weak |
| 96 BookmarkMenuCocoaController* controller_; // strong | 100 BookmarkMenuCocoaController* controller_; // strong |
| 97 | 101 |
| 98 // In order to appropriately update items in the bookmark menu, without | 102 // In order to appropriately update items in the bookmark menu, without |
| 99 // forcing a rebuild, map the model's nodes to menu items. | 103 // forcing a rebuild, map the model's nodes to menu items. |
| 100 std::map<const BookmarkNode*, NSMenuItem*> bookmark_nodes_; | 104 std::map<const BookmarkNode*, NSMenuItem*> bookmark_nodes_; |
| 101 }; | 105 }; |
| 102 | 106 |
| 103 #endif // CHROME_BROWSER_COCOA_BOOKMARK_MENU_BRIDGE_H_ | 107 #endif // CHROME_BROWSER_COCOA_BOOKMARK_MENU_BRIDGE_H_ |
| OLD | NEW |