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