infobar_container.h revision 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801
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_VIEWS_INFOBARS_INFOBAR_CONTAINER_H_
6#define CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_CONTAINER_H_
7#pragma once
8
9#include "chrome/browser/ui/views/accessible_pane_view.h"
10#include "chrome/common/notification_observer.h"
11#include "chrome/common/notification_registrar.h"
12#include "views/view.h"
13
14class BrowserView;
15class InfoBarDelegate;
16class TabContents;
17
18// A views::View subclass that contains a collection of InfoBars associated with
19// a TabContents.
20class InfoBarContainer : public AccessiblePaneView,
21                         public NotificationObserver {
22 public:
23  // Implement this interface when you want to receive notifications from the
24  // InfoBarContainer
25  class Delegate {
26   public:
27    virtual ~Delegate() {}
28    virtual void InfoBarContainerSizeChanged(bool is_animating) = 0;
29  };
30
31  explicit InfoBarContainer(Delegate* delegate);
32  virtual ~InfoBarContainer();
33
34  // Changes the TabContents for which this container is showing InfoBars. Can
35  // be NULL.
36  void ChangeTabContents(TabContents* contents);
37
38  // Called by child InfoBars as they animate. If |completed| is true, the
39  // animation has finished running.
40  void InfoBarAnimated(bool completed);
41
42  // Remove the specified InfoBarDelegate from the selected TabContents. This
43  // will notify us back and cause us to close the View. This is called from
44  // the InfoBar's close button handler.
45  void RemoveDelegate(InfoBarDelegate* delegate);
46
47  // Paint the InfoBar arrows on |canvas|. |arrow_center_x| indicates
48  // the desired location of the center of the arrow in the
49  // |outer_view| coordinate system.
50  void PaintInfoBarArrows(gfx::Canvas* canvas,
51                          View* outer_view,
52                          int arrow_center_x);
53
54 private:
55  // AccessiblePaneView:
56  virtual gfx::Size GetPreferredSize();
57  virtual void Layout();
58  virtual AccessibilityTypes::Role GetAccessibleRole();
59  virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
60
61  // NotificationObserver:
62  virtual void Observe(NotificationType type,
63                       const NotificationSource& source,
64                       const NotificationDetails& details);
65
66  // Constructs the InfoBars needed to reflect the state of the current
67  // TabContents associated with this container. No animations are run during
68  // this process.
69  void UpdateInfoBars();
70
71  // Adds an InfoBar for the specified delegate, in response to a notification
72  // from the selected TabContents. The InfoBar's appearance will be animated
73  // if |use_animation| is true.
74  void AddInfoBar(InfoBarDelegate* delegate, bool use_animation);
75
76  // Removes an InfoBar for the specified delegate, in response to a
77  // notification from the selected TabContents. The InfoBar's disappearance
78  // will be animated if |use_animation| is true.
79  void RemoveInfoBar(InfoBarDelegate* delegate, bool use_animation);
80
81  // Replaces an InfoBar for the specified delegate with a new one. There is no
82  // animation.
83  void ReplaceInfoBar(InfoBarDelegate* old_delegate,
84                      InfoBarDelegate* new_delegate);
85
86  NotificationRegistrar registrar_;
87
88  // The Delegate which receives notifications from the InfoBarContainer.
89  Delegate* delegate_;
90
91  // The TabContents for which we are currently showing InfoBars.
92  TabContents* tab_contents_;
93
94  DISALLOW_COPY_AND_ASSIGN(InfoBarContainer);
95};
96
97#endif  // CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_CONTAINER_H_
98