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
8#import <Cocoa/Cocoa.h>
9
10#include "base/mac/scoped_nsobject.h"
11#include "base/memory/scoped_ptr.h"
12#import "chrome/browser/ui/cocoa/view_resizer.h"
13
14@class BrowserWindowController;
15@class InfoBarController;
16class InfoBarCocoa;
17class InfoBarContainerCocoa;
18class TabStripModel;
19
20namespace content {
21class WebContents;
22}
23
24namespace infobars {
25class InfoBarDelegate;
26}
27
28// Protocol for basic container methods, as needed by an InfoBarController.
29// This protocol exists to make mocking easier in unittests.
30@protocol InfoBarContainerControllerBase
31- (BrowserWindowController*)browserWindowController;
32- (BOOL)shouldSuppressTopInfoBarTip;
33- (CGFloat)infobarArrowX;
34@end
35
36// Controller for the infobar container view, which is the superview
37// of all the infobar views.  This class owns zero or more
38// InfoBarControllers, which manage the infobar views.  This class
39// also receives tab strip model notifications and handles
40// adding/removing infobars when needed.
41@interface InfoBarContainerController
42    : NSViewController<InfoBarContainerControllerBase> {
43 @private
44  // Needed to send resize messages when infobars are added or removed.
45  id<ViewResizer> resizeDelegate_;  // weak
46
47  // The WebContents we are currently showing infobars for.
48  content::WebContents* currentWebContents_;  // weak
49
50  // Holds the InfoBarControllers currently owned by this container.
51  base::scoped_nsobject<NSMutableArray> infobarControllers_;
52
53  // The C++ instance that bridges to the cross platform code.
54  scoped_ptr<InfoBarContainerCocoa> containerCocoa_;
55
56  // If YES then the first info bar doesn't draw a tip.
57  BOOL shouldSuppressTopInfoBarTip_;
58
59  // If YES then an infobar animation is in progress.
60  BOOL isAnimating_;
61}
62
63@property(nonatomic, assign) BOOL shouldSuppressTopInfoBarTip;
64
65- (id)initWithResizeDelegate:(id<ViewResizer>)resizeDelegate;
66
67// Modifies this container to display infobars for the given |contents|.
68- (void)changeWebContents:(content::WebContents*)contents;
69
70// Stripped down version of TabStripModelObserverBridge:tabDetachedWithContents.
71// Forwarded by BWC. Removes all infobars if |contents| is the current tab
72// contents.
73- (void)tabDetachedWithContents:(content::WebContents*)contents;
74
75// Returns the amount of additional height the container view needs to draw the
76// anti-spoofing tip. This is the total amount of overlap for all infobars.
77- (CGFloat)overlappingTipHeight;
78
79// Adds the given infobar.
80- (void)addInfoBar:(InfoBarCocoa*)infobar
81          position:(NSUInteger)position;
82
83// Removes the given infobar.
84- (void)removeInfoBar:(InfoBarCocoa*)infobar;
85
86// Positions the infobar views in the container view and notifies
87// |browser_controller_| that it needs to resize the container view.
88- (void)positionInfoBarsAndRedraw:(BOOL)isAnimating;
89
90// Set the max arrow height of the top infobar.
91- (void)setMaxTopArrowHeight:(NSInteger)height;
92
93// The height of all the info bars. Does not include the top arrow.
94- (CGFloat)heightOfInfoBars;
95
96@end
97
98#endif  // CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_CONTAINER_CONTROLLER_H_
99