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.
5 #import <Cocoa/Cocoa.h>
7 #include "base/mac/scoped_nsobject.h"
8 #include "base/memory/weak_ptr.h"
10 @protocol InfoBarContainerControllerBase
;
12 class InfoBarDelegate
;
14 @
class InfoBarGradientView
;
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
> {
22 id
<InfoBarContainerControllerBase
> containerController_
; // weak, owns us
23 base::WeakPtr
<InfoBarCocoa
> infobar_
;
26 IBOutlet InfoBarGradientView
* infoBarView_
;
27 IBOutlet NSImageView
* image_
;
28 IBOutlet NSTextField
* labelPlaceholder_
;
29 IBOutlet NSButton
* okButton_
;
30 IBOutlet NSButton
* cancelButton_
;
31 IBOutlet NSButton
* closeButton_
;
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_|
37 base::scoped_nsobject
<NSTextView
> label_
;
40 @
property(nonatomic
, assign
)
41 id
<InfoBarContainerControllerBase
> containerController
;
42 @
property(nonatomic
, readonly
) InfoBarDelegate
* delegate
;
43 @
property(nonatomic
, readonly
) InfoBarCocoa
* infobar
;
45 // Initializes a new InfoBarController and takes a WeakPtr to |infobar|.
46 - (id
)initWithInfoBar
:(InfoBarCocoa
*)infobar
;
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).
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
;
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
;
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.
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
;
74 // Subclasses must override this method to perform cleanup just before the
76 - (void)infobarWillHide
;
78 // Subclasses must override this method to perform cleanup just before the
80 - (void)infobarWillClose
;
82 // Removes the OK and Cancel buttons and resizes the textfield to use the
84 - (void)removeButtons
;
86 // Updates the view's arrow position.
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
;
97 /////////////////////////////////////////////////////////////////////////
98 // InfoBarController subclasses, one for each InfoBarDelegate
99 // subclass. Each of these subclasses overrides addAdditionalControls to
100 // configure its view as necessary.