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_VIEWS_INFOBARS_INFOBAR_CONTAINER_H_ | 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_INFOBAR_CONTAINER_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_CONTAINER_H_ | 6 #define CHROME_BROWSER_TAB_CONTENTS_INFOBAR_CONTAINER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "content/common/notification_observer.h" | 12 #include "content/common/notification_observer.h" |
13 #include "content/common/notification_registrar.h" | 13 #include "content/common/notification_registrar.h" |
14 #include "third_party/skia/include/core/SkColor.h" | 14 #include "third_party/skia/include/core/SkColor.h" |
15 | 15 |
16 class InfoBar; | 16 class InfoBar; |
17 class InfoBarDelegate; | 17 class InfoBarDelegate; |
18 class TabContents; | 18 class TabContentsWrapper; |
19 | 19 |
20 // InfoBarContainer is a cross-platform base class to handle the visibility- | 20 // InfoBarContainer is a cross-platform base class to handle the visibility- |
21 // related aspects of InfoBars. While InfoBars own themselves, the | 21 // related aspects of InfoBars. While InfoBars own themselves, the |
22 // InfoBarContainer is responsible for telling particular InfoBars that they | 22 // InfoBarContainer is responsible for telling particular InfoBars that they |
23 // should be hidden or visible. | 23 // should be hidden or visible. |
24 // | 24 // |
25 // Platforms need to subclass this to implement a few platform-specific | 25 // Platforms need to subclass this to implement a few platform-specific |
26 // functions, which are pure virtual here. | 26 // functions, which are pure virtual here. |
27 class InfoBarContainer : public NotificationObserver { | 27 class InfoBarContainer : public NotificationObserver { |
28 public: | 28 public: |
(...skipping 10 matching lines...) Expand all Loading... |
39 // drawn, and if so, at what |x| coordinate. |x| may be NULL. | 39 // drawn, and if so, at what |x| coordinate. |x| may be NULL. |
40 virtual bool DrawInfoBarArrows(int* x) const = 0; | 40 virtual bool DrawInfoBarArrows(int* x) const = 0; |
41 | 41 |
42 protected: | 42 protected: |
43 virtual ~Delegate(); | 43 virtual ~Delegate(); |
44 }; | 44 }; |
45 | 45 |
46 explicit InfoBarContainer(Delegate* delegate); | 46 explicit InfoBarContainer(Delegate* delegate); |
47 virtual ~InfoBarContainer(); | 47 virtual ~InfoBarContainer(); |
48 | 48 |
49 // Changes the TabContents for which this container is showing infobars. This | 49 // Changes the TabContentsWrapper for which this container is showing |
50 // will remove all current infobars from the container, add the infobars from | 50 // infobars. This will remove all current infobars from the container, add |
51 // |contents|, and show them all. |contents| may be NULL. | 51 // the infobars from |contents|, and show them all. |contents| may be NULL. |
52 void ChangeTabContents(TabContents* contents); | 52 void ChangeTabContents(TabContentsWrapper* contents); |
53 | 53 |
54 // Returns the amount by which to overlap the toolbar above, and, when | 54 // Returns the amount by which to overlap the toolbar above, and, when |
55 // |total_height| is non-NULL, set it to the height of the InfoBarContainer | 55 // |total_height| is non-NULL, set it to the height of the InfoBarContainer |
56 // (including overlap). | 56 // (including overlap). |
57 int GetVerticalOverlap(int* total_height); | 57 int GetVerticalOverlap(int* total_height); |
58 | 58 |
59 // Called by the delegate when the distance between what the top infobar's | 59 // Called by the delegate when the distance between what the top infobar's |
60 // "unspoofable" arrow would point to and the top infobar itself changes. | 60 // "unspoofable" arrow would point to and the top infobar itself changes. |
61 // This enables the top infobar to show a longer arrow (e.g. because of a | 61 // This enables the top infobar to show a longer arrow (e.g. because of a |
62 // visible bookmark bar) or shorter (e.g. due to being in a popup window) if | 62 // visible bookmark bar) or shorter (e.g. due to being in a popup window) if |
63 // desired. | 63 // desired. |
64 // | 64 // |
65 // IMPORTANT: This MUST NOT result in a call back to | 65 // IMPORTANT: This MUST NOT result in a call back to |
66 // Delegate::InfoBarContainerStateChanged() unless it causes an actual | 66 // Delegate::InfoBarContainerStateChanged() unless it causes an actual |
67 // change, lest we infinitely recurse. | 67 // change, lest we infinitely recurse. |
68 void SetMaxTopArrowHeight(int height); | 68 void SetMaxTopArrowHeight(int height); |
69 | 69 |
70 // Called when a contained infobar has animated or by some other means changed | 70 // Called when a contained infobar has animated or by some other means changed |
71 // its height, or when it stops animating. The container is expected to do | 71 // its height, or when it stops animating. The container is expected to do |
72 // anything necessary to respond, e.g. re-layout. | 72 // anything necessary to respond, e.g. re-layout. |
73 void OnInfoBarStateChanged(bool is_animating); | 73 void OnInfoBarStateChanged(bool is_animating); |
74 | 74 |
75 // Removes the specified InfoBarDelegate from the selected TabContents. This | 75 // Removes the specified InfoBarDelegate from the selected TabContentsWrapper. |
76 // will notify us back and cause us to close the InfoBar. This is called from | 76 // This will notify us back and cause us to close the InfoBar. This is called |
77 // the InfoBar's close button handler. | 77 // from the InfoBar's close button handler. |
78 void RemoveDelegate(InfoBarDelegate* delegate); | 78 void RemoveDelegate(InfoBarDelegate* delegate); |
79 | 79 |
80 // Called by |infobar| to request that it be removed from the container, as it | 80 // Called by |infobar| to request that it be removed from the container, as it |
81 // is about to delete itself. At this point, |infobar| should already be | 81 // is about to delete itself. At this point, |infobar| should already be |
82 // hidden. | 82 // hidden. |
83 void RemoveInfoBar(InfoBar* infobar); | 83 void RemoveInfoBar(InfoBar* infobar); |
84 | 84 |
85 const Delegate* delegate() const { return delegate_; } | 85 const Delegate* delegate() const { return delegate_; } |
86 | 86 |
87 protected: | 87 protected: |
88 // Subclasses must call this during destruction, so that we can remove | 88 // Subclasses must call this during destruction, so that we can remove |
89 // infobars (which will call the pure virtual functions below) while the | 89 // infobars (which will call the pure virtual functions below) while the |
90 // subclass portion of |this| has not yet been destroyed. | 90 // subclass portion of |this| has not yet been destroyed. |
91 void RemoveAllInfoBarsForDestruction(); | 91 void RemoveAllInfoBarsForDestruction(); |
92 | 92 |
93 // These must be implemented on each platform to e.g. adjust the visible | 93 // These must be implemented on each platform to e.g. adjust the visible |
94 // object hierarchy. | 94 // object hierarchy. |
95 virtual void PlatformSpecificAddInfoBar(InfoBar* infobar) = 0; | 95 virtual void PlatformSpecificAddInfoBar(InfoBar* infobar) = 0; |
96 virtual void PlatformSpecificRemoveInfoBar(InfoBar* infobar) = 0; | 96 virtual void PlatformSpecificRemoveInfoBar(InfoBar* infobar) = 0; |
97 | 97 |
98 private: | 98 private: |
99 typedef std::vector<InfoBar*> InfoBars; | 99 typedef std::vector<InfoBar*> InfoBars; |
100 | 100 |
101 // NotificationObserver: | 101 // NotificationObserver: |
102 virtual void Observe(NotificationType type, | 102 virtual void Observe(NotificationType type, |
103 const NotificationSource& source, | 103 const NotificationSource& source, |
104 const NotificationDetails& details) OVERRIDE; | 104 const NotificationDetails& details) OVERRIDE; |
105 | 105 |
106 // Removes an InfoBar for the specified delegate, in response to a | 106 // Removes an InfoBar for the specified delegate, in response to a |
107 // notification from the selected TabContents. The InfoBar's disappearance | 107 // notification from the selected TabContentsWrapper. The InfoBar's |
108 // will be animated if |use_animation| is true. | 108 // disappearance will be animated if |use_animation| is true. |
109 void RemoveInfoBar(InfoBarDelegate* delegate, bool use_animation); | 109 void RemoveInfoBar(InfoBarDelegate* delegate, bool use_animation); |
110 | 110 |
111 // Adds |infobar| to this container and calls Show() on it. |animate| is | 111 // Adds |infobar| to this container and calls Show() on it. |animate| is |
112 // passed along to infobar->Show(). Depending on the value of | 112 // passed along to infobar->Show(). Depending on the value of |
113 // |callback_status|, this calls infobar->set_container(this) either before or | 113 // |callback_status|, this calls infobar->set_container(this) either before or |
114 // after the call to Show() so that OnInfoBarAnimated() either will or won't | 114 // after the call to Show() so that OnInfoBarAnimated() either will or won't |
115 // be called as a result. | 115 // be called as a result. |
116 enum CallbackStatus { NO_CALLBACK, WANT_CALLBACK }; | 116 enum CallbackStatus { NO_CALLBACK, WANT_CALLBACK }; |
117 void AddInfoBar(InfoBar* infobar, | 117 void AddInfoBar(InfoBar* infobar, |
118 bool animate, | 118 bool animate, |
119 CallbackStatus callback_status); | 119 CallbackStatus callback_status); |
120 | 120 |
121 void UpdateInfoBarArrowTargetHeights(); | 121 void UpdateInfoBarArrowTargetHeights(); |
122 int ArrowTargetHeightForInfoBar(size_t infobar_index) const; | 122 int ArrowTargetHeightForInfoBar(size_t infobar_index) const; |
123 | 123 |
124 NotificationRegistrar registrar_; | 124 NotificationRegistrar registrar_; |
125 Delegate* delegate_; | 125 Delegate* delegate_; |
126 TabContents* tab_contents_; | 126 TabContentsWrapper* tab_contents_; |
127 InfoBars infobars_; | 127 InfoBars infobars_; |
128 | 128 |
129 // Calculated in SetMaxTopArrowHeight(). | 129 // Calculated in SetMaxTopArrowHeight(). |
130 int top_arrow_target_height_; | 130 int top_arrow_target_height_; |
131 | 131 |
132 DISALLOW_COPY_AND_ASSIGN(InfoBarContainer); | 132 DISALLOW_COPY_AND_ASSIGN(InfoBarContainer); |
133 }; | 133 }; |
134 | 134 |
135 #endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_CONTAINER_H_ | 135 #endif // CHROME_BROWSER_TAB_CONTENTS_INFOBAR_CONTAINER_H_ |
OLD | NEW |