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