| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_CONTAINER_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_CONTAINER_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_CONTAINER_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_CONTAINER_CONTROLLER_H_ |
| 7 | 7 |
| 8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
| 9 | 9 |
| 10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #import "chrome/browser/ui/cocoa/view_resizer.h" | 12 #import "chrome/browser/ui/cocoa/view_resizer.h" |
| 13 #include "content/public/browser/notification_registrar.h" | |
| 14 | 13 |
| 15 @class BrowserWindowController; | 14 @class BrowserWindowController; |
| 16 @class InfoBarController; | 15 @class InfoBarController; |
| 17 class InfoBar; | 16 class InfoBarCocoa; |
| 17 class InfoBarContainerCocoa; |
| 18 class InfoBarDelegate; | 18 class InfoBarDelegate; |
| 19 class InfoBarNotificationObserver; | |
| 20 class TabStripModel; | 19 class TabStripModel; |
| 21 | 20 |
| 22 namespace content { | 21 namespace content { |
| 23 class WebContents; | 22 class WebContents; |
| 24 } | 23 } |
| 25 | 24 |
| 26 // Protocol for basic container methods, as needed by an InfoBarController. | 25 // Protocol for basic container methods, as needed by an InfoBarController. |
| 27 // This protocol exists to make mocking easier in unittests. | 26 // This protocol exists to make mocking easier in unittests. |
| 28 @protocol InfoBarContainer | 27 @protocol InfoBarContainerControllerBase |
| 29 - (void)willRemoveController:(InfoBarController*)controller; | |
| 30 - (void)removeController:(InfoBarController*)controller; | |
| 31 - (BrowserWindowController*)browserWindowController; | 28 - (BrowserWindowController*)browserWindowController; |
| 29 - (BOOL)shouldSuppressTopInfoBarTip; |
| 30 - (CGFloat)infobarArrowX; |
| 32 @end | 31 @end |
| 33 | 32 |
| 34 | |
| 35 namespace infobars { | |
| 36 | |
| 37 // The height of an infobar without the tip. | |
| 38 const CGFloat kBaseHeight = 36.0; | |
| 39 | |
| 40 // The height of the infobar tip. | |
| 41 const CGFloat kTipHeight = 12.0; | |
| 42 | |
| 43 }; // namespace infobars | |
| 44 | |
| 45 | |
| 46 // Controller for the infobar container view, which is the superview | 33 // Controller for the infobar container view, which is the superview |
| 47 // of all the infobar views. This class owns zero or more | 34 // of all the infobar views. This class owns zero or more |
| 48 // InfoBarControllers, which manage the infobar views. This class | 35 // InfoBarControllers, which manage the infobar views. This class |
| 49 // also receives tab strip model notifications and handles | 36 // also receives tab strip model notifications and handles |
| 50 // adding/removing infobars when needed. | 37 // adding/removing infobars when needed. |
| 51 @interface InfoBarContainerController : NSViewController <ViewResizer, | 38 @interface InfoBarContainerController |
| 52 InfoBarContainer> { | 39 : NSViewController<InfoBarContainerControllerBase> { |
| 53 @private | 40 @private |
| 54 // Needed to send resize messages when infobars are added or removed. | 41 // Needed to send resize messages when infobars are added or removed. |
| 55 id<ViewResizer> resizeDelegate_; // weak | 42 id<ViewResizer> resizeDelegate_; // weak |
| 56 | 43 |
| 57 // The WebContents we are currently showing infobars for. | 44 // The WebContents we are currently showing infobars for. |
| 58 content::WebContents* currentWebContents_; // weak | 45 content::WebContents* currentWebContents_; // weak |
| 59 | 46 |
| 60 // Holds the InfoBarControllers currently owned by this container. | 47 // Holds the InfoBarControllers currently owned by this container. |
| 61 base::scoped_nsobject<NSMutableArray> infobarControllers_; | 48 base::scoped_nsobject<NSMutableArray> infobarControllers_; |
| 62 | 49 |
| 63 // Holds InfoBarControllers when they are in the process of animating out. | 50 // The C++ instance that bridges to the cross platform code. |
| 64 base::scoped_nsobject<NSMutableSet> closingInfoBars_; | 51 scoped_ptr<InfoBarContainerCocoa> containerCocoa_; |
| 65 | |
| 66 // Lets us registers for INFOBAR_ADDED/INFOBAR_REMOVED | |
| 67 // notifications. The actual notifications are sent to the | |
| 68 // InfoBarNotificationObserver object, which proxies them back to us. | |
| 69 content::NotificationRegistrar registrar_; | |
| 70 scoped_ptr<InfoBarNotificationObserver> infoBarObserver_; | |
| 71 | 52 |
| 72 // If YES then the first info bar doesn't draw a tip. | 53 // If YES then the first info bar doesn't draw a tip. |
| 73 BOOL shouldSuppressTopInfoBarTip_; | 54 BOOL shouldSuppressTopInfoBarTip_; |
| 55 |
| 56 // If YES then an infobar animation is in progress. |
| 57 BOOL isAnimating_; |
| 58 |
| 59 // The last overlap tip height. This is used to ensure that the info bar |
| 60 // position is updated if the infobar height doesn't change but the overlap |
| 61 // does change. |
| 62 int oldOverlappingTipHeight_; |
| 74 } | 63 } |
| 75 | 64 |
| 76 @property(nonatomic, assign) BOOL shouldSuppressTopInfoBarTip; | 65 @property(nonatomic, assign) BOOL shouldSuppressTopInfoBarTip; |
| 77 | 66 |
| 78 - (id)initWithResizeDelegate:(id<ViewResizer>)resizeDelegate; | 67 - (id)initWithResizeDelegate:(id<ViewResizer>)resizeDelegate; |
| 79 | 68 |
| 80 // Informs the container that the |controller| is going to close. It adds the | 69 // Modifies this container to display infobars for the given |contents|. |
| 81 // controller to |closingInfoBars_|. Once the animation is complete, the | |
| 82 // controller calls |-removeController:| to finalize cleanup. | |
| 83 - (void)willRemoveController:(InfoBarController*)controller; | |
| 84 | |
| 85 // Removes |controller| from the list of controllers in this container and | |
| 86 // removes its view from the view hierarchy. This method is safe to call while | |
| 87 // |controller| is still on the call stack. | |
| 88 - (void)removeController:(InfoBarController*)controller; | |
| 89 | |
| 90 // Modifies this container to display infobars for the given | |
| 91 // |contents|. Registers for INFOBAR_ADDED and INFOBAR_REMOVED | |
| 92 // notifications for |contents|. If we are currently showing any | |
| 93 // infobars, removes them first and deregisters for any | |
| 94 // notifications. |contents| can be NULL, in which case no infobars | |
| 95 // are shown and no notifications are registered for. | |
| 96 - (void)changeWebContents:(content::WebContents*)contents; | 70 - (void)changeWebContents:(content::WebContents*)contents; |
| 97 | 71 |
| 98 // Stripped down version of TabStripModelObserverBridge:tabDetachedWithContents. | 72 // Stripped down version of TabStripModelObserverBridge:tabDetachedWithContents. |
| 99 // Forwarded by BWC. Removes all infobars and deregisters for any notifications | 73 // Forwarded by BWC. Removes all infobars if |contents| is the current tab |
| 100 // if |contents| is the current tab contents. | 74 // contents. |
| 101 - (void)tabDetachedWithContents:(content::WebContents*)contents; | 75 - (void)tabDetachedWithContents:(content::WebContents*)contents; |
| 102 | 76 |
| 103 // Returns the number of active infobars. This is | 77 // Returns the amount of additional height the container view needs to draw the |
| 104 // |infobarControllers_ - closingInfoBars_|. | 78 // anti-spoofing tip. This is the total amount of overlap for all infobars. |
| 105 - (NSUInteger)infobarCount; | 79 - (CGFloat)overlappingTipHeight; |
| 106 | 80 |
| 107 // Returns the amount of additional height the container view needs to draw the | 81 // Adds the given infobar. |
| 108 // anti-spoofing tip. This will return 0 if |-infobarCount| is 0. This is the | 82 - (void)addInfoBar:(InfoBarCocoa*)infobar |
| 109 // total amount of overlap for all infobars. | 83 position:(NSUInteger)position; |
| 110 - (CGFloat)overlappingTipHeight; | 84 |
| 85 // Removes the given infobar. |
| 86 - (void)removeInfoBar:(InfoBarCocoa*)infobar; |
| 87 |
| 88 // Positions the infobar views in the container view and notifies |
| 89 // |browser_controller_| that it needs to resize the container view. |
| 90 - (void)positionInfoBarsAndRedraw:(BOOL)isAnimating; |
| 111 | 91 |
| 112 @end | 92 @end |
| 113 | 93 |
| 114 | |
| 115 @interface InfoBarContainerController (ForTheObserverAndTesting) | |
| 116 | |
| 117 // Adds the given infobar. Takes ownership of |infobar|. | |
| 118 - (void)addInfoBar:(InfoBar*)infobar animate:(BOOL)animate; | |
| 119 | |
| 120 // Closes all the infobar views for a given delegate, either immediately or by | |
| 121 // starting a close animation. | |
| 122 - (void)closeInfoBarsForDelegate:(InfoBarDelegate*)delegate | |
| 123 animate:(BOOL)animate; | |
| 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. Infobars which were already closing will be | |
| 135 // completely closed (i.e. the InfoBarDelegate will be deleted and we'll get a | |
| 136 // callback to removeController). Other infobars will simply stop animating and | |
| 137 // disappear. Callers must call positionInfoBarsAndRedraw() after calling this | |
| 138 // method. | |
| 139 - (void)removeAllInfoBars; | |
| 140 | |
| 141 @end | |
| 142 | |
| 143 #endif // CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_CONTAINER_CONTROLLER_H_ | 94 #endif // CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_CONTAINER_CONTROLLER_H_ |
| OLD | NEW |