| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/media_indicator_button.h" | 5 #include "chrome/browser/ui/views/tabs/media_indicator_button.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "chrome/browser/ui/views/tabs/tab.h" | 8 #include "chrome/browser/ui/views/tabs/tab.h" |
| 9 #include "chrome/browser/ui/views/tabs/tab_controller.h" | 9 #include "chrome/browser/ui/views/tabs/tab_controller.h" |
| 10 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" | 10 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 : button_(button) {} | 42 : button_(button) {} |
| 43 ~FadeAnimationDelegate() override {} | 43 ~FadeAnimationDelegate() override {} |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 // gfx::AnimationDelegate | 46 // gfx::AnimationDelegate |
| 47 void AnimationProgressed(const gfx::Animation* animation) override { | 47 void AnimationProgressed(const gfx::Animation* animation) override { |
| 48 button_->SchedulePaint(); | 48 button_->SchedulePaint(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void AnimationCanceled(const gfx::Animation* animation) override { | 51 void AnimationCanceled(const gfx::Animation* animation) override { |
| 52 button_->showing_media_state_ = button_->media_state_; | 52 AnimationEnded(animation); |
| 53 button_->SchedulePaint(); | |
| 54 } | 53 } |
| 55 | 54 |
| 56 void AnimationEnded(const gfx::Animation* animation) override { | 55 void AnimationEnded(const gfx::Animation* animation) override { |
| 57 button_->showing_media_state_ = button_->media_state_; | 56 button_->showing_media_state_ = button_->media_state_; |
| 58 button_->SchedulePaint(); | 57 button_->parent_tab_->MediaStateChanged(); |
| 59 } | 58 } |
| 60 | 59 |
| 61 MediaIndicatorButton* const button_; | 60 MediaIndicatorButton* const button_; |
| 62 | 61 |
| 63 DISALLOW_COPY_AND_ASSIGN(FadeAnimationDelegate); | 62 DISALLOW_COPY_AND_ASSIGN(FadeAnimationDelegate); |
| 64 }; | 63 }; |
| 65 | 64 |
| 66 MediaIndicatorButton::MediaIndicatorButton(Tab* parent_tab) | 65 MediaIndicatorButton::MediaIndicatorButton(Tab* parent_tab) |
| 67 : views::ImageButton(NULL), | 66 : views::ImageButton(NULL), |
| 68 parent_tab_(parent_tab), | 67 parent_tab_(parent_tab), |
| 69 media_state_(TAB_MEDIA_STATE_NONE), | 68 media_state_(TAB_MEDIA_STATE_NONE), |
| 70 showing_media_state_(TAB_MEDIA_STATE_NONE) { | 69 showing_media_state_(TAB_MEDIA_STATE_NONE) { |
| 71 DCHECK(parent_tab_); | 70 DCHECK(parent_tab_); |
| 72 SetEventTargeter( | 71 SetEventTargeter( |
| 73 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); | 72 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
| 74 } | 73 } |
| 75 | 74 |
| 76 MediaIndicatorButton::~MediaIndicatorButton() {} | 75 MediaIndicatorButton::~MediaIndicatorButton() {} |
| 77 | 76 |
| 78 void MediaIndicatorButton::TransitionToMediaState(TabMediaState next_state) { | 77 void MediaIndicatorButton::TransitionToMediaState(TabMediaState next_state) { |
| 79 if (next_state == media_state_) | 78 if (next_state == media_state_) |
| 80 return; | 79 return; |
| 81 | 80 |
| 81 TabMediaState previous_media_showing_state = showing_media_state_; |
| 82 |
| 82 if (next_state != TAB_MEDIA_STATE_NONE) | 83 if (next_state != TAB_MEDIA_STATE_NONE) |
| 83 ResetImages(next_state); | 84 ResetImages(next_state); |
| 84 | 85 |
| 85 if ((media_state_ == TAB_MEDIA_STATE_AUDIO_PLAYING && | 86 if ((media_state_ == TAB_MEDIA_STATE_AUDIO_PLAYING && |
| 86 next_state == TAB_MEDIA_STATE_AUDIO_MUTING) || | 87 next_state == TAB_MEDIA_STATE_AUDIO_MUTING) || |
| 87 (media_state_ == TAB_MEDIA_STATE_AUDIO_MUTING && | 88 (media_state_ == TAB_MEDIA_STATE_AUDIO_MUTING && |
| 88 next_state == TAB_MEDIA_STATE_AUDIO_PLAYING) || | 89 next_state == TAB_MEDIA_STATE_AUDIO_PLAYING) || |
| 89 (media_state_ == TAB_MEDIA_STATE_AUDIO_MUTING && | 90 (media_state_ == TAB_MEDIA_STATE_AUDIO_MUTING && |
| 90 next_state == TAB_MEDIA_STATE_NONE)) { | 91 next_state == TAB_MEDIA_STATE_NONE)) { |
| 91 // Instant user feedback: No fade animation. | 92 // Instant user feedback: No fade animation. |
| 92 showing_media_state_ = next_state; | 93 showing_media_state_ = next_state; |
| 93 fade_animation_.reset(); | 94 fade_animation_.reset(); |
| 94 } else { | 95 } else { |
| 95 if (next_state == TAB_MEDIA_STATE_NONE) | 96 if (next_state == TAB_MEDIA_STATE_NONE) |
| 96 showing_media_state_ = media_state_; // Fading-out indicator. | 97 showing_media_state_ = media_state_; // Fading-out indicator. |
| 97 else | 98 else |
| 98 showing_media_state_ = next_state; // Fading-in to next indicator. | 99 showing_media_state_ = next_state; // Fading-in to next indicator. |
| 99 fade_animation_ = chrome::CreateTabMediaIndicatorFadeAnimation(next_state); | 100 fade_animation_ = chrome::CreateTabMediaIndicatorFadeAnimation(next_state); |
| 100 if (!fade_animation_delegate_) | 101 if (!fade_animation_delegate_) |
| 101 fade_animation_delegate_.reset(new FadeAnimationDelegate(this)); | 102 fade_animation_delegate_.reset(new FadeAnimationDelegate(this)); |
| 102 fade_animation_->set_delegate(fade_animation_delegate_.get()); | 103 fade_animation_->set_delegate(fade_animation_delegate_.get()); |
| 103 fade_animation_->Start(); | 104 fade_animation_->Start(); |
| 104 } | 105 } |
| 105 | 106 |
| 106 media_state_ = next_state; | 107 media_state_ = next_state; |
| 107 | 108 |
| 109 if (previous_media_showing_state != showing_media_state_) |
| 110 parent_tab_->MediaStateChanged(); |
| 111 |
| 108 UpdateEnabledForMuteToggle(); | 112 UpdateEnabledForMuteToggle(); |
| 109 | 113 |
| 110 // An indicator state change should be made visible immediately, instead of | 114 // An indicator state change should be made visible immediately, instead of |
| 111 // the user being surprised when their mouse leaves the button. | 115 // the user being surprised when their mouse leaves the button. |
| 112 if (state() == views::CustomButton::STATE_HOVERED) { | 116 if (state() == views::CustomButton::STATE_HOVERED) { |
| 113 SetState(enabled() ? views::CustomButton::STATE_NORMAL : | 117 SetState(enabled() ? views::CustomButton::STATE_NORMAL : |
| 114 views::CustomButton::STATE_DISABLED); | 118 views::CustomButton::STATE_DISABLED); |
| 115 } | 119 } |
| 116 | 120 |
| 117 // Note: The calls to SetImage(), SetEnabled(), and SetState() above will call | 121 // Note: The calls to SetImage(), SetEnabled(), and SetState() above will call |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 SkColor color = parent_tab_->button_color(); | 260 SkColor color = parent_tab_->button_color(); |
| 257 gfx::ImageSkia indicator_image = | 261 gfx::ImageSkia indicator_image = |
| 258 chrome::GetTabMediaIndicatorImage(state, color).AsImageSkia(); | 262 chrome::GetTabMediaIndicatorImage(state, color).AsImageSkia(); |
| 259 SetImage(views::CustomButton::STATE_NORMAL, &indicator_image); | 263 SetImage(views::CustomButton::STATE_NORMAL, &indicator_image); |
| 260 SetImage(views::CustomButton::STATE_DISABLED, &indicator_image); | 264 SetImage(views::CustomButton::STATE_DISABLED, &indicator_image); |
| 261 gfx::ImageSkia affordance_image = | 265 gfx::ImageSkia affordance_image = |
| 262 chrome::GetTabMediaIndicatorAffordanceImage(state, color).AsImageSkia(); | 266 chrome::GetTabMediaIndicatorAffordanceImage(state, color).AsImageSkia(); |
| 263 SetImage(views::CustomButton::STATE_HOVERED, &affordance_image); | 267 SetImage(views::CustomButton::STATE_HOVERED, &affordance_image); |
| 264 SetImage(views::CustomButton::STATE_PRESSED, &affordance_image); | 268 SetImage(views::CustomButton::STATE_PRESSED, &affordance_image); |
| 265 } | 269 } |
| OLD | NEW |