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

Side by Side Diff: chrome/browser/tab_contents/infobar_container.cc

Issue 6989001: Misc. infobar stuff: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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/views/infobars/infobar_container.h" 5 #if defined(TOOLKIT_VIEWS) // TODO(pkasting): Port non-views to use this.
6 6
7 #include "chrome/browser/tab_contents/infobar_container.h"
8
9 #include "chrome/browser/tab_contents/infobar.h"
7 #include "chrome/browser/tab_contents/infobar_delegate.h" 10 #include "chrome/browser/tab_contents/infobar_delegate.h"
8 #include "chrome/browser/ui/views/infobars/infobar.h" 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
9 #include "content/browser/tab_contents/tab_contents.h"
10 #include "content/common/notification_details.h" 12 #include "content/common/notification_details.h"
11 #include "content/common/notification_source.h" 13 #include "content/common/notification_source.h"
12 #include "ui/base/animation/slide_animation.h" 14 #include "ui/base/animation/slide_animation.h"
13 15
14 InfoBarContainer::Delegate::~Delegate() { 16 InfoBarContainer::Delegate::~Delegate() {
15 } 17 }
16 18
17 InfoBarContainer::InfoBarContainer(Delegate* delegate) 19 InfoBarContainer::InfoBarContainer(Delegate* delegate)
18 : delegate_(delegate), 20 : delegate_(delegate),
19 tab_contents_(NULL), 21 tab_contents_(NULL),
20 top_arrow_target_height_(InfoBar::kDefaultArrowTargetHeight) { 22 top_arrow_target_height_(InfoBar::kDefaultArrowTargetHeight) {
21 } 23 }
22 24
23 InfoBarContainer::~InfoBarContainer() { 25 InfoBarContainer::~InfoBarContainer() {
24 // RemoveAllInfoBarsForDestruction() should have already cleared our infobars. 26 // RemoveAllInfoBarsForDestruction() should have already cleared our infobars.
25 DCHECK(infobars_.empty()); 27 DCHECK(infobars_.empty());
26 } 28 }
27 29
28 void InfoBarContainer::ChangeTabContents(TabContents* contents) { 30 void InfoBarContainer::ChangeTabContents(TabContentsWrapper* contents) {
29 registrar_.RemoveAll(); 31 registrar_.RemoveAll();
30 32
31 while (!infobars_.empty()) { 33 while (!infobars_.empty()) {
32 InfoBar* infobar = infobars_.front(); 34 InfoBar* infobar = infobars_.front();
33 // NULL the container pointer first so that if the infobar is currently 35 // NULL the container pointer first so that if the infobar is currently
34 // animating, OnInfoBarAnimated() won't get called; we'll manually trigger 36 // animating, OnInfoBarStateChanged() won't get called; we'll manually
35 // this once for the whole set of changes below. This also prevents 37 // trigger this once for the whole set of changes below. This also prevents
36 // InfoBar::MaybeDelete() from calling RemoveInfoBar() a second time if the 38 // InfoBar::MaybeDelete() from calling RemoveInfoBar() a second time if the
37 // infobar happens to be at zero height (dunno if this can actually happen). 39 // infobar happens to be at zero height (dunno if this can actually happen).
38 infobar->set_container(NULL); 40 infobar->set_container(NULL);
39 RemoveInfoBar(infobar); 41 RemoveInfoBar(infobar);
40 } 42 }
41 43
42 tab_contents_ = contents; 44 tab_contents_ = contents;
43 if (tab_contents_) { 45 if (tab_contents_) {
44 Source<TabContents> tc_source(tab_contents_); 46 Source<TabContents> tc_source(tab_contents_->tab_contents());
45 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED, 47 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
46 tc_source); 48 tc_source);
47 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, 49 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
48 tc_source); 50 tc_source);
49 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, 51 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
50 tc_source); 52 tc_source);
51 53
52 for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) { 54 for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) {
53 // As when we removed the infobars above, we prevent callbacks to 55 // As when we removed the infobars above, we prevent callbacks to
54 // OnInfoBarAnimated() for each infobar. 56 // OnInfoBarAnimated() for each infobar.
55 AddInfoBar(tab_contents_->GetInfoBarDelegateAt(i)->CreateInfoBar(), false, 57 AddInfoBar(
56 NO_CALLBACK); 58 tab_contents_->GetInfoBarDelegateAt(i)->CreateInfoBar(tab_contents_),
59 false, NO_CALLBACK);
57 } 60 }
58 } 61 }
59 62
60 // Now that everything is up to date, signal the delegate to re-layout. 63 // Now that everything is up to date, signal the delegate to re-layout.
61 OnInfoBarStateChanged(false); 64 OnInfoBarStateChanged(false);
62 } 65 }
63 66
64 int InfoBarContainer::GetVerticalOverlap(int* total_height) { 67 int InfoBarContainer::GetVerticalOverlap(int* total_height) {
65 // Our |total_height| is the sum of the preferred heights of the InfoBars 68 // Our |total_height| is the sum of the preferred heights of the InfoBars
66 // contained within us plus the |vertical_overlap|. 69 // contained within us plus the |vertical_overlap|.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // and at worst disastrous to call that. 116 // and at worst disastrous to call that.
114 delegate_ = NULL; 117 delegate_ = NULL;
115 ChangeTabContents(NULL); 118 ChangeTabContents(NULL);
116 } 119 }
117 120
118 void InfoBarContainer::Observe(NotificationType type, 121 void InfoBarContainer::Observe(NotificationType type,
119 const NotificationSource& source, 122 const NotificationSource& source,
120 const NotificationDetails& details) { 123 const NotificationDetails& details) {
121 switch (type.value) { 124 switch (type.value) {
122 case NotificationType::TAB_CONTENTS_INFOBAR_ADDED: 125 case NotificationType::TAB_CONTENTS_INFOBAR_ADDED:
123 AddInfoBar(Details<InfoBarDelegate>(details)->CreateInfoBar(), true, 126 AddInfoBar(
124 WANT_CALLBACK); 127 Details<InfoBarDelegate>(details)->CreateInfoBar(tab_contents_), true,
128 WANT_CALLBACK);
125 break; 129 break;
126 130
127 case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED: 131 case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED:
128 RemoveInfoBar(Details<InfoBarDelegate>(details).ptr(), true); 132 RemoveInfoBar(Details<InfoBarDelegate>(details).ptr(), true);
129 break; 133 break;
130 134
131 case NotificationType::TAB_CONTENTS_INFOBAR_REPLACED: { 135 case NotificationType::TAB_CONTENTS_INFOBAR_REPLACED: {
132 typedef std::pair<InfoBarDelegate*, InfoBarDelegate*> InfoBarPair; 136 typedef std::pair<InfoBarDelegate*, InfoBarDelegate*> InfoBarPair;
133 InfoBarPair* infobar_pair = Details<InfoBarPair>(details).ptr(); 137 InfoBarPair* infobar_pair = Details<InfoBarPair>(details).ptr();
134 RemoveInfoBar(infobar_pair->first, false); 138 RemoveInfoBar(infobar_pair->first, false);
135 AddInfoBar(infobar_pair->second->CreateInfoBar(), false, WANT_CALLBACK); 139 AddInfoBar(infobar_pair->second->CreateInfoBar(tab_contents_), false,
140 WANT_CALLBACK);
136 break; 141 break;
137 } 142 }
138 143
139 default: 144 default:
140 NOTREACHED(); 145 NOTREACHED();
141 break; 146 break;
142 } 147 }
143 } 148 }
144 149
145 void InfoBarContainer::RemoveInfoBar(InfoBarDelegate* delegate, 150 void InfoBarContainer::RemoveInfoBar(InfoBarDelegate* delegate,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 const_cast<const InfoBar*>(infobars_.front())->animation(); 194 const_cast<const InfoBar*>(infobars_.front())->animation();
190 if ((infobar_index > 1) || first_infobar_animation->IsShowing()) 195 if ((infobar_index > 1) || first_infobar_animation->IsShowing())
191 return InfoBar::kDefaultArrowTargetHeight; 196 return InfoBar::kDefaultArrowTargetHeight;
192 // When the first infobar is animating closed, we animate the second infobar's 197 // When the first infobar is animating closed, we animate the second infobar's
193 // arrow target height from the default to the top target height. Note that 198 // arrow target height from the default to the top target height. Note that
194 // the animation values here are going from 1.0 -> 0.0 as the top bar closes. 199 // the animation values here are going from 1.0 -> 0.0 as the top bar closes.
195 return top_arrow_target_height_ + static_cast<int>( 200 return top_arrow_target_height_ + static_cast<int>(
196 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * 201 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) *
197 first_infobar_animation->GetCurrentValue()); 202 first_infobar_animation->GetCurrentValue());
198 } 203 }
204
205 #endif // TOOLKIT_VIEWS
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/infobar_container.h ('k') | chrome/browser/tab_contents/infobar_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698