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 #import "base/mac/scoped_nsobject.h"
11 #include "base/memory/scoped_ptr.h"
12 #import "chrome/browser/ui/cocoa/has_weak_browser_pointer.h"
13 #import "ui/base/cocoa/menu_controller.h"
15 class BookmarkMenuBridge
;
17 @
class BrowserActionsContainerView
;
18 @
class BrowserActionsController
;
19 @
class MenuTrackedRootView
;
20 class RecentTabsMenuModelDelegate
;
21 @
class ToolbarController
;
22 @
class WrenchMenuButtonViewController
;
23 class WrenchMenuModel
;
25 namespace wrench_menu_controller
{
26 // The vertical offset of the wrench bubbles from the wrench menu button.
27 extern const CGFloat kWrenchBubblePointOffsetY
;
30 namespace WrenchMenuControllerInternal
{
31 class AcceleratorDelegate
;
32 class ZoomLevelObserver
;
33 } // namespace WrenchMenuControllerInternal
35 // The Wrench menu has a creative layout, with buttons in menu items. There is
36 // a cross-platform model for this special menu, but on the Mac it's easier to
37 // get spacing and alignment precisely right using a NIB. To do that, we
38 // subclass the generic MenuController implementation and special-case the two
39 // items that require specific layout and load them from the NIB.
41 // This object is owned by the ToolbarController and receives its NIB-based
42 // views using the shim view controller below.
43 @interface WrenchMenuController
44 : MenuController
<NSMenuDelegate
, HasWeakBrowserPointer
> {
46 // Used to provide accelerators for the menu.
47 scoped_ptr
<WrenchMenuControllerInternal::AcceleratorDelegate
>
50 // The model, rebuilt each time the |-menuNeedsUpdate:|.
51 scoped_ptr
<WrenchMenuModel
> wrenchMenuModel_
;
53 // Used to update icons in the recent tabs menu. This must be declared after
54 // |wrenchMenuModel_| so that it gets deleted first.
55 scoped_ptr
<RecentTabsMenuModelDelegate
> recentTabsMenuModelDelegate_
;
57 // A shim NSViewController that loads the buttons from the NIB because ObjC
58 // doesn't have multiple inheritance as this class is a MenuController.
59 base::scoped_nsobject
<WrenchMenuButtonViewController
> buttonViewController_
;
61 // The browser for which this controller exists.
62 Browser
* browser_
; // weak
64 // Used to build the bookmark submenu.
65 scoped_ptr
<BookmarkMenuBridge
> bookmarkMenuBridge_
;
67 // Observer for page zoom level change notifications.
68 scoped_ptr
<WrenchMenuControllerInternal::ZoomLevelObserver
> observer_
;
70 // The controller for the toolbar actions overflow that is stored in the
72 // This will only be present if the extension action redesign switch is on.
73 base::scoped_nsobject
<BrowserActionsController
> browserActionsController_
;
75 // The menu item containing the browser actions overflow container.
76 NSMenuItem
* browserActionsMenuItem_
;
79 // Designated initializer.
80 - (id
)initWithBrowser
:(Browser
*)browser
;
82 // Used to dispatch commands from the Wrench menu. The custom items within the
83 // menu cannot be hooked up directly to First Responder because the window in
84 // which the controls reside is not the BrowserWindowController, but a
85 // NSCarbonMenuWindow; this screws up the typical |-commandDispatch:| system.
86 - (IBAction
)dispatchWrenchMenuCommand
:(id
)sender
;
88 // Returns the weak reference to the WrenchMenuModel.
89 - (WrenchMenuModel
*)wrenchMenuModel
;
91 // Creates a RecentTabsMenuModelDelegate instance which will take care of
92 // updating the recent tabs submenu.
93 - (void)updateRecentTabsSubmenu
;
95 // Retuns the weak reference to the BrowserActionsController.
96 - (BrowserActionsController
*)browserActionsController
;
100 ////////////////////////////////////////////////////////////////////////////////
102 // Shim view controller that merely unpacks objects from a NIB.
103 @interface WrenchMenuButtonViewController
: NSViewController
{
105 WrenchMenuController
* controller_
;
107 MenuTrackedRootView
* editItem_
;
110 NSButton
* editPaste_
;
112 MenuTrackedRootView
* zoomItem_
;
114 NSButton
* zoomDisplay_
;
115 NSButton
* zoomMinus_
;
116 NSButton
* zoomFullScreen_
;
118 MenuTrackedRootView
* toolbarActionsOverflowItem_
;
119 BrowserActionsContainerView
* overflowActionsContainerView_
;
122 @
property(assign
, nonatomic
) IBOutlet MenuTrackedRootView
* editItem
;
123 @
property(assign
, nonatomic
) IBOutlet NSButton
* editCut
;
124 @
property(assign
, nonatomic
) IBOutlet NSButton
* editCopy
;
125 @
property(assign
, nonatomic
) IBOutlet NSButton
* editPaste
;
126 @
property(assign
, nonatomic
) IBOutlet MenuTrackedRootView
* zoomItem
;
127 @
property(assign
, nonatomic
) IBOutlet NSButton
* zoomPlus
;
128 @
property(assign
, nonatomic
) IBOutlet NSButton
* zoomDisplay
;
129 @
property(assign
, nonatomic
) IBOutlet NSButton
* zoomMinus
;
130 @
property(assign
, nonatomic
) IBOutlet NSButton
* zoomFullScreen
;
131 @
property(assign
, nonatomic
)
132 IBOutlet MenuTrackedRootView
* toolbarActionsOverflowItem
;
133 @
property(assign
, nonatomic
)
134 IBOutlet BrowserActionsContainerView
* overflowActionsContainerView
;
136 - (id
)initWithController
:(WrenchMenuController
*)controller
;
137 - (IBAction
)dispatchWrenchMenuCommand
:(id
)sender
;
141 #endif // CHROME_BROWSER_UI_COCOA_WRENCH_MENU_WRENCH_MENU_CONTROLLER_H_