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

Side by Side Diff: chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc

Issue 7006010: Change InfoBar-related notifications to be sourced from a TabContentsWrapper, not a TabContents. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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 | 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 #include "chrome/browser/ui/gtk/infobars/infobar_container_gtk.h" 5 #include "chrome/browser/ui/gtk/infobars/infobar_container_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 void InfoBarContainerGtk::ChangeTabContents(TabContentsWrapper* contents) { 89 void InfoBarContainerGtk::ChangeTabContents(TabContentsWrapper* contents) {
90 if (tab_contents_) 90 if (tab_contents_)
91 registrar_.RemoveAll(); 91 registrar_.RemoveAll();
92 92
93 gtk_util::RemoveAllChildren(widget()); 93 gtk_util::RemoveAllChildren(widget());
94 UpdateToolbarInfoBarState(NULL, false); 94 UpdateToolbarInfoBarState(NULL, false);
95 95
96 tab_contents_ = contents; 96 tab_contents_ = contents;
97 if (tab_contents_) { 97 if (tab_contents_) {
98 UpdateInfoBars(); 98 UpdateInfoBars();
99 Source<TabContents> source(tab_contents_->tab_contents()); 99 Source<TabContentsWrapper> source(tab_contents_);
100 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED, source); 100 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED, source);
101 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, 101 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
102 source); 102 source);
103 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, 103 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
104 source); 104 source);
105 } 105 }
106 } 106 }
107 107
108 void InfoBarContainerGtk::RemoveDelegate(InfoBarDelegate* delegate) { 108 void InfoBarContainerGtk::RemoveDelegate(InfoBarDelegate* delegate) {
109 tab_contents_->RemoveInfoBar(delegate); 109 tab_contents_->RemoveInfoBar(delegate);
110 } 110 }
111 111
112 int InfoBarContainerGtk::TotalHeightOfAnimatingBars() const { 112 int InfoBarContainerGtk::TotalHeightOfAnimatingBars() const {
113 int sum = 0; 113 int sum = 0;
114 gtk_container_foreach(GTK_CONTAINER(widget()), SumAnimatingBarHeight, &sum); 114 gtk_container_foreach(GTK_CONTAINER(widget()), SumAnimatingBarHeight, &sum);
115 return sum; 115 return sum;
116 } 116 }
117 117
118 // InfoBarContainerGtk, NotificationObserver implementation: ------------------- 118 // InfoBarContainerGtk, NotificationObserver implementation: -------------------
119 119
120 void InfoBarContainerGtk::Observe(NotificationType type, 120 void InfoBarContainerGtk::Observe(NotificationType type,
121 const NotificationSource& source, 121 const NotificationSource& source,
122 const NotificationDetails& details) { 122 const NotificationDetails& details) {
123 if (type == NotificationType::TAB_CONTENTS_INFOBAR_ADDED) { 123 switch (type.value) {
124 AddInfoBar(Details<InfoBarDelegate>(details).ptr(), true); 124 case NotificationType::TAB_CONTENTS_INFOBAR_ADDED:
125 } else if (type == NotificationType::TAB_CONTENTS_INFOBAR_REMOVED) { 125 AddInfoBar(Details<InfoBar>(details).ptr(), true);
126 RemoveInfoBar(Details<InfoBarDelegate>(details).ptr(), true); 126 break;
127 } else if (type == NotificationType::TAB_CONTENTS_INFOBAR_REPLACED) {
128 std::pair<InfoBarDelegate*, InfoBarDelegate*>* delegates =
129 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details).ptr();
130 127
131 // By not animating the removal/addition, this appears to be a replace. 128 case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED: {
132 RemoveInfoBar(delegates->first, false); 129 typedef std::pair<InfoBarDelegate*, bool> RemoveDetails;
133 AddInfoBar(delegates->second, false); 130 RemoveDetails* remove_details = Details<RemoveDetails>(details).ptr();
134 } else { 131 RemoveInfoBar(remove_details->first, remove_details->second);
135 NOTREACHED(); 132 break;
133 }
134
135 case NotificationType::TAB_CONTENTS_INFOBAR_REPLACED: {
136 typedef std::pair<InfoBarDelegate*, InfoBar*> ReplaceDetails;
137 ReplaceDetails* replace_details = Details<ReplaceDetails>(details).ptr();
138 RemoveInfoBar(replace_details->first, false);
139 AddInfoBar(replace_details->second, false);
140 break;
141 }
142
143 default:
144 NOTREACHED();
145 break;
136 } 146 }
137 } 147 }
138 148
139 // InfoBarContainerGtk, private: ----------------------------------------------- 149 // InfoBarContainerGtk, private: -----------------------------------------------
140 150
141 void InfoBarContainerGtk::UpdateInfoBars() { 151 void InfoBarContainerGtk::UpdateInfoBars() {
142 for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) { 152 for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) {
143 InfoBarDelegate* delegate = tab_contents_->GetInfoBarDelegateAt(i); 153 InfoBarDelegate* delegate = tab_contents_->GetInfoBarDelegateAt(i);
144 AddInfoBar(delegate, false); 154 AddInfoBar(delegate->CreateInfoBar(tab_contents_), false);
145 } 155 }
146 } 156 }
147 157
148 void InfoBarContainerGtk::ShowArrowForDelegate(InfoBarDelegate* delegate, 158 void InfoBarContainerGtk::ShowArrowForDelegate(InfoBarDelegate* delegate,
149 bool animate) { 159 bool animate) {
150 GList* children = gtk_container_get_children(GTK_CONTAINER(widget())); 160 GList* children = gtk_container_get_children(GTK_CONTAINER(widget()));
151 if (!children) 161 if (!children)
152 return; 162 return;
153 163
154 // Iterate through the infobars and find the last one that isn't closing. 164 // Iterate through the infobars and find the last one that isn't closing.
(...skipping 13 matching lines...) Expand all
168 } 178 }
169 179
170 if (last_bar) 180 if (last_bar)
171 last_bar->ShowArrowFor(this_bar, animate); 181 last_bar->ShowArrowFor(this_bar, animate);
172 else 182 else
173 UpdateToolbarInfoBarState(this_bar, animate); 183 UpdateToolbarInfoBarState(this_bar, animate);
174 184
175 g_list_free(children); 185 g_list_free(children);
176 } 186 }
177 187
178 void InfoBarContainerGtk::AddInfoBar(InfoBarDelegate* delegate, bool animate) { 188 void InfoBarContainerGtk::AddInfoBar(InfoBar* infobar, bool animate) {
179 InfoBar* infobar = delegate->CreateInfoBar(tab_contents_);
180 infobar->set_container(this); 189 infobar->set_container(this);
181 infobar->SetThemeProvider(GtkThemeService::GetFrom(profile_)); 190 infobar->SetThemeProvider(GtkThemeService::GetFrom(profile_));
182 gtk_box_pack_start(GTK_BOX(widget()), infobar->widget(), 191 gtk_box_pack_start(GTK_BOX(widget()), infobar->widget(),
183 FALSE, FALSE, 0); 192 FALSE, FALSE, 0);
184 193
185 infobar->Show(animate); 194 infobar->Show(animate);
186 ShowArrowForDelegate(delegate, animate); 195 ShowArrowForDelegate(infobar->delegate(), animate);
187 } 196 }
188 197
189 void InfoBarContainerGtk::RemoveInfoBar(InfoBarDelegate* delegate, 198 void InfoBarContainerGtk::RemoveInfoBar(InfoBarDelegate* delegate,
190 bool animate) { 199 bool animate) {
191 if (animate) { 200 if (animate) {
192 gtk_container_foreach(GTK_CONTAINER(widget()), 201 gtk_container_foreach(GTK_CONTAINER(widget()),
193 AnimateClosingForDelegate, delegate); 202 AnimateClosingForDelegate, delegate);
194 } else { 203 } else {
195 gtk_container_foreach(GTK_CONTAINER(widget()), ClosingForDelegate, 204 gtk_container_foreach(GTK_CONTAINER(widget()), ClosingForDelegate,
196 delegate); 205 delegate);
(...skipping 11 matching lines...) Expand all
208 } 217 }
209 218
210 void InfoBarContainerGtk::UpdateToolbarInfoBarState(InfoBar* infobar, 219 void InfoBarContainerGtk::UpdateToolbarInfoBarState(InfoBar* infobar,
211 bool animate) { 220 bool animate) {
212 GtkWindow* parent = platform_util::GetTopLevel(widget()); 221 GtkWindow* parent = platform_util::GetTopLevel(widget());
213 BrowserWindowGtk* browser_window = 222 BrowserWindowGtk* browser_window =
214 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent); 223 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent);
215 if (browser_window) 224 if (browser_window)
216 browser_window->SetInfoBarShowing(infobar, animate); 225 browser_window->SetInfoBarShowing(infobar, animate);
217 } 226 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698