Home | History | Annotate | Download | only in infobars
      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 #include "content/public/browser/notification_registrar.h"
     14 
     15 @class BrowserWindowController;
     16 @class InfoBarController;
     17 class InfoBar;
     18 class InfoBarDelegate;
     19 class InfoBarNotificationObserver;
     20 class TabStripModel;
     21 
     22 namespace content {
     23 class WebContents;
     24 }
     25 
     26 // Protocol for basic container methods, as needed by an InfoBarController.
     27 // This protocol exists to make mocking easier in unittests.
     28 @protocol InfoBarContainer
     29 - (void)willRemoveController:(InfoBarController*)controller;
     30 - (void)removeController:(InfoBarController*)controller;
     31 - (BrowserWindowController*)browserWindowController;
     32 @end
     33 
     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
     47 // of all the infobar views.  This class owns zero or more
     48 // InfoBarControllers, which manage the infobar views.  This class
     49 // also receives tab strip model notifications and handles
     50 // adding/removing infobars when needed.
     51 @interface InfoBarContainerController : NSViewController <ViewResizer,
     52                                                           InfoBarContainer> {
     53  @private
     54   // Needed to send resize messages when infobars are added or removed.
     55   id<ViewResizer> resizeDelegate_;  // weak
     56 
     57   // The WebContents we are currently showing infobars for.
     58   content::WebContents* currentWebContents_;  // weak
     59 
     60   // Holds the InfoBarControllers currently owned by this container.
     61   base::scoped_nsobject<NSMutableArray> infobarControllers_;
     62 
     63   // Holds InfoBarControllers when they are in the process of animating out.
     64   base::scoped_nsobject<NSMutableSet> closingInfoBars_;
     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 
     72   // If YES then the first info bar doesn't draw a tip.
     73   BOOL shouldSuppressTopInfoBarTip_;
     74 }
     75 
     76 @property(nonatomic, assign) BOOL shouldSuppressTopInfoBarTip;
     77 
     78 - (id)initWithResizeDelegate:(id<ViewResizer>)resizeDelegate;
     79 
     80 // Informs the container that the |controller| is going to close. It adds the
     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;
     97 
     98 // Stripped down version of TabStripModelObserverBridge:tabDetachedWithContents.
     99 // Forwarded by BWC. Removes all infobars and deregisters for any notifications
    100 // if |contents| is the current tab contents.
    101 - (void)tabDetachedWithContents:(content::WebContents*)contents;
    102 
    103 // Returns the number of active infobars. This is
    104 // |infobarControllers_ - closingInfoBars_|.
    105 - (NSUInteger)infobarCount;
    106 
    107 // Returns the amount of additional height the container view needs to draw the
    108 // anti-spoofing tip. This will return 0 if |-infobarCount| is 0. This is the
    109 // total amount of overlap for all infobars.
    110 - (CGFloat)overlappingTipHeight;
    111 
    112 @end
    113 
    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_
    144