OLD | NEW |
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/views/infobars/infobars.h" | 5 #include "chrome/browser/views/infobars/infobars.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "app/slide_animation.h" | 9 #include "app/slide_animation.h" |
10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 close_button_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_CLOSE)); | 135 close_button_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_CLOSE)); |
136 AddChildView(close_button_); | 136 AddChildView(close_button_); |
137 | 137 |
138 animation_.reset(new SlideAnimation(this)); | 138 animation_.reset(new SlideAnimation(this)); |
139 animation_->SetTweenType(Tween::LINEAR); | 139 animation_->SetTweenType(Tween::LINEAR); |
140 } | 140 } |
141 | 141 |
142 InfoBar::~InfoBar() { | 142 InfoBar::~InfoBar() { |
143 } | 143 } |
144 | 144 |
145 void InfoBar::AnimateOpen() { | |
146 animation_->Show(); | |
147 } | |
148 | |
149 void InfoBar::Open() { | |
150 // Set the animation value to 1.0 so that GetPreferredSize() returns the right | |
151 // size. | |
152 animation_->Reset(1.0); | |
153 if (container_) | |
154 container_->InfoBarAnimated(false); | |
155 } | |
156 | |
157 void InfoBar::AnimateClose() { | |
158 bool restore_focus = true; | |
159 #if defined(OS_WIN) | |
160 // Do not restore focus (and active state with it) on Windows if some other | |
161 // top-level window became active. | |
162 if (GetWidget() && | |
163 !win_util::DoesWindowBelongToActiveWindow(GetWidget()->GetNativeView())) { | |
164 restore_focus = false; | |
165 } | |
166 #endif // defined(OS_WIN) | |
167 DestroyFocusTracker(restore_focus); | |
168 animation_->Hide(); | |
169 } | |
170 | |
171 void InfoBar::Close() { | |
172 GetParent()->RemoveChildView(this); | |
173 // Note that we only tell the delegate we're closed here, and not when we're | |
174 // simply destroyed (by virtue of a tab switch or being moved from window to | |
175 // window), since this action can cause the delegate to destroy itself. | |
176 if (delegate_) { | |
177 delegate_->InfoBarClosed(); | |
178 delegate_ = NULL; | |
179 } | |
180 } | |
181 | |
182 // InfoBar, views::View overrides: --------------------------------------------- | 145 // InfoBar, views::View overrides: --------------------------------------------- |
183 | 146 |
184 bool InfoBar::GetAccessibleRole(AccessibilityTypes::Role* role) { | 147 bool InfoBar::GetAccessibleRole(AccessibilityTypes::Role* role) { |
185 DCHECK(role); | 148 DCHECK(role); |
186 | 149 |
187 *role = AccessibilityTypes::ROLE_PANE; | 150 *role = AccessibilityTypes::ROLE_PANE; |
188 return true; | 151 return true; |
189 } | 152 } |
190 | 153 |
191 gfx::Size InfoBar::GetPreferredSize() { | 154 gfx::Size InfoBar::GetPreferredSize() { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 if (container_) { | 216 if (container_) { |
254 container_->InfoBarAnimated(false); | 217 container_->InfoBarAnimated(false); |
255 | 218 |
256 if (!animation_->IsShowing()) | 219 if (!animation_->IsShowing()) |
257 Close(); | 220 Close(); |
258 } | 221 } |
259 } | 222 } |
260 | 223 |
261 // InfoBar, private: ----------------------------------------------------------- | 224 // InfoBar, private: ----------------------------------------------------------- |
262 | 225 |
| 226 void InfoBar::AnimateOpen() { |
| 227 animation_->Show(); |
| 228 } |
| 229 |
| 230 void InfoBar::Open() { |
| 231 // Set the animation value to 1.0 so that GetPreferredSize() returns the right |
| 232 // size. |
| 233 animation_->Reset(1.0); |
| 234 if (container_) |
| 235 container_->InfoBarAnimated(false); |
| 236 } |
| 237 |
| 238 void InfoBar::AnimateClose() { |
| 239 bool restore_focus = true; |
| 240 #if defined(OS_WIN) |
| 241 // Do not restore focus (and active state with it) on Windows if some other |
| 242 // top-level window became active. |
| 243 if (GetWidget() && |
| 244 !win_util::DoesWindowBelongToActiveWindow(GetWidget()->GetNativeView())) { |
| 245 restore_focus = false; |
| 246 } |
| 247 #endif // defined(OS_WIN) |
| 248 DestroyFocusTracker(restore_focus); |
| 249 animation_->Hide(); |
| 250 } |
| 251 |
| 252 void InfoBar::Close() { |
| 253 GetParent()->RemoveChildView(this); |
| 254 // Note that we only tell the delegate we're closed here, and not when we're |
| 255 // simply destroyed (by virtue of a tab switch or being moved from window to |
| 256 // window), since this action can cause the delegate to destroy itself. |
| 257 if (delegate_) { |
| 258 delegate_->InfoBarClosed(); |
| 259 delegate_ = NULL; |
| 260 } |
| 261 } |
| 262 |
263 void InfoBar::InfoBarAdded() { | 263 void InfoBar::InfoBarAdded() { |
264 // The container_ pointer must be set before adding to the view hierarchy. | 264 // The container_ pointer must be set before adding to the view hierarchy. |
265 DCHECK(container_); | 265 DCHECK(container_); |
266 #if defined(OS_WIN) | 266 #if defined(OS_WIN) |
267 // When we're added to a view hierarchy within a widget, we create an | 267 // When we're added to a view hierarchy within a widget, we create an |
268 // external focus tracker to track what was focused in case we obtain | 268 // external focus tracker to track what was focused in case we obtain |
269 // focus so that we can restore focus when we're removed. | 269 // focus so that we can restore focus when we're removed. |
270 views::Widget* widget = GetWidget(); | 270 views::Widget* widget = GetWidget(); |
271 if (widget) { | 271 if (widget) { |
272 focus_tracker_.reset(new views::ExternalFocusTracker(this, | 272 focus_tracker_.reset(new views::ExternalFocusTracker(this, |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 | 594 |
595 InfoBar* LinkInfoBarDelegate::CreateInfoBar() { | 595 InfoBar* LinkInfoBarDelegate::CreateInfoBar() { |
596 return new LinkInfoBar(this); | 596 return new LinkInfoBar(this); |
597 } | 597 } |
598 | 598 |
599 // ConfirmInfoBarDelegate, InfoBarDelegate overrides: -------------------------- | 599 // ConfirmInfoBarDelegate, InfoBarDelegate overrides: -------------------------- |
600 | 600 |
601 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { | 601 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { |
602 return new ConfirmInfoBar(this); | 602 return new ConfirmInfoBar(this); |
603 } | 603 } |
OLD | NEW |