summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-14 23:34:24 +0000
committerjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-14 23:34:24 +0000
commit49a8253a362257647c9b8e86d30ae9aee1b2e400 (patch)
tree8d48eba2246f410b5319a65e9d985c729e6a77ee /ash
parent66056fb4231a5f762dc5bf2a7b040e377852a88a (diff)
downloadchromium_src-49a8253a362257647c9b8e86d30ae9aee1b2e400.zip
chromium_src-49a8253a362257647c9b8e86d30ae9aee1b2e400.tar.gz
chromium_src-49a8253a362257647c9b8e86d30ae9aee1b2e400.tar.bz2
Consolidate volume_control_delegate and sysmte_tray_delegate
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
Diffstat (limited to 'ash')
-rw-r--r--ash/accelerators/accelerator_controller.cc17
-rw-r--r--ash/accelerators/accelerator_controller.h8
-rw-r--r--ash/accelerators/accelerator_controller_unittest.cc25
-rw-r--r--ash/system/audio/tray_volume.cc42
-rw-r--r--ash/system/status_area_widget.cc69
-rw-r--r--ash/system/tray/system_tray_delegate.h23
-rw-r--r--ash/volume_control_delegate.h12
-rw-r--r--ash/wm/system_gesture_event_filter.cc7
-rw-r--r--ash/wm/system_gesture_event_filter_unittest.cc14
9 files changed, 133 insertions, 84 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc
index bae8d89..8cf7869 100644
--- a/ash/accelerators/accelerator_controller.cc
+++ b/ash/accelerators/accelerator_controller.cc
@@ -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())
@@ -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:
diff --git a/ash/accelerators/accelerator_controller.h b/ash/accelerators/accelerator_controller.h
index 77769ec..1f18a00 100644
--- a/ash/accelerators/accelerator_controller.h
+++ b/ash/accelerators/accelerator_controller.h
@@ -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();
@@ -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.
diff --git a/ash/accelerators/accelerator_controller_unittest.cc b/ash/accelerators/accelerator_controller_unittest.cc
index 9f48103..25804d2 100644
--- a/ash/accelerators/accelerator_controller_unittest.cc
+++ b/ash/accelerators/accelerator_controller_unittest.cc
@@ -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"
@@ -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_;
@@ -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));
@@ -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));
@@ -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));
@@ -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));
diff --git a/ash/system/audio/tray_volume.cc b/ash/system/audio/tray_volume.cc
index 7b32718..e2025a5 100644
--- a/ash/system/audio/tray_volume.cc
+++ b/ash/system/audio/tray_volume.cc
@@ -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"
@@ -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 {
@@ -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)))));
@@ -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();
}
@@ -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));
@@ -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);
@@ -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.
@@ -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();
}
@@ -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) {
@@ -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);
diff --git a/ash/system/status_area_widget.cc b/ash/system/status_area_widget.cc
index 4209f38..32f4871 100644
--- a/ash/system/status_area_widget.cc
+++ b/ash/system/status_area_widget.cc
@@ -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"
@@ -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() {}
@@ -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_;
}
@@ -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);
};
diff --git a/ash/system/tray/system_tray_delegate.h b/ash/system/tray/system_tray_delegate.h
index 6af67fe..a772d92 100644
--- a/ash/system/tray/system_tray_delegate.h
+++ b/ash/system/tray/system_tray_delegate.h
@@ -13,6 +13,7 @@
#include "ash/system/user/login_status.h"
#include "base/file_path.h"
#include "base/i18n/time_formatting.h"
+#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
#include "ui/gfx/image/image_skia.h"
@@ -96,6 +97,8 @@ struct ASH_EXPORT IMEInfo {
typedef std::vector<IMEInfo> IMEInfoList;
+class VolumeControlDelegate;
+
class SystemTrayDelegate {
public:
virtual ~SystemTrayDelegate() {}
@@ -142,18 +145,6 @@ class SystemTrayDelegate {
// Shows help.
virtual void ShowHelp() = 0;
- // Is the system audio muted?
- virtual bool IsAudioMuted() const = 0;
-
- // Mutes/Unmutes the audio system.
- virtual void SetAudioMuted(bool muted) = 0;
-
- // Gets the volume level. The range is [0, 1.0].
- virtual float GetVolumeLevel() const = 0;
-
- // Sets the volume level. The range is [0, 1.0].
- virtual void SetVolumeLevel(float level) = 0;
-
// Gets whether the caps lock is on.
virtual bool IsCapsLockOn() const = 0;
@@ -278,6 +269,14 @@ class SystemTrayDelegate {
// Shows UI for changing proxy settings.
virtual void ChangeProxySettings() = 0;
+
+ // Returns VolumeControlDelegate.
+ virtual VolumeControlDelegate* GetVolumeControlDelegate() const = 0;
+
+ // Sets VolumeControlDelegate.
+ virtual void SetVolumeControlDelegate(
+ scoped_ptr<VolumeControlDelegate> delegate) = 0;
+
};
} // namespace ash
diff --git a/ash/volume_control_delegate.h b/ash/volume_control_delegate.h
index 24410f1..db2a99b 100644
--- a/ash/volume_control_delegate.h
+++ b/ash/volume_control_delegate.h
@@ -20,6 +20,18 @@ class VolumeControlDelegate {
virtual bool HandleVolumeDown(const ui::Accelerator& accelerator) = 0;
virtual bool HandleVolumeUp(const ui::Accelerator& accelerator) = 0;
+ // Is the system audio muted?
+ virtual bool IsAudioMuted() const = 0;
+
+ // Mutes/Unmutes the audio system.
+ virtual void SetAudioMuted(bool muted) = 0;
+
+ // Gets the volume level. The range is [0, 1.0].
+ virtual float GetVolumeLevel() const = 0;
+
+ // Sets the volume level. The range is [0, 1.0].
+ virtual void SetVolumeLevel(float level) = 0;
+
// Requests that the volume be set to |percent|, in the range
// [0.0, 100.0].
virtual void SetVolumePercent(double percent) = 0;
diff --git a/ash/wm/system_gesture_event_filter.cc b/ash/wm/system_gesture_event_filter.cc
index 3d79937..36be556 100644
--- a/ash/wm/system_gesture_event_filter.cc
+++ b/ash/wm/system_gesture_event_filter.cc
@@ -13,6 +13,7 @@
#include "ash/shell_delegate.h"
#include "ash/shell_window_ids.h"
#include "ash/system/brightness/brightness_control_delegate.h"
+#include "ash/system/tray/system_tray_delegate.h"
#include "ash/volume_control_delegate.h"
#include "ash/wm/property_util.h"
#include "ash/wm/window_animations.h"
@@ -692,10 +693,8 @@ bool SystemGestureEventFilter::HandleDeviceControl(
if (delegate)
delegate->SetBrightnessPercent(100.0 - percent, true);
} else if (start_location_ == BEZEL_START_RIGHT) {
- ash::VolumeControlDelegate* delegate =
- accelerator->volume_control_delegate();
- if (delegate)
- delegate->SetVolumePercent(100.0 - percent);
+ Shell::GetInstance()->tray_delegate()->GetVolumeControlDelegate()->
+ SetVolumePercent(100.0 - percent);
} else {
return true;
}
diff --git a/ash/wm/system_gesture_event_filter_unittest.cc b/ash/wm/system_gesture_event_filter_unittest.cc
index 38e0deb..2985ef4 100644
--- a/ash/wm/system_gesture_event_filter_unittest.cc
+++ b/ash/wm/system_gesture_event_filter_unittest.cc
@@ -10,6 +10,7 @@
#include "ash/launcher/launcher_model.h"
#include "ash/shell.h"
#include "ash/system/brightness/brightness_control_delegate.h"
+#include "ash/system/tray/system_tray_delegate.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/test_launcher_delegate.h"
#include "ash/volume_control_delegate.h"
@@ -69,6 +70,17 @@ class DummyVolumeControlDelegate : public VolumeControlDelegate,
virtual void SetVolumePercent(double percent) OVERRIDE {
SetPercent(percent);
}
+ 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 {
+ }
+
private:
DISALLOW_COPY_AND_ASSIGN(DummyVolumeControlDelegate);
@@ -199,7 +211,7 @@ TEST_F(SystemGestureEventFilterTest, DeviceControl) {
DummyVolumeControlDelegate* delegateVolume =
new DummyVolumeControlDelegate();
- accelerator->SetVolumeControlDelegate(
+ ash::Shell::GetInstance()->tray_delegate()->SetVolumeControlDelegate(
scoped_ptr<VolumeControlDelegate>(delegateVolume).Pass());
const int kTouchId = 5;