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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_COCOA_WRENCH_MENU_WRENCH_MENU_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_COCOA_WRENCH_MENU_WRENCH_MENU_CONTROLLER_H_
8 #import <Cocoa/Cocoa.h>
10 #include "base/memory/scoped_ptr.h"
11 #import "ui/base/cocoa/menu_controller.h"
13 class BookmarkMenuBridge;
15 @class MenuTrackedRootView;
16 class RecentTabsMenuModelDelegate;
17 @class ToolbarController;
18 @class WrenchMenuButtonViewController;
19 class WrenchMenuModel;
21 namespace WrenchMenuControllerInternal {
22 class AcceleratorDelegate;
23 class ZoomLevelObserver;
24 } // namespace WrenchMenuControllerInternal
26 // The Wrench menu has a creative layout, with buttons in menu items. There is
27 // a cross-platform model for this special menu, but on the Mac it's easier to
28 // get spacing and alignment precisely right using a NIB. To do that, we
29 // subclass the generic MenuController implementation and special-case the two
30 // items that require specific layout and load them from the NIB.
32 // This object is owned by the ToolbarController and receives its NIB-based
33 // views using the shim view controller below.
34 @interface WrenchMenuController : MenuController<NSMenuDelegate> {
36 // Used to provide accelerators for the menu.
37 scoped_ptr<WrenchMenuControllerInternal::AcceleratorDelegate>
40 // The model, rebuilt each time the |-menuNeedsUpdate:|.
41 scoped_ptr<WrenchMenuModel> wrenchMenuModel_;
43 // Used to update icons in the recent tabs menu. This must be declared after
44 // |wrenchMenuModel_| so that it gets deleted first.
45 scoped_ptr<RecentTabsMenuModelDelegate> recentTabsMenuModelDelegate_;
47 // A shim NSViewController that loads the buttons from the NIB because ObjC
48 // doesn't have multiple inheritance as this class is a MenuController.
49 base::scoped_nsobject<WrenchMenuButtonViewController> buttonViewController_;
51 // The browser for which this controller exists.
52 Browser* browser_; // weak
54 // Used to build the bookmark submenu.
55 scoped_ptr<BookmarkMenuBridge> bookmarkMenuBridge_;
57 // Observer for page zoom level change notifications.
58 scoped_ptr<WrenchMenuControllerInternal::ZoomLevelObserver> observer_;
61 // Designated initializer.
62 - (id)initWithBrowser:(Browser*)browser;
64 // Used to dispatch commands from the Wrench menu. The custom items within the
65 // menu cannot be hooked up directly to First Responder because the window in
66 // which the controls reside is not the BrowserWindowController, but a
67 // NSCarbonMenuWindow; this screws up the typical |-commandDispatch:| system.
68 - (IBAction)dispatchWrenchMenuCommand:(id)sender;
70 // Returns the weak reference to the WrenchMenuModel.
71 - (WrenchMenuModel*)wrenchMenuModel;
73 // Creates a RecentTabsMenuModelDelegate instance which will take care of
74 // updating the recent tabs submenu.
75 - (void)updateRecentTabsSubmenu;
79 ////////////////////////////////////////////////////////////////////////////////
81 // Shim view controller that merely unpacks objects from a NIB.
82 @interface WrenchMenuButtonViewController : NSViewController {
84 WrenchMenuController* controller_;
86 MenuTrackedRootView* editItem_;
91 MenuTrackedRootView* zoomItem_;
93 NSButton* zoomDisplay_;
95 NSButton* zoomFullScreen_;
98 @property(assign, nonatomic) IBOutlet MenuTrackedRootView* editItem;
99 @property(assign, nonatomic) IBOutlet NSButton* editCut;
100 @property(assign, nonatomic) IBOutlet NSButton* editCopy;
101 @property(assign, nonatomic) IBOutlet NSButton* editPaste;
102 @property(assign, nonatomic) IBOutlet MenuTrackedRootView* zoomItem;
103 @property(assign, nonatomic) IBOutlet NSButton* zoomPlus;
104 @property(assign, nonatomic) IBOutlet NSButton* zoomDisplay;
105 @property(assign, nonatomic) IBOutlet NSButton* zoomMinus;
106 @property(assign, nonatomic) IBOutlet NSButton* zoomFullScreen;
108 - (id)initWithController:(WrenchMenuController*)controller;
109 - (IBAction)dispatchWrenchMenuCommand:(id)sender;
113 #endif // CHROME_BROWSER_UI_COCOA_WRENCH_MENU_WRENCH_MENU_CONTROLLER_H_