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

Unified Diff: chrome/browser/views/infobars/infobar_container.cc

Issue 165029: Fix a few bugs with the theme infobar: (Closed)
Patch Set: Created 11 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/views/infobars/infobar_container.cc
diff --git a/chrome/browser/views/infobars/infobar_container.cc b/chrome/browser/views/infobars/infobar_container.cc
index 530236c94b309f581eb95b0f170e785d5ca8de53..792729bb920781fdc77391e4cc8da38986fdc441 100644
--- a/chrome/browser/views/infobars/infobar_container.cc
+++ b/chrome/browser/views/infobars/infobar_container.cc
@@ -38,6 +38,8 @@ void InfoBarContainer::ChangeTabContents(TabContents* contents) {
tc_source);
registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
tc_source);
+ registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
+ tc_source);
}
}
@@ -109,9 +111,13 @@ void InfoBarContainer::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
if (type == NotificationType::TAB_CONTENTS_INFOBAR_ADDED) {
- AddInfoBar(Details<InfoBarDelegate>(details).ptr());
+ AddInfoBar(Details<InfoBarDelegate>(details).ptr(), true); // animated
} else if (type == NotificationType::TAB_CONTENTS_INFOBAR_REMOVED) {
- RemoveInfoBar(Details<InfoBarDelegate>(details).ptr());
+ RemoveInfoBar(Details<InfoBarDelegate>(details).ptr(), true); // animated
+ } else if (type == NotificationType::TAB_CONTENTS_INFOBAR_REPLACED) {
+ std::pair<InfoBarDelegate*, InfoBarDelegate*>* delegates =
+ Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details).ptr();
+ ReplaceInfoBar(delegates->first, delegates->second);
} else {
NOTREACHED();
}
@@ -129,20 +135,37 @@ void InfoBarContainer::UpdateInfoBars() {
}
}
-void InfoBarContainer::AddInfoBar(InfoBarDelegate* delegate) {
+void InfoBarContainer::AddInfoBar(InfoBarDelegate* delegate,
+ bool use_animation) {
InfoBar* infobar = delegate->CreateInfoBar();
infobar->set_container(this);
- infobar->AnimateOpen();
AddChildView(infobar);
+
+ if (use_animation)
+ infobar->AnimateOpen();
+ else
+ infobar->Open();
}
-void InfoBarContainer::RemoveInfoBar(InfoBarDelegate* delegate) {
+void InfoBarContainer::RemoveInfoBar(InfoBarDelegate* delegate,
+ bool use_animation) {
int index = 0;
for (; index < tab_contents_->infobar_delegate_count(); ++index) {
if (tab_contents_->GetInfoBarDelegateAt(index) == delegate)
break;
}
- // The View will be removed once the Close animation completes.
- static_cast<InfoBar*>(GetChildViewAt(index))->AnimateClose();
+ InfoBar* infobar = static_cast<InfoBar*>(GetChildViewAt(index));
+ if (use_animation) {
+ // The View will be removed once the Close animation completes.
+ infobar->AnimateClose();
+ } else {
+ infobar->Close();
+ }
+}
+
+void InfoBarContainer::ReplaceInfoBar(InfoBarDelegate* old_delegate,
+ InfoBarDelegate* new_delegate) {
+ RemoveInfoBar(old_delegate, false); // no animation
+ AddInfoBar(new_delegate, false); // no animation
}

Powered by Google App Engine
This is Rietveld 408576698