Home | History | Annotate | Download | only in wrench_menu
      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 
     13 class BookmarkMenuBridge;
     14 class Browser;
     15 @class MenuTrackedRootView;
     16 class RecentTabsMenuModelDelegate;
     17 @class ToolbarController;
     18 @class WrenchMenuButtonViewController;
     19 class WrenchMenuModel;
     20 
     21 namespace WrenchMenuControllerInternal {
     22 class AcceleratorDelegate;
     23 class ZoomLevelObserver;
     24 }  // namespace WrenchMenuControllerInternal
     25 
     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.
     31 //
     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> {
     35  @private
     36   // Used to provide accelerators for the menu.
     37   scoped_ptr<WrenchMenuControllerInternal::AcceleratorDelegate>
     38       acceleratorDelegate_;
     39 
     40   // The model, rebuilt each time the |-menuNeedsUpdate:|.
     41   scoped_ptr<WrenchMenuModel> wrenchMenuModel_;
     42 
     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_;
     46 
     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_;
     50 
     51   // The browser for which this controller exists.
     52   Browser* browser_;  // weak
     53 
     54   // Used to build the bookmark submenu.
     55   scoped_ptr<BookmarkMenuBridge> bookmarkMenuBridge_;
     56 
     57   // Observer for page zoom level change notifications.
     58   scoped_ptr<WrenchMenuControllerInternal::ZoomLevelObserver> observer_;
     59 }
     60 
     61 // Designated initializer.
     62 - (id)initWithBrowser:(Browser*)browser;
     63 
     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;
     69 
     70 // Returns the weak reference to the WrenchMenuModel.
     71 - (WrenchMenuModel*)wrenchMenuModel;
     72 
     73 // Creates a RecentTabsMenuModelDelegate instance which will take care of
     74 // updating the recent tabs submenu.
     75 - (void)updateRecentTabsSubmenu;
     76 
     77 @end
     78 
     79 ////////////////////////////////////////////////////////////////////////////////
     80 
     81 // Shim view controller that merely unpacks objects from a NIB.
     82 @interface WrenchMenuButtonViewController : NSViewController {
     83  @private
     84   WrenchMenuController* controller_;
     85 
     86   MenuTrackedRootView* editItem_;
     87   NSButton* editCut_;
     88   NSButton* editCopy_;
     89   NSButton* editPaste_;
     90 
     91   MenuTrackedRootView* zoomItem_;
     92   NSButton* zoomPlus_;
     93   NSButton* zoomDisplay_;
     94   NSButton* zoomMinus_;
     95   NSButton* zoomFullScreen_;
     96 }
     97 
     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;
    107 
    108 - (id)initWithController:(WrenchMenuController*)controller;
    109 - (IBAction)dispatchWrenchMenuCommand:(id)sender;
    110 
    111 @end
    112 
    113 #endif  // CHROME_BROWSER_UI_COCOA_WRENCH_MENU_WRENCH_MENU_CONTROLLER_H_
    114