Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: trunk/src/chrome/browser/infobars/infobar_container.h

Issue 102163002: Revert 238283 "Infobar system refactor." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "content/public/browser/notification_observer.h" 12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h" 13 #include "content/public/browser/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 InfoBarService; 18 class InfoBarService;
18 19
19 // InfoBarContainer is a cross-platform base class to handle the visibility- 20 // InfoBarContainer is a cross-platform base class to handle the visibility-
20 // related aspects of InfoBars. While InfoBarService owns the InfoBars, the 21 // related aspects of InfoBars. While InfoBars own themselves, the
21 // InfoBarContainer is responsible for telling particular InfoBars that they 22 // InfoBarContainer is responsible for telling particular InfoBars that they
22 // should be hidden or visible. 23 // should be hidden or visible.
23 // 24 //
24 // Platforms need to subclass this to implement a few platform-specific 25 // Platforms need to subclass this to implement a few platform-specific
25 // functions, which are pure virtual here. 26 // functions, which are pure virtual here.
26 class InfoBarContainer : public content::NotificationObserver { 27 class InfoBarContainer : public content::NotificationObserver {
27 public: 28 public:
28 class Delegate { 29 class Delegate {
29 public: 30 public:
30 // The separator color may vary depending on where the container is hosted. 31 // The separator color may vary depending on where the container is hosted.
31 virtual SkColor GetInfoBarSeparatorColor() const = 0; 32 virtual SkColor GetInfoBarSeparatorColor() const = 0;
32 33
33 // The delegate is notified each time the infobar container changes height, 34 // The delegate is notified each time the infobar container changes height,
34 // as well as when it stops animating. 35 // as well as when it stops animating.
35 virtual void InfoBarContainerStateChanged(bool is_animating) = 0; 36 virtual void InfoBarContainerStateChanged(bool is_animating) = 0;
36 37
37 // The delegate needs to tell us whether "unspoofable" arrows should be 38 // The delegate needs to tell us whether "unspoofable" arrows should be
38 // 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.
39 virtual bool DrawInfoBarArrows(int* x) const = 0; 40 virtual bool DrawInfoBarArrows(int* x) const = 0;
40 41
41 protected: 42 protected:
42 virtual ~Delegate(); 43 virtual ~Delegate();
43 }; 44 };
44 45
45 explicit InfoBarContainer(Delegate* delegate); 46 explicit InfoBarContainer(Delegate* delegate);
46 virtual ~InfoBarContainer(); 47 virtual ~InfoBarContainer();
47 48
48 // Changes the InfoBarService for which this container is showing infobars. 49 // Changes the InfoBarService for which this container is showing infobars.
49 // This will hide all current infobars, remove them from the container, add 50 // This will remove all current infobars from the container, add the infobars
50 // the infobars from |infobar_service|, and show them all. |infobar_service| 51 // from |infobar_service|, and show them all. |infobar_service| may be NULL.
51 // may be NULL.
52 void ChangeInfoBarService(InfoBarService* infobar_service); 52 void ChangeInfoBarService(InfoBarService* infobar_service);
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 // Called by |infobar| to request that it be removed from the container. At 75 // Called by |infobar| to request that it be removed from the container. At
76 // this point, |infobar| should already be hidden. 76 // this point, |infobar| should already be hidden. Once the infobar is
77 // removed, it is guaranteed to delete itself and will not be re-added again.
77 void RemoveInfoBar(InfoBar* infobar); 78 void RemoveInfoBar(InfoBar* infobar);
78 79
79 const Delegate* delegate() const { return delegate_; } 80 const Delegate* delegate() const { return delegate_; }
80 81
81 protected: 82 protected:
82 // Subclasses must call this during destruction, so that we can remove 83 // Subclasses must call this during destruction, so that we can remove
83 // infobars (which will call the pure virtual functions below) while the 84 // infobars (which will call the pure virtual functions below) while the
84 // subclass portion of |this| has not yet been destroyed. 85 // subclass portion of |this| has not yet been destroyed.
85 void RemoveAllInfoBarsForDestruction(); 86 void RemoveAllInfoBarsForDestruction();
86 87
(...skipping 12 matching lines...) Expand all
99 virtual void PlatformSpecificInfoBarStateChanged(bool is_animating) {} 100 virtual void PlatformSpecificInfoBarStateChanged(bool is_animating) {}
100 101
101 private: 102 private:
102 typedef std::vector<InfoBar*> InfoBars; 103 typedef std::vector<InfoBar*> InfoBars;
103 104
104 // content::NotificationObserver: 105 // content::NotificationObserver:
105 virtual void Observe(int type, 106 virtual void Observe(int type,
106 const content::NotificationSource& source, 107 const content::NotificationSource& source,
107 const content::NotificationDetails& details) OVERRIDE; 108 const content::NotificationDetails& details) OVERRIDE;
108 109
110 // Hides an InfoBar for the specified delegate, in response to a notification
111 // from the selected InfoBarService. The InfoBar's disappearance will be
112 // animated if |use_animation| is true. The InfoBar will call back to
113 // RemoveInfoBar() to remove itself once it's hidden (which may mean
114 // synchronously). Returns the position within |infobars_| the infobar was
115 // previously at.
116 size_t HideInfoBar(InfoBar* infobar, bool use_animation);
117
118 // Find an existing infobar in the container.
119 InfoBar* FindInfoBar(InfoBarDelegate* delegate);
120
109 // Hides all infobars in this container without animation. 121 // Hides all infobars in this container without animation.
110 void HideAllInfoBars(); 122 void HideAllInfoBars();
111 123
112 // Adds |infobar| to this container before the existing infobar at position 124 // Adds |infobar| to this container before the existing infobar at position
113 // |position| and calls Show() on it. |animate| is passed along to 125 // |position| and calls Show() on it. |animate| is passed along to
114 // infobar->Show(). Depending on the value of |callback_status|, this calls 126 // infobar->Show(). Depending on the value of |callback_status|, this calls
115 // infobar->set_container(this) either before or after the call to Show() so 127 // infobar->set_container(this) either before or after the call to Show() so
116 // that OnInfoBarStateChanged() either will or won't be called as a result. 128 // that OnInfoBarStateChanged() either will or won't be called as a result.
129 //
130 // This should be called only once for an infobar -- once it's added, it can
131 // be repeatedly shown and hidden, but not removed and then re-added (see
132 // comments on RemoveInfoBar()).
117 enum CallbackStatus { NO_CALLBACK, WANT_CALLBACK }; 133 enum CallbackStatus { NO_CALLBACK, WANT_CALLBACK };
118 void AddInfoBar(InfoBar* infobar, 134 void AddInfoBar(InfoBar* infobar,
119 size_t position, 135 size_t position,
120 bool animate, 136 bool animate,
121 CallbackStatus callback_status); 137 CallbackStatus callback_status);
122 138
123 void UpdateInfoBarArrowTargetHeights(); 139 void UpdateInfoBarArrowTargetHeights();
124 int ArrowTargetHeightForInfoBar(size_t infobar_index) const; 140 int ArrowTargetHeightForInfoBar(size_t infobar_index) const;
125 141
126 content::NotificationRegistrar registrar_; 142 content::NotificationRegistrar registrar_;
127 Delegate* delegate_; 143 Delegate* delegate_;
128 InfoBarService* infobar_service_; 144 InfoBarService* infobar_service_;
129 InfoBars infobars_; 145 InfoBars infobars_;
130 146
131 // Calculated in SetMaxTopArrowHeight(). 147 // Calculated in SetMaxTopArrowHeight().
132 int top_arrow_target_height_; 148 int top_arrow_target_height_;
133 149
134 DISALLOW_COPY_AND_ASSIGN(InfoBarContainer); 150 DISALLOW_COPY_AND_ASSIGN(InfoBarContainer);
135 }; 151 };
136 152
137 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_ 153 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/infobars/infobar.cc ('k') | trunk/src/chrome/browser/infobars/infobar_container.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698