| 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 "ash/system/audio/volume_view.h" | 5 #include "ash/system/audio/volume_view.h" |
| 6 | 6 |
| 7 #include "ash/ash_constants.h" | 7 #include "ash/ash_constants.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/system/audio/tray_audio.h" | 9 #include "ash/system/audio/tray_audio.h" |
| 10 #include "ash/system/audio/tray_audio_delegate.h" | 10 #include "ash/system/audio/tray_audio_delegate.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 system::TrayAudioDelegate* audio_delegate) | 43 system::TrayAudioDelegate* audio_delegate) |
| 44 : views::ToggleImageButton(listener), | 44 : views::ToggleImageButton(listener), |
| 45 audio_delegate_(audio_delegate), | 45 audio_delegate_(audio_delegate), |
| 46 image_index_(-1) { | 46 image_index_(-1) { |
| 47 SetImageAlignment(ALIGN_CENTER, ALIGN_MIDDLE); | 47 SetImageAlignment(ALIGN_CENTER, ALIGN_MIDDLE); |
| 48 image_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 48 image_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 49 IDR_AURA_UBER_TRAY_VOLUME_LEVELS); | 49 IDR_AURA_UBER_TRAY_VOLUME_LEVELS); |
| 50 Update(); | 50 Update(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 virtual ~VolumeButton() {} | 53 ~VolumeButton() override {} |
| 54 | 54 |
| 55 void Update() { | 55 void Update() { |
| 56 float level = | 56 float level = |
| 57 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f; | 57 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f; |
| 58 int image_index = audio_delegate_->IsOutputAudioMuted() ? | 58 int image_index = audio_delegate_->IsOutputAudioMuted() ? |
| 59 0 : (level == 1.0 ? | 59 0 : (level == 1.0 ? |
| 60 kVolumeLevels : | 60 kVolumeLevels : |
| 61 std::max(1, int(std::ceil(level * (kVolumeLevels - 1))))); | 61 std::max(1, int(std::ceil(level * (kVolumeLevels - 1))))); |
| 62 if (image_index != image_index_) { | 62 if (image_index != image_index_) { |
| 63 gfx::Rect region(0, image_index * kVolumeImageHeight, | 63 gfx::Rect region(0, image_index * kVolumeImageHeight, |
| 64 kVolumeImageWidth, kVolumeImageHeight); | 64 kVolumeImageWidth, kVolumeImageHeight); |
| 65 gfx::ImageSkia image_skia = gfx::ImageSkiaOperations::ExtractSubset( | 65 gfx::ImageSkia image_skia = gfx::ImageSkiaOperations::ExtractSubset( |
| 66 *(image_.ToImageSkia()), region); | 66 *(image_.ToImageSkia()), region); |
| 67 SetImage(views::CustomButton::STATE_NORMAL, &image_skia); | 67 SetImage(views::CustomButton::STATE_NORMAL, &image_skia); |
| 68 image_index_ = image_index; | 68 image_index_ = image_index; |
| 69 } | 69 } |
| 70 SchedulePaint(); | 70 SchedulePaint(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 // Overridden from views::View. | 74 // Overridden from views::View. |
| 75 virtual gfx::Size GetPreferredSize() const override { | 75 gfx::Size GetPreferredSize() const override { |
| 76 gfx::Size size = views::ToggleImageButton::GetPreferredSize(); | 76 gfx::Size size = views::ToggleImageButton::GetPreferredSize(); |
| 77 size.set_height(kTrayPopupItemHeight); | 77 size.set_height(kTrayPopupItemHeight); |
| 78 return size; | 78 return size; |
| 79 } | 79 } |
| 80 | 80 |
| 81 system::TrayAudioDelegate* audio_delegate_; | 81 system::TrayAudioDelegate* audio_delegate_; |
| 82 gfx::Image image_; | 82 gfx::Image image_; |
| 83 int image_index_; | 83 int image_index_; |
| 84 | 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(VolumeButton); | 85 DISALLOW_COPY_AND_ASSIGN(VolumeButton); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 class VolumeSlider : public views::Slider { | 88 class VolumeSlider : public views::Slider { |
| 89 public: | 89 public: |
| 90 VolumeSlider(views::SliderListener* listener, | 90 VolumeSlider(views::SliderListener* listener, |
| 91 system::TrayAudioDelegate* audio_delegate) | 91 system::TrayAudioDelegate* audio_delegate) |
| 92 : views::Slider(listener, views::Slider::HORIZONTAL), | 92 : views::Slider(listener, views::Slider::HORIZONTAL), |
| 93 audio_delegate_(audio_delegate) { | 93 audio_delegate_(audio_delegate) { |
| 94 set_focus_border_color(kFocusBorderColor); | 94 set_focus_border_color(kFocusBorderColor); |
| 95 SetValue( | 95 SetValue( |
| 96 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f); | 96 static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f); |
| 97 SetAccessibleName( | 97 SetAccessibleName( |
| 98 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | 98 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
| 99 IDS_ASH_STATUS_TRAY_VOLUME)); | 99 IDS_ASH_STATUS_TRAY_VOLUME)); |
| 100 Update(); | 100 Update(); |
| 101 } | 101 } |
| 102 virtual ~VolumeSlider() {} | 102 ~VolumeSlider() override {} |
| 103 | 103 |
| 104 void Update() { | 104 void Update() { |
| 105 UpdateState(!audio_delegate_->IsOutputAudioMuted()); | 105 UpdateState(!audio_delegate_->IsOutputAudioMuted()); |
| 106 } | 106 } |
| 107 | 107 |
| 108 private: | 108 private: |
| 109 system::TrayAudioDelegate* audio_delegate_; | 109 system::TrayAudioDelegate* audio_delegate_; |
| 110 | 110 |
| 111 DISALLOW_COPY_AND_ASSIGN(VolumeSlider); | 111 DISALLOW_COPY_AND_ASSIGN(VolumeSlider); |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 // Vertical bar separator that can be placed on the VolumeView. | 114 // Vertical bar separator that can be placed on the VolumeView. |
| 115 class BarSeparator : public views::View { | 115 class BarSeparator : public views::View { |
| 116 public: | 116 public: |
| 117 BarSeparator() {} | 117 BarSeparator() {} |
| 118 virtual ~BarSeparator() {} | 118 ~BarSeparator() override {} |
| 119 | 119 |
| 120 // Overriden from views::View. | 120 // Overriden from views::View. |
| 121 virtual gfx::Size GetPreferredSize() const override { | 121 gfx::Size GetPreferredSize() const override { |
| 122 return gfx::Size(kBarSeparatorWidth, kBarSeparatorHeight); | 122 return gfx::Size(kBarSeparatorWidth, kBarSeparatorHeight); |
| 123 } | 123 } |
| 124 | 124 |
| 125 private: | 125 private: |
| 126 virtual void OnPaint(gfx::Canvas* canvas) override { | 126 void OnPaint(gfx::Canvas* canvas) override { |
| 127 canvas->FillRect(gfx::Rect(width() / 2, 0, 1, height()), | 127 canvas->FillRect(gfx::Rect(width() / 2, 0, 1, height()), |
| 128 kButtonStrokeColor); | 128 kButtonStrokeColor); |
| 129 } | 129 } |
| 130 | 130 |
| 131 DISALLOW_COPY_AND_ASSIGN(BarSeparator); | 131 DISALLOW_COPY_AND_ASSIGN(BarSeparator); |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 VolumeView::VolumeView(SystemTrayItem* owner, | 134 VolumeView::VolumeView(SystemTrayItem* owner, |
| 135 system::TrayAudioDelegate* audio_delegate, | 135 system::TrayAudioDelegate* audio_delegate, |
| 136 bool is_default_view) | 136 bool is_default_view) |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 | 320 |
| 321 bool VolumeView::PerformAction(const ui::Event& event) { | 321 bool VolumeView::PerformAction(const ui::Event& event) { |
| 322 if (!more_->visible()) | 322 if (!more_->visible()) |
| 323 return false; | 323 return false; |
| 324 owner_->TransitionDetailedView(); | 324 owner_->TransitionDetailedView(); |
| 325 return true; | 325 return true; |
| 326 } | 326 } |
| 327 | 327 |
| 328 } // namespace tray | 328 } // namespace tray |
| 329 } // namespace ash | 329 } // namespace ash |
| OLD | NEW |