• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #import <Cocoa/Cocoa.h>
6 
7 #import "base/mac/cocoa_protocols.h"
8 #include "base/memory/scoped_nsobject.h"
9 
10 @class AnimatableView;
11 @class HoverCloseButton;
12 @protocol InfoBarContainer;
13 class InfoBarDelegate;
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<InfoBarContainer> containerController_;  // weak, owns us
23   BOOL infoBarClosing_;
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 HoverCloseButton* closeButton_;
32 
33   // In rare instances, it can be possible for |delegate_| to delete itself
34   // while this controller is still alive.  Always check |delegate_| against
35   // NULL before using it.
36   InfoBarDelegate* delegate_;  // weak, can be NULL
37 
38   // Text fields don't work as well with embedded links as text views, but
39   // text views cannot conveniently be created in IB. The xib file contains
40   // a text field |labelPlaceholder_| that's replaced by this text view |label_|
41   // in -awakeFromNib.
42   scoped_nsobject<NSTextView> label_;
43 };
44 
45 // Initializes a new InfoBarController.
46 - (id)initWithDelegate:(InfoBarDelegate*)delegate;
47 
48 // Called when someone clicks on the OK or Cancel buttons.  Subclasses
49 // must override if they do not hide the buttons.
50 - (void)ok:(id)sender;
51 - (void)cancel:(id)sender;
52 
53 // Called when someone clicks on the close button.  Dismisses the
54 // infobar without taking any action.
55 - (IBAction)dismiss:(id)sender;
56 
57 // Returns a pointer to this controller's view, cast as an AnimatableView.
58 - (AnimatableView*)animatableView;
59 
60 // Open or animate open the infobar.
61 - (void)open;
62 - (void)animateOpen;
63 
64 // Close or animate close the infobar.
65 - (void)close;
66 - (void)animateClosed;
67 
68 // Subclasses can override this method to add additional controls to
69 // the infobar view.  This method is called by awakeFromNib.  The
70 // default implementation does nothing.
71 - (void)addAdditionalControls;
72 
73 // Subclasses must override this method to perform cleanup just before the
74 // infobar closes.
75 - (void)infobarWillClose;
76 
77 // Sets the info bar message to the specified |message|.
78 - (void)setLabelToMessage:(NSString*)message;
79 
80 // Removes the OK and Cancel buttons and resizes the textfield to use the
81 // space.
82 - (void)removeButtons;
83 
84 @property(nonatomic, assign) id<InfoBarContainer> containerController;
85 @property(nonatomic, readonly) InfoBarDelegate* delegate;
86 
87 @end
88 
89 /////////////////////////////////////////////////////////////////////////
90 // InfoBarController subclasses, one for each InfoBarDelegate
91 // subclass.  Each of these subclasses overrides addAdditionalControls to
92 // configure its view as necessary.
93 
94 @interface LinkInfoBarController : InfoBarController
95 // Called when there is a click on the link in the infobar.
96 - (void)linkClicked;
97 @end
98 
99 
100 @interface ConfirmInfoBarController : InfoBarController
101 // Called when the OK and Cancel buttons are clicked.
102 - (IBAction)ok:(id)sender;
103 - (IBAction)cancel:(id)sender;
104 // Called when there is a click on the link in the infobar.
105 - (void)linkClicked;
106 @end
107