Home | History | Annotate | Download | only in cocoa
      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_MENU_BUTTON_H_
      6 #define CHROME_BROWSER_UI_COCOA_MENU_BUTTON_H_
      7 #pragma once
      8 
      9 #import <Cocoa/Cocoa.h>
     10 
     11 #include "base/memory/scoped_nsobject.h"
     12 #import "chrome/browser/ui/cocoa/toolbar/toolbar_button.h"
     13 
     14 // This a button which displays a user-provided menu "attached" below it upon
     15 // being clicked or dragged (or clicked and held). It expects a
     16 // |ClickHoldButtonCell| as cell.
     17 //
     18 // There are two different behaviors of this button depending on the value of
     19 // the |openMenuOnClick| property. If YES, the target-action mechanism will be
     20 // handled internally to always show the menu when clicked. This behavior is
     21 // used for the Wrench menu, for example. When the property is NO, the button
     22 // can have a separate target-action but will open the menu when clicked and
     23 // held. This is used for the toolbar back/forward buttons, which have a
     24 // primary action and the menu as a secondary click-hold action. The default
     25 // value is NO so that custom actions can be hooked up in Interface Builder.
     26 @interface MenuButton : ToolbarButton {
     27  @private
     28   scoped_nsobject<NSMenu> attachedMenu_;
     29   BOOL attachedMenuEnabled_;
     30   BOOL openMenuOnClick_;
     31   scoped_nsobject<NSPopUpButtonCell> popUpCell_;
     32 }
     33 
     34 // The menu to display. Note that it should have no (i.e., a blank) title and
     35 // that the 0-th entry should be blank (and won't be displayed). (This is
     36 // because we use a pulldown list, for which Cocoa uses the 0-th item as "title"
     37 // in the button. This might change if we ever switch to a pop-up. Our direct
     38 // use of the given NSMenu object means that the one can set and use NSMenu's
     39 // delegate as usual.)
     40 @property(retain, nonatomic) IBOutlet NSMenu* attachedMenu;
     41 
     42 // Whether or not to open the menu when the button is clicked. Otherwise, the
     43 // menu will only be opened when clicked and held.
     44 @property(assign, nonatomic) BOOL openMenuOnClick;
     45 
     46 @end  // @interface MenuButton
     47 
     48 // Available for subclasses.
     49 @interface MenuButton (Protected)
     50 - (void)configureCell;
     51 @end
     52 
     53 #endif  // CHROME_BROWSER_UI_COCOA_MENU_BUTTON_H_
     54