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

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

Issue 4767001: Make TabContents own its infobar delegates.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/gtk/infobar_container_gtk.h" 5 #include "chrome/browser/gtk/infobar_container_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "chrome/browser/browser_window.h" 10 #include "chrome/browser/browser_window.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // InfoBarContainerGtk, NotificationObserver implementation: ------------------- 116 // InfoBarContainerGtk, NotificationObserver implementation: -------------------
117 117
118 void InfoBarContainerGtk::Observe(NotificationType type, 118 void InfoBarContainerGtk::Observe(NotificationType type,
119 const NotificationSource& source, 119 const NotificationSource& source,
120 const NotificationDetails& details) { 120 const NotificationDetails& details) {
121 if (type == NotificationType::TAB_CONTENTS_INFOBAR_ADDED) { 121 if (type == NotificationType::TAB_CONTENTS_INFOBAR_ADDED) {
122 AddInfoBar(Details<InfoBarDelegate>(details).ptr(), true); 122 AddInfoBar(Details<InfoBarDelegate>(details).ptr(), true);
123 } else if (type == NotificationType::TAB_CONTENTS_INFOBAR_REMOVED) { 123 } else if (type == NotificationType::TAB_CONTENTS_INFOBAR_REMOVED) {
124 RemoveInfoBar(Details<InfoBarDelegate>(details).ptr(), true); 124 RemoveInfoBar(Details<InfoBarDelegate>(details).ptr(), true);
125 } else if (type == NotificationType::TAB_CONTENTS_INFOBAR_REPLACED) { 125 } else if (type == NotificationType::TAB_CONTENTS_INFOBAR_REPLACED) {
126 std::pair<InfoBarDelegate*, InfoBarDelegate*>* delegates = 126 typedef std::pair<InfoBarDelegate*, InfoBarDelegate*> DelegatePair;
127 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details).ptr(); 127 DelegatePair* delegate_pair = Details<DelegatePair>(details).ptr();
128 128
129 // By not animating the removal/addition, this appears to be a replace. 129 // By not animating the removal/addition, this appears to be a replace.
130 RemoveInfoBar(delegates->first, false); 130 RemoveInfoBar(delegate_pair->first, false);
131 AddInfoBar(delegates->second, false); 131 AddInfoBar(delegate_pair->second, false);
132 } else { 132 } else {
133 NOTREACHED(); 133 NOTREACHED();
134 } 134 }
135 } 135 }
136 136
137 // InfoBarContainerGtk, private: ----------------------------------------------- 137 // InfoBarContainerGtk, private: -----------------------------------------------
138 138
139 void InfoBarContainerGtk::UpdateInfoBars() { 139 void InfoBarContainerGtk::UpdateInfoBars() {
140 for (int i = 0; i < tab_contents_->infobar_delegate_count(); ++i) { 140 for (int i = 0; i < tab_contents_->infobar_delegate_count(); ++i) {
141 InfoBarDelegate* delegate = tab_contents_->GetInfoBarDelegateAt(i); 141 InfoBarDelegate* delegate = tab_contents_->GetInfoBarDelegateAt(i);
142 AddInfoBar(delegate, false); 142 AddInfoBar(delegate, false);
143 } 143 }
144 } 144 }
145 145
146 void InfoBarContainerGtk::ShowArrowForDelegate(InfoBarDelegate* delegate, 146 void InfoBarContainerGtk::ShowArrowForDelegate(InfoBarDelegate* delegate,
147 bool animate) { 147 bool animate) {
148 GList* children = gtk_container_get_children(GTK_CONTAINER(widget())); 148 GList* children = gtk_container_get_children(GTK_CONTAINER(widget()));
149 if (!children) 149 if (!children)
150 return; 150 return;
151 151
152 // Iterate through the infobars and find the last one that isn't closing. 152 // Iterate through the infobars and find the last one that isn't closing.
153 InfoBar* last_bar = NULL; 153 InfoBar* last_bar = NULL;
154 InfoBar* this_bar = NULL; 154 InfoBar* this_bar = NULL;
155 for (GList* iter = children; iter != NULL; iter = iter->next) { 155 for (GList* iter = children; iter != NULL; iter = iter->next) {
156 this_bar = reinterpret_cast<InfoBar*>( 156 this_bar = reinterpret_cast<InfoBar*>(
157 g_object_get_data(G_OBJECT(iter->data), kInfoBar)); 157 g_object_get_data(G_OBJECT(iter->data), kInfoBar));
158 158
159 if (this_bar->delegate() == delegate) 159 if ((delegate != NULL) && (this_bar->delegate() == delegate))
160 break; 160 break;
161 161
162 if (!this_bar->IsClosing()) 162 if (!this_bar->IsClosing())
163 last_bar = this_bar; 163 last_bar = this_bar;
164 164
165 this_bar = NULL; 165 this_bar = NULL;
166 } 166 }
167 167
168 if (last_bar) 168 if (last_bar)
169 last_bar->ShowArrowFor(this_bar, animate); 169 last_bar->ShowArrowFor(this_bar, animate);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } 210 }
211 211
212 void InfoBarContainerGtk::UpdateToolbarInfoBarState( 212 void InfoBarContainerGtk::UpdateToolbarInfoBarState(
213 InfoBar* infobar, bool animate) { 213 InfoBar* infobar, bool animate) {
214 GtkWindow* parent = platform_util::GetTopLevel(widget()); 214 GtkWindow* parent = platform_util::GetTopLevel(widget());
215 BrowserWindowGtk* browser_window = 215 BrowserWindowGtk* browser_window =
216 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent); 216 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent);
217 if (browser_window) 217 if (browser_window)
218 browser_window->SetInfoBarShowing(infobar, animate); 218 browser_window->SetInfoBarShowing(infobar, animate);
219 } 219 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698