OLD | NEW |
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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 // TODO(pkasting): Port Mac to use this. | 7 // TODO(pkasting): Port Mac to use this. |
8 #if defined(TOOLKIT_VIEWS) || defined(TOOLKIT_GTK) | 8 #if defined(TOOLKIT_VIEWS) || defined(TOOLKIT_GTK) |
9 | 9 |
10 #include "chrome/browser/tab_contents/infobar_container.h" | 10 #include "chrome/browser/tab_contents/infobar_container.h" |
11 | 11 |
12 #include "chrome/browser/tab_contents/infobar.h" | 12 #include "chrome/browser/tab_contents/infobar.h" |
13 #include "chrome/browser/tab_contents/infobar_delegate.h" | 13 #include "chrome/browser/tab_contents/infobar_delegate.h" |
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 15 #include "chrome/common/chrome_notification_types.h" |
15 #include "content/common/notification_details.h" | 16 #include "content/common/notification_details.h" |
16 #include "content/common/notification_source.h" | 17 #include "content/common/notification_source.h" |
17 #include "ui/base/animation/slide_animation.h" | 18 #include "ui/base/animation/slide_animation.h" |
18 | 19 |
19 InfoBarContainer::Delegate::~Delegate() { | 20 InfoBarContainer::Delegate::~Delegate() { |
20 } | 21 } |
21 | 22 |
22 InfoBarContainer::InfoBarContainer(Delegate* delegate) | 23 InfoBarContainer::InfoBarContainer(Delegate* delegate) |
23 : delegate_(delegate), | 24 : delegate_(delegate), |
24 tab_contents_(NULL), | 25 tab_contents_(NULL), |
(...skipping 11 matching lines...) Expand all Loading... |
36 while (!infobars_.empty()) { | 37 while (!infobars_.empty()) { |
37 InfoBar* infobar = infobars_.front(); | 38 InfoBar* infobar = infobars_.front(); |
38 // Inform the infobar that it's hidden. If it was already closing, this | 39 // Inform the infobar that it's hidden. If it was already closing, this |
39 // closes its delegate. | 40 // closes its delegate. |
40 infobar->Hide(false); | 41 infobar->Hide(false); |
41 } | 42 } |
42 | 43 |
43 tab_contents_ = contents; | 44 tab_contents_ = contents; |
44 if (tab_contents_) { | 45 if (tab_contents_) { |
45 Source<TabContentsWrapper> tc_source(tab_contents_); | 46 Source<TabContentsWrapper> tc_source(tab_contents_); |
46 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED, | 47 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
47 tc_source); | 48 tc_source); |
48 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, | 49 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
49 tc_source); | 50 tc_source); |
50 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, | 51 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, |
51 tc_source); | 52 tc_source); |
52 | 53 |
53 for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) { | 54 for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) { |
54 // As when we removed the infobars above, we prevent callbacks to | 55 // As when we removed the infobars above, we prevent callbacks to |
55 // OnInfoBarAnimated() for each infobar. | 56 // OnInfoBarAnimated() for each infobar. |
56 AddInfoBar( | 57 AddInfoBar( |
57 tab_contents_->GetInfoBarDelegateAt(i)->CreateInfoBar(tab_contents_), | 58 tab_contents_->GetInfoBarDelegateAt(i)->CreateInfoBar(tab_contents_), |
58 i, false, NO_CALLBACK); | 59 i, false, NO_CALLBACK); |
59 } | 60 } |
60 } | 61 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // and at worst disastrous to call that. | 114 // and at worst disastrous to call that. |
114 delegate_ = NULL; | 115 delegate_ = NULL; |
115 | 116 |
116 // TODO(pkasting): Remove this once TabContentsWrapper calls CloseSoon(). | 117 // TODO(pkasting): Remove this once TabContentsWrapper calls CloseSoon(). |
117 for (size_t i = infobars_.size(); i > 0; --i) | 118 for (size_t i = infobars_.size(); i > 0; --i) |
118 infobars_[i - 1]->CloseSoon(); | 119 infobars_[i - 1]->CloseSoon(); |
119 | 120 |
120 ChangeTabContents(NULL); | 121 ChangeTabContents(NULL); |
121 } | 122 } |
122 | 123 |
123 void InfoBarContainer::Observe(NotificationType type, | 124 void InfoBarContainer::Observe(int type, |
124 const NotificationSource& source, | 125 const NotificationSource& source, |
125 const NotificationDetails& details) { | 126 const NotificationDetails& details) { |
126 switch (type.value) { | 127 switch (type) { |
127 case NotificationType::TAB_CONTENTS_INFOBAR_ADDED: | 128 case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED: |
128 AddInfoBar( | 129 AddInfoBar( |
129 Details<InfoBarAddedDetails>(details)->CreateInfoBar(tab_contents_), | 130 Details<InfoBarAddedDetails>(details)->CreateInfoBar(tab_contents_), |
130 infobars_.size(), true, WANT_CALLBACK); | 131 infobars_.size(), true, WANT_CALLBACK); |
131 break; | 132 break; |
132 | 133 |
133 case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED: { | 134 case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED: { |
134 InfoBarRemovedDetails* removed_details = | 135 InfoBarRemovedDetails* removed_details = |
135 Details<InfoBarRemovedDetails>(details).ptr(); | 136 Details<InfoBarRemovedDetails>(details).ptr(); |
136 RemoveInfoBar(removed_details->first, removed_details->second); | 137 RemoveInfoBar(removed_details->first, removed_details->second); |
137 break; | 138 break; |
138 } | 139 } |
139 | 140 |
140 case NotificationType::TAB_CONTENTS_INFOBAR_REPLACED: { | 141 case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED: { |
141 InfoBarReplacedDetails* replaced_details = | 142 InfoBarReplacedDetails* replaced_details = |
142 Details<InfoBarReplacedDetails>(details).ptr(); | 143 Details<InfoBarReplacedDetails>(details).ptr(); |
143 AddInfoBar(replaced_details->second->CreateInfoBar(tab_contents_), | 144 AddInfoBar(replaced_details->second->CreateInfoBar(tab_contents_), |
144 RemoveInfoBar(replaced_details->first, false), false, WANT_CALLBACK); | 145 RemoveInfoBar(replaced_details->first, false), false, WANT_CALLBACK); |
145 break; | 146 break; |
146 } | 147 } |
147 | 148 |
148 default: | 149 default: |
149 NOTREACHED(); | 150 NOTREACHED(); |
150 break; | 151 break; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 return InfoBar::kDefaultArrowTargetHeight; | 207 return InfoBar::kDefaultArrowTargetHeight; |
207 // When the first infobar is animating closed, we animate the second infobar's | 208 // When the first infobar is animating closed, we animate the second infobar's |
208 // arrow target height from the default to the top target height. Note that | 209 // arrow target height from the default to the top target height. Note that |
209 // the animation values here are going from 1.0 -> 0.0 as the top bar closes. | 210 // the animation values here are going from 1.0 -> 0.0 as the top bar closes. |
210 return top_arrow_target_height_ + static_cast<int>( | 211 return top_arrow_target_height_ + static_cast<int>( |
211 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * | 212 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * |
212 first_infobar_animation.GetCurrentValue()); | 213 first_infobar_animation.GetCurrentValue()); |
213 } | 214 } |
214 | 215 |
215 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK) | 216 #endif // TOOLKIT_VIEWS || defined(TOOLKIT_GTK) |
OLD | NEW |