Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: chrome/browser/ui/cocoa/infobars/infobar_controller.h

Issue 23338005: Mac InfoBar: Use cross platform infobar classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "base/mac/scoped_nsobject.h" 7 #include "base/mac/scoped_nsobject.h"
8 8
9 @class AnimatableView; 9 @protocol InfoBarContainerControllerBase;
10 @protocol InfoBarContainer; 10 class InfoBarCocoa;
11 class InfoBarDelegate; 11 class InfoBarDelegate;
12 class InfoBarService; 12 class InfoBarService;
13 @class InfoBarGradientView; 13 @class InfoBarGradientView;
14 14
15 // A controller for an infobar in the browser window. There is one 15 // A controller for an infobar in the browser window. There is one
16 // controller per infobar view. The base InfoBarController is able to 16 // controller per infobar view. The base InfoBarController is able to
17 // draw an icon, a text message, and a close button. Subclasses can 17 // draw an icon, a text message, and a close button. Subclasses can
18 // override addAdditionalControls to customize the UI. 18 // override addAdditionalControls to customize the UI.
19 @interface InfoBarController : NSViewController<NSTextViewDelegate> { 19 @interface InfoBarController : NSViewController<NSTextViewDelegate> {
20 @private 20 @private
21 id<InfoBarContainer> containerController_; // weak, owns us 21 id<InfoBarContainerControllerBase> containerController_; // weak, owns us
22 InfoBarService* owner_; // weak 22 InfoBarCocoa* infobar_; // weak, owns us
23 BOOL infoBarClosing_;
24 23
25 @protected 24 @protected
26 IBOutlet InfoBarGradientView* infoBarView_; 25 IBOutlet InfoBarGradientView* infoBarView_;
27 IBOutlet NSImageView* image_; 26 IBOutlet NSImageView* image_;
28 IBOutlet NSTextField* labelPlaceholder_; 27 IBOutlet NSTextField* labelPlaceholder_;
29 IBOutlet NSButton* okButton_; 28 IBOutlet NSButton* okButton_;
30 IBOutlet NSButton* cancelButton_; 29 IBOutlet NSButton* cancelButton_;
31 IBOutlet NSButton* closeButton_; 30 IBOutlet NSButton* closeButton_;
32 31
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 32 // 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 33 // 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_| 34 // a text field |labelPlaceholder_| that's replaced by this text view |label_|
41 // in -awakeFromNib. 35 // in -awakeFromNib.
42 base::scoped_nsobject<NSTextView> label_; 36 base::scoped_nsobject<NSTextView> label_;
43 }; 37 }
38
39 @property(nonatomic, assign)
40 id<InfoBarContainerControllerBase> containerController;
41 @property(nonatomic, readonly) InfoBarDelegate* delegate;
42 @property(nonatomic, readonly) InfoBarCocoa* infobar;
44 43
45 // Initializes a new InfoBarController. 44 // Initializes a new InfoBarController.
46 - (id)initWithDelegate:(InfoBarDelegate*)delegate 45 - (id)initWithInfoBar:(InfoBarCocoa*)infobar;
47 owner:(InfoBarService*)owner;
48 46
49 // Returns YES if the infobar is owned. If this is NO, it is not safe to call 47 // Returns YES if the infobar is owned. If this is NO, it is not safe to call
50 // any delegate functions, since they might attempt to access the owner. Code 48 // any delegate functions, since they might attempt to access the owner. Code
51 // should generally just do nothing at all in this case (once we're closing, all 49 // should generally just do nothing at all in this case (once we're closing, all
52 // controls can safely just go dead). 50 // controls can safely just go dead).
53 - (BOOL)isOwned; 51 - (BOOL)isOwned;
54 52
55 // Called when someone clicks on the OK or Cancel buttons. Subclasses 53 // Called when someone clicks on the OK or Cancel buttons. Subclasses
56 // must override if they do not hide the buttons. 54 // must override if they do not hide the buttons.
57 - (void)ok:(id)sender; 55 - (void)ok:(id)sender;
58 - (void)cancel:(id)sender; 56 - (void)cancel:(id)sender;
59 57
60 // Called when someone clicks on the close button. Dismisses the infobar 58 // Called when someone clicks on the close button. Dismisses the infobar
61 // without taking any action. 59 // without taking any action.
62 // NOTE: Subclasses should not call this to close the infobar as it will lead to 60 // NOTE: Subclasses should not call this to close the infobar as it will lead to
63 // errors in stat counting. Call -removeSelf instead. 61 // errors in stat counting. Call -removeSelf instead.
64 - (IBAction)dismiss:(id)sender; 62 - (IBAction)dismiss:(id)sender;
65 63
66 // Asks the container controller to remove the infobar for this delegate. This 64 // Asks the container controller to remove the infobar for this delegate. This
67 // call will trigger a notification that starts the infobar animating closed. 65 // call will trigger a notification that starts the infobar animating closed.
68 - (void)removeSelf; 66 - (void)removeSelf;
69 67
70 // Returns a pointer to this controller's view, cast as an AnimatableView.
71 - (AnimatableView*)animatableView;
72
73 // Open or animate open the infobar.
74 - (void)open;
75 - (void)animateOpen;
76
77 // Close or animate close the infobar.
78 - (void)close;
79 - (void)animateClosed;
80
81 // Subclasses can override this method to add additional controls to 68 // Subclasses can override this method to add additional controls to
82 // the infobar view. This method is called by awakeFromNib. The 69 // the infobar view. This method is called by awakeFromNib. The
83 // default implementation does nothing. 70 // default implementation does nothing.
84 - (void)addAdditionalControls; 71 - (void)addAdditionalControls;
85 72
86 // Subclasses must override this method to perform cleanup just before the 73 // Subclasses must override this method to perform cleanup just before the
87 // infobar closes. 74 // infobar closes.
88 - (void)infobarWillClose; 75 - (void)infobarWillClose;
89 76
90 // Removes the OK and Cancel buttons and resizes the textfield to use the 77 // Removes the OK and Cancel buttons and resizes the textfield to use the
91 // space. 78 // space.
92 - (void)removeButtons; 79 - (void)removeButtons;
93 80
94 - (void)setHasTip:(BOOL)hasTip; 81 // Updates the view's arrow position.
95 82 - (void)layoutArrow;
96 @property(nonatomic, assign) id<InfoBarContainer> containerController;
97 @property(nonatomic, readonly) InfoBarDelegate* delegate;
98 83
99 @end 84 @end
100 85
101 @interface InfoBarController (Protected) 86 @interface InfoBarController (Protected)
102 // Closes and disables the provided menu. Subclasses should call this for each 87 // Closes and disables the provided menu. Subclasses should call this for each
103 // popup menu in -infobarWillClose. 88 // popup menu in -infobarWillClose.
104 - (void)disablePopUpMenu:(NSMenu*)menu; 89 - (void)disablePopUpMenu:(NSMenu*)menu;
105 @end 90 @end
106 91
107 ///////////////////////////////////////////////////////////////////////// 92 /////////////////////////////////////////////////////////////////////////
108 // InfoBarController subclasses, one for each InfoBarDelegate 93 // InfoBarController subclasses, one for each InfoBarDelegate
109 // subclass. Each of these subclasses overrides addAdditionalControls to 94 // subclass. Each of these subclasses overrides addAdditionalControls to
110 // configure its view as necessary. 95 // configure its view as necessary.
111
112
113
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698