| 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 "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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 InfoBarView::InfoBarView(InfoBarDelegate* delegate) | 53 InfoBarView::InfoBarView(InfoBarDelegate* delegate) |
| 54 : InfoBar(delegate), | 54 : InfoBar(delegate), |
| 55 container_(NULL), | 55 container_(NULL), |
| 56 delegate_(delegate), | 56 delegate_(delegate), |
| 57 icon_(NULL), | 57 icon_(NULL), |
| 58 close_button_(NULL), | 58 close_button_(NULL), |
| 59 ALLOW_THIS_IN_INITIALIZER_LIST(animation_(new ui::SlideAnimation(this))), | 59 ALLOW_THIS_IN_INITIALIZER_LIST(animation_(new ui::SlideAnimation(this))), |
| 60 ALLOW_THIS_IN_INITIALIZER_LIST(delete_factory_(this)), | 60 ALLOW_THIS_IN_INITIALIZER_LIST(delete_factory_(this)), |
| 61 target_height_(kDefaultTargetHeight), | 61 target_height_(kDefaultTargetHeight), |
| 62 tab_height_(0), |
| 63 bar_height_(0), |
| 62 fill_path_(new SkPath), | 64 fill_path_(new SkPath), |
| 63 stroke_path_(new SkPath) { | 65 stroke_path_(new SkPath) { |
| 64 set_parent_owned(false); // InfoBar deletes itself at the appropriate time. | 66 set_parent_owned(false); // InfoBar deletes itself at the appropriate time. |
| 65 | 67 |
| 66 InfoBarDelegate::Type infobar_type = delegate->GetInfoBarType(); | 68 InfoBarDelegate::Type infobar_type = delegate->GetInfoBarType(); |
| 67 set_background(new InfoBarBackground(infobar_type)); | 69 set_background(new InfoBarBackground(infobar_type)); |
| 68 | 70 |
| 69 animation_->SetTweenType(ui::Tween::LINEAR); | 71 animation_->SetTweenType(ui::Tween::LINEAR); |
| 70 } | 72 } |
| 71 | 73 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 276 |
| 275 void InfoBarView::PaintChildren(gfx::Canvas* canvas) { | 277 void InfoBarView::PaintChildren(gfx::Canvas* canvas) { |
| 276 canvas->Save(); | 278 canvas->Save(); |
| 277 | 279 |
| 278 // TODO(scr): This really should be the |fill_path_|, but the clipPath seems | 280 // TODO(scr): This really should be the |fill_path_|, but the clipPath seems |
| 279 // broken on non-Windows platforms (crbug.com/75154). For now, just clip to | 281 // broken on non-Windows platforms (crbug.com/75154). For now, just clip to |
| 280 // the bar bounds. | 282 // the bar bounds. |
| 281 // | 283 // |
| 282 // gfx::CanvasSkia* canvas_skia = canvas->AsCanvasSkia(); | 284 // gfx::CanvasSkia* canvas_skia = canvas->AsCanvasSkia(); |
| 283 // canvas_skia->clipPath(*fill_path_); | 285 // canvas_skia->clipPath(*fill_path_); |
| 284 int tab_height = AnimatedTabHeight(); | 286 DCHECK_EQ(tab_height_ + bar_height_, height()) |
| 285 int bar_height = AnimatedBarHeight(); | 287 << "Bounds set in OnBoundsChanged doesn't match PaintChildren."; |
| 286 DCHECK_EQ(tab_height + bar_height, height()) | 288 canvas->ClipRectInt(0, tab_height_, width(), bar_height_); |
| 287 << "Animation progressed between OnBoundsChanged & PaintChildren."; | |
| 288 canvas->ClipRectInt(0, tab_height, width(), bar_height); | |
| 289 | 289 |
| 290 views::View::PaintChildren(canvas); | 290 views::View::PaintChildren(canvas); |
| 291 canvas->Restore(); | 291 canvas->Restore(); |
| 292 } | 292 } |
| 293 | 293 |
| 294 void InfoBarView::ButtonPressed(views::Button* sender, | 294 void InfoBarView::ButtonPressed(views::Button* sender, |
| 295 const views::Event& event) { | 295 const views::Event& event) { |
| 296 if (sender == close_button_) { | 296 if (sender == close_button_) { |
| 297 if (delegate_) | 297 if (delegate_) |
| 298 delegate_->InfoBarDismissed(); | 298 delegate_->InfoBarDismissed(); |
| 299 RemoveInfoBar(); | 299 RemoveInfoBar(); |
| 300 } | 300 } |
| 301 } | 301 } |
| 302 | 302 |
| 303 void InfoBarView::AnimationProgressed(const ui::Animation* animation) { | 303 void InfoBarView::AnimationProgressed(const ui::Animation* animation) { |
| 304 InvalidateLayout(); |
| 305 |
| 304 if (container_) | 306 if (container_) |
| 305 container_->OnInfoBarAnimated(false); | 307 container_->OnInfoBarAnimated(false); |
| 306 } | 308 } |
| 307 | 309 |
| 308 int InfoBarView::ContentMinimumWidth() const { | 310 int InfoBarView::ContentMinimumWidth() const { |
| 309 return 0; | 311 return 0; |
| 310 } | 312 } |
| 311 | 313 |
| 312 void InfoBarView::RemoveInfoBar() const { | 314 void InfoBarView::RemoveInfoBar() const { |
| 313 if (container_) | 315 if (container_) |
| 314 container_->RemoveDelegate(delegate()); | 316 container_->RemoveDelegate(delegate()); |
| 315 } | 317 } |
| 316 | 318 |
| 319 void InfoBarView::SetTargetHeight(int height) { |
| 320 if (target_height_ != height) { |
| 321 target_height_ = height; |
| 322 |
| 323 InvalidateLayout(); |
| 324 |
| 325 if (container_) |
| 326 container_->OnInfoBarAnimated(!animation_->is_animating()); |
| 327 } |
| 328 } |
| 329 |
| 317 int InfoBarView::StartX() const { | 330 int InfoBarView::StartX() const { |
| 318 // Ensure we don't return a value greater than EndX(), so children can safely | 331 // Ensure we don't return a value greater than EndX(), so children can safely |
| 319 // set something's width to "EndX() - StartX()" without risking that being | 332 // set something's width to "EndX() - StartX()" without risking that being |
| 320 // negative. | 333 // negative. |
| 321 return std::min(EndX(), | 334 return std::min(EndX(), |
| 322 ((icon_ != NULL) ? icon_->bounds().right() : 0) + kHorizontalPadding); | 335 ((icon_ != NULL) ? icon_->bounds().right() : 0) + kHorizontalPadding); |
| 323 } | 336 } |
| 324 | 337 |
| 325 int InfoBarView::EndX() const { | 338 int InfoBarView::EndX() const { |
| 326 const int kCloseButtonSpacing = 12; | 339 const int kCloseButtonSpacing = 12; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 351 | 364 |
| 352 int InfoBarView::AnimatedBarHeight() const { | 365 int InfoBarView::AnimatedBarHeight() const { |
| 353 return static_cast<int>(target_height_ * animation_->GetCurrentValue()); | 366 return static_cast<int>(target_height_ * animation_->GetCurrentValue()); |
| 354 } | 367 } |
| 355 | 368 |
| 356 gfx::Size InfoBarView::GetPreferredSize() { | 369 gfx::Size InfoBarView::GetPreferredSize() { |
| 357 return gfx::Size(0, AnimatedTabHeight() + AnimatedBarHeight()); | 370 return gfx::Size(0, AnimatedTabHeight() + AnimatedBarHeight()); |
| 358 } | 371 } |
| 359 | 372 |
| 360 void InfoBarView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 373 void InfoBarView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 361 int tab_height = AnimatedTabHeight(); | 374 tab_height_ = AnimatedTabHeight(); |
| 362 int bar_height = AnimatedBarHeight(); | 375 bar_height_ = AnimatedBarHeight(); |
| 363 int divider_y = tab_height - 1; | 376 int divider_y = tab_height_ - 1; |
| 364 DCHECK_EQ(tab_height + bar_height, height()) | 377 DCHECK_EQ(tab_height_ + bar_height_, height()) |
| 365 << "Animation progressed between Layout & OnBoundsChanged."; | 378 << "Animation progressed between Layout & OnBoundsChanged."; |
| 366 | 379 |
| 367 int mirrored_x = GetMirroredXWithWidthInView(0, kTabWidth); | 380 int mirrored_x = GetMirroredXWithWidthInView(0, kTabWidth); |
| 368 stroke_path_->rewind(); | 381 stroke_path_->rewind(); |
| 369 fill_path_->rewind(); | 382 fill_path_->rewind(); |
| 370 | 383 |
| 371 if (tab_height) { | 384 if (tab_height_) { |
| 372 stroke_path_->moveTo(SkIntToScalar(mirrored_x), | 385 stroke_path_->moveTo(SkIntToScalar(mirrored_x), |
| 373 SkIntToScalar(divider_y)); | 386 SkIntToScalar(divider_y)); |
| 374 stroke_path_->rCubicTo( | 387 stroke_path_->rCubicTo( |
| 375 SkScalarDiv(kCurveWidth, 2), 0.0, | 388 SkScalarDiv(kCurveWidth, 2), 0.0, |
| 376 SkScalarDiv(kCurveWidth, 2), | 389 SkScalarDiv(kCurveWidth, 2), |
| 377 SkIntToScalar(-divider_y), | 390 SkIntToScalar(-divider_y), |
| 378 SkIntToScalar(kCurveWidth), | 391 SkIntToScalar(kCurveWidth), |
| 379 SkIntToScalar(-divider_y)); | 392 SkIntToScalar(-divider_y)); |
| 380 stroke_path_->rLineTo(SkScalarMulAdd(kTabIconPadding, 2, kMaxIconWidth), | 393 stroke_path_->rLineTo(SkScalarMulAdd(kTabIconPadding, 2, kMaxIconWidth), |
| 381 0.0); | 394 0.0); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 396 | 409 |
| 397 // Fill and stroke have different opinions about how to treat paths. | 410 // Fill and stroke have different opinions about how to treat paths. |
| 398 // Because in Skia integral coordinates represent pixel boundaries, | 411 // Because in Skia integral coordinates represent pixel boundaries, |
| 399 // offsetting the path makes it go exactly through pixel centers; this | 412 // offsetting the path makes it go exactly through pixel centers; this |
| 400 // results in lines that are exactly where we expect, instead of having odd | 413 // results in lines that are exactly where we expect, instead of having odd |
| 401 // "off by one" issues. Were we to do this for |fill_path|, however, which | 414 // "off by one" issues. Were we to do this for |fill_path|, however, which |
| 402 // tries to fill "inside" the path (using some questionable math), we'd get | 415 // tries to fill "inside" the path (using some questionable math), we'd get |
| 403 // a fill at a very different place than we'd want. | 416 // a fill at a very different place than we'd want. |
| 404 stroke_path_->offset(SK_ScalarHalf, SK_ScalarHalf); | 417 stroke_path_->offset(SK_ScalarHalf, SK_ScalarHalf); |
| 405 } | 418 } |
| 406 if (bar_height) { | 419 if (bar_height_) { |
| 407 fill_path_->addRect(0.0, SkIntToScalar(tab_height), | 420 fill_path_->addRect(0.0, SkIntToScalar(tab_height_), |
| 408 SkIntToScalar(width()), SkIntToScalar(height())); | 421 SkIntToScalar(width()), SkIntToScalar(height())); |
| 409 } | 422 } |
| 410 } | 423 } |
| 411 | 424 |
| 412 void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) { | 425 void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) { |
| 413 // This will trigger some screen readers to read the entire contents of this | 426 // This will trigger some screen readers to read the entire contents of this |
| 414 // infobar. | 427 // infobar. |
| 415 if (focused_before && focused_now && !this->Contains(focused_before) && | 428 if (focused_before && focused_now && !this->Contains(focused_before) && |
| 416 this->Contains(focused_now) && GetWidget()) { | 429 this->Contains(focused_now) && GetWidget()) { |
| 417 GetWidget()->NotifyAccessibilityEvent( | 430 GetWidget()->NotifyAccessibilityEvent( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 446 // window), since this action can cause the delegate to destroy itself. | 459 // window), since this action can cause the delegate to destroy itself. |
| 447 if (delegate_) { | 460 if (delegate_) { |
| 448 delegate_->InfoBarClosed(); | 461 delegate_->InfoBarClosed(); |
| 449 delegate_ = NULL; | 462 delegate_ = NULL; |
| 450 } | 463 } |
| 451 } | 464 } |
| 452 | 465 |
| 453 void InfoBarView::DeleteSelf() { | 466 void InfoBarView::DeleteSelf() { |
| 454 delete this; | 467 delete this; |
| 455 } | 468 } |
| OLD | NEW |