Chromium Code Reviews| 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; |
| 80 bool previous_media_showing_state = showing_media_state_; | |
|
miu
2016/02/01 20:28:32
The type should be TabMediaState, not bool.
enne (OOO)
2016/02/01 20:36:33
Eep! Thanks.
| |
| 81 | 81 |
| 82 if (next_state != TAB_MEDIA_STATE_NONE) | 82 if (next_state != TAB_MEDIA_STATE_NONE) |
| 83 ResetImages(next_state); | 83 ResetImages(next_state); |
| 84 | 84 |
| 85 if ((media_state_ == TAB_MEDIA_STATE_AUDIO_PLAYING && | 85 if ((media_state_ == TAB_MEDIA_STATE_AUDIO_PLAYING && |
| 86 next_state == TAB_MEDIA_STATE_AUDIO_MUTING) || | 86 next_state == TAB_MEDIA_STATE_AUDIO_MUTING) || |
| 87 (media_state_ == TAB_MEDIA_STATE_AUDIO_MUTING && | 87 (media_state_ == TAB_MEDIA_STATE_AUDIO_MUTING && |
| 88 next_state == TAB_MEDIA_STATE_AUDIO_PLAYING) || | 88 next_state == TAB_MEDIA_STATE_AUDIO_PLAYING) || |
| 89 (media_state_ == TAB_MEDIA_STATE_AUDIO_MUTING && | 89 (media_state_ == TAB_MEDIA_STATE_AUDIO_MUTING && |
| 90 next_state == TAB_MEDIA_STATE_NONE)) { | 90 next_state == TAB_MEDIA_STATE_NONE)) { |
| 91 // Instant user feedback: No fade animation. | 91 // Instant user feedback: No fade animation. |
| 92 showing_media_state_ = next_state; | 92 showing_media_state_ = next_state; |
| 93 fade_animation_.reset(); | 93 fade_animation_.reset(); |
| 94 } else { | 94 } else { |
| 95 if (next_state == TAB_MEDIA_STATE_NONE) | 95 if (next_state == TAB_MEDIA_STATE_NONE) |
| 96 showing_media_state_ = media_state_; // Fading-out indicator. | 96 showing_media_state_ = media_state_; // Fading-out indicator. |
| 97 else | 97 else |
| 98 showing_media_state_ = next_state; // Fading-in to next indicator. | 98 showing_media_state_ = next_state; // Fading-in to next indicator. |
| 99 fade_animation_ = chrome::CreateTabMediaIndicatorFadeAnimation(next_state); | 99 fade_animation_ = chrome::CreateTabMediaIndicatorFadeAnimation(next_state); |
| 100 if (!fade_animation_delegate_) | 100 if (!fade_animation_delegate_) |
| 101 fade_animation_delegate_.reset(new FadeAnimationDelegate(this)); | 101 fade_animation_delegate_.reset(new FadeAnimationDelegate(this)); |
| 102 fade_animation_->set_delegate(fade_animation_delegate_.get()); | 102 fade_animation_->set_delegate(fade_animation_delegate_.get()); |
| 103 fade_animation_->Start(); | 103 fade_animation_->Start(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 media_state_ = next_state; | 106 media_state_ = next_state; |
| 107 | 107 |
| 108 if (previous_media_showing_state != showing_media_state_) | |
| 109 parent_tab_->MediaStateChanged(); | |
| 110 | |
| 108 UpdateEnabledForMuteToggle(); | 111 UpdateEnabledForMuteToggle(); |
| 109 | 112 |
| 110 // An indicator state change should be made visible immediately, instead of | 113 // An indicator state change should be made visible immediately, instead of |
| 111 // the user being surprised when their mouse leaves the button. | 114 // the user being surprised when their mouse leaves the button. |
| 112 if (state() == views::CustomButton::STATE_HOVERED) { | 115 if (state() == views::CustomButton::STATE_HOVERED) { |
| 113 SetState(enabled() ? views::CustomButton::STATE_NORMAL : | 116 SetState(enabled() ? views::CustomButton::STATE_NORMAL : |
| 114 views::CustomButton::STATE_DISABLED); | 117 views::CustomButton::STATE_DISABLED); |
| 115 } | 118 } |
| 116 | 119 |
| 117 // Note: The calls to SetImage(), SetEnabled(), and SetState() above will call | 120 // 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(); | 259 SkColor color = parent_tab_->button_color(); |
| 257 gfx::ImageSkia indicator_image = | 260 gfx::ImageSkia indicator_image = |
| 258 chrome::GetTabMediaIndicatorImage(state, color).AsImageSkia(); | 261 chrome::GetTabMediaIndicatorImage(state, color).AsImageSkia(); |
| 259 SetImage(views::CustomButton::STATE_NORMAL, &indicator_image); | 262 SetImage(views::CustomButton::STATE_NORMAL, &indicator_image); |
| 260 SetImage(views::CustomButton::STATE_DISABLED, &indicator_image); | 263 SetImage(views::CustomButton::STATE_DISABLED, &indicator_image); |
| 261 gfx::ImageSkia affordance_image = | 264 gfx::ImageSkia affordance_image = |
| 262 chrome::GetTabMediaIndicatorAffordanceImage(state, color).AsImageSkia(); | 265 chrome::GetTabMediaIndicatorAffordanceImage(state, color).AsImageSkia(); |
| 263 SetImage(views::CustomButton::STATE_HOVERED, &affordance_image); | 266 SetImage(views::CustomButton::STATE_HOVERED, &affordance_image); |
| 264 SetImage(views::CustomButton::STATE_PRESSED, &affordance_image); | 267 SetImage(views::CustomButton::STATE_PRESSED, &affordance_image); |
| 265 } | 268 } |
| OLD | NEW |