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 <stddef.h> | 7 #include <stddef.h> |
8 #include <limits> | 8 #include <limits> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 #include "ui/views/window/non_client_view.h" | 61 #include "ui/views/window/non_client_view.h" |
62 | 62 |
63 #if defined(USE_AURA) | 63 #if defined(USE_AURA) |
64 #include "ui/aura/env.h" | 64 #include "ui/aura/env.h" |
65 #endif | 65 #endif |
66 | 66 |
67 using base::UserMetricsAction; | 67 using base::UserMetricsAction; |
68 | 68 |
69 namespace { | 69 namespace { |
70 | 70 |
71 // How long the pulse throb takes. | |
72 const int kPulseDurationMs = 200; | |
73 | |
74 // Width of touch tabs. | 71 // Width of touch tabs. |
75 const int kTouchWidth = 120; | 72 const int kTouchWidth = 120; |
76 | 73 |
77 const int kExtraLeftPaddingToBalanceCloseButtonPadding = 2; | 74 const int kExtraLeftPaddingToBalanceCloseButtonPadding = 2; |
78 const int kAfterTitleSpacing = 4; | 75 const int kAfterTitleSpacing = 4; |
79 | 76 |
80 // When a non-pinned tab becomes a pinned tab the width of the tab animates. If | 77 // When a non-pinned tab becomes a pinned tab the width of the tab animates. If |
81 // the width of a pinned tab is at least kPinnedTabExtraWidthToRenderAsNormal | 78 // the width of a pinned tab is at least kPinnedTabExtraWidthToRenderAsNormal |
82 // larger than the desired pinned tab width then the tab is rendered as a normal | 79 // larger than the desired pinned tab width then the tab is rendered as a normal |
83 // tab. This is done to avoid having the title immediately disappear when | 80 // tab. This is done to avoid having the title immediately disappear when |
84 // transitioning a tab from normal to pinned tab. | 81 // transitioning a tab from normal to pinned tab. |
85 const int kPinnedTabExtraWidthToRenderAsNormal = 30; | 82 const int kPinnedTabExtraWidthToRenderAsNormal = 30; |
86 | 83 |
87 // How opaque to make the hover state (out of 1). | 84 // How opaque to make the hover state (out of 1). |
88 const double kHoverOpacity = 0.33; | 85 const double kHoverOpacity = 0.33; |
89 | 86 |
90 // Opacity of the active tab background painted over inactive selected tabs. | 87 // Opacity of the active tab background painted over inactive selected tabs. |
91 const double kSelectedTabOpacity = 0.3; | 88 const double kSelectedTabOpacity = 0.3; |
92 | 89 |
93 // Inactive selected tabs have their throb value scaled by this. | 90 // Inactive selected tabs have their throb value scaled by this. |
94 const double kSelectedTabThrobScale = 0.95 - kSelectedTabOpacity; | 91 const double kSelectedTabThrobScale = 0.95 - kSelectedTabOpacity; |
95 | 92 |
96 // Durations for the various parts of the pinned tab title animation. | |
97 const int kPinnedTitleChangeAnimationDuration1MS = 1600; | |
98 const int kPinnedTitleChangeAnimationStart1MS = 0; | |
99 const int kPinnedTitleChangeAnimationEnd1MS = 1900; | |
100 const int kPinnedTitleChangeAnimationDuration2MS = 0; | |
101 const int kPinnedTitleChangeAnimationDuration3MS = 550; | |
102 const int kPinnedTitleChangeAnimationStart3MS = 150; | |
103 const int kPinnedTitleChangeAnimationEnd3MS = 800; | |
104 const int kPinnedTitleChangeAnimationIntervalMS = 40; | |
105 | |
106 // Offset from the right edge for the start of the pinned title change | 93 // Offset from the right edge for the start of the pinned title change |
107 // animation. | 94 // animation. |
108 const int kPinnedTitleChangeInitialXOffset = 6; | 95 const int kPinnedTitleChangeInitialXOffset = 6; |
109 | 96 |
110 // Max number of images to cache. This has to be at least two since rounding | 97 // Max number of images to cache. This has to be at least two since rounding |
111 // errors may lead to tabs in the same tabstrip having different sizes. | 98 // errors may lead to tabs in the same tabstrip having different sizes. |
112 const size_t kMaxImageCacheSize = 4; | 99 const size_t kMaxImageCacheSize = 4; |
113 | 100 |
114 // Height of the miniature tab strip in immersive mode. | 101 // Height of the miniature tab strip in immersive mode. |
115 const int kImmersiveTabHeight = 3; | 102 const int kImmersiveTabHeight = 3; |
(...skipping 19 matching lines...) Expand all Loading... |
135 | 122 |
136 // Returns the width of the tab endcap at scale 1. More precisely, this is the | 123 // Returns the width of the tab endcap at scale 1. More precisely, this is the |
137 // width of the curve making up either the outer or inner edge of the stroke; | 124 // width of the curve making up either the outer or inner edge of the stroke; |
138 // since these two curves are horizontally offset by 1 px (regardless of scale), | 125 // since these two curves are horizontally offset by 1 px (regardless of scale), |
139 // the total width of the endcap from tab outer edge to the inside end of the | 126 // the total width of the endcap from tab outer edge to the inside end of the |
140 // stroke inner edge is (GetUnscaledEndcapWidth() * scale) + 1. | 127 // stroke inner edge is (GetUnscaledEndcapWidth() * scale) + 1. |
141 float GetUnscaledEndcapWidth() { | 128 float GetUnscaledEndcapWidth() { |
142 return GetLayoutInsets(TAB).left() - 0.5f; | 129 return GetLayoutInsets(TAB).left() - 0.5f; |
143 } | 130 } |
144 | 131 |
145 // Stop()s |animation| and then deletes it. We do this rather than just deleting | |
146 // so that the delegate is notified before the destruction. | |
147 void StopAndDeleteAnimation(scoped_ptr<gfx::Animation> animation) { | |
148 if (animation) | |
149 animation->Stop(); | |
150 } | |
151 | |
152 void DrawHighlight(gfx::Canvas* canvas, | 132 void DrawHighlight(gfx::Canvas* canvas, |
153 const SkPoint& p, | 133 const SkPoint& p, |
154 SkScalar radius, | 134 SkScalar radius, |
155 SkAlpha alpha) { | 135 SkAlpha alpha) { |
156 const SkColor colors[2] = { SkColorSetA(SK_ColorWHITE, alpha), | 136 const SkColor colors[2] = { SkColorSetA(SK_ColorWHITE, alpha), |
157 SkColorSetA(SK_ColorWHITE, 0) }; | 137 SkColorSetA(SK_ColorWHITE, 0) }; |
158 skia::RefPtr<SkShader> shader = skia::AdoptRef(SkGradientShader::CreateRadial( | 138 skia::RefPtr<SkShader> shader = skia::AdoptRef(SkGradientShader::CreateRadial( |
159 p, radius, colors, nullptr, 2, SkShader::kClamp_TileMode)); | 139 p, radius, colors, nullptr, 2, SkShader::kClamp_TileMode)); |
160 SkPaint paint; | 140 SkPaint paint; |
161 paint.setStyle(SkPaint::kFill_Style); | 141 paint.setStyle(SkPaint::kFill_Style); |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 // static | 477 // static |
498 const char Tab::kViewClassName[] = "Tab"; | 478 const char Tab::kViewClassName[] = "Tab"; |
499 Tab::TabImages Tab::active_images_ = {0}; | 479 Tab::TabImages Tab::active_images_ = {0}; |
500 Tab::TabImages Tab::inactive_images_ = {0}; | 480 Tab::TabImages Tab::inactive_images_ = {0}; |
501 Tab::TabImages Tab::mask_images_ = {0}; | 481 Tab::TabImages Tab::mask_images_ = {0}; |
502 Tab::ImageCache* Tab::image_cache_ = NULL; | 482 Tab::ImageCache* Tab::image_cache_ = NULL; |
503 | 483 |
504 //////////////////////////////////////////////////////////////////////////////// | 484 //////////////////////////////////////////////////////////////////////////////// |
505 // Tab, public: | 485 // Tab, public: |
506 | 486 |
507 Tab::Tab(TabController* controller) | 487 Tab::Tab(TabController* controller, gfx::AnimationContainer* container) |
508 : controller_(controller), | 488 : controller_(controller), |
509 closing_(false), | 489 closing_(false), |
510 dragging_(false), | 490 dragging_(false), |
511 detached_(false), | 491 detached_(false), |
512 favicon_hiding_offset_(0), | 492 favicon_hiding_offset_(0), |
513 immersive_loading_step_(0), | 493 immersive_loading_step_(0), |
514 should_display_crashed_favicon_(false), | 494 should_display_crashed_favicon_(false), |
| 495 pulse_animation_(new gfx::ThrobAnimation(this)), |
| 496 crash_icon_animation_(new FaviconCrashAnimation(this)), |
| 497 animation_container_(container), |
515 throbber_(nullptr), | 498 throbber_(nullptr), |
516 media_indicator_button_(nullptr), | 499 media_indicator_button_(nullptr), |
517 close_button_(nullptr), | 500 close_button_(nullptr), |
518 title_(new views::Label()), | 501 title_(new views::Label()), |
519 tab_activated_with_last_tap_down_(false), | 502 tab_activated_with_last_tap_down_(false), |
520 hover_controller_(this), | 503 hover_controller_(this), |
521 showing_icon_(false), | 504 showing_icon_(false), |
522 showing_media_indicator_(false), | 505 showing_media_indicator_(false), |
523 showing_close_button_(false), | 506 showing_close_button_(false), |
524 button_color_(SK_ColorTRANSPARENT) { | 507 button_color_(SK_ColorTRANSPARENT) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 SkColorSetRGB(0xA8, 0x35, 0x2A)); | 547 SkColorSetRGB(0xA8, 0x35, 0x2A)); |
565 close_button_->SetImage(views::CustomButton::STATE_HOVERED, &hovered); | 548 close_button_->SetImage(views::CustomButton::STATE_HOVERED, &hovered); |
566 close_button_->SetImage(views::CustomButton::STATE_PRESSED, &pressed); | 549 close_button_->SetImage(views::CustomButton::STATE_PRESSED, &pressed); |
567 | 550 |
568 // Disable animation so that the red danger sign shows up immediately | 551 // Disable animation so that the red danger sign shows up immediately |
569 // to help avoid mis-clicks. | 552 // to help avoid mis-clicks. |
570 close_button_->SetAnimationDuration(0); | 553 close_button_->SetAnimationDuration(0); |
571 AddChildView(close_button_); | 554 AddChildView(close_button_); |
572 | 555 |
573 set_context_menu_controller(this); | 556 set_context_menu_controller(this); |
| 557 |
| 558 const int kPulseDurationMs = 200; |
| 559 pulse_animation_->SetSlideDuration(kPulseDurationMs); |
| 560 pulse_animation_->SetContainer(animation_container_.get()); |
| 561 |
| 562 const int kPinnedTitleChangeAnimationDuration1MS = 1600; |
| 563 const int kPinnedTitleChangeAnimationStart1MS = 0; |
| 564 const int kPinnedTitleChangeAnimationEnd1MS = 1900; |
| 565 const int kPinnedTitleChangeAnimationDuration2MS = 0; |
| 566 const int kPinnedTitleChangeAnimationDuration3MS = 550; |
| 567 const int kPinnedTitleChangeAnimationStart3MS = 150; |
| 568 const int kPinnedTitleChangeAnimationEnd3MS = 800; |
| 569 const int kPinnedTitleChangeAnimationIntervalMS = 40; |
| 570 gfx::MultiAnimation::Parts parts; |
| 571 parts.push_back(gfx::MultiAnimation::Part( |
| 572 kPinnedTitleChangeAnimationDuration1MS, |
| 573 kPinnedTitleChangeAnimationStart1MS, |
| 574 kPinnedTitleChangeAnimationEnd1MS, |
| 575 gfx::Tween::EASE_OUT)); |
| 576 parts.push_back(gfx::MultiAnimation::Part( |
| 577 kPinnedTitleChangeAnimationDuration2MS, |
| 578 gfx::Tween::ZERO)); |
| 579 parts.push_back(gfx::MultiAnimation::Part( |
| 580 kPinnedTitleChangeAnimationDuration3MS, |
| 581 kPinnedTitleChangeAnimationStart3MS, |
| 582 kPinnedTitleChangeAnimationEnd3MS, |
| 583 gfx::Tween::EASE_IN)); |
| 584 const base::TimeDelta timeout = |
| 585 base::TimeDelta::FromMilliseconds(kPinnedTitleChangeAnimationIntervalMS); |
| 586 pinned_title_change_animation_.reset(new gfx::MultiAnimation(parts, timeout)); |
| 587 pinned_title_change_animation_->SetContainer(animation_container_.get()); |
| 588 pinned_title_change_animation_->set_delegate(this); |
| 589 |
| 590 hover_controller_.SetAnimationContainer(animation_container_.get()); |
574 } | 591 } |
575 | 592 |
576 Tab::~Tab() { | 593 Tab::~Tab() { |
577 } | 594 } |
578 | 595 |
579 void Tab::SetAnimationContainer(gfx::AnimationContainer* container) { | |
580 animation_container_ = container; | |
581 hover_controller_.SetAnimationContainer(container); | |
582 } | |
583 | |
584 bool Tab::IsActive() const { | 596 bool Tab::IsActive() const { |
585 return controller_->IsActiveTab(this); | 597 return controller_->IsActiveTab(this); |
586 } | 598 } |
587 | 599 |
588 void Tab::ActiveStateChanged() { | 600 void Tab::ActiveStateChanged() { |
589 OnButtonColorMaybeChanged(); | 601 OnButtonColorMaybeChanged(); |
590 media_indicator_button_->UpdateEnabledForMuteToggle(); | 602 media_indicator_button_->UpdateEnabledForMuteToggle(); |
591 Layout(); | 603 Layout(); |
592 } | 604 } |
593 | 605 |
(...skipping 18 matching lines...) Expand all Loading... |
612 base::string16 title = data_.title; | 624 base::string16 title = data_.title; |
613 if (title.empty()) { | 625 if (title.empty()) { |
614 title = data_.loading ? | 626 title = data_.loading ? |
615 l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE) : | 627 l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE) : |
616 CoreTabHelper::GetDefaultTitle(); | 628 CoreTabHelper::GetDefaultTitle(); |
617 } else { | 629 } else { |
618 Browser::FormatTitleForDisplay(&title); | 630 Browser::FormatTitleForDisplay(&title); |
619 } | 631 } |
620 title_->SetText(title); | 632 title_->SetText(title); |
621 | 633 |
622 if (data_.IsCrashed()) { | 634 if (!data_.IsCrashed()) { |
623 if (!should_display_crashed_favicon_ && !crash_icon_animation_) { | 635 crash_icon_animation_->Stop(); |
624 data_.media_state = TAB_MEDIA_STATE_NONE; | |
625 crash_icon_animation_.reset(new FaviconCrashAnimation(this)); | |
626 crash_icon_animation_->Start(); | |
627 } | |
628 } else { | |
629 if (crash_icon_animation_) | |
630 crash_icon_animation_.reset(); | |
631 should_display_crashed_favicon_ = false; | 636 should_display_crashed_favicon_ = false; |
632 favicon_hiding_offset_ = 0; | 637 favicon_hiding_offset_ = 0; |
| 638 } else if (!should_display_crashed_favicon_ && |
| 639 !crash_icon_animation_->is_animating()) { |
| 640 data_.media_state = TAB_MEDIA_STATE_NONE; |
| 641 crash_icon_animation_->Start(); |
633 } | 642 } |
634 | 643 |
635 if (data_.media_state != old.media_state) | 644 if (data_.media_state != old.media_state) |
636 media_indicator_button_->TransitionToMediaState(data_.media_state); | 645 media_indicator_button_->TransitionToMediaState(data_.media_state); |
637 | 646 |
638 if (old.pinned != data_.pinned) | 647 if (old.pinned != data_.pinned) |
639 StopPinnedTabTitleAnimation(); | 648 StopPinnedTabTitleAnimation(); |
640 | 649 |
641 DataChanged(old); | 650 DataChanged(old); |
642 | 651 |
643 Layout(); | 652 Layout(); |
644 SchedulePaint(); | 653 SchedulePaint(); |
645 } | 654 } |
646 | 655 |
647 void Tab::UpdateLoadingAnimation(TabRendererData::NetworkState state) { | 656 void Tab::UpdateLoadingAnimation(TabRendererData::NetworkState state) { |
648 if (state == data_.network_state && | 657 if (state == data_.network_state && |
649 state == TabRendererData::NETWORK_STATE_NONE) { | 658 state == TabRendererData::NETWORK_STATE_NONE) { |
650 // If the network state is none and hasn't changed, do nothing. Otherwise we | 659 // If the network state is none and hasn't changed, do nothing. Otherwise we |
651 // need to advance the animation frame. | 660 // need to advance the animation frame. |
652 return; | 661 return; |
653 } | 662 } |
654 | 663 |
655 data_.network_state = state; | 664 data_.network_state = state; |
656 AdvanceLoadingAnimation(); | 665 AdvanceLoadingAnimation(); |
657 } | 666 } |
658 | 667 |
659 void Tab::StartPulse() { | 668 void Tab::StartPulse() { |
660 pulse_animation_.reset(new gfx::ThrobAnimation(this)); | |
661 pulse_animation_->SetSlideDuration(kPulseDurationMs); | |
662 if (animation_container_.get()) | |
663 pulse_animation_->SetContainer(animation_container_.get()); | |
664 pulse_animation_->StartThrobbing(std::numeric_limits<int>::max()); | 669 pulse_animation_->StartThrobbing(std::numeric_limits<int>::max()); |
665 } | 670 } |
666 | 671 |
667 void Tab::StopPulse() { | 672 void Tab::StopPulse() { |
668 StopAndDeleteAnimation(std::move(pulse_animation_)); | 673 pulse_animation_->Stop(); |
669 } | 674 } |
670 | 675 |
671 void Tab::StartPinnedTabTitleAnimation() { | 676 void Tab::StartPinnedTabTitleAnimation() { |
672 if (!data().pinned) | 677 if (data().pinned) |
673 return; | 678 pinned_title_change_animation_->Start(); |
674 if (!pinned_title_change_animation_) { | |
675 gfx::MultiAnimation::Parts parts; | |
676 parts.push_back( | |
677 gfx::MultiAnimation::Part(kPinnedTitleChangeAnimationDuration1MS, | |
678 gfx::Tween::EASE_OUT)); | |
679 parts.push_back( | |
680 gfx::MultiAnimation::Part(kPinnedTitleChangeAnimationDuration2MS, | |
681 gfx::Tween::ZERO)); | |
682 parts.push_back( | |
683 gfx::MultiAnimation::Part(kPinnedTitleChangeAnimationDuration3MS, | |
684 gfx::Tween::EASE_IN)); | |
685 parts[0].start_time_ms = kPinnedTitleChangeAnimationStart1MS; | |
686 parts[0].end_time_ms = kPinnedTitleChangeAnimationEnd1MS; | |
687 parts[2].start_time_ms = kPinnedTitleChangeAnimationStart3MS; | |
688 parts[2].end_time_ms = kPinnedTitleChangeAnimationEnd3MS; | |
689 base::TimeDelta timeout = base::TimeDelta::FromMilliseconds( | |
690 kPinnedTitleChangeAnimationIntervalMS); | |
691 pinned_title_change_animation_.reset( | |
692 new gfx::MultiAnimation(parts, timeout)); | |
693 if (animation_container_.get()) | |
694 pinned_title_change_animation_->SetContainer(animation_container_.get()); | |
695 pinned_title_change_animation_->set_delegate(this); | |
696 } | |
697 pinned_title_change_animation_->Start(); | |
698 } | 679 } |
699 | 680 |
700 void Tab::StopPinnedTabTitleAnimation() { | 681 void Tab::StopPinnedTabTitleAnimation() { |
701 StopAndDeleteAnimation(std::move(pinned_title_change_animation_)); | 682 pinned_title_change_animation_->Stop(); |
702 } | 683 } |
703 | 684 |
704 int Tab::GetWidthOfLargestSelectableRegion() const { | 685 int Tab::GetWidthOfLargestSelectableRegion() const { |
705 // Assume the entire region to the left of the media indicator and/or close | 686 // Assume the entire region to the left of the media indicator and/or close |
706 // buttons is available for click-to-select. If neither are visible, the | 687 // buttons is available for click-to-select. If neither are visible, the |
707 // entire tab region is available. | 688 // entire tab region is available. |
708 const int indicator_left = showing_media_indicator_ ? | 689 const int indicator_left = showing_media_indicator_ ? |
709 media_indicator_button_->x() : width(); | 690 media_indicator_button_->x() : width(); |
710 const int close_button_left = showing_close_button_ ? | 691 const int close_button_left = showing_close_button_ ? |
711 close_button_->x() : width(); | 692 close_button_->x() : width(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 return (GetUnscaledEndcapWidth() - 4) / | 754 return (GetUnscaledEndcapWidth() - 4) / |
774 (GetMinimumInactiveSize().height() - 4); | 755 (GetMinimumInactiveSize().height() - 4); |
775 } | 756 } |
776 | 757 |
777 //////////////////////////////////////////////////////////////////////////////// | 758 //////////////////////////////////////////////////////////////////////////////// |
778 // Tab, AnimationDelegate overrides: | 759 // Tab, AnimationDelegate overrides: |
779 | 760 |
780 void Tab::AnimationProgressed(const gfx::Animation* animation) { | 761 void Tab::AnimationProgressed(const gfx::Animation* animation) { |
781 // Ignore if the pulse animation is being performed on active tab because | 762 // Ignore if the pulse animation is being performed on active tab because |
782 // it repaints the same image. See |Tab::PaintTabBackground()|. | 763 // it repaints the same image. See |Tab::PaintTabBackground()|. |
783 if (animation == pulse_animation_.get() && IsActive()) | 764 if ((animation != pulse_animation_.get()) || !IsActive()) |
784 return; | 765 SchedulePaint(); |
785 SchedulePaint(); | |
786 } | 766 } |
787 | 767 |
788 void Tab::AnimationCanceled(const gfx::Animation* animation) { | 768 void Tab::AnimationCanceled(const gfx::Animation* animation) { |
789 SchedulePaint(); | 769 SchedulePaint(); |
790 } | 770 } |
791 | 771 |
792 void Tab::AnimationEnded(const gfx::Animation* animation) { | 772 void Tab::AnimationEnded(const gfx::Animation* animation) { |
793 SchedulePaint(); | 773 SchedulePaint(); |
794 } | 774 } |
795 | 775 |
796 //////////////////////////////////////////////////////////////////////////////// | 776 //////////////////////////////////////////////////////////////////////////////// |
797 // Tab, views::ButtonListener overrides: | 777 // Tab, views::ButtonListener overrides: |
798 | 778 |
799 void Tab::ButtonPressed(views::Button* sender, const ui::Event& event) { | 779 void Tab::ButtonPressed(views::Button* sender, const ui::Event& event) { |
800 if (media_indicator_button_ && media_indicator_button_->visible()) { | 780 if (!media_indicator_button_ || !media_indicator_button_->visible()) |
801 if (media_indicator_button_->enabled()) | |
802 content::RecordAction(UserMetricsAction("CloseTab_MuteToggleAvailable")); | |
803 else if (data_.media_state == TAB_MEDIA_STATE_AUDIO_PLAYING) | |
804 content::RecordAction(UserMetricsAction("CloseTab_AudioIndicator")); | |
805 else | |
806 content::RecordAction(UserMetricsAction("CloseTab_RecordingIndicator")); | |
807 } else { | |
808 content::RecordAction(UserMetricsAction("CloseTab_NoMediaIndicator")); | 781 content::RecordAction(UserMetricsAction("CloseTab_NoMediaIndicator")); |
809 } | 782 else if (media_indicator_button_->enabled()) |
| 783 content::RecordAction(UserMetricsAction("CloseTab_MuteToggleAvailable")); |
| 784 else if (data_.media_state == TAB_MEDIA_STATE_AUDIO_PLAYING) |
| 785 content::RecordAction(UserMetricsAction("CloseTab_AudioIndicator")); |
| 786 else |
| 787 content::RecordAction(UserMetricsAction("CloseTab_RecordingIndicator")); |
810 | 788 |
811 const CloseTabSource source = | 789 const CloseTabSource source = |
812 (event.type() == ui::ET_MOUSE_RELEASED && | 790 (event.type() == ui::ET_MOUSE_RELEASED && |
813 (event.flags() & ui::EF_FROM_TOUCH) == 0) ? CLOSE_TAB_FROM_MOUSE : | 791 !(event.flags() & ui::EF_FROM_TOUCH)) ? CLOSE_TAB_FROM_MOUSE |
814 CLOSE_TAB_FROM_TOUCH; | 792 : CLOSE_TAB_FROM_TOUCH; |
815 DCHECK_EQ(close_button_, sender); | 793 DCHECK_EQ(close_button_, sender); |
816 controller_->CloseTab(this, source); | 794 controller_->CloseTab(this, source); |
817 if (event.type() == ui::ET_GESTURE_TAP) | 795 if (event.type() == ui::ET_GESTURE_TAP) |
818 TouchUMA::RecordGestureAction(TouchUMA::GESTURE_TABCLOSE_TAP); | 796 TouchUMA::RecordGestureAction(TouchUMA::GESTURE_TABCLOSE_TAP); |
819 } | 797 } |
820 | 798 |
821 //////////////////////////////////////////////////////////////////////////////// | 799 //////////////////////////////////////////////////////////////////////////////// |
822 // Tab, views::ContextMenuController overrides: | 800 // Tab, views::ContextMenuController overrides: |
823 | 801 |
824 void Tab::ShowContextMenuForView(views::View* source, | 802 void Tab::ShowContextMenuForView(views::View* source, |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 void Tab::PaintTab(gfx::Canvas* canvas) { | 1201 void Tab::PaintTab(gfx::Canvas* canvas) { |
1224 PaintTabBackground(canvas); | 1202 PaintTabBackground(canvas); |
1225 | 1203 |
1226 if (showing_icon_) | 1204 if (showing_icon_) |
1227 PaintIcon(canvas); | 1205 PaintIcon(canvas); |
1228 } | 1206 } |
1229 | 1207 |
1230 void Tab::PaintImmersiveTab(gfx::Canvas* canvas) { | 1208 void Tab::PaintImmersiveTab(gfx::Canvas* canvas) { |
1231 // Use transparency for the draw-attention animation. | 1209 // Use transparency for the draw-attention animation. |
1232 int alpha = 255; | 1210 int alpha = 255; |
1233 if (pulse_animation_ && pulse_animation_->is_animating() && !data().pinned) { | 1211 if (pulse_animation_->is_animating() && !data().pinned) { |
1234 alpha = pulse_animation_->CurrentValueBetween( | 1212 alpha = pulse_animation_->CurrentValueBetween( |
1235 255, static_cast<int>(255 * kImmersiveTabMinThrobOpacity)); | 1213 255, gfx::ToRoundedInt(255 * kImmersiveTabMinThrobOpacity)); |
1236 } | 1214 } |
1237 | 1215 |
1238 // Draw a gray rectangle to represent the tab. This works for pinned tabs as | 1216 // Draw a gray rectangle to represent the tab. This works for pinned tabs as |
1239 // well as regular ones. The active tab has a brigher bar. | 1217 // well as regular ones. The active tab has a brigher bar. |
1240 SkColor color = | 1218 SkColor color = |
1241 IsActive() ? kImmersiveActiveTabColor : kImmersiveInactiveTabColor; | 1219 IsActive() ? kImmersiveActiveTabColor : kImmersiveInactiveTabColor; |
1242 gfx::Rect bar_rect = GetImmersiveBarRect(); | 1220 gfx::Rect bar_rect = GetImmersiveBarRect(); |
1243 canvas->FillRect(bar_rect, SkColorSetA(color, alpha)); | 1221 canvas->FillRect(bar_rect, SkColorSetA(color, alpha)); |
1244 | 1222 |
1245 // Paint network activity indicator. | 1223 // Paint network activity indicator. |
(...skipping 27 matching lines...) Expand all Loading... |
1273 | 1251 |
1274 void Tab::PaintTabBackground(gfx::Canvas* canvas) { | 1252 void Tab::PaintTabBackground(gfx::Canvas* canvas) { |
1275 const int kActiveTabFillId = IDR_THEME_TOOLBAR; | 1253 const int kActiveTabFillId = IDR_THEME_TOOLBAR; |
1276 const bool has_custom_image = | 1254 const bool has_custom_image = |
1277 GetThemeProvider()->HasCustomImage(kActiveTabFillId); | 1255 GetThemeProvider()->HasCustomImage(kActiveTabFillId); |
1278 const int y_offset = -GetYInsetForActiveTabBackground(); | 1256 const int y_offset = -GetYInsetForActiveTabBackground(); |
1279 if (IsActive()) { | 1257 if (IsActive()) { |
1280 PaintTabBackgroundUsingFillId(canvas, true, kActiveTabFillId, | 1258 PaintTabBackgroundUsingFillId(canvas, true, kActiveTabFillId, |
1281 has_custom_image, y_offset); | 1259 has_custom_image, y_offset); |
1282 } else { | 1260 } else { |
1283 if (pinned_title_change_animation_ && | 1261 if (pinned_title_change_animation_->is_animating()) |
1284 pinned_title_change_animation_->is_animating()) | |
1285 PaintInactiveTabBackgroundWithTitleChange(canvas); | 1262 PaintInactiveTabBackgroundWithTitleChange(canvas); |
1286 else | 1263 else |
1287 PaintInactiveTabBackground(canvas); | 1264 PaintInactiveTabBackground(canvas); |
1288 | 1265 |
1289 const double throb_value = GetThrobValue(); | 1266 const double throb_value = GetThrobValue(); |
1290 if (throb_value > 0) { | 1267 if (throb_value > 0) { |
1291 canvas->SaveLayerAlpha(gfx::ToRoundedInt(throb_value * 0xff), | 1268 canvas->SaveLayerAlpha(gfx::ToRoundedInt(throb_value * 0xff), |
1292 GetLocalBounds()); | 1269 GetLocalBounds()); |
1293 PaintTabBackgroundUsingFillId(canvas, true, kActiveTabFillId, | 1270 PaintTabBackgroundUsingFillId(canvas, true, kActiveTabFillId, |
1294 has_custom_image, y_offset); | 1271 has_custom_image, y_offset); |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1619 } | 1596 } |
1620 | 1597 |
1621 double Tab::GetThrobValue() { | 1598 double Tab::GetThrobValue() { |
1622 const bool is_selected = IsSelected(); | 1599 const bool is_selected = IsSelected(); |
1623 double val = is_selected ? kSelectedTabOpacity : 0; | 1600 double val = is_selected ? kSelectedTabOpacity : 0; |
1624 const double offset = | 1601 const double offset = |
1625 is_selected ? (kSelectedTabThrobScale * kHoverOpacity) : kHoverOpacity; | 1602 is_selected ? (kSelectedTabThrobScale * kHoverOpacity) : kHoverOpacity; |
1626 | 1603 |
1627 // Showing both the pulse and title change animation at the same time is too | 1604 // Showing both the pulse and title change animation at the same time is too |
1628 // much. | 1605 // much. |
1629 if (pulse_animation_ && pulse_animation_->is_animating() && | 1606 if (pulse_animation_->is_animating() && |
1630 (!pinned_title_change_animation_ || | 1607 !pinned_title_change_animation_->is_animating()) { |
1631 !pinned_title_change_animation_->is_animating())) { | |
1632 val += pulse_animation_->GetCurrentValue() * offset; | 1608 val += pulse_animation_->GetCurrentValue() * offset; |
1633 } else if (hover_controller_.ShouldDraw()) { | 1609 } else if (hover_controller_.ShouldDraw()) { |
1634 val += hover_controller_.GetAnimationValue() * offset; | 1610 val += hover_controller_.GetAnimationValue() * offset; |
1635 } | 1611 } |
1636 return val; | 1612 return val; |
1637 } | 1613 } |
1638 | 1614 |
1639 void Tab::SetFaviconHidingOffset(int offset) { | 1615 void Tab::SetFaviconHidingOffset(int offset) { |
1640 favicon_hiding_offset_ = offset; | 1616 favicon_hiding_offset_ = offset; |
1641 ScheduleIconPaint(); | 1617 ScheduleIconPaint(); |
(...skipping 21 matching lines...) Expand all Loading... |
1663 &close_button_normal_image); | 1639 &close_button_normal_image); |
1664 } | 1640 } |
1665 } | 1641 } |
1666 | 1642 |
1667 void Tab::ScheduleIconPaint() { | 1643 void Tab::ScheduleIconPaint() { |
1668 gfx::Rect bounds = favicon_bounds_; | 1644 gfx::Rect bounds = favicon_bounds_; |
1669 if (bounds.IsEmpty()) | 1645 if (bounds.IsEmpty()) |
1670 return; | 1646 return; |
1671 | 1647 |
1672 // Extends the area to the bottom when the crash animation is in progress. | 1648 // Extends the area to the bottom when the crash animation is in progress. |
1673 if (crash_icon_animation_) | 1649 if (crash_icon_animation_->is_animating()) |
1674 bounds.set_height(height() - bounds.y()); | 1650 bounds.set_height(height() - bounds.y()); |
1675 bounds.set_x(GetMirroredXForRect(bounds)); | 1651 bounds.set_x(GetMirroredXForRect(bounds)); |
1676 SchedulePaintInRect(bounds); | 1652 SchedulePaintInRect(bounds); |
1677 } | 1653 } |
1678 | 1654 |
1679 void Tab::GetFillPath(float scale, SkPath* fill) const { | 1655 void Tab::GetFillPath(float scale, SkPath* fill) const { |
1680 const float right = width() * scale; | 1656 const float right = width() * scale; |
1681 const float bottom = height() * scale; | 1657 const float bottom = height() * scale; |
1682 const float unscaled_endcap_width = GetUnscaledEndcapWidth(); | 1658 const float unscaled_endcap_width = GetUnscaledEndcapWidth(); |
1683 | 1659 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1780 inactive_images_.image_c = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_CENTER); | 1756 inactive_images_.image_c = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_CENTER); |
1781 inactive_images_.image_r = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_RIGHT); | 1757 inactive_images_.image_r = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_RIGHT); |
1782 inactive_images_.l_width = inactive_images_.image_l->width(); | 1758 inactive_images_.l_width = inactive_images_.image_l->width(); |
1783 inactive_images_.r_width = inactive_images_.image_r->width(); | 1759 inactive_images_.r_width = inactive_images_.image_r->width(); |
1784 | 1760 |
1785 mask_images_.image_l = rb.GetImageSkiaNamed(IDR_TAB_ALPHA_LEFT); | 1761 mask_images_.image_l = rb.GetImageSkiaNamed(IDR_TAB_ALPHA_LEFT); |
1786 mask_images_.image_r = rb.GetImageSkiaNamed(IDR_TAB_ALPHA_RIGHT); | 1762 mask_images_.image_r = rb.GetImageSkiaNamed(IDR_TAB_ALPHA_RIGHT); |
1787 mask_images_.l_width = mask_images_.image_l->width(); | 1763 mask_images_.l_width = mask_images_.image_l->width(); |
1788 mask_images_.r_width = mask_images_.image_r->width(); | 1764 mask_images_.r_width = mask_images_.image_r->width(); |
1789 } | 1765 } |
OLD | NEW |