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

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

Issue 190063006: Infobar Componentization Proof of Concept (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor fixes Created 6 years, 9 months 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
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 "chrome/browser/infobars/infobar_manager.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "third_party/skia/include/core/SkColor.h" 13 #include "third_party/skia/include/core/SkColor.h"
15 14
16 class InfoBar; 15 class InfoBar;
17 class InfoBarService;
18 16
19 // InfoBarContainer is a cross-platform base class to handle the visibility- 17 // InfoBarContainer is a cross-platform base class to handle the visibility-
20 // related aspects of InfoBars. While InfoBarService owns the InfoBars, the 18 // related aspects of InfoBars. While InfoBarManager owns the InfoBars, the
21 // InfoBarContainer is responsible for telling particular InfoBars that they 19 // InfoBarContainer is responsible for telling particular InfoBars that they
22 // should be hidden or visible. 20 // should be hidden or visible.
23 // 21 //
24 // Platforms need to subclass this to implement a few platform-specific 22 // Platforms need to subclass this to implement a few platform-specific
25 // functions, which are pure virtual here. 23 // functions, which are pure virtual here.
26 class InfoBarContainer : public content::NotificationObserver { 24 class InfoBarContainer : InfoBarManager::Observer {
droger 2014/03/18 15:59:53 InfoBarContained now observes InfoBarManager inste
27 public: 25 public:
28 class Delegate { 26 class Delegate {
29 public: 27 public:
30 // 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.
31 virtual SkColor GetInfoBarSeparatorColor() const = 0; 29 virtual SkColor GetInfoBarSeparatorColor() const = 0;
32 30
33 // The delegate is notified each time the infobar container changes height, 31 // The delegate is notified each time the infobar container changes height,
34 // as well as when it stops animating. 32 // as well as when it stops animating.
35 virtual void InfoBarContainerStateChanged(bool is_animating) = 0; 33 virtual void InfoBarContainerStateChanged(bool is_animating) = 0;
36 34
37 // The delegate needs to tell us whether "unspoofable" arrows should be 35 // The delegate needs to tell us whether "unspoofable" arrows should be
38 // 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.
39 virtual bool DrawInfoBarArrows(int* x) const = 0; 37 virtual bool DrawInfoBarArrows(int* x) const = 0;
40 38
41 protected: 39 protected:
42 virtual ~Delegate(); 40 virtual ~Delegate();
43 }; 41 };
44 42
45 explicit InfoBarContainer(Delegate* delegate); 43 explicit InfoBarContainer(Delegate* delegate);
46 virtual ~InfoBarContainer(); 44 virtual ~InfoBarContainer();
47 45
48 // Changes the InfoBarService for which this container is showing infobars. 46 // Changes the InfoBarManager for which this container is showing infobars.
49 // 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
50 // the infobars from |infobar_service|, and show them all. |infobar_service| 48 // the infobars from |infobar_manager|, and show them all. |infobar_manager|
51 // may be NULL. 49 // may be NULL.
52 void ChangeInfoBarService(InfoBarService* infobar_service); 50 void ChangeInfoBarManager(InfoBarManager* infobar_manager);
53 51
54 // 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
55 // |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
56 // (including overlap). 54 // (including overlap).
57 int GetVerticalOverlap(int* total_height); 55 int GetVerticalOverlap(int* total_height);
58 56
59 // 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
60 // "unspoofable" arrow would point to and the top infobar itself changes. 58 // "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 59 // 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 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
94 // until the translate infobar is implemented as three different infobars like 92 // until the translate infobar is implemented as three different infobars like
95 // GTK does. 93 // GTK does.
96 virtual void PlatformSpecificReplaceInfoBar(InfoBar* old_infobar, 94 virtual void PlatformSpecificReplaceInfoBar(InfoBar* old_infobar,
97 InfoBar* new_infobar) {} 95 InfoBar* new_infobar) {}
98 virtual void PlatformSpecificRemoveInfoBar(InfoBar* infobar) = 0; 96 virtual void PlatformSpecificRemoveInfoBar(InfoBar* infobar) = 0;
99 virtual void PlatformSpecificInfoBarStateChanged(bool is_animating) {} 97 virtual void PlatformSpecificInfoBarStateChanged(bool is_animating) {}
100 98
101 private: 99 private:
102 typedef std::vector<InfoBar*> InfoBars; 100 typedef std::vector<InfoBar*> InfoBars;
103 101
104 // content::NotificationObserver: 102 // InfoBarManager::Observer:
105 virtual void Observe(int type, 103 virtual void OnInfoBarAdded(InfoBar* infobar) OVERRIDE;
106 const content::NotificationSource& source, 104 virtual void OnInfoBarReplaced(InfoBar* old_infobar,
Peter Kasting 2014/03/18 18:29:17 Nit: Here and elsewhere, put these in alphabetical
107 const content::NotificationDetails& details) OVERRIDE; 105 InfoBar* new_infobar) OVERRIDE;
106 virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) OVERRIDE;
108 107
109 // Hides all infobars in this container without animation. 108 // Hides all infobars in this container without animation.
110 void HideAllInfoBars(); 109 void HideAllInfoBars();
111 110
112 // Adds |infobar| to this container before the existing infobar at position 111 // Adds |infobar| to this container before the existing infobar at position
113 // |position| and calls Show() on it. |animate| is passed along to 112 // |position| and calls Show() on it. |animate| is passed along to
114 // infobar->Show(). Depending on the value of |callback_status|, this calls 113 // 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 114 // 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. 115 // that OnInfoBarStateChanged() either will or won't be called as a result.
117 enum CallbackStatus { NO_CALLBACK, WANT_CALLBACK }; 116 enum CallbackStatus { NO_CALLBACK, WANT_CALLBACK };
118 void AddInfoBar(InfoBar* infobar, 117 void AddInfoBar(InfoBar* infobar,
119 size_t position, 118 size_t position,
120 bool animate, 119 bool animate,
121 CallbackStatus callback_status); 120 CallbackStatus callback_status);
122 121
123 void UpdateInfoBarArrowTargetHeights(); 122 void UpdateInfoBarArrowTargetHeights();
124 int ArrowTargetHeightForInfoBar(size_t infobar_index) const; 123 int ArrowTargetHeightForInfoBar(size_t infobar_index) const;
125 124
126 content::NotificationRegistrar registrar_;
127 Delegate* delegate_; 125 Delegate* delegate_;
128 InfoBarService* infobar_service_; 126 InfoBarManager* infobar_manager_;
129 InfoBars infobars_; 127 InfoBars infobars_;
130 128
131 // Calculated in SetMaxTopArrowHeight(). 129 // Calculated in SetMaxTopArrowHeight().
132 int top_arrow_target_height_; 130 int top_arrow_target_height_;
133 131
134 DISALLOW_COPY_AND_ASSIGN(InfoBarContainer); 132 DISALLOW_COPY_AND_ASSIGN(InfoBarContainer);
135 }; 133 };
136 134
137 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_ 135 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698