Commit cfa9765a authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Add audio detailed view to UnifiedSystemTray.

This CL adds audio detailed view (audio settings) to UnifiedSystemTray.
Audio settings is only accessible when there are multiple audio inputs
or outputs.

TEST=manual
BUG=847770

Change-Id: Ifee6be242c9c89bdb8012f3a6c905fca042aa1c6
Reviewed-on: https://chromium-review.googlesource.com/1098871Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567184}
parent 748df134
......@@ -571,6 +571,8 @@ component("ash") {
"system/audio/display_speaker_controller.h",
"system/audio/tray_audio.cc",
"system/audio/tray_audio.h",
"system/audio/unified_audio_detailed_view_controller.cc",
"system/audio/unified_audio_detailed_view_controller.h",
"system/audio/unified_volume_slider_controller.cc",
"system/audio/unified_volume_slider_controller.h",
"system/audio/unified_volume_view.cc",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/audio/unified_audio_detailed_view_controller.h"
#include "ash/system/audio/audio_detailed_view.h"
#include "ash/system/unified/unified_detailed_view_delegate.h"
using chromeos::CrasAudioHandler;
namespace ash {
UnifiedAudioDetailedViewController::UnifiedAudioDetailedViewController(
UnifiedSystemTrayController* tray_controller)
: detailed_view_delegate_(
std::make_unique<UnifiedDetailedViewDelegate>(tray_controller)) {
DCHECK(CrasAudioHandler::IsInitialized());
CrasAudioHandler::Get()->AddAudioObserver(this);
}
UnifiedAudioDetailedViewController::~UnifiedAudioDetailedViewController() {
DCHECK(CrasAudioHandler::IsInitialized());
CrasAudioHandler::Get()->RemoveAudioObserver(this);
}
views::View* UnifiedAudioDetailedViewController::CreateView() {
DCHECK(!view_);
view_ = new tray::AudioDetailedView(detailed_view_delegate_.get());
view_->Update();
return view_;
}
void UnifiedAudioDetailedViewController::OnAudioNodesChanged() {
view_->Update();
}
void UnifiedAudioDetailedViewController::OnActiveOutputNodeChanged() {
view_->Update();
}
void UnifiedAudioDetailedViewController::OnActiveInputNodeChanged() {
view_->Update();
}
} // namespace ash
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_AUDIO_UNIFIED_AUDIO_DETAILED_VIEW_CONTROLLER_H_
#define ASH_SYSTEM_AUDIO_UNIFIED_AUDIO_DETAILED_VIEW_CONTROLLER_H_
#include <memory>
#include "ash/system/unified/detailed_view_controller.h"
#include "base/macros.h"
#include "chromeos/audio/cras_audio_handler.h"
namespace ash {
namespace tray {
class AudioDetailedView;
} // namespace tray
class DetailedViewDelegate;
class UnifiedSystemTrayController;
// Controller of Audio detailed view in UnifiedSystemTray.
class UnifiedAudioDetailedViewController
: public DetailedViewController,
public chromeos::CrasAudioHandler::AudioObserver {
public:
explicit UnifiedAudioDetailedViewController(
UnifiedSystemTrayController* tray_controller);
~UnifiedAudioDetailedViewController() override;
// DetailedViewControllerBase:
views::View* CreateView() override;
// CrasAudioHandler::AudioObserver.
void OnAudioNodesChanged() override;
void OnActiveOutputNodeChanged() override;
void OnActiveInputNodeChanged() override;
private:
const std::unique_ptr<DetailedViewDelegate> detailed_view_delegate_;
tray::AudioDetailedView* view_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(UnifiedAudioDetailedViewController);
};
} // namespace ash
#endif // ASH_SYSTEM_AUDIO_UNIFIED_AUDIO_DETAILED_VIEW_CONTROLLER_H_
......@@ -8,6 +8,7 @@
#include "ash/metrics/user_metrics_recorder.h"
#include "ash/shell.h"
#include "ash/system/audio/unified_volume_view.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
......@@ -15,23 +16,30 @@ using chromeos::CrasAudioHandler;
namespace ash {
UnifiedVolumeSliderController::UnifiedVolumeSliderController() = default;
UnifiedVolumeSliderController::UnifiedVolumeSliderController(
UnifiedSystemTrayController* tray_controller)
: tray_controller_(tray_controller) {}
UnifiedVolumeSliderController::~UnifiedVolumeSliderController() = default;
views::View* UnifiedVolumeSliderController::CreateView() {
DCHECK(!slider_);
slider_ = new UnifiedVolumeView(this);
slider_ = new UnifiedVolumeView(this, !!tray_controller_);
return slider_;
}
void UnifiedVolumeSliderController::ButtonPressed(views::Button* sender,
const ui::Event& event) {
bool mute_on = !CrasAudioHandler::Get()->IsOutputMuted();
if (mute_on)
base::RecordAction(base::UserMetricsAction("StatusArea_Audio_Muted"));
else
base::RecordAction(base::UserMetricsAction("StatusArea_Audio_Unmuted"));
CrasAudioHandler::Get()->SetOutputMute(mute_on);
if (sender == slider_->button()) {
bool mute_on = !CrasAudioHandler::Get()->IsOutputMuted();
if (mute_on)
base::RecordAction(base::UserMetricsAction("StatusArea_Audio_Muted"));
else
base::RecordAction(base::UserMetricsAction("StatusArea_Audio_Unmuted"));
CrasAudioHandler::Get()->SetOutputMute(mute_on);
} else if (sender == slider_->more_button()) {
tray_controller_->ShowAudioDetailedView();
}
}
void UnifiedVolumeSliderController::SliderValueChanged(
......
......@@ -9,10 +9,16 @@
namespace ash {
class UnifiedSystemTrayController;
class UnifiedVolumeView;
// Controller of a slider that can change audio volume.
class UnifiedVolumeSliderController : public UnifiedSliderListener {
public:
UnifiedVolumeSliderController();
// |tray_controller| may be null if the volume slider is in slider bubble, not
// main bubble.
explicit UnifiedVolumeSliderController(
UnifiedSystemTrayController* tray_controller);
~UnifiedVolumeSliderController() override;
// UnifiedSliderListener:
......@@ -24,7 +30,8 @@ class UnifiedVolumeSliderController : public UnifiedSliderListener {
views::SliderChangeReason reason) override;
private:
UnifiedSliderView* slider_ = nullptr;
UnifiedSystemTrayController* const tray_controller_;
UnifiedVolumeView* slider_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(UnifiedVolumeSliderController);
};
......
......@@ -7,6 +7,7 @@
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/audio/unified_volume_slider_controller.h"
#include "ash/system/unified/top_shortcut_button.h"
using chromeos::CrasAudioHandler;
......@@ -42,12 +43,18 @@ const gfx::VectorIcon& GetVolumeIconForLevel(float level) {
} // namespace
UnifiedVolumeView::UnifiedVolumeView(UnifiedVolumeSliderController* controller)
UnifiedVolumeView::UnifiedVolumeView(UnifiedVolumeSliderController* controller,
bool is_main_view)
: UnifiedSliderView(controller,
kSystemMenuVolumeHighIcon,
IDS_ASH_STATUS_TRAY_VOLUME) {
IDS_ASH_STATUS_TRAY_VOLUME),
more_button_(new TopShortcutButton(controller,
kSystemMenuArrowRightIcon,
IDS_ASH_STATUS_TRAY_AUDIO)),
is_main_view_(is_main_view) {
DCHECK(CrasAudioHandler::IsInitialized());
CrasAudioHandler::Get()->AddAudioObserver(this);
AddChildView(more_button_);
Update();
}
......@@ -66,6 +73,10 @@ void UnifiedVolumeView::Update() {
button()->SetToggled(!is_muted);
button()->SetVectorIcon(GetVolumeIconForLevel(is_muted ? 0.f : level));
more_button_->SetVisible(is_main_view_ &&
(CrasAudioHandler::Get()->has_alternative_input() ||
CrasAudioHandler::Get()->has_alternative_output()));
// Slider's value is in finer granularity than audio volume level(0.01),
// there will be a small discrepancy between slider's value and volume level
// on audio side. To avoid the jittering in slider UI, do not set change
......@@ -97,4 +108,8 @@ void UnifiedVolumeView::OnActiveInputNodeChanged() {
Update();
}
void UnifiedVolumeView::ChildVisibilityChanged(views::View* child) {
Layout();
}
} // namespace ash
......@@ -16,9 +16,12 @@ class UnifiedVolumeSliderController;
class UnifiedVolumeView : public UnifiedSliderView,
public chromeos::CrasAudioHandler::AudioObserver {
public:
explicit UnifiedVolumeView(UnifiedVolumeSliderController* controller);
UnifiedVolumeView(UnifiedVolumeSliderController* controller,
bool is_main_view);
~UnifiedVolumeView() override;
views::Button* more_button() { return more_button_; }
private:
void Update();
......@@ -29,6 +32,12 @@ class UnifiedVolumeView : public UnifiedSliderView,
void OnActiveOutputNodeChanged() override;
void OnActiveInputNodeChanged() override;
// UnifiedSliderView:
void ChildVisibilityChanged(views::View* child) override;
TopShortcutButton* const more_button_;
const bool is_main_view_;
DISALLOW_COPY_AND_ASSIGN(UnifiedVolumeView);
};
......
......@@ -138,7 +138,8 @@ void UnifiedSliderBubbleController::ShowBubble(SliderType slider_type) {
void UnifiedSliderBubbleController::CreateSliderController() {
switch (slider_type_) {
case SLIDER_TYPE_VOLUME:
slider_controller_ = std::make_unique<UnifiedVolumeSliderController>();
slider_controller_ =
std::make_unique<UnifiedVolumeSliderController>(nullptr);
return;
case SLIDER_TYPE_DISPLAY_BRIGHTNESS:
slider_controller_ =
......
......@@ -78,7 +78,6 @@ class UnifiedSliderView : public views::View {
bool readonly = false);
~UnifiedSliderView() override;
protected:
UnifiedSliderButton* button() { return button_; }
views::Slider* slider() { return slider_; }
......
......@@ -9,6 +9,7 @@
#include "ash/multi_profile_uma.h"
#include "ash/session/session_controller.h"
#include "ash/shell.h"
#include "ash/system/audio/unified_audio_detailed_view_controller.h"
#include "ash/system/audio/unified_volume_slider_controller.h"
#include "ash/system/bluetooth/bluetooth_feature_pod_controller.h"
#include "ash/system/bluetooth/unified_bluetooth_detailed_view_controller.h"
......@@ -68,7 +69,8 @@ UnifiedSystemTrayView* UnifiedSystemTrayController::CreateView() {
unified_view_ = new UnifiedSystemTrayView(this, model_->expanded_on_open());
InitFeaturePods();
volume_slider_controller_ = std::make_unique<UnifiedVolumeSliderController>();
volume_slider_controller_ =
std::make_unique<UnifiedVolumeSliderController>(this);
unified_view_->AddSliderView(volume_slider_controller_->CreateView());
brightness_slider_controller_ =
......@@ -219,6 +221,10 @@ void UnifiedSystemTrayController::ShowIMEDetailedView() {
ShowDetailedView(std::make_unique<UnifiedIMEDetailedViewController>(this));
}
void UnifiedSystemTrayController::ShowAudioDetailedView() {
ShowDetailedView(std::make_unique<UnifiedAudioDetailedViewController>(this));
}
void UnifiedSystemTrayController::TransitionToMainView(bool restore_focus) {
detailed_view_controller_.reset();
unified_view_->ResetDetailedView();
......
......@@ -69,6 +69,8 @@ class ASH_EXPORT UnifiedSystemTrayController : public gfx::AnimationDelegate {
void ShowVPNDetailedView();
// Show the detailed view of IME. Called from the view.
void ShowIMEDetailedView();
// Show the detailed view of audio. Called from the view.
void ShowAudioDetailedView();
// If you want to add a new detailed view, add here.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment