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_INFOBARS_INFOBAR_CONTAINER_H_ | 5 #ifndef CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_ |
6 #define CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_ | 6 #define CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_manager.h" |
13 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
14 | 14 |
15 class InfoBar; | 15 class InfoBar; |
16 | 16 |
17 // InfoBarContainer is a cross-platform base class to handle the visibility- | 17 // InfoBarContainer is a cross-platform base class to handle the visibility- |
18 // related aspects of InfoBars. While InfoBarService owns the InfoBars, the | 18 // related aspects of InfoBars. While InfoBarManager owns the InfoBars, the |
19 // InfoBarContainer is responsible for telling particular InfoBars that they | 19 // InfoBarContainer is responsible for telling particular InfoBars that they |
20 // should be hidden or visible. | 20 // should be hidden or visible. |
21 // | 21 // |
22 // Platforms need to subclass this to implement a few platform-specific | 22 // Platforms need to subclass this to implement a few platform-specific |
23 // functions, which are pure virtual here. | 23 // functions, which are pure virtual here. |
24 class InfoBarContainer : public InfoBarService::Observer { | 24 class InfoBarContainer : public InfoBarManager::Observer { |
25 public: | 25 public: |
26 class Delegate { | 26 class Delegate { |
27 public: | 27 public: |
28 // The separator color may vary depending on where the container is hosted. | 28 // The separator color may vary depending on where the container is hosted. |
29 virtual SkColor GetInfoBarSeparatorColor() const = 0; | 29 virtual SkColor GetInfoBarSeparatorColor() const = 0; |
30 | 30 |
31 // The delegate is notified each time the infobar container changes height, | 31 // The delegate is notified each time the infobar container changes height, |
32 // as well as when it stops animating. | 32 // as well as when it stops animating. |
33 virtual void InfoBarContainerStateChanged(bool is_animating) = 0; | 33 virtual void InfoBarContainerStateChanged(bool is_animating) = 0; |
34 | 34 |
35 // The delegate needs to tell us whether "unspoofable" arrows should be | 35 // The delegate needs to tell us whether "unspoofable" arrows should be |
36 // drawn, and if so, at what |x| coordinate. |x| may be NULL. | 36 // drawn, and if so, at what |x| coordinate. |x| may be NULL. |
37 virtual bool DrawInfoBarArrows(int* x) const = 0; | 37 virtual bool DrawInfoBarArrows(int* x) const = 0; |
38 | 38 |
39 protected: | 39 protected: |
40 virtual ~Delegate(); | 40 virtual ~Delegate(); |
41 }; | 41 }; |
42 | 42 |
43 explicit InfoBarContainer(Delegate* delegate); | 43 explicit InfoBarContainer(Delegate* delegate); |
44 virtual ~InfoBarContainer(); | 44 virtual ~InfoBarContainer(); |
45 | 45 |
46 // Changes the InfoBarService for which this container is showing infobars. | 46 // Changes the InfoBarManager for which this container is showing infobars. |
47 // This will hide all current infobars, remove them from the container, add | 47 // This will hide all current infobars, remove them from the container, add |
48 // the infobars from |infobar_service|, and show them all. |infobar_service| | 48 // the infobars from |infobar_manager|, and show them all. |infobar_manager| |
49 // may be NULL. | 49 // may be NULL. |
50 void ChangeInfoBarService(InfoBarService* infobar_service); | 50 void ChangeInfoBarManager(InfoBarManager* infobar_manager); |
51 | 51 |
52 // Returns the amount by which to overlap the toolbar above, and, when | 52 // Returns the amount by which to overlap the toolbar above, and, when |
53 // |total_height| is non-NULL, set it to the height of the InfoBarContainer | 53 // |total_height| is non-NULL, set it to the height of the InfoBarContainer |
54 // (including overlap). | 54 // (including overlap). |
55 int GetVerticalOverlap(int* total_height); | 55 int GetVerticalOverlap(int* total_height); |
56 | 56 |
57 // Called by the delegate when the distance between what the top infobar's | 57 // Called by the delegate when the distance between what the top infobar's |
58 // "unspoofable" arrow would point to and the top infobar itself changes. | 58 // "unspoofable" arrow would point to and the top infobar itself changes. |
59 // This enables the top infobar to show a longer arrow (e.g. because of a | 59 // This enables the top infobar to show a longer arrow (e.g. because of a |
60 // visible bookmark bar) or shorter (e.g. due to being in a popup window) if | 60 // visible bookmark bar) or shorter (e.g. due to being in a popup window) if |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // until the translate infobar is implemented as three different infobars like | 92 // until the translate infobar is implemented as three different infobars like |
93 // GTK does. | 93 // GTK does. |
94 virtual void PlatformSpecificReplaceInfoBar(InfoBar* old_infobar, | 94 virtual void PlatformSpecificReplaceInfoBar(InfoBar* old_infobar, |
95 InfoBar* new_infobar) {} | 95 InfoBar* new_infobar) {} |
96 virtual void PlatformSpecificRemoveInfoBar(InfoBar* infobar) = 0; | 96 virtual void PlatformSpecificRemoveInfoBar(InfoBar* infobar) = 0; |
97 virtual void PlatformSpecificInfoBarStateChanged(bool is_animating) {} | 97 virtual void PlatformSpecificInfoBarStateChanged(bool is_animating) {} |
98 | 98 |
99 private: | 99 private: |
100 typedef std::vector<InfoBar*> InfoBars; | 100 typedef std::vector<InfoBar*> InfoBars; |
101 | 101 |
102 // InfoBarService::Observer: | 102 // InfoBarManager::Observer: |
103 virtual void OnInfoBarAdded(InfoBar* infobar) OVERRIDE; | 103 virtual void OnInfoBarAdded(InfoBar* infobar) OVERRIDE; |
104 virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) OVERRIDE; | 104 virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) OVERRIDE; |
105 virtual void OnInfoBarReplaced(InfoBar* old_infobar, | 105 virtual void OnInfoBarReplaced(InfoBar* old_infobar, |
106 InfoBar* new_infobar) OVERRIDE; | 106 InfoBar* new_infobar) OVERRIDE; |
107 virtual void OnServiceShuttingDown(InfoBarService* service) OVERRIDE; | 107 virtual void OnManagerShuttingDown(InfoBarManager* manager) OVERRIDE; |
108 | 108 |
109 // Adds |infobar| to this container before the existing infobar at position | 109 // Adds |infobar| to this container before the existing infobar at position |
110 // |position| and calls Show() on it. |animate| is passed along to | 110 // |position| and calls Show() on it. |animate| is passed along to |
111 // infobar->Show(). Depending on the value of |callback_status|, this calls | 111 // infobar->Show(). Depending on the value of |callback_status|, this calls |
112 // infobar->set_container(this) either before or after the call to Show() so | 112 // infobar->set_container(this) either before or after the call to Show() so |
113 // that OnInfoBarStateChanged() either will or won't be called as a result. | 113 // that OnInfoBarStateChanged() either will or won't be called as a result. |
114 enum CallbackStatus { NO_CALLBACK, WANT_CALLBACK }; | 114 enum CallbackStatus { NO_CALLBACK, WANT_CALLBACK }; |
115 void AddInfoBar(InfoBar* infobar, | 115 void AddInfoBar(InfoBar* infobar, |
116 size_t position, | 116 size_t position, |
117 bool animate, | 117 bool animate, |
118 CallbackStatus callback_status); | 118 CallbackStatus callback_status); |
119 | 119 |
120 void UpdateInfoBarArrowTargetHeights(); | 120 void UpdateInfoBarArrowTargetHeights(); |
121 int ArrowTargetHeightForInfoBar(size_t infobar_index) const; | 121 int ArrowTargetHeightForInfoBar(size_t infobar_index) const; |
122 | 122 |
123 Delegate* delegate_; | 123 Delegate* delegate_; |
124 InfoBarService* infobar_service_; | 124 InfoBarManager* infobar_manager_; |
125 InfoBars infobars_; | 125 InfoBars infobars_; |
126 | 126 |
127 // Calculated in SetMaxTopArrowHeight(). | 127 // Calculated in SetMaxTopArrowHeight(). |
128 int top_arrow_target_height_; | 128 int top_arrow_target_height_; |
129 | 129 |
130 DISALLOW_COPY_AND_ASSIGN(InfoBarContainer); | 130 DISALLOW_COPY_AND_ASSIGN(InfoBarContainer); |
131 }; | 131 }; |
132 | 132 |
133 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_ | 133 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_ |
OLD | NEW |