| 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 "chrome/browser/ui/views/tabs/tab.h" | 7 #include "chrome/browser/ui/views/tabs/tab.h" |
| 8 #include "chrome/browser/ui/views/tabs/tab_controller.h" | 8 #include "chrome/browser/ui/views/tabs/tab_controller.h" |
| 9 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" | 9 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" |
| 10 #include "content/public/browser/user_metrics.h" | 10 #include "content/public/browser/user_metrics.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 SetEventTargeter( | 64 SetEventTargeter( |
| 65 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); | 65 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
| 66 } | 66 } |
| 67 | 67 |
| 68 MediaIndicatorButton::~MediaIndicatorButton() {} | 68 MediaIndicatorButton::~MediaIndicatorButton() {} |
| 69 | 69 |
| 70 void MediaIndicatorButton::TransitionToMediaState(TabMediaState next_state) { | 70 void MediaIndicatorButton::TransitionToMediaState(TabMediaState next_state) { |
| 71 if (next_state == media_state_) | 71 if (next_state == media_state_) |
| 72 return; | 72 return; |
| 73 | 73 |
| 74 if (next_state != TAB_MEDIA_STATE_NONE) { | 74 if (next_state != TAB_MEDIA_STATE_NONE) |
| 75 ui::ThemeProvider* tp = GetThemeProvider(); | 75 ResetImages(next_state); |
| 76 gfx::ImageSkia indicator_image = | |
| 77 chrome::GetTabMediaIndicatorImage(next_state, tp).AsImageSkia(); | |
| 78 SetImage(views::CustomButton::STATE_NORMAL, &indicator_image); | |
| 79 SetImage(views::CustomButton::STATE_DISABLED, &indicator_image); | |
| 80 gfx::ImageSkia affordance_image = | |
| 81 chrome::GetTabMediaIndicatorAffordanceImage(next_state, tp) | |
| 82 .AsImageSkia(); | |
| 83 SetImage(views::CustomButton::STATE_HOVERED, &affordance_image); | |
| 84 SetImage(views::CustomButton::STATE_PRESSED, &affordance_image); | |
| 85 } | |
| 86 | 76 |
| 87 if ((media_state_ == TAB_MEDIA_STATE_AUDIO_PLAYING && | 77 if ((media_state_ == TAB_MEDIA_STATE_AUDIO_PLAYING && |
| 88 next_state == TAB_MEDIA_STATE_AUDIO_MUTING) || | 78 next_state == TAB_MEDIA_STATE_AUDIO_MUTING) || |
| 89 (media_state_ == TAB_MEDIA_STATE_AUDIO_MUTING && | 79 (media_state_ == TAB_MEDIA_STATE_AUDIO_MUTING && |
| 90 next_state == TAB_MEDIA_STATE_AUDIO_PLAYING) || | 80 next_state == TAB_MEDIA_STATE_AUDIO_PLAYING) || |
| 91 (media_state_ == TAB_MEDIA_STATE_AUDIO_MUTING && | 81 (media_state_ == TAB_MEDIA_STATE_AUDIO_MUTING && |
| 92 next_state == TAB_MEDIA_STATE_NONE)) { | 82 next_state == TAB_MEDIA_STATE_NONE)) { |
| 93 // Instant user feedback: No fade animation. | 83 // Instant user feedback: No fade animation. |
| 94 showing_media_state_ = next_state; | 84 showing_media_state_ = next_state; |
| 95 fade_animation_.reset(); | 85 fade_animation_.reset(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // Note that IsTriggerableEvent() is also overridden to provide an even wider | 121 // Note that IsTriggerableEvent() is also overridden to provide an even wider |
| 132 // requirement for tap gestures. | 122 // requirement for tap gestures. |
| 133 if (enable && !GetTab()->IsActive()) { | 123 if (enable && !GetTab()->IsActive()) { |
| 134 const int required_width = width() * kMinMouseSelectableAreaPercent / 100; | 124 const int required_width = width() * kMinMouseSelectableAreaPercent / 100; |
| 135 enable = (GetTab()->GetWidthOfLargestSelectableRegion() >= required_width); | 125 enable = (GetTab()->GetWidthOfLargestSelectableRegion() >= required_width); |
| 136 } | 126 } |
| 137 | 127 |
| 138 SetEnabled(enable); | 128 SetEnabled(enable); |
| 139 } | 129 } |
| 140 | 130 |
| 131 void MediaIndicatorButton::OnParentTabButtonColorChanged() { |
| 132 if (media_state_ == TAB_MEDIA_STATE_AUDIO_PLAYING || |
| 133 media_state_ == TAB_MEDIA_STATE_AUDIO_MUTING) |
| 134 ResetImages(media_state_); |
| 135 } |
| 136 |
| 141 const char* MediaIndicatorButton::GetClassName() const { | 137 const char* MediaIndicatorButton::GetClassName() const { |
| 142 return kViewClassName; | 138 return kViewClassName; |
| 143 } | 139 } |
| 144 | 140 |
| 145 views::View* MediaIndicatorButton::GetTooltipHandlerForPoint( | 141 views::View* MediaIndicatorButton::GetTooltipHandlerForPoint( |
| 146 const gfx::Point& point) { | 142 const gfx::Point& point) { |
| 147 return NULL; // Tab (the parent View) provides the tooltip. | 143 return NULL; // Tab (the parent View) provides the tooltip. |
| 148 } | 144 } |
| 149 | 145 |
| 150 bool MediaIndicatorButton::OnMousePressed(const ui::MouseEvent& event) { | 146 bool MediaIndicatorButton::OnMousePressed(const ui::MouseEvent& event) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 return false; | 234 return false; |
| 239 } | 235 } |
| 240 | 236 |
| 241 return views::ImageButton::IsTriggerableEvent(event); | 237 return views::ImageButton::IsTriggerableEvent(event); |
| 242 } | 238 } |
| 243 | 239 |
| 244 Tab* MediaIndicatorButton::GetTab() const { | 240 Tab* MediaIndicatorButton::GetTab() const { |
| 245 DCHECK_EQ(static_cast<views::View*>(parent_tab_), parent()); | 241 DCHECK_EQ(static_cast<views::View*>(parent_tab_), parent()); |
| 246 return parent_tab_; | 242 return parent_tab_; |
| 247 } | 243 } |
| 244 |
| 245 void MediaIndicatorButton::ResetImages(TabMediaState state) { |
| 246 SkColor color = parent_tab_->button_color(); |
| 247 gfx::ImageSkia indicator_image = |
| 248 chrome::GetTabMediaIndicatorImage(state, color).AsImageSkia(); |
| 249 SetImage(views::CustomButton::STATE_NORMAL, &indicator_image); |
| 250 SetImage(views::CustomButton::STATE_DISABLED, &indicator_image); |
| 251 gfx::ImageSkia affordance_image = |
| 252 chrome::GetTabMediaIndicatorAffordanceImage(state, color).AsImageSkia(); |
| 253 SetImage(views::CustomButton::STATE_HOVERED, &affordance_image); |
| 254 SetImage(views::CustomButton::STATE_PRESSED, &affordance_image); |
| 255 } |
| OLD | NEW |