wrench_menu_controller.h revision ddb351dbec246cf1fab5ec20d2d5520909041de1
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
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#pragma once
8
9#import <Cocoa/Cocoa.h>
10
11#import "base/mac/cocoa_protocols.h"
12#include "base/memory/scoped_ptr.h"
13#import "chrome/browser/ui/cocoa/menu_controller.h"
14
15@class MenuTrackedRootView;
16@class ToolbarController;
17class WrenchMenuModel;
18
19namespace WrenchMenuControllerInternal {
20class ZoomLevelObserver;
21}  // namespace WrenchMenuControllerInternal
22
23// The Wrench menu has a creative layout, with buttons in menu items. There is
24// a cross-platform model for this special menu, but on the Mac it's easier to
25// get spacing and alignment precisely right using a NIB. To do that, we
26// subclass the generic MenuController implementation and special-case the two
27// items that require specific layout and load them from the NIB.
28//
29// This object is instantiated in Toolbar.xib and is configured by the
30// ToolbarController.
31@interface WrenchMenuController : MenuController<NSMenuDelegate> {
32  IBOutlet MenuTrackedRootView* editItem_;
33  IBOutlet NSButton* editCut_;
34  IBOutlet NSButton* editCopy_;
35  IBOutlet NSButton* editPaste_;
36
37  IBOutlet MenuTrackedRootView* zoomItem_;
38  IBOutlet NSButton* zoomPlus_;
39  IBOutlet NSButton* zoomDisplay_;
40  IBOutlet NSButton* zoomMinus_;
41  IBOutlet NSButton* zoomFullScreen_;
42
43  scoped_ptr<WrenchMenuControllerInternal::ZoomLevelObserver> observer_;
44}
45
46// Designated initializer; called within the NIB.
47- (id)init;
48
49// Used to dispatch commands from the Wrench menu. The custom items within the
50// menu cannot be hooked up directly to First Responder because the window in
51// which the controls reside is not the BrowserWindowController, but a
52// NSCarbonMenuWindow; this screws up the typical |-commandDispatch:| system.
53- (IBAction)dispatchWrenchMenuCommand:(id)sender;
54
55// Returns the weak reference to the WrenchMenuModel.
56- (WrenchMenuModel*)wrenchMenuModel;
57
58@end
59
60////////////////////////////////////////////////////////////////////////////////
61
62@interface WrenchMenuController (UnitTesting)
63// |-dispatchWrenchMenuCommand:| calls this after it has determined the tag of
64// the sender. The default implementation executes the command on the outermost
65// run loop using |-performSelector...withDelay:|. This is not desirable in
66// unit tests because it's hard to test around run loops in a deterministic
67// manner. To avoid those headaches, tests should provide an alternative
68// implementation.
69- (void)dispatchCommandInternal:(NSInteger)tag;
70@end
71
72#endif  // CHROME_BROWSER_UI_COCOA_WRENCH_MENU_WRENCH_MENU_CONTROLLER_H_
73