Skip to content

Commit

Permalink
Consolidate volume_control_delegate and sysmte_tray_delegate
Browse files Browse the repository at this point in the history
BUG=115936


Review URL: https://chromiumcodereview.appspot.com/10825264

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151607 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jennyz@chromium.org committed Aug 14, 2012
1 parent 66056fb commit 49a8253
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 105 deletions.
17 changes: 6 additions & 11 deletions ash/accelerators/accelerator_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -499,16 +499,16 @@ bool AcceleratorController::PerformAction(int action,
HandleKeyboardBrightnessUp(accelerator);
break;
case VOLUME_MUTE:
if (volume_control_delegate_.get())
return volume_control_delegate_->HandleVolumeMute(accelerator);
return shell->tray_delegate()->GetVolumeControlDelegate()->
HandleVolumeMute(accelerator);
break;
case VOLUME_DOWN:
if (volume_control_delegate_.get())
return volume_control_delegate_->HandleVolumeDown(accelerator);
return shell->tray_delegate()->GetVolumeControlDelegate()->
HandleVolumeDown(accelerator);
break;
case VOLUME_UP:
if (volume_control_delegate_.get())
return volume_control_delegate_->HandleVolumeUp(accelerator);
return shell->tray_delegate()->GetVolumeControlDelegate()->
HandleVolumeUp(accelerator);
break;
case FOCUS_LAUNCHER:
if (shell->launcher())
Expand Down Expand Up @@ -699,11 +699,6 @@ void AcceleratorController::SetScreenshotDelegate(
screenshot_delegate_.swap(screenshot_delegate);
}

void AcceleratorController::SetVolumeControlDelegate(
scoped_ptr<VolumeControlDelegate> volume_control_delegate) {
volume_control_delegate_.swap(volume_control_delegate);
}

////////////////////////////////////////////////////////////////////////////////
// AcceleratorController, ui::AcceleratorTarget implementation:

Expand Down
8 changes: 0 additions & 8 deletions ash/accelerators/accelerator_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,10 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget {
keyboard_brightness_control_delegate);
void SetScreenshotDelegate(
scoped_ptr<ScreenshotDelegate> screenshot_delegate);
void SetVolumeControlDelegate(
scoped_ptr<VolumeControlDelegate> volume_control_delegate);

BrightnessControlDelegate* brightness_control_delegate() const {
return brightness_control_delegate_.get();
}

VolumeControlDelegate* volume_control_delegate() const {
return volume_control_delegate_.get();
}

private:
// Initializes the accelerators this class handles as a target.
void Init();
Expand All @@ -116,7 +109,6 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget {
scoped_ptr<KeyboardBrightnessControlDelegate>
keyboard_brightness_control_delegate_;
scoped_ptr<ScreenshotDelegate> screenshot_delegate_;
scoped_ptr<VolumeControlDelegate> volume_control_delegate_;

// A map from accelerators to the AcceleratorAction values, which are used in
// the implementation.
Expand Down
25 changes: 18 additions & 7 deletions ash/accelerators/accelerator_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "ash/shell_window_ids.h"
#include "ash/system/brightness/brightness_control_delegate.h"
#include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/test_shell_delegate.h"
#include "ash/volume_control_delegate.h"
Expand Down Expand Up @@ -143,6 +144,16 @@ class DummyVolumeControlDelegate : public VolumeControlDelegate {
}
virtual void SetVolumePercent(double percent) OVERRIDE {
}
virtual bool IsAudioMuted() const OVERRIDE {
return false;
}
virtual void SetAudioMuted(bool muted) OVERRIDE {
}
virtual float GetVolumeLevel() const OVERRIDE {
return 0.0;
}
virtual void SetVolumeLevel(float level) OVERRIDE {
}

int handle_volume_mute_count() const {
return handle_volume_mute_count_;
Expand Down Expand Up @@ -615,12 +626,12 @@ TEST_F(AcceleratorControllerTest, GlobalAccelerators) {
const ui::Accelerator f9(ui::VKEY_F9, ui::EF_NONE);
const ui::Accelerator f10(ui::VKEY_F10, ui::EF_NONE);
{
EXPECT_FALSE(GetController()->Process(f8));
EXPECT_FALSE(GetController()->Process(f9));
EXPECT_FALSE(GetController()->Process(f10));
EXPECT_TRUE(GetController()->Process(f8));
EXPECT_TRUE(GetController()->Process(f9));
EXPECT_TRUE(GetController()->Process(f10));
DummyVolumeControlDelegate* delegate =
new DummyVolumeControlDelegate(false);
GetController()->SetVolumeControlDelegate(
ash::Shell::GetInstance()->tray_delegate()->SetVolumeControlDelegate(
scoped_ptr<VolumeControlDelegate>(delegate).Pass());
EXPECT_EQ(0, delegate->handle_volume_mute_count());
EXPECT_FALSE(GetController()->Process(f8));
Expand All @@ -637,7 +648,7 @@ TEST_F(AcceleratorControllerTest, GlobalAccelerators) {
}
{
DummyVolumeControlDelegate* delegate = new DummyVolumeControlDelegate(true);
GetController()->SetVolumeControlDelegate(
ash::Shell::GetInstance()->tray_delegate()->SetVolumeControlDelegate(
scoped_ptr<VolumeControlDelegate>(delegate).Pass());
EXPECT_EQ(0, delegate->handle_volume_mute_count());
EXPECT_TRUE(GetController()->Process(f8));
Expand All @@ -658,7 +669,7 @@ TEST_F(AcceleratorControllerTest, GlobalAccelerators) {
{
DummyVolumeControlDelegate* delegate =
new DummyVolumeControlDelegate(false);
GetController()->SetVolumeControlDelegate(
ash::Shell::GetInstance()->tray_delegate()->SetVolumeControlDelegate(
scoped_ptr<VolumeControlDelegate>(delegate).Pass());
EXPECT_EQ(0, delegate->handle_volume_mute_count());
EXPECT_FALSE(GetController()->Process(volume_mute));
Expand All @@ -675,7 +686,7 @@ TEST_F(AcceleratorControllerTest, GlobalAccelerators) {
}
{
DummyVolumeControlDelegate* delegate = new DummyVolumeControlDelegate(true);
GetController()->SetVolumeControlDelegate(
ash::Shell::GetInstance()->tray_delegate()->SetVolumeControlDelegate(
scoped_ptr<VolumeControlDelegate>(delegate).Pass());
EXPECT_EQ(0, delegate->handle_volume_mute_count());
EXPECT_TRUE(GetController()->Process(volume_mute));
Expand Down
42 changes: 23 additions & 19 deletions ash/system/audio/tray_volume.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_views.h"
#include "ash/volume_control_delegate.h"
#include "base/utf_string_conversions.h"
#include "grit/ash_strings.h"
#include "grit/ui_resources.h"
Expand Down Expand Up @@ -39,8 +40,19 @@ const int kVolumeImageHeight = 25;
// The one for mute is at the 0 index and the other
// four are used for ascending volume levels.
const int kVolumeLevels = 4;

bool IsAudioMuted() {
return Shell::GetInstance()->tray_delegate()->
GetVolumeControlDelegate()->IsAudioMuted();
}

float GetVolumeLevel() {
return Shell::GetInstance()->tray_delegate()->
GetVolumeControlDelegate()->GetVolumeLevel();
}

} // namespace

namespace tray {

class VolumeButton : public views::ToggleImageButton {
Expand All @@ -58,10 +70,8 @@ class VolumeButton : public views::ToggleImageButton {
virtual ~VolumeButton() {}

void Update() {
ash::SystemTrayDelegate* delegate =
ash::Shell::GetInstance()->tray_delegate();
float level = delegate->GetVolumeLevel();
int image_index = delegate->IsAudioMuted() ?
float level = GetVolumeLevel();
int image_index = IsAudioMuted() ?
0 : (level == 1.0 ?
kVolumeLevels :
std::max(1, int(std::ceil(level * (kVolumeLevels - 1)))));
Expand Down Expand Up @@ -101,9 +111,7 @@ class MuteButton : public ash::internal::TrayBarButtonWithTitle {
virtual ~MuteButton() {}

void Update() {
ash::SystemTrayDelegate* delegate =
ash::Shell::GetInstance()->tray_delegate();
UpdateButton(delegate->IsAudioMuted());
UpdateButton(IsAudioMuted());
SchedulePaint();
}

Expand All @@ -115,7 +123,7 @@ class VolumeSlider : public views::Slider {
explicit VolumeSlider(views::SliderListener* listener)
: views::Slider(listener, views::Slider::HORIZONTAL) {
set_focus_border_color(kFocusBorderColor);
SetValue(ash::Shell::GetInstance()->tray_delegate()->GetVolumeLevel());
SetValue(GetVolumeLevel());
SetAccessibleName(
ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
IDS_ASH_STATUS_TRAY_VOLUME));
Expand All @@ -124,7 +132,7 @@ class VolumeSlider : public views::Slider {
virtual ~VolumeSlider() {}

void Update() {
UpdateState(!ash::Shell::GetInstance()->tray_delegate()->IsAudioMuted());
UpdateState(!IsAudioMuted());
}

DISALLOW_COPY_AND_ASSIGN(VolumeSlider);
Expand Down Expand Up @@ -179,9 +187,8 @@ class VolumeView : public views::View,
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE {
CHECK(sender == icon_ || sender == mute_);
ash::SystemTrayDelegate* delegate =
ash::Shell::GetInstance()->tray_delegate();
delegate->SetAudioMuted(!delegate->IsAudioMuted());
ash::Shell::GetInstance()->tray_delegate()->
GetVolumeControlDelegate()->SetAudioMuted(!IsAudioMuted());
}

// Overridden from views:SliderListener.
Expand All @@ -190,9 +197,8 @@ class VolumeView : public views::View,
float old_value,
views::SliderChangeReason reason) OVERRIDE {
if (reason == views::VALUE_CHANGED_BY_USER) {
ash::SystemTrayDelegate* delegate =
ash::Shell::GetInstance()->tray_delegate();
delegate->SetVolumeLevel(value);
ash::Shell::GetInstance()->tray_delegate()->
GetVolumeControlDelegate()->SetVolumeLevel(value);
}
icon_->Update();
}
Expand All @@ -216,9 +222,7 @@ TrayVolume::~TrayVolume() {
}

bool TrayVolume::GetInitialVisibility() {
ash::SystemTrayDelegate* delegate =
ash::Shell::GetInstance()->tray_delegate();
return delegate->IsAudioMuted();
return IsAudioMuted();
}

views::View* TrayVolume::CreateDefaultView(user::LoginStatus status) {
Expand Down Expand Up @@ -248,7 +252,7 @@ void TrayVolume::OnVolumeChanged(float percent) {
tray_view()->SetVisible(GetInitialVisibility());

if (volume_view_) {
if (ash::Shell::GetInstance()->tray_delegate()->IsAudioMuted())
if (IsAudioMuted())
percent = 0.0;
volume_view_->SetVolumeLevel(percent);
SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds);
Expand Down
69 changes: 47 additions & 22 deletions ash/system/status_area_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/web_notification/web_notification_tray.h"
#include "ash/volume_control_delegate.h"
#include "base/i18n/time_formatting.h"
#include "base/utf_string_conversions.h"
#include "ui/aura/window.h"
Expand All @@ -22,15 +23,46 @@ namespace ash {

namespace {

class DummyVolumeControlDelegate : public VolumeControlDelegate {
public:
DummyVolumeControlDelegate() {}
virtual ~DummyVolumeControlDelegate() {}

virtual bool HandleVolumeMute(const ui::Accelerator& accelerator) OVERRIDE {
return true;
}
virtual bool HandleVolumeDown(const ui::Accelerator& accelerator) OVERRIDE {
return true;
}
virtual bool HandleVolumeUp(const ui::Accelerator& accelerator) OVERRIDE {
return true;
}
virtual void SetVolumePercent(double percent) OVERRIDE {
}
virtual bool IsAudioMuted() const OVERRIDE {
return true;
}
virtual void SetAudioMuted(bool muted) OVERRIDE {
}
virtual float GetVolumeLevel() const OVERRIDE {
return 0.0;
}
virtual void SetVolumeLevel(float level) OVERRIDE {
}

private:
DISALLOW_COPY_AND_ASSIGN(DummyVolumeControlDelegate);
};

class DummySystemTrayDelegate : public SystemTrayDelegate {
public:
DummySystemTrayDelegate()
: muted_(false),
wifi_enabled_(true),
: wifi_enabled_(true),
cellular_enabled_(true),
bluetooth_enabled_(true),
volume_(0.5),
caps_lock_enabled_(false) {
caps_lock_enabled_(false),
volume_control_delegate_(
ALLOW_THIS_IN_INITIALIZER_LIST(new DummyVolumeControlDelegate)) {
}

virtual ~DummySystemTrayDelegate() {}
Expand Down Expand Up @@ -91,22 +123,6 @@ class DummySystemTrayDelegate : public SystemTrayDelegate {
virtual void ShowHelp() OVERRIDE {
}

virtual bool IsAudioMuted() const OVERRIDE {
return muted_;
}

virtual void SetAudioMuted(bool muted) OVERRIDE {
muted_ = muted;
}

virtual float GetVolumeLevel() const OVERRIDE {
return volume_;
}

virtual void SetVolumeLevel(float volume) OVERRIDE {
volume_ = volume;
}

virtual bool IsCapsLockOn() const OVERRIDE {
return caps_lock_enabled_;
}
Expand Down Expand Up @@ -260,13 +276,22 @@ class DummySystemTrayDelegate : public SystemTrayDelegate {
virtual void ChangeProxySettings() OVERRIDE {
}

bool muted_;
virtual VolumeControlDelegate* GetVolumeControlDelegate() const OVERRIDE {
return volume_control_delegate_.get();
}

virtual void SetVolumeControlDelegate(
scoped_ptr<VolumeControlDelegate> delegate) OVERRIDE {
volume_control_delegate_.swap(delegate);
}


bool wifi_enabled_;
bool cellular_enabled_;
bool bluetooth_enabled_;
float volume_;
bool caps_lock_enabled_;
gfx::ImageSkia null_image_;
scoped_ptr<VolumeControlDelegate> volume_control_delegate_;

DISALLOW_COPY_AND_ASSIGN(DummySystemTrayDelegate);
};
Expand Down
Loading

0 comments on commit 49a8253

Please sign in to comment.