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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/views/infobars/infobar_container.h" 5 #include "chrome/browser/views/infobars/infobar_container.h"
6 6
7 #include "chrome/browser/tab_contents/infobar_delegate.h" 7 #include "chrome/browser/tab_contents/infobar_delegate.h"
8 #include "chrome/browser/tab_contents/tab_contents.h" 8 #include "chrome/browser/tab_contents/tab_contents.h"
9 #include "chrome/browser/views/frame/browser_view.h" 9 #include "chrome/browser/views/frame/browser_view.h"
10 #include "chrome/browser/views/infobars/infobars.h" 10 #include "chrome/browser/views/infobars/infobars.h"
(...skipping 20 matching lines...) Expand all
31 // hierarchy does this automatically (see InfoBar::InfoBarRemoved). 31 // hierarchy does this automatically (see InfoBar::InfoBarRemoved).
32 RemoveAllChildViews(false); 32 RemoveAllChildViews(false);
33 tab_contents_ = contents; 33 tab_contents_ = contents;
34 if (tab_contents_) { 34 if (tab_contents_) {
35 UpdateInfoBars(); 35 UpdateInfoBars();
36 Source<TabContents> tc_source(tab_contents_); 36 Source<TabContents> tc_source(tab_contents_);
37 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED, 37 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
38 tc_source); 38 tc_source);
39 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, 39 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
40 tc_source); 40 tc_source);
41 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
42 tc_source);
41 } 43 }
42 } 44 }
43 45
44 void InfoBarContainer::InfoBarAnimated(bool completed) { 46 void InfoBarContainer::InfoBarAnimated(bool completed) {
45 if (browser_view_) 47 if (browser_view_)
46 browser_view_->SelectedTabToolbarSizeChanged(!completed); 48 browser_view_->SelectedTabToolbarSizeChanged(!completed);
47 } 49 }
48 50
49 void InfoBarContainer::RemoveDelegate(InfoBarDelegate* delegate) { 51 void InfoBarContainer::RemoveDelegate(InfoBarDelegate* delegate) {
50 tab_contents_->RemoveInfoBar(delegate); 52 tab_contents_->RemoveInfoBar(delegate);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 browser_view_->SelectedTabToolbarSizeChanged(false); 104 browser_view_->SelectedTabToolbarSizeChanged(false);
103 } 105 }
104 } 106 }
105 107
106 // InfoBarContainer, NotificationObserver implementation: ---------------------- 108 // InfoBarContainer, NotificationObserver implementation: ----------------------
107 109
108 void InfoBarContainer::Observe(NotificationType type, 110 void InfoBarContainer::Observe(NotificationType type,
109 const NotificationSource& source, 111 const NotificationSource& source,
110 const NotificationDetails& details) { 112 const NotificationDetails& details) {
111 if (type == NotificationType::TAB_CONTENTS_INFOBAR_ADDED) { 113 if (type == NotificationType::TAB_CONTENTS_INFOBAR_ADDED) {
112 AddInfoBar(Details<InfoBarDelegate>(details).ptr()); 114 AddInfoBar(Details<InfoBarDelegate>(details).ptr(), true); // animated
113 } else if (type == NotificationType::TAB_CONTENTS_INFOBAR_REMOVED) { 115 } else if (type == NotificationType::TAB_CONTENTS_INFOBAR_REMOVED) {
114 RemoveInfoBar(Details<InfoBarDelegate>(details).ptr()); 116 RemoveInfoBar(Details<InfoBarDelegate>(details).ptr(), true); // animated
117 } else if (type == NotificationType::TAB_CONTENTS_INFOBAR_REPLACED) {
118 std::pair<InfoBarDelegate*, InfoBarDelegate*>* delegates =
119 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details).ptr();
120 ReplaceInfoBar(delegates->first, delegates->second);
115 } else { 121 } else {
116 NOTREACHED(); 122 NOTREACHED();
117 } 123 }
118 } 124 }
119 125
120 // InfoBarContainer, private: -------------------------------------------------- 126 // InfoBarContainer, private: --------------------------------------------------
121 127
122 void InfoBarContainer::UpdateInfoBars() { 128 void InfoBarContainer::UpdateInfoBars() {
123 for (int i = 0; i < tab_contents_->infobar_delegate_count(); ++i) { 129 for (int i = 0; i < tab_contents_->infobar_delegate_count(); ++i) {
124 InfoBarDelegate* delegate = tab_contents_->GetInfoBarDelegateAt(i); 130 InfoBarDelegate* delegate = tab_contents_->GetInfoBarDelegateAt(i);
125 InfoBar* infobar = delegate->CreateInfoBar(); 131 InfoBar* infobar = delegate->CreateInfoBar();
126 infobar->set_container(this); 132 infobar->set_container(this);
127 AddChildView(infobar); 133 AddChildView(infobar);
128 infobar->Open(); 134 infobar->Open();
129 } 135 }
130 } 136 }
131 137
132 void InfoBarContainer::AddInfoBar(InfoBarDelegate* delegate) { 138 void InfoBarContainer::AddInfoBar(InfoBarDelegate* delegate,
139 bool use_animation) {
133 InfoBar* infobar = delegate->CreateInfoBar(); 140 InfoBar* infobar = delegate->CreateInfoBar();
134 infobar->set_container(this); 141 infobar->set_container(this);
135 infobar->AnimateOpen();
136 AddChildView(infobar); 142 AddChildView(infobar);
143
144 if (use_animation)
145 infobar->AnimateOpen();
146 else
147 infobar->Open();
137 } 148 }
138 149
139 void InfoBarContainer::RemoveInfoBar(InfoBarDelegate* delegate) { 150 void InfoBarContainer::RemoveInfoBar(InfoBarDelegate* delegate,
151 bool use_animation) {
140 int index = 0; 152 int index = 0;
141 for (; index < tab_contents_->infobar_delegate_count(); ++index) { 153 for (; index < tab_contents_->infobar_delegate_count(); ++index) {
142 if (tab_contents_->GetInfoBarDelegateAt(index) == delegate) 154 if (tab_contents_->GetInfoBarDelegateAt(index) == delegate)
143 break; 155 break;
144 } 156 }
145 157
146 // The View will be removed once the Close animation completes. 158 InfoBar* infobar = static_cast<InfoBar*>(GetChildViewAt(index));
147 static_cast<InfoBar*>(GetChildViewAt(index))->AnimateClose(); 159 if (use_animation) {
160 // The View will be removed once the Close animation completes.
161 infobar->AnimateClose();
162 } else {
163 infobar->Close();
164 }
148 } 165 }
166
167 void InfoBarContainer::ReplaceInfoBar(InfoBarDelegate* old_delegate,
168 InfoBarDelegate* new_delegate) {
169 RemoveInfoBar(old_delegate, false); // no animation
170 AddInfoBar(new_delegate, false); // no animation
171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698