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 #ifndef CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_CONTAINER_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_CONTAINER_CONTROLLER_H_ 7 #pragma once 8 9 #import <Cocoa/Cocoa.h> 10 11 #include "base/memory/scoped_nsobject.h" 12 #include "base/memory/scoped_ptr.h" 13 #import "chrome/browser/ui/cocoa/view_resizer.h" 14 #include "content/common/notification_registrar.h" 15 16 @class InfoBarController; 17 class InfoBarDelegate; 18 class InfoBarNotificationObserver; 19 class TabContents; 20 class TabStripModel; 21 22 // Protocol for basic container methods, as needed by an InfoBarController. 23 // This protocol exists to make mocking easier in unittests. 24 @protocol InfoBarContainer 25 - (void)removeDelegate:(InfoBarDelegate*)delegate; 26 - (void)willRemoveController:(InfoBarController*)controller; 27 - (void)removeController:(InfoBarController*)controller; 28 @end 29 30 31 namespace infobars { 32 33 // How tall the tip is on a normal infobar. 34 const CGFloat kBaseHeight = 36.0; 35 36 }; // namespace infobars 37 38 39 // Controller for the infobar container view, which is the superview 40 // of all the infobar views. This class owns zero or more 41 // InfoBarControllers, which manage the infobar views. This class 42 // also receives tab strip model notifications and handles 43 // adding/removing infobars when needed. 44 @interface InfoBarContainerController : NSViewController <ViewResizer, 45 InfoBarContainer> { 46 @private 47 // Needed to send resize messages when infobars are added or removed. 48 id<ViewResizer> resizeDelegate_; // weak 49 50 // The TabContents we are currently showing infobars for. 51 TabContents* currentTabContents_; // weak 52 53 // Holds the InfoBarControllers currently owned by this container. 54 scoped_nsobject<NSMutableArray> infobarControllers_; 55 56 // Holds InfoBarControllers when they are in the process of animating out. 57 scoped_nsobject<NSMutableSet> closingInfoBars_; 58 59 // Lets us registers for INFOBAR_ADDED/INFOBAR_REMOVED 60 // notifications. The actual notifications are sent to the 61 // InfoBarNotificationObserver object, which proxies them back to us. 62 NotificationRegistrar registrar_; 63 scoped_ptr<InfoBarNotificationObserver> infoBarObserver_; 64 } 65 66 - (id)initWithResizeDelegate:(id<ViewResizer>)resizeDelegate; 67 68 // Informs the selected TabContents that the infobars for the given 69 // |delegate| need to be removed. Does not remove any infobar views 70 // directly, as they will be removed when handling the subsequent 71 // INFOBAR_REMOVED notification. Does not notify |delegate| that the 72 // infobar was closed. 73 - (void)removeDelegate:(InfoBarDelegate*)delegate; 74 75 // Informs the container that the |controller| is going to close. It adds the 76 // controller to |closingInfoBars_|. Once the animation is complete, the 77 // controller calls |-removeController:| to finalize cleanup. 78 - (void)willRemoveController:(InfoBarController*)controller; 79 80 // Removes |controller| from the list of controllers in this container and 81 // removes its view from the view hierarchy. This method is safe to call while 82 // |controller| is still on the call stack. 83 - (void)removeController:(InfoBarController*)controller; 84 85 // Modifies this container to display infobars for the given 86 // |contents|. Registers for INFOBAR_ADDED and INFOBAR_REMOVED 87 // notifications for |contents|. If we are currently showing any 88 // infobars, removes them first and deregisters for any 89 // notifications. |contents| can be NULL, in which case no infobars 90 // are shown and no notifications are registered for. 91 - (void)changeTabContents:(TabContents*)contents; 92 93 // Stripped down version of TabStripModelObserverBridge:tabDetachedWithContents. 94 // Forwarded by BWC. Removes all infobars and deregisters for any notifications 95 // if |contents| is the current tab contents. 96 - (void)tabDetachedWithContents:(TabContents*)contents; 97 98 // Returns the number of active infobars. This is 99 // |infobarControllers_ - closingInfoBars_|. 100 - (NSUInteger)infobarCount; 101 102 // Returns the amount of additional height the container view needs to draw the 103 // anti-spoofing tip. This will return 0 if |-infobarCount| is 0. This is the 104 // total amount of overlap for all infobars. 105 - (CGFloat)antiSpoofHeight; 106 107 @end 108 109 110 @interface InfoBarContainerController (ForTheObserverAndTesting) 111 112 // Adds an infobar view for the given delegate. 113 - (void)addInfoBar:(InfoBarDelegate*)delegate animate:(BOOL)animate; 114 115 // Closes all the infobar views for a given delegate, either immediately or by 116 // starting a close animation. 117 - (void)closeInfoBarsForDelegate:(InfoBarDelegate*)delegate 118 animate:(BOOL)animate; 119 120 // Replaces all info bars for the delegate with a new info bar. 121 // This simply calls closeInfoBarsForDelegate: and then addInfoBar:. 122 - (void)replaceInfoBarsForDelegate:(InfoBarDelegate*)old_delegate 123 with:(InfoBarDelegate*)new_delegate; 124 125 // Positions the infobar views in the container view and notifies 126 // |browser_controller_| that it needs to resize the container view. 127 - (void)positionInfoBarsAndRedraw; 128 129 @end 130 131 132 @interface InfoBarContainerController (JustForTesting) 133 134 // Removes all infobar views. Callers must call 135 // positionInfoBarsAndRedraw() after calling this method. 136 - (void)removeAllInfoBars; 137 138 @end 139 140 #endif // CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_CONTAINER_CONTROLLER_H_ 141