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

Side by Side Diff: chrome/browser/ui/views/infobars/infobar_view.cc

Issue 6609047: [linux_views][Win] spoof proof redesign infobar extension with tab. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 9 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_view.h" 5 #include "chrome/browser/ui/views/infobars/infobar_view.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 9 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
10 #include "chrome/browser/ui/views/infobars/infobar_background.h" 10 #include "chrome/browser/ui/views/infobars/infobar_background.h"
(...skipping 24 matching lines...) Expand all
35 #include "ui/base/win/hwnd_util.h" 35 #include "ui/base/win/hwnd_util.h"
36 #include "ui/gfx/icon_util.h" 36 #include "ui/gfx/icon_util.h"
37 #endif 37 #endif
38 38
39 // static 39 // static
40 const int InfoBarView::kDefaultTargetHeight = 36; 40 const int InfoBarView::kDefaultTargetHeight = 36;
41 const int InfoBarView::kButtonButtonSpacing = 10; 41 const int InfoBarView::kButtonButtonSpacing = 10;
42 const int InfoBarView::kEndOfLabelSpacing = 16; 42 const int InfoBarView::kEndOfLabelSpacing = 16;
43 const int InfoBarView::kHorizontalPadding = 6; 43 const int InfoBarView::kHorizontalPadding = 6;
44 44
45 const int InfoBarView::kCurveDistance = 13;
46 const int InfoBarView::kIconWidth = 29;
47 const int InfoBarView::kTabHeight = 9;
48 const int InfoBarView::kTabPadding = 4;
49
50 const int InfoBarView::kTabWidth = kCurveDistance * 2 + kIconWidth +
51 kTabPadding;
52
45 InfoBarView::InfoBarView(InfoBarDelegate* delegate) 53 InfoBarView::InfoBarView(InfoBarDelegate* delegate)
46 : InfoBar(delegate), 54 : InfoBar(delegate),
47 container_(NULL), 55 container_(NULL),
48 delegate_(delegate), 56 delegate_(delegate),
49 icon_(NULL), 57 icon_(NULL),
50 close_button_(NULL), 58 close_button_(NULL),
51 ALLOW_THIS_IN_INITIALIZER_LIST(animation_(new ui::SlideAnimation(this))), 59 ALLOW_THIS_IN_INITIALIZER_LIST(tab_animation_(new ui::SlideAnimation(this) )),
Peter Kasting 2011/03/04 22:23:42 Nit: 80 columns (but this should go away when you
Sheridan Rawlins 2011/03/05 18:06:54 Done.
60 ALLOW_THIS_IN_INITIALIZER_LIST(bar_animation_(new ui::SlideAnimation(this) )),
52 ALLOW_THIS_IN_INITIALIZER_LIST(delete_factory_(this)), 61 ALLOW_THIS_IN_INITIALIZER_LIST(delete_factory_(this)),
53 target_height_(kDefaultTargetHeight) { 62 target_height_(kDefaultTargetHeight),
63 stroke_path_(new SkPath),
64 fill_path_(new SkPath),
65 clip_path_(new SkPath) {
54 set_parent_owned(false); // InfoBar deletes itself at the appropriate time. 66 set_parent_owned(false); // InfoBar deletes itself at the appropriate time.
55 67
56 InfoBarDelegate::Type infobar_type = delegate->GetInfoBarType(); 68 InfoBarDelegate::Type infobar_type = delegate->GetInfoBarType();
57 set_background(new InfoBarBackground(infobar_type)); 69 set_background(new InfoBarBackground(infobar_type));
58 70
59 animation_->SetTweenType(ui::Tween::LINEAR); 71 tab_animation_->SetTweenType(ui::Tween::LINEAR);
72 bar_animation_->SetTweenType(ui::Tween::LINEAR);
60 } 73 }
61 74
62 void InfoBarView::Show(bool animate) { 75 void InfoBarView::Show(bool animate) {
63 if (animate) { 76 if (animate) {
64 animation_->Show(); 77 AnimationShow();
65 } else { 78 } else {
66 animation_->Reset(1.0); 79 AnimationReset(1.0);
80 InvalidateLayout();
67 if (container_) 81 if (container_)
68 container_->OnInfoBarAnimated(true); 82 container_->OnInfoBarAnimated(true);
69 } 83 }
70 } 84 }
71 85
72 void InfoBarView::Hide(bool animate) { 86 void InfoBarView::Hide(bool animate) {
73 if (animate) { 87 if (animate) {
74 bool restore_focus = true; 88 bool restore_focus = true;
75 #if defined(OS_WIN) 89 #if defined(OS_WIN)
76 // Do not restore focus (and active state with it) on Windows if some other 90 // Do not restore focus (and active state with it) on Windows if some other
77 // top-level window became active. 91 // top-level window became active.
78 if (GetWidget() && 92 if (GetWidget() &&
79 !ui::DoesWindowBelongToActiveWindow(GetWidget()->GetNativeView())) 93 !ui::DoesWindowBelongToActiveWindow(GetWidget()->GetNativeView()))
80 restore_focus = false; 94 restore_focus = false;
81 #endif // defined(OS_WIN) 95 #endif // defined(OS_WIN)
82 DestroyFocusTracker(restore_focus); 96 DestroyFocusTracker(restore_focus);
83 animation_->Hide(); 97 AnimationHide();
84 } else { 98 } else {
85 animation_->Reset(0.0); 99 AnimationReset(0.0);
86 Close(); 100 Close();
87 } 101 }
88 } 102 }
89 103
90 void InfoBarView::Close() { 104 void InfoBarView::Close() {
91 parent()->RemoveChildView(this); 105 parent()->RemoveChildView(this);
92 if (container_) 106 if (container_)
93 container_->OnInfoBarAnimated(true); 107 container_->OnInfoBarAnimated(true);
94 // Note that we only tell the delegate we're closed here, and not when we're 108 // Note that we only tell the delegate we're closed here, and not when we're
95 // simply destroyed (by virtue of a tab switch or being moved from window to 109 // simply destroyed (by virtue of a tab switch or being moved from window to
96 // window), since this action can cause the delegate to destroy itself. 110 // window), since this action can cause the delegate to destroy itself.
97 if (delegate_) { 111 if (delegate_) {
98 delegate_->InfoBarClosed(); 112 delegate_->InfoBarClosed();
99 delegate_ = NULL; 113 delegate_ = NULL;
100 } 114 }
101 } 115 }
102 116
103 void InfoBarView::PaintArrow(gfx::Canvas* canvas,
104 View* outer_view,
105 int arrow_center_x) {
106 gfx::Point infobar_top(0, y());
107 ConvertPointToView(parent(), outer_view, &infobar_top);
108 int infobar_top_y = infobar_top.y();
109 SkPoint gradient_points[2] = {
110 {SkIntToScalar(0), SkIntToScalar(infobar_top_y)},
111 {SkIntToScalar(0), SkIntToScalar(infobar_top_y + target_height_)}
112 };
113 InfoBarDelegate::Type infobar_type = delegate_->GetInfoBarType();
114 SkColor gradient_colors[2] = {
115 InfoBarBackground::GetTopColor(infobar_type),
116 InfoBarBackground::GetBottomColor(infobar_type),
117 };
118 SkShader* gradient_shader = SkGradientShader::CreateLinear(gradient_points,
119 gradient_colors, NULL, 2, SkShader::kMirror_TileMode);
120 SkPaint paint;
121 paint.setStrokeWidth(1);
122 paint.setStyle(SkPaint::kFill_Style);
123 paint.setShader(gradient_shader);
124 gradient_shader->unref();
125
126 // The size of the arrow (its height; also half its width). The
127 // arrow area is |arrow_size| ^ 2. By taking the square root of the
128 // animation value, we cause a linear animation of the area, which
129 // matches the perception of the animation of the InfoBar.
130 const int kArrowSize = 10;
131 int arrow_size = static_cast<int>(kArrowSize *
132 sqrt(animation_->GetCurrentValue()));
133 SkPath fill_path;
134 fill_path.moveTo(SkPoint::Make(SkIntToScalar(arrow_center_x - arrow_size),
135 SkIntToScalar(infobar_top_y)));
136 fill_path.rLineTo(SkIntToScalar(arrow_size), SkIntToScalar(-arrow_size));
137 fill_path.rLineTo(SkIntToScalar(arrow_size), SkIntToScalar(arrow_size));
138 SkPath border_path(fill_path);
139 fill_path.close();
140 gfx::CanvasSkia* canvas_skia = canvas->AsCanvasSkia();
141 canvas_skia->drawPath(fill_path, paint);
142
143 // Fill and stroke have different opinions about how to treat paths. Because
144 // in Skia integral coordinates represent pixel boundaries, offsetting the
145 // path makes it go exactly through pixel centers; this results in lines that
146 // are exactly where we expect, instead of having odd "off by one" issues.
147 // Were we to do this for |fill_path|, however, which tries to fill "inside"
148 // the path (using some questionable math), we'd get a fill at a very
149 // different place than we'd want.
150 border_path.offset(SK_ScalarHalf, SK_ScalarHalf);
151 paint.setShader(NULL);
152 paint.setColor(SkColorSetA(ResourceBundle::toolbar_separator_color,
153 SkColorGetA(gradient_colors[0])));
154 paint.setStyle(SkPaint::kStroke_Style);
155 canvas_skia->drawPath(border_path, paint);
156 }
157
158 InfoBarView::~InfoBarView() { 117 InfoBarView::~InfoBarView() {
159 } 118 }
160 119
161 // static 120 // static
162 views::Label* InfoBarView::CreateLabel(const string16& text) { 121 views::Label* InfoBarView::CreateLabel(const string16& text) {
163 views::Label* label = new views::Label(UTF16ToWideHack(text), 122 views::Label* label = new views::Label(UTF16ToWideHack(text),
164 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); 123 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont));
165 label->SetColor(SK_ColorBLACK); 124 label->SetColor(SK_ColorBLACK);
166 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 125 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
167 return label; 126 return label;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 text_button->SetIcon(*IconUtil::CreateSkBitmapFromHICON(icon_info.hIcon, 193 text_button->SetIcon(*IconUtil::CreateSkBitmapFromHICON(icon_info.hIcon,
235 gfx::Size(GetSystemMetrics(SM_CXSMICON), 194 gfx::Size(GetSystemMetrics(SM_CXSMICON),
236 GetSystemMetrics(SM_CYSMICON)))); 195 GetSystemMetrics(SM_CYSMICON))));
237 } 196 }
238 #endif 197 #endif
239 return text_button; 198 return text_button;
240 } 199 }
241 200
242 void InfoBarView::Layout() { 201 void InfoBarView::Layout() {
243 int start_x = kHorizontalPadding; 202 int start_x = kHorizontalPadding;
203
Peter Kasting 2011/03/04 22:23:42 Nit: No blank line
Sheridan Rawlins 2011/03/05 18:06:54 Done.
244 if (icon_ != NULL) { 204 if (icon_ != NULL) {
205 // Center the icon vertically and horizontally within the tab.
245 gfx::Size icon_size = icon_->GetPreferredSize(); 206 gfx::Size icon_size = icon_->GetPreferredSize();
246 icon_->SetBounds(start_x, OffsetY(icon_size), icon_size.width(), 207 int center_x = std::max((kTabWidth - icon_size.width()) / 2, 0);
247 icon_size.height()); 208 int full_height = target_height_ + kTabHeight;
209 int preferred_height = preferred_tab_height() + preferred_bar_height();
210 int center_y =
211 std::max((full_height - icon_size.height()) / 2, 0) -
212 (full_height - preferred_height);
213 icon_->SetBounds(center_x, center_y, icon_size.width(), icon_size.height());
248 start_x += icon_->bounds().right(); 214 start_x += icon_->bounds().right();
249 } 215 }
250 216
251 gfx::Size button_size = close_button_->GetPreferredSize(); 217 gfx::Size button_size = close_button_->GetPreferredSize();
252 close_button_->SetBounds(std::max(start_x + ContentMinimumWidth(), 218 close_button_->SetBounds(std::max(start_x + ContentMinimumWidth(),
253 width() - kHorizontalPadding - button_size.width()), 219 width() - kHorizontalPadding - button_size.width()),
254 OffsetY(button_size), button_size.width(), button_size.height()); 220 OffsetY(button_size), button_size.width(), button_size.height());
255 } 221 }
256 222
257 void InfoBarView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { 223 void InfoBarView::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 close_button_->SetAccessibleName( 259 close_button_->SetAccessibleName(
294 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); 260 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE));
295 close_button_->SetFocusable(true); 261 close_button_->SetFocusable(true);
296 AddChildView(close_button_); 262 AddChildView(close_button_);
297 } 263 }
298 } else { 264 } else {
299 DestroyFocusTracker(false); 265 DestroyFocusTracker(false);
300 // NULL our container_ pointer so that if Animation::Stop results in 266 // NULL our container_ pointer so that if Animation::Stop results in
301 // AnimationEnded being called, we do not try and delete ourselves twice. 267 // AnimationEnded being called, we do not try and delete ourselves twice.
302 container_ = NULL; 268 container_ = NULL;
303 animation_->Stop(); 269 AnimationStop();
304 // Finally, clean ourselves up when we're removed from the view hierarchy 270 // Finally, clean ourselves up when we're removed from the view hierarchy
305 // since no-one refers to us now. 271 // since no-one refers to us now.
306 MessageLoop::current()->PostTask(FROM_HERE, 272 MessageLoop::current()->PostTask(FROM_HERE,
307 delete_factory_.NewRunnableMethod(&InfoBarView::DeleteSelf)); 273 delete_factory_.NewRunnableMethod(&InfoBarView::DeleteSelf));
308 if (GetFocusManager()) 274 if (GetFocusManager())
309 GetFocusManager()->RemoveFocusChangeListener(this); 275 GetFocusManager()->RemoveFocusChangeListener(this);
310 } 276 }
311 } 277 }
312 278
313 // For accessibility, ensure the close button is the last child view. 279 // For accessibility, ensure the close button is the last child view.
314 if ((close_button_ != NULL) && (parent == this) && (child != close_button_) && 280 if ((close_button_ != NULL) && (parent == this) && (child != close_button_) &&
315 (close_button_->parent() == this) && 281 (close_button_->parent() == this) &&
316 (GetChildViewAt(child_count() - 1) != close_button_)) { 282 (GetChildViewAt(child_count() - 1) != close_button_)) {
317 RemoveChildView(close_button_); 283 RemoveChildView(close_button_);
318 AddChildView(close_button_); 284 AddChildView(close_button_);
319 } 285 }
320 } 286 }
321 287
288 void InfoBarView::PaintChildren(gfx::Canvas* canvas) {
289 canvas->Save();
290
291 // TODO(scr): This really should be the |clip_path_|, but the
292 // clipPath seems broken. Try to get a reduction and file a bug
293 // with skia. For now, just clip to the bar bounds.
Peter Kasting 2011/03/04 22:23:42 Did you contact Mike Reed? He may be able to just
Sheridan Rawlins 2011/03/05 18:06:54 I definitely want to file a bug for this, but it s
294 //
295 // gfx::CanvasSkia* canvas_skia = canvas->AsCanvasSkia();
296 // canvas_skia->clipPath(*clip_path_);
297 int tab_height = preferred_tab_height();
298 int bar_height = preferred_bar_height();
299 DCHECK_EQ(tab_height + bar_height, height());
300 canvas->ClipRectInt(0, tab_height, width(), bar_height);
301
302 views::View::PaintChildren(canvas);
303 canvas->Restore();
304 }
305
322 void InfoBarView::ButtonPressed(views::Button* sender, 306 void InfoBarView::ButtonPressed(views::Button* sender,
323 const views::Event& event) { 307 const views::Event& event) {
324 if (sender == close_button_) { 308 if (sender == close_button_) {
325 if (delegate_) 309 if (delegate_)
326 delegate_->InfoBarDismissed(); 310 delegate_->InfoBarDismissed();
327 RemoveInfoBar(); 311 RemoveInfoBar();
328 } 312 }
329 } 313 }
330 314
331 void InfoBarView::AnimationProgressed(const ui::Animation* animation) { 315 void InfoBarView::AnimationProgressed(const ui::Animation* animation) {
316 // If multiple infobars, the InfoBarContainer's bounds won't change
317 // when only the bottom tab is animating.
318 InvalidateLayout();
332 if (container_) 319 if (container_)
333 container_->OnInfoBarAnimated(false); 320 container_->OnInfoBarAnimated(false);
334 } 321 }
335 322
336 int InfoBarView::ContentMinimumWidth() const { 323 int InfoBarView::ContentMinimumWidth() const {
337 return 0; 324 return 0;
338 } 325 }
339 326
340 void InfoBarView::RemoveInfoBar() const { 327 void InfoBarView::RemoveInfoBar() const {
341 if (container_) 328 if (container_)
(...skipping 11 matching lines...) Expand all
353 int InfoBarView::EndX() const { 340 int InfoBarView::EndX() const {
354 const int kCloseButtonSpacing = 12; 341 const int kCloseButtonSpacing = 12;
355 return close_button_->x() - kCloseButtonSpacing; 342 return close_button_->x() - kCloseButtonSpacing;
356 } 343 }
357 344
358 int InfoBarView::CenterY(const gfx::Size prefsize) const { 345 int InfoBarView::CenterY(const gfx::Size prefsize) const {
359 return std::max((target_height_ - prefsize.height()) / 2, 0); 346 return std::max((target_height_ - prefsize.height()) / 2, 0);
360 } 347 }
361 348
362 int InfoBarView::OffsetY(const gfx::Size prefsize) const { 349 int InfoBarView::OffsetY(const gfx::Size prefsize) const {
363 return CenterY(prefsize) - (target_height_ - height()); 350 return CenterY(prefsize) + preferred_tab_height() - (target_height_ -
351 preferred_bar_height());
352 }
353
354 int InfoBarView::preferred_tab_height() const {
355 // TODO(scr): hookup tab_animation_
356 return static_cast<int>(kTabHeight * tab_animation_->GetCurrentValue());
357 }
358
359 int InfoBarView::preferred_bar_height() const {
360 return static_cast<int>(target_height_ * bar_animation_->GetCurrentValue());
364 } 361 }
365 362
366 void InfoBarView::GetAccessibleState(ui::AccessibleViewState* state) { 363 void InfoBarView::GetAccessibleState(ui::AccessibleViewState* state) {
367 state->name = l10n_util::GetStringUTF16( 364 state->name = l10n_util::GetStringUTF16(
368 (delegate_->GetInfoBarType() == InfoBarDelegate::WARNING_TYPE) ? 365 (delegate_->GetInfoBarType() == InfoBarDelegate::WARNING_TYPE) ?
369 IDS_ACCNAME_INFOBAR_WARNING : IDS_ACCNAME_INFOBAR_PAGE_ACTION); 366 IDS_ACCNAME_INFOBAR_WARNING : IDS_ACCNAME_INFOBAR_PAGE_ACTION);
370 state->role = ui::AccessibilityTypes::ROLE_ALERT; 367 state->role = ui::AccessibilityTypes::ROLE_ALERT;
371 } 368 }
372 369
373 gfx::Size InfoBarView::GetPreferredSize() { 370 gfx::Size InfoBarView::GetPreferredSize() {
374 return gfx::Size(0, 371 return gfx::Size(0, preferred_tab_height() + preferred_bar_height());
375 static_cast<int>(target_height_ * animation_->GetCurrentValue())); 372 }
373
374 void InfoBarView::OnBoundsChanged() {
375 views::View::OnBoundsChanged();
376 int tab_height = preferred_tab_height();
377 int bar_height = preferred_bar_height();
378 DCHECK_EQ(tab_height + bar_height, height());
379
380 // Fill and stroke have different opinions about how to treat paths. Because
381 // in Skia integral coordinates represent pixel boundaries, offsetting the
382 // path makes it go exactly through pixel centers; this results in lines that
383 // are exactly where we expect, instead of having odd "off by one" issues.
384 // Were we to do this for |fill_path|, however, which tries to fill "inside"
385 // the path (using some questionable math), we'd get a fill at a very
386 // different place than we'd want.
387 int mirrored_x = GetMirroredXWithWidthInView(0, kTabWidth);
388 stroke_path_->rewind();
389 if (tab_height) {
390 stroke_path_->moveTo(SkIntToScalar(mirrored_x) + SK_ScalarHalf,
Peter Kasting 2011/03/04 22:23:42 These offsets all seem wrong to me. It seems like
Sheridan Rawlins 2011/03/05 18:06:54 Ok. Instead of the SK_Scalar1, I added a kTabStro
391 SkIntToScalar(tab_height) - SK_ScalarHalf);
392 stroke_path_->rCubicTo(
393 SkScalarDiv(kCurveDistance, 2), 0.0,
394 SkScalarDiv(kCurveDistance, 2), SK_Scalar1 - SkIntToScalar(tab_height),
395 SkIntToScalar(kCurveDistance), SK_Scalar1 - SkIntToScalar(tab_height));
396 stroke_path_->rLineTo(SkIntToScalar(kTabPadding + kIconWidth), 0.0);
397 stroke_path_->rCubicTo(
398 SkScalarDiv(kCurveDistance, 2), 0.0,
399 SkScalarDiv(kCurveDistance, 2), SkIntToScalar(tab_height) - SK_Scalar1,
400 SkIntToScalar(kCurveDistance), SkIntToScalar(tab_height) - SK_Scalar1);
401 }
402
403 fill_path_->rewind();
404 if (tab_height + bar_height) {
405 fill_path_->moveTo(SkIntToScalar(mirrored_x), SkIntToScalar(tab_height));
406 fill_path_->rCubicTo(
407 SkScalarDiv(kCurveDistance, 2), 0.0,
408 SkScalarDiv(kCurveDistance, 2), -SkIntToScalar(tab_height),
409 SkIntToScalar(kCurveDistance), -SkIntToScalar(tab_height));
410 fill_path_->rLineTo(SkIntToScalar(kTabPadding + kIconWidth), 0.0);
411 fill_path_->rCubicTo(
412 SkScalarDiv(kCurveDistance, 2), 0.0,
413 SkScalarDiv(kCurveDistance, 2), SkIntToScalar(tab_height),
414 SkIntToScalar(kCurveDistance), SkIntToScalar(tab_height));
415 fill_path_->lineTo(SkIntToScalar(width()), SkIntToScalar(tab_height));
416 fill_path_->lineTo(SkIntToScalar(width()),
417 SkIntToScalar(height()));
418 fill_path_->lineTo(SkIntToScalar(0), SkIntToScalar(height()));
419 fill_path_->lineTo(SkIntToScalar(0), SkIntToScalar(tab_height));
420 fill_path_->close();
421 }
422
423 // Use the same clip path as the fill path.
Peter Kasting 2011/03/04 22:23:42 Nit: We shouldn't even have |clip_path_|, then.
Sheridan Rawlins 2011/03/05 18:06:54 Done.
424 *clip_path_ = *fill_path_;
376 } 425 }
377 426
378 void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) { 427 void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) {
379 // This will trigger some screen readers to read the entire contents of this 428 // This will trigger some screen readers to read the entire contents of this
380 // infobar. 429 // infobar.
381 if (focused_before && focused_now && !this->Contains(focused_before) && 430 if (focused_before && focused_now && !this->Contains(focused_before) &&
382 this->Contains(focused_now)) { 431 this->Contains(focused_now)) {
383 GetWidget()->NotifyAccessibilityEvent( 432 GetWidget()->NotifyAccessibilityEvent(
384 this, ui::AccessibilityTypes::EVENT_ALERT, true); 433 this, ui::AccessibilityTypes::EVENT_ALERT, true);
385 } 434 }
386 } 435 }
387 436
388 void InfoBarView::AnimationEnded(const ui::Animation* animation) { 437 void InfoBarView::AnimationEnded(const ui::Animation* animation) {
389 if (container_ && !animation_->IsShowing()) 438 if (animation == bar_animation_.get()) {
390 Close(); 439 if (bar_animation_->IsShowing())
440 tab_animation_->Show();
441 else if (container_)
442 Close();
443 }
444 if (animation == tab_animation_.get()) {
445 if (!tab_animation_->IsShowing())
446 bar_animation_->Hide();
447 }
448 }
449
450 void InfoBarView::AnimationReset(double value) {
451 // Since we animate the bar first and then the tab, distribute the
452 // value across the two animation objects.
453 double double_value = value * 2.0;
454 bar_animation_->Reset(std::min(double_value, 1.0));
455 tab_animation_->Reset(std::max(double_value - 1.0, 0.0));
456 }
457
458 void InfoBarView::AnimationShow() {
459 bar_animation_->Show();
460 }
461
462 void InfoBarView::AnimationHide() {
463 tab_animation_->Hide();
464 }
465
466 void InfoBarView::AnimationStop() {
467 tab_animation_->Stop();
468 bar_animation_->Stop();
391 } 469 }
392 470
393 void InfoBarView::DestroyFocusTracker(bool restore_focus) { 471 void InfoBarView::DestroyFocusTracker(bool restore_focus) {
394 if (focus_tracker_ != NULL) { 472 if (focus_tracker_ != NULL) {
395 if (restore_focus) 473 if (restore_focus)
396 focus_tracker_->FocusLastFocusedExternalView(); 474 focus_tracker_->FocusLastFocusedExternalView();
397 focus_tracker_->SetFocusManager(NULL); 475 focus_tracker_->SetFocusManager(NULL);
398 focus_tracker_.reset(); 476 focus_tracker_.reset();
399 } 477 }
400 } 478 }
401 479
402 void InfoBarView::DeleteSelf() { 480 void InfoBarView::DeleteSelf() {
403 delete this; 481 delete this;
404 } 482 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698