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 #import <Cocoa/Cocoa.h> 6 7 #include "base/mac/scoped_nsobject.h" 8 #include "base/memory/weak_ptr.h" 9 10 @protocol InfoBarContainerControllerBase; 11 class InfoBarCocoa; 12 class InfoBarDelegate; 13 class InfoBarService; 14 @class InfoBarGradientView; 15 16 // A controller for an infobar in the browser window. There is one 17 // controller per infobar view. The base InfoBarController is able to 18 // draw an icon, a text message, and a close button. Subclasses can 19 // override addAdditionalControls to customize the UI. 20 @interface InfoBarController : NSViewController<NSTextViewDelegate> { 21 @private 22 id<InfoBarContainerControllerBase> containerController_; // weak, owns us 23 base::WeakPtr<InfoBarCocoa> infobar_; 24 25 @protected 26 IBOutlet InfoBarGradientView* infoBarView_; 27 IBOutlet NSImageView* image_; 28 IBOutlet NSTextField* labelPlaceholder_; 29 IBOutlet NSButton* okButton_; 30 IBOutlet NSButton* cancelButton_; 31 IBOutlet NSButton* closeButton_; 32 33 // Text fields don't work as well with embedded links as text views, but 34 // text views cannot conveniently be created in IB. The xib file contains 35 // a text field |labelPlaceholder_| that's replaced by this text view |label_| 36 // in -awakeFromNib. 37 base::scoped_nsobject<NSTextView> label_; 38 } 39 40 @property(nonatomic, assign) 41 id<InfoBarContainerControllerBase> containerController; 42 @property(nonatomic, readonly) InfoBarDelegate* delegate; 43 @property(nonatomic, readonly) InfoBarCocoa* infobar; 44 45 // Initializes a new InfoBarController and takes a WeakPtr to |infobar|. 46 - (id)initWithInfoBar:(InfoBarCocoa*)infobar; 47 48 // Returns YES if the infobar is owned. If this is NO, it is not safe to call 49 // any delegate functions, since they might attempt to access the owner. Code 50 // should generally just do nothing at all in this case (once we're closing, all 51 // controls can safely just go dead). 52 - (BOOL)isOwned; 53 54 // Called when someone clicks on the OK or Cancel buttons. Subclasses 55 // must override if they do not hide the buttons. 56 - (void)ok:(id)sender; 57 - (void)cancel:(id)sender; 58 59 // Called when someone clicks on the close button. Dismisses the infobar 60 // without taking any action. 61 // NOTE: Subclasses should not call this to close the infobar as it will lead to 62 // errors in stat counting. Call -removeSelf instead. 63 - (IBAction)dismiss:(id)sender; 64 65 // Asks the container controller to remove the infobar for this delegate. This 66 // call will trigger a notification that starts the infobar animating closed. 67 - (void)removeSelf; 68 69 // Subclasses can override this method to add additional controls to 70 // the infobar view. This method is called by awakeFromNib. The 71 // default implementation does nothing. 72 - (void)addAdditionalControls; 73 74 // Subclasses must override this method to perform cleanup just before the 75 // infobar hides. 76 - (void)infobarWillHide; 77 78 // Subclasses must override this method to perform cleanup just before the 79 // infobar closes. 80 - (void)infobarWillClose; 81 82 // Removes the OK and Cancel buttons and resizes the textfield to use the 83 // space. 84 - (void)removeButtons; 85 86 // Updates the view's arrow position. 87 - (void)layoutArrow; 88 89 @end 90 91 @interface InfoBarController (Protected) 92 // Disables the provided menu. Subclasses should call this for each popup menu 93 // in -infobarWillClose. 94 - (void)disablePopUpMenu:(NSMenu*)menu; 95 @end 96 97 ///////////////////////////////////////////////////////////////////////// 98 // InfoBarController subclasses, one for each InfoBarDelegate 99 // subclass. Each of these subclasses overrides addAdditionalControls to 100 // configure its view as necessary. 101