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 19 matching lines...) Expand all Loading... | |
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 if (!should_display_crashed_favicon_ && |
636 !crash_icon_animation_->is_animating()) { | |
624 data_.media_state = TAB_MEDIA_STATE_NONE; | 637 data_.media_state = TAB_MEDIA_STATE_NONE; |
625 crash_icon_animation_.reset(new FaviconCrashAnimation(this)); | |
626 crash_icon_animation_->Start(); | 638 crash_icon_animation_->Start(); |
627 } | 639 } |
628 } else { | 640 } else { |
629 if (crash_icon_animation_) | 641 if (crash_icon_animation_->is_animating()) |
630 crash_icon_animation_.reset(); | 642 crash_icon_animation_->Stop(); |
sky
2016/02/19 05:01:04
Indenting is off here (looks like it was before to
Peter Kasting
2016/02/22 07:39:05
But we know that is_animating() is true from the c
sky
2016/02/22 16:42:08
Sorry if I wasn't clear. I'm suggesting there is n
Peter Kasting
2016/02/24 12:24:49
Done.
| |
631 should_display_crashed_favicon_ = false; | 643 should_display_crashed_favicon_ = false; |
632 favicon_hiding_offset_ = 0; | 644 favicon_hiding_offset_ = 0; |
633 } | 645 } |
634 | 646 |
635 if (data_.media_state != old.media_state) | 647 if (data_.media_state != old.media_state) |
636 media_indicator_button_->TransitionToMediaState(data_.media_state); | 648 media_indicator_button_->TransitionToMediaState(data_.media_state); |
637 | 649 |
638 if (old.pinned != data_.pinned) | 650 if (old.pinned != data_.pinned) |
639 StopPinnedTabTitleAnimation(); | 651 StopPinnedTabTitleAnimation(); |
640 | 652 |
641 DataChanged(old); | 653 DataChanged(old); |
642 | 654 |
643 Layout(); | 655 Layout(); |
644 SchedulePaint(); | 656 SchedulePaint(); |
645 } | 657 } |
646 | 658 |
647 void Tab::UpdateLoadingAnimation(TabRendererData::NetworkState state) { | 659 void Tab::UpdateLoadingAnimation(TabRendererData::NetworkState state) { |
648 if (state == data_.network_state && | 660 if (state == data_.network_state && |
649 state == TabRendererData::NETWORK_STATE_NONE) { | 661 state == TabRendererData::NETWORK_STATE_NONE) { |
650 // If the network state is none and hasn't changed, do nothing. Otherwise we | 662 // If the network state is none and hasn't changed, do nothing. Otherwise we |
651 // need to advance the animation frame. | 663 // need to advance the animation frame. |
652 return; | 664 return; |
653 } | 665 } |
654 | 666 |
655 data_.network_state = state; | 667 data_.network_state = state; |
656 AdvanceLoadingAnimation(); | 668 AdvanceLoadingAnimation(); |
657 } | 669 } |
658 | 670 |
659 void Tab::StartPulse() { | 671 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()); | 672 pulse_animation_->StartThrobbing(std::numeric_limits<int>::max()); |
665 } | 673 } |
666 | 674 |
667 void Tab::StopPulse() { | 675 void Tab::StopPulse() { |
668 StopAndDeleteAnimation(std::move(pulse_animation_)); | 676 pulse_animation_->Stop(); |
669 } | 677 } |
670 | 678 |
671 void Tab::StartPinnedTabTitleAnimation() { | 679 void Tab::StartPinnedTabTitleAnimation() { |
672 if (!data().pinned) | 680 if (data().pinned) |
673 return; | 681 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 } | 682 } |
699 | 683 |
700 void Tab::StopPinnedTabTitleAnimation() { | 684 void Tab::StopPinnedTabTitleAnimation() { |
701 StopAndDeleteAnimation(std::move(pinned_title_change_animation_)); | 685 pinned_title_change_animation_->Stop(); |
702 } | 686 } |
703 | 687 |
704 int Tab::GetWidthOfLargestSelectableRegion() const { | 688 int Tab::GetWidthOfLargestSelectableRegion() const { |
705 // Assume the entire region to the left of the media indicator and/or close | 689 // 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 | 690 // buttons is available for click-to-select. If neither are visible, the |
707 // entire tab region is available. | 691 // entire tab region is available. |
708 const int indicator_left = showing_media_indicator_ ? | 692 const int indicator_left = showing_media_indicator_ ? |
709 media_indicator_button_->x() : width(); | 693 media_indicator_button_->x() : width(); |
710 const int close_button_left = showing_close_button_ ? | 694 const int close_button_left = showing_close_button_ ? |
711 close_button_->x() : width(); | 695 close_button_->x() : width(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
773 return (GetUnscaledEndcapWidth() - 4) / | 757 return (GetUnscaledEndcapWidth() - 4) / |
774 (GetMinimumInactiveSize().height() - 4); | 758 (GetMinimumInactiveSize().height() - 4); |
775 } | 759 } |
776 | 760 |
777 //////////////////////////////////////////////////////////////////////////////// | 761 //////////////////////////////////////////////////////////////////////////////// |
778 // Tab, AnimationDelegate overrides: | 762 // Tab, AnimationDelegate overrides: |
779 | 763 |
780 void Tab::AnimationProgressed(const gfx::Animation* animation) { | 764 void Tab::AnimationProgressed(const gfx::Animation* animation) { |
781 // Ignore if the pulse animation is being performed on active tab because | 765 // Ignore if the pulse animation is being performed on active tab because |
782 // it repaints the same image. See |Tab::PaintTabBackground()|. | 766 // it repaints the same image. See |Tab::PaintTabBackground()|. |
783 if (animation == pulse_animation_.get() && IsActive()) | 767 if ((animation != pulse_animation_.get()) || !IsActive()) |
784 return; | 768 SchedulePaint(); |
785 SchedulePaint(); | |
786 } | 769 } |
787 | 770 |
788 void Tab::AnimationCanceled(const gfx::Animation* animation) { | 771 void Tab::AnimationCanceled(const gfx::Animation* animation) { |
789 SchedulePaint(); | 772 SchedulePaint(); |
790 } | 773 } |
791 | 774 |
792 void Tab::AnimationEnded(const gfx::Animation* animation) { | 775 void Tab::AnimationEnded(const gfx::Animation* animation) { |
793 SchedulePaint(); | 776 SchedulePaint(); |
794 } | 777 } |
795 | 778 |
796 //////////////////////////////////////////////////////////////////////////////// | 779 //////////////////////////////////////////////////////////////////////////////// |
797 // Tab, views::ButtonListener overrides: | 780 // Tab, views::ButtonListener overrides: |
798 | 781 |
799 void Tab::ButtonPressed(views::Button* sender, const ui::Event& event) { | 782 void Tab::ButtonPressed(views::Button* sender, const ui::Event& event) { |
800 if (media_indicator_button_ && media_indicator_button_->visible()) { | 783 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")); | 784 content::RecordAction(UserMetricsAction("CloseTab_NoMediaIndicator")); |
809 } | 785 else if (media_indicator_button_->enabled()) |
786 content::RecordAction(UserMetricsAction("CloseTab_MuteToggleAvailable")); | |
787 else if (data_.media_state == TAB_MEDIA_STATE_AUDIO_PLAYING) | |
788 content::RecordAction(UserMetricsAction("CloseTab_AudioIndicator")); | |
789 else | |
790 content::RecordAction(UserMetricsAction("CloseTab_RecordingIndicator")); | |
810 | 791 |
811 const CloseTabSource source = | 792 const CloseTabSource source = |
812 (event.type() == ui::ET_MOUSE_RELEASED && | 793 (event.type() == ui::ET_MOUSE_RELEASED && |
813 (event.flags() & ui::EF_FROM_TOUCH) == 0) ? CLOSE_TAB_FROM_MOUSE : | 794 !(event.flags() & ui::EF_FROM_TOUCH)) ? CLOSE_TAB_FROM_MOUSE |
814 CLOSE_TAB_FROM_TOUCH; | 795 : CLOSE_TAB_FROM_TOUCH; |
815 DCHECK_EQ(close_button_, sender); | 796 DCHECK_EQ(close_button_, sender); |
816 controller_->CloseTab(this, source); | 797 controller_->CloseTab(this, source); |
817 if (event.type() == ui::ET_GESTURE_TAP) | 798 if (event.type() == ui::ET_GESTURE_TAP) |
818 TouchUMA::RecordGestureAction(TouchUMA::GESTURE_TABCLOSE_TAP); | 799 TouchUMA::RecordGestureAction(TouchUMA::GESTURE_TABCLOSE_TAP); |
819 } | 800 } |
820 | 801 |
821 //////////////////////////////////////////////////////////////////////////////// | 802 //////////////////////////////////////////////////////////////////////////////// |
822 // Tab, views::ContextMenuController overrides: | 803 // Tab, views::ContextMenuController overrides: |
823 | 804 |
824 void Tab::ShowContextMenuForView(views::View* source, | 805 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) { | 1204 void Tab::PaintTab(gfx::Canvas* canvas) { |
1224 PaintTabBackground(canvas); | 1205 PaintTabBackground(canvas); |
1225 | 1206 |
1226 if (showing_icon_) | 1207 if (showing_icon_) |
1227 PaintIcon(canvas); | 1208 PaintIcon(canvas); |
1228 } | 1209 } |
1229 | 1210 |
1230 void Tab::PaintImmersiveTab(gfx::Canvas* canvas) { | 1211 void Tab::PaintImmersiveTab(gfx::Canvas* canvas) { |
1231 // Use transparency for the draw-attention animation. | 1212 // Use transparency for the draw-attention animation. |
1232 int alpha = 255; | 1213 int alpha = 255; |
1233 if (pulse_animation_ && pulse_animation_->is_animating() && !data().pinned) { | 1214 if (pulse_animation_->is_animating() && !data().pinned) { |
1234 alpha = pulse_animation_->CurrentValueBetween( | 1215 alpha = pulse_animation_->CurrentValueBetween( |
1235 255, static_cast<int>(255 * kImmersiveTabMinThrobOpacity)); | 1216 255, gfx::ToRoundedInt(255 * kImmersiveTabMinThrobOpacity)); |
1236 } | 1217 } |
1237 | 1218 |
1238 // Draw a gray rectangle to represent the tab. This works for pinned tabs as | 1219 // 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. | 1220 // well as regular ones. The active tab has a brigher bar. |
1240 SkColor color = | 1221 SkColor color = |
1241 IsActive() ? kImmersiveActiveTabColor : kImmersiveInactiveTabColor; | 1222 IsActive() ? kImmersiveActiveTabColor : kImmersiveInactiveTabColor; |
1242 gfx::Rect bar_rect = GetImmersiveBarRect(); | 1223 gfx::Rect bar_rect = GetImmersiveBarRect(); |
1243 canvas->FillRect(bar_rect, SkColorSetA(color, alpha)); | 1224 canvas->FillRect(bar_rect, SkColorSetA(color, alpha)); |
1244 | 1225 |
1245 // Paint network activity indicator. | 1226 // Paint network activity indicator. |
(...skipping 27 matching lines...) Expand all Loading... | |
1273 | 1254 |
1274 void Tab::PaintTabBackground(gfx::Canvas* canvas) { | 1255 void Tab::PaintTabBackground(gfx::Canvas* canvas) { |
1275 const int kActiveTabFillId = IDR_THEME_TOOLBAR; | 1256 const int kActiveTabFillId = IDR_THEME_TOOLBAR; |
1276 const bool has_custom_image = | 1257 const bool has_custom_image = |
1277 GetThemeProvider()->HasCustomImage(kActiveTabFillId); | 1258 GetThemeProvider()->HasCustomImage(kActiveTabFillId); |
1278 const int y_offset = -GetYInsetForActiveTabBackground(); | 1259 const int y_offset = -GetYInsetForActiveTabBackground(); |
1279 if (IsActive()) { | 1260 if (IsActive()) { |
1280 PaintTabBackgroundUsingFillId(canvas, true, kActiveTabFillId, | 1261 PaintTabBackgroundUsingFillId(canvas, true, kActiveTabFillId, |
1281 has_custom_image, y_offset); | 1262 has_custom_image, y_offset); |
1282 } else { | 1263 } else { |
1283 if (pinned_title_change_animation_ && | 1264 if (pinned_title_change_animation_->is_animating()) |
1284 pinned_title_change_animation_->is_animating()) | |
1285 PaintInactiveTabBackgroundWithTitleChange(canvas); | 1265 PaintInactiveTabBackgroundWithTitleChange(canvas); |
1286 else | 1266 else |
1287 PaintInactiveTabBackground(canvas); | 1267 PaintInactiveTabBackground(canvas); |
1288 | 1268 |
1289 const double throb_value = GetThrobValue(); | 1269 const double throb_value = GetThrobValue(); |
1290 if (throb_value > 0) { | 1270 if (throb_value > 0) { |
1291 canvas->SaveLayerAlpha(gfx::ToRoundedInt(throb_value * 0xff), | 1271 canvas->SaveLayerAlpha(gfx::ToRoundedInt(throb_value * 0xff), |
1292 GetLocalBounds()); | 1272 GetLocalBounds()); |
1293 PaintTabBackgroundUsingFillId(canvas, true, kActiveTabFillId, | 1273 PaintTabBackgroundUsingFillId(canvas, true, kActiveTabFillId, |
1294 has_custom_image, y_offset); | 1274 has_custom_image, y_offset); |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1619 } | 1599 } |
1620 | 1600 |
1621 double Tab::GetThrobValue() { | 1601 double Tab::GetThrobValue() { |
1622 const bool is_selected = IsSelected(); | 1602 const bool is_selected = IsSelected(); |
1623 double val = is_selected ? kSelectedTabOpacity : 0; | 1603 double val = is_selected ? kSelectedTabOpacity : 0; |
1624 const double offset = | 1604 const double offset = |
1625 is_selected ? (kSelectedTabThrobScale * kHoverOpacity) : kHoverOpacity; | 1605 is_selected ? (kSelectedTabThrobScale * kHoverOpacity) : kHoverOpacity; |
1626 | 1606 |
1627 // Showing both the pulse and title change animation at the same time is too | 1607 // Showing both the pulse and title change animation at the same time is too |
1628 // much. | 1608 // much. |
1629 if (pulse_animation_ && pulse_animation_->is_animating() && | 1609 if (pulse_animation_->is_animating() && |
1630 (!pinned_title_change_animation_ || | 1610 !pinned_title_change_animation_->is_animating()) { |
1631 !pinned_title_change_animation_->is_animating())) { | |
1632 val += pulse_animation_->GetCurrentValue() * offset; | 1611 val += pulse_animation_->GetCurrentValue() * offset; |
1633 } else if (hover_controller_.ShouldDraw()) { | 1612 } else if (hover_controller_.ShouldDraw()) { |
1634 val += hover_controller_.GetAnimationValue() * offset; | 1613 val += hover_controller_.GetAnimationValue() * offset; |
1635 } | 1614 } |
1636 return val; | 1615 return val; |
1637 } | 1616 } |
1638 | 1617 |
1639 void Tab::SetFaviconHidingOffset(int offset) { | 1618 void Tab::SetFaviconHidingOffset(int offset) { |
1640 favicon_hiding_offset_ = offset; | 1619 favicon_hiding_offset_ = offset; |
1641 ScheduleIconPaint(); | 1620 ScheduleIconPaint(); |
(...skipping 21 matching lines...) Expand all Loading... | |
1663 &close_button_normal_image); | 1642 &close_button_normal_image); |
1664 } | 1643 } |
1665 } | 1644 } |
1666 | 1645 |
1667 void Tab::ScheduleIconPaint() { | 1646 void Tab::ScheduleIconPaint() { |
1668 gfx::Rect bounds = favicon_bounds_; | 1647 gfx::Rect bounds = favicon_bounds_; |
1669 if (bounds.IsEmpty()) | 1648 if (bounds.IsEmpty()) |
1670 return; | 1649 return; |
1671 | 1650 |
1672 // Extends the area to the bottom when the crash animation is in progress. | 1651 // Extends the area to the bottom when the crash animation is in progress. |
1673 if (crash_icon_animation_) | 1652 if (crash_icon_animation_->is_animating()) |
1674 bounds.set_height(height() - bounds.y()); | 1653 bounds.set_height(height() - bounds.y()); |
1675 bounds.set_x(GetMirroredXForRect(bounds)); | 1654 bounds.set_x(GetMirroredXForRect(bounds)); |
1676 SchedulePaintInRect(bounds); | 1655 SchedulePaintInRect(bounds); |
1677 } | 1656 } |
1678 | 1657 |
1679 void Tab::GetFillPath(float scale, SkPath* fill) const { | 1658 void Tab::GetFillPath(float scale, SkPath* fill) const { |
1680 const float right = width() * scale; | 1659 const float right = width() * scale; |
1681 const float bottom = height() * scale; | 1660 const float bottom = height() * scale; |
1682 const float unscaled_endcap_width = GetUnscaledEndcapWidth(); | 1661 const float unscaled_endcap_width = GetUnscaledEndcapWidth(); |
1683 | 1662 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1780 inactive_images_.image_c = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_CENTER); | 1759 inactive_images_.image_c = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_CENTER); |
1781 inactive_images_.image_r = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_RIGHT); | 1760 inactive_images_.image_r = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_RIGHT); |
1782 inactive_images_.l_width = inactive_images_.image_l->width(); | 1761 inactive_images_.l_width = inactive_images_.image_l->width(); |
1783 inactive_images_.r_width = inactive_images_.image_r->width(); | 1762 inactive_images_.r_width = inactive_images_.image_r->width(); |
1784 | 1763 |
1785 mask_images_.image_l = rb.GetImageSkiaNamed(IDR_TAB_ALPHA_LEFT); | 1764 mask_images_.image_l = rb.GetImageSkiaNamed(IDR_TAB_ALPHA_LEFT); |
1786 mask_images_.image_r = rb.GetImageSkiaNamed(IDR_TAB_ALPHA_RIGHT); | 1765 mask_images_.image_r = rb.GetImageSkiaNamed(IDR_TAB_ALPHA_RIGHT); |
1787 mask_images_.l_width = mask_images_.image_l->width(); | 1766 mask_images_.l_width = mask_images_.image_l->width(); |
1788 mask_images_.r_width = mask_images_.image_r->width(); | 1767 mask_images_.r_width = mask_images_.image_r->width(); |
1789 } | 1768 } |
OLD | NEW |