- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / infobars / infobar_controller.h
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 closes.
76 - (void)infobarWillClose;
77
78 // Removes the OK and Cancel buttons and resizes the textfield to use the
79 // space.
80 - (void)removeButtons;
81
82 // Updates the view's arrow position.
83 - (void)layoutArrow;
84
85 @end
86
87 @interface InfoBarController (Protected)
88 // Closes and disables the provided menu.  Subclasses should call this for each
89 // popup menu in -infobarWillClose.
90 - (void)disablePopUpMenu:(NSMenu*)menu;
91 @end
92
93 /////////////////////////////////////////////////////////////////////////
94 // InfoBarController subclasses, one for each InfoBarDelegate
95 // subclass.  Each of these subclasses overrides addAdditionalControls to
96 // configure its view as necessary.