OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/tabs/tab.h" | 5 #include "chrome/browser/ui/views/tabs/tab.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 close_button_->SetImage(views::CustomButton::STATE_PRESSED, | 467 close_button_->SetImage(views::CustomButton::STATE_PRESSED, |
468 rb.GetImageSkiaNamed(IDR_TAB_CLOSE_P)); | 468 rb.GetImageSkiaNamed(IDR_TAB_CLOSE_P)); |
469 close_button_->SetAccessibleName( | 469 close_button_->SetAccessibleName( |
470 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | 470 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
471 // Disable animation so that the red danger sign shows up immediately | 471 // Disable animation so that the red danger sign shows up immediately |
472 // to help avoid mis-clicks. | 472 // to help avoid mis-clicks. |
473 close_button_->SetAnimationDuration(0); | 473 close_button_->SetAnimationDuration(0); |
474 AddChildView(close_button_); | 474 AddChildView(close_button_); |
475 | 475 |
476 set_context_menu_controller(this); | 476 set_context_menu_controller(this); |
| 477 |
| 478 tab_audio_indicator_.reset(new TabAudioIndicator(this)); |
477 } | 479 } |
478 | 480 |
479 Tab::~Tab() { | 481 Tab::~Tab() { |
480 } | 482 } |
481 | 483 |
482 void Tab::set_animation_container(ui::AnimationContainer* container) { | 484 void Tab::set_animation_container(ui::AnimationContainer* container) { |
483 animation_container_ = container; | 485 animation_container_ = container; |
484 hover_controller_.SetAnimationContainer(container); | 486 hover_controller_.SetAnimationContainer(container); |
| 487 tab_audio_indicator_->SetAnimationContainer(container); |
485 } | 488 } |
486 | 489 |
487 bool Tab::IsActive() const { | 490 bool Tab::IsActive() const { |
488 return controller() ? controller()->IsActiveTab(this) : true; | 491 return controller() ? controller()->IsActiveTab(this) : true; |
489 } | 492 } |
490 | 493 |
491 bool Tab::IsSelected() const { | 494 bool Tab::IsSelected() const { |
492 return controller() ? controller()->IsTabSelected(this) : true; | 495 return controller() ? controller()->IsTabSelected(this) : true; |
493 } | 496 } |
494 | 497 |
(...skipping 18 matching lines...) Expand all Loading... |
513 // automatically since we don't want to get into a crash loop. | 516 // automatically since we don't want to get into a crash loop. |
514 if (IsSelected() || | 517 if (IsSelected() || |
515 data_.crashed_status != base::TERMINATION_STATUS_PROCESS_WAS_KILLED) | 518 data_.crashed_status != base::TERMINATION_STATUS_PROCESS_WAS_KILLED) |
516 StartCrashAnimation(); | 519 StartCrashAnimation(); |
517 #else | 520 #else |
518 StartCrashAnimation(); | 521 StartCrashAnimation(); |
519 #endif | 522 #endif |
520 } | 523 } |
521 } else if (!data_.CaptureActive() && old.CaptureActive()) { | 524 } else if (!data_.CaptureActive() && old.CaptureActive()) { |
522 StopIconAnimation(); | 525 StopIconAnimation(); |
523 if (data_.AudioActive()) | |
524 StartAudioPlayingAnimation(); | |
525 } else if (data_.CaptureActive() && !old.CaptureActive()) { | 526 } else if (data_.CaptureActive() && !old.CaptureActive()) { |
526 // Capture indicator overrides the audio indicator if presently shown. | |
527 old.audio_state = TabRendererData::AUDIO_STATE_NONE; | |
528 data_.audio_state = TabRendererData::AUDIO_STATE_NONE; | |
529 StartRecordingAnimation(); | 527 StartRecordingAnimation(); |
530 } else if (!data_.CaptureActive()) { | |
531 // Start or stop the audio indicator only if not capturing. | |
532 if (!data_.AudioActive() && old.AudioActive()) { | |
533 StopIconAnimation(); | |
534 } else if (data_.AudioActive() && !old.AudioActive()) { | |
535 StartAudioPlayingAnimation(); | |
536 } | |
537 } else { | 528 } else { |
538 if (IsPerformingCrashAnimation()) | 529 if (IsPerformingCrashAnimation()) |
539 StopIconAnimation(); | 530 StopIconAnimation(); |
540 ResetCrashedFavicon(); | 531 ResetCrashedFavicon(); |
541 } | 532 } |
542 | 533 |
543 if (old.mini != data_.mini) { | 534 if (old.mini != data_.mini) { |
544 if (tab_animation_.get() && tab_animation_->is_animating()) { | 535 if (tab_animation_.get() && tab_animation_->is_animating()) { |
545 tab_animation_->Stop(); | 536 tab_animation_->Stop(); |
546 tab_animation_.reset(NULL); | 537 tab_animation_.reset(NULL); |
547 } | 538 } |
548 } | 539 } |
549 | 540 |
| 541 tab_audio_indicator_->SetIsPlayingAudio(data_.AudioActive()); |
| 542 |
550 DataChanged(old); | 543 DataChanged(old); |
551 | 544 |
552 Layout(); | 545 Layout(); |
553 SchedulePaint(); | 546 SchedulePaint(); |
554 } | 547 } |
555 | 548 |
556 void Tab::UpdateLoadingAnimation(TabRendererData::NetworkState state) { | 549 void Tab::UpdateLoadingAnimation(TabRendererData::NetworkState state) { |
557 if (state == data_.network_state && | 550 if (state == data_.network_state && |
558 state == TabRendererData::NETWORK_STATE_NONE) { | 551 state == TabRendererData::NETWORK_STATE_NONE) { |
559 // If the network state is none and hasn't changed, do nothing. Otherwise we | 552 // If the network state is none and hasn't changed, do nothing. Otherwise we |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 int Tab::GetMiniWidth() { | 654 int Tab::GetMiniWidth() { |
662 return browser_defaults::kMiniTabWidth; | 655 return browser_defaults::kMiniTabWidth; |
663 } | 656 } |
664 | 657 |
665 // static | 658 // static |
666 int Tab::GetImmersiveHeight() { | 659 int Tab::GetImmersiveHeight() { |
667 return kImmersiveTabHeight; | 660 return kImmersiveTabHeight; |
668 } | 661 } |
669 | 662 |
670 //////////////////////////////////////////////////////////////////////////////// | 663 //////////////////////////////////////////////////////////////////////////////// |
| 664 // Tab, TabAudioIndicator::Delegate overrides: |
| 665 |
| 666 void Tab::ScheduleAudioIndicatorPaint() { |
| 667 // No need to schedule a paint if another animation is active. The other |
| 668 // animation will do its own scheduling. |
| 669 if (!icon_animation_) |
| 670 ScheduleIconPaint(); |
| 671 } |
| 672 |
| 673 //////////////////////////////////////////////////////////////////////////////// |
671 // Tab, AnimationDelegate overrides: | 674 // Tab, AnimationDelegate overrides: |
672 | 675 |
673 void Tab::AnimationProgressed(const ui::Animation* animation) { | 676 void Tab::AnimationProgressed(const ui::Animation* animation) { |
674 // Ignore if the pulse animation is being performed on active tab because | 677 // Ignore if the pulse animation is being performed on active tab because |
675 // it repaints the same image. See |Tab::PaintTabBackground()|. | 678 // it repaints the same image. See |Tab::PaintTabBackground()|. |
676 if (animation == tab_animation_.get() && IsActive()) | 679 if (animation == tab_animation_.get() && IsActive()) |
677 return; | 680 return; |
678 SchedulePaint(); | 681 SchedulePaint(); |
679 } | 682 } |
680 | 683 |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 DrawIconCenter(canvas, projection_screen, 0, | 1425 DrawIconCenter(canvas, projection_screen, 0, |
1423 data().favicon.width(), | 1426 data().favicon.width(), |
1424 data().favicon.height(), | 1427 data().favicon.height(), |
1425 bounds, true, SkPaint()); | 1428 bounds, true, SkPaint()); |
1426 } else { | 1429 } else { |
1427 DrawIconCenter(canvas, data().favicon, 0, | 1430 DrawIconCenter(canvas, data().favicon, 0, |
1428 data().favicon.width(), | 1431 data().favicon.width(), |
1429 data().favicon.height(), | 1432 data().favicon.height(), |
1430 bounds, true, SkPaint()); | 1433 bounds, true, SkPaint()); |
1431 | 1434 |
1432 if (data().audio_state == TabRendererData::AUDIO_STATE_PLAYING) { | 1435 // Draw the audio indicator UI only if no other icon animation is |
1433 // If audio is playing, we draw on top of the icon the | 1436 // active. |
1434 // current equalizer animiation frame. | 1437 if (!icon_animation_ && tab_audio_indicator_->IsAnimating()) |
1435 ui::ThemeProvider* tp = GetThemeProvider(); | 1438 tab_audio_indicator_->Paint(canvas, bounds); |
1436 gfx::ImageSkia equalizer(*tp->GetImageSkiaNamed(IDR_AUDIO_ANIMATION)); | |
1437 int icon_size = equalizer.height(); | |
1438 int number_of_frames = equalizer.width() / icon_size; | |
1439 int frame = static_cast<int>( | |
1440 icon_animation_->GetCurrentValue() * number_of_frames); | |
1441 int image_offset = frame * icon_size; | |
1442 DrawIconAtLocation(canvas, equalizer, image_offset, | |
1443 bounds.x(), bounds.y() + 1, | |
1444 icon_size, icon_size, | |
1445 false, SkPaint()); | |
1446 } | |
1447 } | 1439 } |
1448 } | 1440 } |
1449 } | 1441 } |
1450 canvas->Restore(); | 1442 canvas->Restore(); |
1451 | 1443 |
1452 // Paint recording or projecting animation overlay. | 1444 // Paint recording or projecting animation overlay. |
1453 if (data().capture_state != TabRendererData::CAPTURE_STATE_NONE) | 1445 if (data().capture_state != TabRendererData::CAPTURE_STATE_NONE) |
1454 PaintCaptureState(canvas, bounds); | 1446 PaintCaptureState(canvas, bounds); |
1455 } | 1447 } |
1456 | 1448 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1692 } | 1684 } |
1693 | 1685 |
1694 void Tab::StartRecordingAnimation() { | 1686 void Tab::StartRecordingAnimation() { |
1695 ui::ThrobAnimation* animation = new ui::ThrobAnimation(this); | 1687 ui::ThrobAnimation* animation = new ui::ThrobAnimation(this); |
1696 animation->SetTweenType(ui::Tween::EASE_IN_OUT); | 1688 animation->SetTweenType(ui::Tween::EASE_IN_OUT); |
1697 animation->SetThrobDuration(kRecordingDurationMs); | 1689 animation->SetThrobDuration(kRecordingDurationMs); |
1698 animation->StartThrobbing(-1); | 1690 animation->StartThrobbing(-1); |
1699 icon_animation_.reset(animation); | 1691 icon_animation_.reset(animation); |
1700 } | 1692 } |
1701 | 1693 |
1702 void Tab::StartAudioPlayingAnimation() { | |
1703 ui::ThrobAnimation* animation = new ui::ThrobAnimation(this); | |
1704 animation->SetTweenType(ui::Tween::LINEAR); | |
1705 animation->SetThrobDuration(2000); | |
1706 animation->StartThrobbing(-1); | |
1707 icon_animation_.reset(animation); | |
1708 } | |
1709 | |
1710 bool Tab::IsPerformingCrashAnimation() const { | 1694 bool Tab::IsPerformingCrashAnimation() const { |
1711 return icon_animation_.get() && data_.IsCrashed(); | 1695 return icon_animation_.get() && data_.IsCrashed(); |
1712 } | 1696 } |
1713 | 1697 |
1714 void Tab::ScheduleIconPaint() { | 1698 void Tab::ScheduleIconPaint() { |
1715 gfx::Rect bounds = GetIconBounds(); | 1699 gfx::Rect bounds = GetIconBounds(); |
1716 if (bounds.IsEmpty()) | 1700 if (bounds.IsEmpty()) |
1717 return; | 1701 return; |
1718 | 1702 |
1719 // Extends the area to the bottom when sad_favicon is | 1703 // Extends the area to the bottom when sad_favicon is |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1817 const gfx::ImageSkia& image) { | 1801 const gfx::ImageSkia& image) { |
1818 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); | 1802 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); |
1819 ImageCacheEntry entry; | 1803 ImageCacheEntry entry; |
1820 entry.resource_id = resource_id; | 1804 entry.resource_id = resource_id; |
1821 entry.scale_factor = scale_factor; | 1805 entry.scale_factor = scale_factor; |
1822 entry.image = image; | 1806 entry.image = image; |
1823 image_cache_->push_front(entry); | 1807 image_cache_->push_front(entry); |
1824 if (image_cache_->size() > kMaxImageCacheSize) | 1808 if (image_cache_->size() > kMaxImageCacheSize) |
1825 image_cache_->pop_back(); | 1809 image_cache_->pop_back(); |
1826 } | 1810 } |
OLD | NEW |