| 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 // C++ controller for the bookmark menu; one per AppController (which | |
| 6 // means there is only one). When bookmarks are changed, this class | |
| 7 // takes care of updating Cocoa bookmark menus. This is not named | |
| 8 // BookmarkMenuController to help avoid confusion between languages. | |
| 9 // This class needs to be C++, not ObjC, since it derives from | |
| 10 // BookmarkModelObserver. | |
| 11 // | |
| 12 // Most Chromium Cocoa menu items are static from a nib (e.g. New | |
| 13 // Tab), but may be enabled/disabled under certain circumstances | |
| 14 // (e.g. Cut and Paste). In addition, most Cocoa menu items have | |
| 15 // firstResponder: as a target. Unusually, bookmark menu items are | |
| 16 // created dynamically. They also have a target of | |
| 17 // BookmarkMenuCocoaController instead of firstResponder. | |
| 18 // See BookmarkMenuBridge::AddNodeToMenu()). | |
| 19 | |
| 20 #ifndef CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_MENU_BRIDGE_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_MENU_BRIDGE_H_ |
| 21 #define CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_MENU_BRIDGE_H_ | 6 #define CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_MENU_BRIDGE_H_ |
| 22 | 7 |
| 23 #include <map> | 8 #include <map> |
| 24 | 9 |
| 25 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 26 #import "chrome/browser/ui/cocoa/main_menu_item.h" | 11 #import "chrome/browser/ui/cocoa/main_menu_item.h" |
| 27 #include "components/bookmarks/browser/bookmark_model_observer.h" | 12 #include "components/bookmarks/browser/bookmark_model_observer.h" |
| 28 | 13 |
| 29 class Profile; | 14 class Profile; |
| 30 @class NSImage; | 15 @class NSImage; |
| 31 @class NSMenu; | 16 @class NSMenu; |
| 32 @class NSMenuItem; | 17 @class NSMenuItem; |
| 33 @class BookmarkMenuCocoaController; | 18 @class BookmarkMenuCocoaController; |
| 34 | 19 |
| 35 namespace bookmarks { | 20 namespace bookmarks { |
| 36 class BookmarkNode; | 21 class BookmarkNode; |
| 37 } | 22 } |
| 38 | 23 |
| 24 // C++ controller for the bookmark menu; one per AppController (which |
| 25 // means there is only one). When bookmarks are changed, this class |
| 26 // takes care of updating Cocoa bookmark menus. This is not named |
| 27 // BookmarkMenuController to help avoid confusion between languages. |
| 28 // This class needs to be C++, not ObjC, since it derives from |
| 29 // BookmarkModelObserver. |
| 30 // |
| 31 // Most Chromium Cocoa menu items are static from a nib (e.g. New |
| 32 // Tab), but may be enabled/disabled under certain circumstances |
| 33 // (e.g. Cut and Paste). In addition, most Cocoa menu items have |
| 34 // firstResponder: as a target. Unusually, bookmark menu items are |
| 35 // created dynamically. They also have a target of |
| 36 // BookmarkMenuCocoaController instead of firstResponder. |
| 37 // See BookmarkMenuBridge::AddNodeToMenu()). |
| 39 class BookmarkMenuBridge : public bookmarks::BookmarkModelObserver, | 38 class BookmarkMenuBridge : public bookmarks::BookmarkModelObserver, |
| 40 public MainMenuItem { | 39 public MainMenuItem { |
| 41 public: | 40 public: |
| 42 BookmarkMenuBridge(Profile* profile, NSMenu* menu); | 41 BookmarkMenuBridge(Profile* profile, NSMenu* menu); |
| 43 ~BookmarkMenuBridge() override; | 42 ~BookmarkMenuBridge() override; |
| 44 | 43 |
| 45 // bookmarks::BookmarkModelObserver: | 44 // bookmarks::BookmarkModelObserver: |
| 46 void BookmarkModelLoaded(bookmarks::BookmarkModel* model, | 45 void BookmarkModelLoaded(bookmarks::BookmarkModel* model, |
| 47 bool ids_reassigned) override; | 46 bool ids_reassigned) override; |
| 48 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override; | 47 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 149 |
| 151 // The folder image so we can use one copy for all. | 150 // The folder image so we can use one copy for all. |
| 152 base::scoped_nsobject<NSImage> folder_image_; | 151 base::scoped_nsobject<NSImage> folder_image_; |
| 153 | 152 |
| 154 // In order to appropriately update items in the bookmark menu, without | 153 // In order to appropriately update items in the bookmark menu, without |
| 155 // forcing a rebuild, map the model's nodes to menu items. | 154 // forcing a rebuild, map the model's nodes to menu items. |
| 156 std::map<const bookmarks::BookmarkNode*, NSMenuItem*> bookmark_nodes_; | 155 std::map<const bookmarks::BookmarkNode*, NSMenuItem*> bookmark_nodes_; |
| 157 }; | 156 }; |
| 158 | 157 |
| 159 #endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_MENU_BRIDGE_H_ | 158 #endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_MENU_BRIDGE_H_ |
| OLD | NEW |