diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-27 20:59:27 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-27 20:59:27 +0000 |
commit | bfb411316d5d6f6a29e01a88f7a94b545b827776 (patch) | |
tree | 99c45616a22f3cb190dd7f068edfdd8941e6d524 /ash | |
parent | bdb730765e736232e1f69a908bbeee3b54393934 (diff) | |
download | chromium_src-bfb411316d5d6f6a29e01a88f7a94b545b827776.zip chromium_src-bfb411316d5d6f6a29e01a88f7a94b545b827776.tar.gz chromium_src-bfb411316d5d6f6a29e01a88f7a94b545b827776.tar.bz2 |
ash: A first step for the uber tray.
As a first step, there are items to open settings, help pages, and an item to
allow [un]muting volume.
The resources have not been uploaded yet. That will be done in a separate CL to
allow this one to go through trybots etc.
This new uber-tray can be turned on at runtime using --ash-uber-tray flag.
BUG=110130
TEST=none yet. will be added when a little more fleshed out.
Review URL: https://chromiumcodereview.appspot.com/9463039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123799 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/ash.gyp | 9 | ||||
-rw-r--r-- | ash/ash_switches.cc | 3 | ||||
-rw-r--r-- | ash/ash_switches.h | 1 | ||||
-rw-r--r-- | ash/shell.cc | 69 | ||||
-rw-r--r-- | ash/shell.h | 10 | ||||
-rw-r--r-- | ash/shell/shell_main.cc | 4 | ||||
-rw-r--r-- | ash/shell_delegate.h | 4 | ||||
-rw-r--r-- | ash/system/audio/tray_volume.cc | 115 | ||||
-rw-r--r-- | ash/system/audio/tray_volume.h | 40 | ||||
-rw-r--r-- | ash/system/settings/tray_settings.cc | 95 | ||||
-rw-r--r-- | ash/system/settings/tray_settings.h | 30 | ||||
-rw-r--r-- | ash/system/tray/system_tray.cc | 100 | ||||
-rw-r--r-- | ash/system/tray/system_tray.h | 47 | ||||
-rw-r--r-- | ash/system/tray/system_tray_delegate.h | 36 | ||||
-rw-r--r-- | ash/system/tray/system_tray_item.cc | 21 | ||||
-rw-r--r-- | ash/system/tray/system_tray_item.h | 54 | ||||
-rw-r--r-- | ash/test/test_shell_delegate.cc | 3 | ||||
-rw-r--r-- | ash/test/test_shell_delegate.h | 1 |
18 files changed, 642 insertions, 0 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index 1919b84..5c3099d 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -110,6 +110,15 @@ 'shell_window_ids.h', 'status_area/status_area_view.cc', 'status_area/status_area_view.h', + 'system/audio/tray_volume.cc', + 'system/audio/tray_volume.h', + 'system/settings/tray_settings.cc', + 'system/settings/tray_settings.h', + 'system/tray/system_tray.cc', + 'system/tray/system_tray.h', + 'system/tray/system_tray_delegate.h', + 'system/tray/system_tray_item.cc', + 'system/tray/system_tray_item.h', 'tooltips/tooltip_controller.cc', 'tooltips/tooltip_controller.h', 'volume_control_delegate.h', diff --git a/ash/ash_switches.cc b/ash/ash_switches.cc index 69067eb..87f4c30 100644 --- a/ash/ash_switches.cc +++ b/ash/ash_switches.cc @@ -11,6 +11,9 @@ namespace ash { namespace switches { +// Use the in-progress uber system tray. +const char kAshUberTray[] = "ash-uber-tray"; + // Force the "compact" window mode regardless of the value of kAuraWindowMode. // This can be used to override a value set in chrome://flags. // TODO(derat): Remove this once the normal mode is usable on all platforms. diff --git a/ash/ash_switches.h b/ash/ash_switches.h index 251b6af..c26cbe7 100644 --- a/ash/ash_switches.h +++ b/ash/ash_switches.h @@ -16,6 +16,7 @@ namespace switches { // see chromeos::LoginUtil::GetOffTheRecordCommandLine().) // Please keep alphabetized. +ASH_EXPORT extern const char kAshUberTray[]; ASH_EXPORT extern const char kAuraForceCompactWindowMode[]; ASH_EXPORT extern const char kAuraGoogleDialogFrames[]; ASH_EXPORT extern const char kAuraLegacyPowerButton[]; diff --git a/ash/shell.cc b/ash/shell.cc index c4fcc52..8be3929 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -15,6 +15,10 @@ #include "ash/shell_delegate.h" #include "ash/shell_factory.h" #include "ash/shell_window_ids.h" +#include "ash/system/audio/tray_volume.h" +#include "ash/system/settings/tray_settings.h" +#include "ash/system/tray/system_tray_delegate.h" +#include "ash/system/tray/system_tray.h" #include "ash/tooltips/tooltip_controller.h" #include "ash/wm/activation_controller.h" #include "ash/wm/base_layout_manager.h" @@ -172,6 +176,46 @@ void CreateSpecialContainers(aura::Window* root_window) { lock_screen_related_containers); } +class DummySystemTrayDelegate : public SystemTrayDelegate { + public: + DummySystemTrayDelegate() + : muted_(false), + volume_(0.5) { + } + + virtual ~DummySystemTrayDelegate() {} + + private: + + // SystemTrayDelegate implementation. + virtual void ShowSettings() OVERRIDE { + } + + virtual void ShowHelp() OVERRIDE { + } + + virtual bool AudioMuted() OVERRIDE { + return muted_; + } + + virtual void SetAudioMuted(bool muted) OVERRIDE { + muted_ = muted; + } + + virtual float VolumeLevel() OVERRIDE { + return volume_; + } + + virtual void SetVolumeLevel(float volume) OVERRIDE { + volume_ = volume; + } + + bool muted_; + float volume_; + + DISALLOW_COPY_AND_ASSIGN(DummySystemTrayDelegate); +}; + } // namespace // static @@ -231,6 +275,9 @@ Shell::~Shell() { // deleted as it has a reference to launcher model. workspace_controller_.reset(); + // The system tray needs to be reset before all the windows are destroyed. + tray_.reset(); + // Delete containers now so that child windows does not access // observers when they are destructed. aura::RootWindow* root_window = GetRootWindow(); @@ -320,6 +367,28 @@ void Shell::Init() { if (!status_widget_) status_widget_ = internal::CreateStatusArea(); + if (command_line->HasSwitch(switches::kAshUberTray)) { + // TODO(sad): This is rather ugly at the moment. This is because we are + // supporting both the old and the new status bar at the same time. This + // will soon get better once the new one is ready and the old one goes out + // the door. + if (delegate_.get()) + status_widget_ = delegate_->CreateStatusArea(); + if (!status_widget_) + status_widget_ = internal::CreateStatusArea(); + status_widget_->GetContentsView()->RemoveAllChildViews(false); + tray_.reset(new SystemTray()); + status_widget_->GetContentsView()->AddChildView(tray_.get()); + + tray_->AddTrayItem(new TrayVolume()); + tray_->AddTrayItem(new TraySettings()); + + if (delegate_.get()) + tray_delegate_.reset(delegate_->CreateSystemTrayDelegate()); + if (!tray_delegate_.get()) + tray_delegate_.reset(new DummySystemTrayDelegate()); + } + aura::Window* default_container = GetContainer(internal::kShellWindowId_DefaultContainer); launcher_.reset(new Launcher(default_container)); diff --git a/ash/shell.h b/ash/shell.h index db60bae..5a57c24 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -42,6 +42,8 @@ class Launcher; class NestedDispatcherController; class PowerButtonController; class ShellDelegate; +class SystemTrayDelegate; +class SystemTray; class VideoDetector; class WindowCycleController; @@ -188,11 +190,14 @@ class ASH_EXPORT Shell { } ShellDelegate* delegate() { return delegate_.get(); } + SystemTrayDelegate* tray_delegate() { return tray_delegate_.get(); } Launcher* launcher() { return launcher_.get(); } internal::ShelfLayoutManager* shelf() const { return shelf_; } + SystemTray* tray() const { return tray_.get(); } + // Made available for tests. internal::ShadowController* shadow_controller() { return shadow_controller_.get(); @@ -240,6 +245,7 @@ class ASH_EXPORT Shell { #endif // !defined(OS_MACOSX) scoped_ptr<ShellDelegate> delegate_; + scoped_ptr<SystemTrayDelegate> tray_delegate_; scoped_ptr<Launcher> launcher_; @@ -287,6 +293,10 @@ class ASH_EXPORT Shell { // Status area with clock, Wi-Fi signal, etc. views::Widget* status_widget_; + // System tray with clock, Wi-Fi signal, etc. (a replacement in progress for + // |status_widget_|). + scoped_ptr<SystemTray> tray_; + // Offset between the corner of the status area and the corner of the screen // when in the compact window mode. gfx::Size compact_status_area_offset_; diff --git a/ash/shell/shell_main.cc b/ash/shell/shell_main.cc index 7d7715d..86601e9 100644 --- a/ash/shell/shell_main.cc +++ b/ash/shell/shell_main.cc @@ -208,6 +208,10 @@ class ShellDelegateImpl : public ash::ShellDelegate { return launcher_delegate_; } + virtual ash::SystemTrayDelegate* CreateSystemTrayDelegate() { + return NULL; + } + private: // Used to update Launcher. Owned by main. WindowWatcher* watcher_; diff --git a/ash/shell_delegate.h b/ash/shell_delegate.h index d4d5f44..55b1a68 100644 --- a/ash/shell_delegate.h +++ b/ash/shell_delegate.h @@ -28,6 +28,7 @@ class LauncherDelegate; class LauncherModel; struct LauncherItem; class ScreenshotDelegate; +class SystemTrayDelegate; // Delegate of the Shell. class ASH_EXPORT ShellDelegate { @@ -84,6 +85,9 @@ class ASH_EXPORT ShellDelegate { // value. virtual LauncherDelegate* CreateLauncherDelegate( ash::LauncherModel* model) = 0; + + // Creates a system-tray delegate. Shell takes ownership of the delegate. + virtual SystemTrayDelegate* CreateSystemTrayDelegate() = 0; }; } // namespace ash diff --git a/ash/system/audio/tray_volume.cc b/ash/system/audio/tray_volume.cc new file mode 100644 index 0000000..a8898ac --- /dev/null +++ b/ash/system/audio/tray_volume.cc @@ -0,0 +1,115 @@ +// Copyright (c) 2012 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/tray_volume.h" + +#include "ash/shell.h" +#include "ash/system/tray/system_tray_delegate.h" +#include "base/utf_string_conversions.h" +#include "grit/ui_resources.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/image/image.h" +#include "ui/views/controls/button/image_button.h" +#include "ui/views/controls/image_view.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/slider.h" +#include "ui/views/layout/box_layout.h" +#include "ui/views/view.h" + +namespace tray { + +class VolumeView : public views::View, + public views::ButtonListener, + public views::SliderListener { + public: + VolumeView() { + SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, + 0, 0, 5)); + + gfx::Image image = ui::ResourceBundle::GetSharedInstance().GetImageNamed( + IDR_AURA_UBER_TRAY_VOLUME); + icon_ = new views::ToggleImageButton(this); + icon_->SetImage(views::CustomButton::BS_NORMAL, image.ToSkBitmap()); + icon_->SetImage(views::CustomButton::BS_HOT, image.ToSkBitmap()); + icon_->SetImage(views::CustomButton::BS_PUSHED, image.ToSkBitmap()); + + image = ui::ResourceBundle::GetSharedInstance().GetImageNamed( + IDR_AURA_UBER_TRAY_VOLUME_MUTE); + icon_->SetToggledImage(views::CustomButton::BS_NORMAL, image.ToSkBitmap()); + icon_->SetToggledImage(views::CustomButton::BS_HOT, image.ToSkBitmap()); + icon_->SetToggledImage(views::CustomButton::BS_PUSHED, image.ToSkBitmap()); + + ash::SystemTrayDelegate* delegate = + ash::Shell::GetInstance()->tray_delegate(); + icon_->SetToggled(delegate->AudioMuted()); + AddChildView(icon_); + + views::Slider* slider = new views::Slider(this, views::Slider::HORIZONTAL); + slider->SetValue(delegate->VolumeLevel()); + AddChildView(slider); + slider->SetVisible(true); + } + + private: + + // Overridden from views::ButtonListener. + virtual void ButtonPressed(views::Button* sender, + const views::Event& event) OVERRIDE { + CHECK(sender == icon_); + ash::SystemTrayDelegate* delegate = + ash::Shell::GetInstance()->tray_delegate(); + delegate->SetAudioMuted(!delegate->AudioMuted()); + + // TODO(sad): Should the icon auto-update its state when mute/unmute happens + // above? + icon_->SetToggled(delegate->AudioMuted()); + } + + // Overridden from views:SliderListener. + virtual void SliderValueChanged(views::Slider* sender, + float value, + float old_value) OVERRIDE { + ash::Shell::GetInstance()->tray_delegate()->SetVolumeLevel(value); + } + + views::ToggleImageButton* icon_; + + DISALLOW_COPY_AND_ASSIGN(VolumeView); +}; + +} // namespace tray + +TrayVolume::TrayVolume() { +} + +TrayVolume::~TrayVolume() { +} + +views::View* TrayVolume::CreateTrayView() { + tray_view_.reset(new views::ImageView()); + tray_view_->SetImage(ui::ResourceBundle::GetSharedInstance().GetImageNamed( + IDR_AURA_UBER_TRAY_VOLUME).ToSkBitmap()); + return tray_view_.get(); +} + +views::View* TrayVolume::CreateDefaultView() { + volume_view_.reset(new tray::VolumeView); + return volume_view_.get(); +} + +views::View* TrayVolume::CreateDetailedView() { + NOTIMPLEMENTED(); + return NULL; +} + +void TrayVolume::DestroyTrayView() { + tray_view_.reset(); +} + +void TrayVolume::DestroyDefaultView() { + volume_view_.reset(); +} + +void TrayVolume::DestroyDetailedView() { +} diff --git a/ash/system/audio/tray_volume.h b/ash/system/audio/tray_volume.h new file mode 100644 index 0000000..f43dc33 --- /dev/null +++ b/ash/system/audio/tray_volume.h @@ -0,0 +1,40 @@ +// Copyright (c) 2012 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_TRAY_VOLUME_H_ +#define ASH_SYSTEM_AUDIO_TRAY_VOLUME_H_ +#pragma once + +#include "ash/system/tray/system_tray_item.h" +#include "base/memory/scoped_ptr.h" + +namespace views { +class ImageView; +} + +namespace tray { +class VolumeView; +} + +class TrayVolume : public ash::SystemTrayItem { + public: + TrayVolume(); + virtual ~TrayVolume(); + + private: + // Overridden from ash::SystemTrayItem + virtual views::View* CreateTrayView() OVERRIDE; + virtual views::View* CreateDefaultView() OVERRIDE; + virtual views::View* CreateDetailedView() OVERRIDE; + virtual void DestroyTrayView() OVERRIDE; + virtual void DestroyDefaultView() OVERRIDE; + virtual void DestroyDetailedView() OVERRIDE; + + scoped_ptr<tray::VolumeView> volume_view_; + scoped_ptr<views::ImageView> tray_view_; + + DISALLOW_COPY_AND_ASSIGN(TrayVolume); +}; + +#endif // ASH_SYSTEM_AUDIO_TRAY_VOLUME_H_ diff --git a/ash/system/settings/tray_settings.cc b/ash/system/settings/tray_settings.cc new file mode 100644 index 0000000..c277c5f --- /dev/null +++ b/ash/system/settings/tray_settings.cc @@ -0,0 +1,95 @@ +// Copyright (c) 2012 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/settings/tray_settings.h" + +#include "ash/shell.h" +#include "ash/system/tray/system_tray_delegate.h" +#include "base/logging.h" +#include "base/utf_string_conversions.h" +#include "grit/ui_resources.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/image/image.h" +#include "ui/views/controls/image_view.h" +#include "ui/views/controls/label.h" +#include "ui/views/layout/box_layout.h" +#include "ui/views/layout/fill_layout.h" +#include "ui/views/view.h" + +namespace { + +class SettingsView : public views::View { + public: + SettingsView() { + SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, + 0, 0, 3)); + views::ImageView* icon = new views::ImageView; + icon->SetImage(ui::ResourceBundle::GetSharedInstance(). + GetImageNamed(IDR_AURA_UBER_TRAY_SETTINGS).ToSkBitmap()); + views::Label* label = new views::Label(ASCIIToUTF16("Settings")); + + AddChildView(icon); + AddChildView(label); + } + + virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE { + ash::Shell::GetInstance()->tray_delegate()->ShowSettings(); + return true; + } + + private: + DISALLOW_COPY_AND_ASSIGN(SettingsView); +}; + +class HelpView : public views::View { + public: + HelpView() { + SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, + 0, 0, 3)); + views::Label* label = new views::Label(ASCIIToUTF16("Help")); + AddChildView(label); + } + + virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE { + ash::Shell::GetInstance()->tray_delegate()->ShowHelp(); + return true; + } + + private: + DISALLOW_COPY_AND_ASSIGN(HelpView); +}; + +} // namespace + +views::View* TraySettings::CreateTrayView() { + return NULL; +} + +views::View* TraySettings::CreateDefaultView() { + views::View* container = new views::View; + views::BoxLayout* layout = + new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 5); + layout->set_spread_blank_space(true); + container->SetLayoutManager(layout); + + views::View* settings = new SettingsView; + container->AddChildView(settings); + views::View* help = new HelpView; + container->AddChildView(help); + return container; +} + +views::View* TraySettings::CreateDetailedView() { + NOTIMPLEMENTED(); + return NULL; +} + +void TraySettings::DestroyTrayView() { +} + +void TraySettings::DestroyDefaultView() { +} + +void TraySettings::DestroyDetailedView() { +} diff --git a/ash/system/settings/tray_settings.h b/ash/system/settings/tray_settings.h new file mode 100644 index 0000000..701f1aa --- /dev/null +++ b/ash/system/settings/tray_settings.h @@ -0,0 +1,30 @@ +// Copyright (c) 2012 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_SETTINGS_TRAY_SETTINGS_H_ +#define ASH_SYSTEM_SETTINGS_TRAY_SETTINGS_H_ +#pragma once + +#include "ash/system/tray/system_tray_item.h" + +class TraySettings : public ash::SystemTrayItem { + public: + TraySettings() { + } + + virtual ~TraySettings() {} + + private: + // Overridden from ash::SystemTrayItem + virtual views::View* CreateTrayView() OVERRIDE; + virtual views::View* CreateDefaultView() OVERRIDE; + virtual views::View* CreateDetailedView() OVERRIDE; + virtual void DestroyTrayView() OVERRIDE; + virtual void DestroyDefaultView() OVERRIDE; + virtual void DestroyDetailedView() OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(TraySettings); +}; + +#endif // ASH_SYSTEM_SETTINGS_TRAY_SETTINGS_H_ diff --git a/ash/system/tray/system_tray.cc b/ash/system/tray/system_tray.cc new file mode 100644 index 0000000..5b29bbf --- /dev/null +++ b/ash/system/tray/system_tray.cc @@ -0,0 +1,100 @@ +// Copyright (c) 2012 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/tray/system_tray.h" + +#include "ash/shell/panel_window.h" +#include "ash/system/tray/system_tray_item.h" +#include "base/logging.h" +#include "base/utf_string_conversions.h" +#include "third_party/skia/include/core/SkColor.h" +#include "ui/views/border.h" +#include "ui/views/bubble/bubble_delegate.h" +#include "ui/views/controls/label.h" +#include "ui/views/layout/box_layout.h" +#include "ui/views/view.h" + +namespace { + +const int kTrayIconHeight = 50; +const int kPadding = 5; + +class SystemTrayBubble : public views::BubbleDelegateView { + public: + explicit SystemTrayBubble(ash::SystemTray* tray) + : views::BubbleDelegateView(tray, views::BubbleBorder::BOTTOM_RIGHT), + tray_(tray) { + } + + virtual ~SystemTrayBubble() { + std::vector<ash::SystemTrayItem*> items = tray_->items(); + for (std::vector<ash::SystemTrayItem*>::iterator it = items.begin(); + it != items.end(); + ++it) { + (*it)->DestroyDefaultView(); + } + } + + private: + // Overridden from views::BubbleDelegateView. + virtual void Init() OVERRIDE { + SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, + 0, 0, 1)); + + std::vector<ash::SystemTrayItem*> items = tray_->items(); + for (std::vector<ash::SystemTrayItem*>::iterator it = items.begin(); + it != items.end(); + ++it) { + views::View* view = (*it)->CreateDefaultView(); + if (it != items.begin()) + view->set_border(views::Border::CreateSolidSidedBorder( + 1, 0, 0, 0, SkColorSetARGB(25, 0, 0, 0))); + AddChildView(view); + } + } + + ash::SystemTray* tray_; + + DISALLOW_COPY_AND_ASSIGN(SystemTrayBubble); +}; + +} // namespace + +namespace ash { + +SystemTray::SystemTray() : items_() { + SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, + 5, 10, 3)); +} + +SystemTray::~SystemTray() { + for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); + it != items_.end(); + ++it) { + (*it)->DestroyTrayView(); + } +} + +void SystemTray::AddTrayItem(SystemTrayItem* item) { + items_.push_back(item); + + views::View* tray_item = item->CreateTrayView(); + if (tray_item) { + AddChildView(tray_item); + PreferredSizeChanged(); + } +} + +void SystemTray::RemoveTrayItem(SystemTrayItem* item) { + NOTIMPLEMENTED(); +} + +bool SystemTray::OnMousePressed(const views::MouseEvent& event) { + SystemTrayBubble* bubble = new SystemTrayBubble(this); + views::BubbleDelegateView::CreateBubble(bubble); + bubble->Show(); + return true; +} + +} // namespace ash diff --git a/ash/system/tray/system_tray.h b/ash/system/tray/system_tray.h new file mode 100644 index 0000000..fb9b8ce --- /dev/null +++ b/ash/system/tray/system_tray.h @@ -0,0 +1,47 @@ +// Copyright (c) 2012 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_TRAY_SYSTEM_TRAY_H_ +#define ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_ +#pragma once + +#include "ash/ash_export.h" +#include "base/basictypes.h" +#include "ui/views/view.h" + +#include <vector> + +namespace views { +class View; +} + +namespace ash { + +class SystemTrayItem; + +class ASH_EXPORT SystemTray : public views::View { + public: + SystemTray(); + virtual ~SystemTray(); + + // Adds a new item in the tray. + void AddTrayItem(SystemTrayItem* item); + + // Removes an existing tray item. + void RemoveTrayItem(SystemTrayItem* item); + + const std::vector<SystemTrayItem*>& items() const { return items_; } + + private: + // Overridden from views::View. + virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; + + std::vector<SystemTrayItem*> items_; + + DISALLOW_COPY_AND_ASSIGN(SystemTray); +}; + +} // namespace ash + +#endif // ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_ diff --git a/ash/system/tray/system_tray_delegate.h b/ash/system/tray/system_tray_delegate.h new file mode 100644 index 0000000..7959361 --- /dev/null +++ b/ash/system/tray/system_tray_delegate.h @@ -0,0 +1,36 @@ +// Copyright (c) 2012 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_SYSTEM_DELEGATE_H_ +#define ASH_SYSTEM_SYSTEM_DELEGATE_H_ +#pragma once + +namespace ash { + +class SystemTrayDelegate { + public: + virtual ~SystemTrayDelegate(){} + + // Shows settings. + virtual void ShowSettings() = 0; + + // Shows help. + virtual void ShowHelp() = 0; + + // Is the system muted? + virtual bool AudioMuted() = 0; + + // Mutes/Unmutes the system. + virtual void SetAudioMuted(bool muted) = 0; + + // Gets volume level. + virtual float VolumeLevel() = 0; + + // Sets the volume level. + virtual void SetVolumeLevel(float level) = 0; +}; + +} // namespace ash + +#endif // ASH_SYSTEM_SYSTEM_DELEGATE_H_ diff --git a/ash/system/tray/system_tray_item.cc b/ash/system/tray/system_tray_item.cc new file mode 100644 index 0000000..ed76fec --- /dev/null +++ b/ash/system/tray/system_tray_item.cc @@ -0,0 +1,21 @@ +// Copyright (c) 2012 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/tray/system_tray_item.h" + +#include "ui/views/view.h" + +namespace ash { + +SystemTrayItem::SystemTrayItem() { +} + +SystemTrayItem::~SystemTrayItem() { +} + +void SystemTrayItem::PopupDetailedView() { + NOTIMPLEMENTED(); +} + +} // namespace ash diff --git a/ash/system/tray/system_tray_item.h b/ash/system/tray/system_tray_item.h new file mode 100644 index 0000000..ab0d7e7 --- /dev/null +++ b/ash/system/tray/system_tray_item.h @@ -0,0 +1,54 @@ +// Copyright (c) 2012 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_TRAY_SYSTEM_TRAY_ITEM_H_ +#define ASH_SYSTEM_TRAY_SYSTEM_TRAY_ITEM_H_ +#pragma once + +#include "ash/ash_export.h" +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" + +namespace views { +class View; +} + +namespace ash { + +class ASH_EXPORT SystemTrayItem { + public: + SystemTrayItem(); + virtual ~SystemTrayItem(); + + // Returns a view to be displayed in the system tray. If this returns NULL, + // then this item is not displayed in the tray. + virtual views::View* CreateTrayView() = 0; + + // Returns a view for the item to be displayed in the list. This view can be + // displayed with a number of other tray items, so this should not be too + // big. + virtual views::View* CreateDefaultView() = 0; + + // Returns a detailed view for the item. This view is displayed standalone. + virtual views::View* CreateDetailedView() = 0; + + // These functions are called when the corresponding view item is about to be + // removed. An item should do appropriate cleanup in these functions. + virtual void DestroyTrayView() = 0; + virtual void DestroyDefaultView() = 0; + virtual void DestroyDetailedView() = 0; + + // Pops up the detailed view for this item. An item can request to show its + // detailed view using this function (e.g. from an observer callback when + // something, e.g. volume, network availability etc. changes). + void PopupDetailedView(); + + private: + + DISALLOW_COPY_AND_ASSIGN(SystemTrayItem); +}; + +} // namespace ash + +#endif // ASH_SYSTEM_TRAY_SYSTEM_TRAY_ITEM_H_ diff --git a/ash/test/test_shell_delegate.cc b/ash/test/test_shell_delegate.cc index 6f7a958..8eb2dfa 100644 --- a/ash/test/test_shell_delegate.cc +++ b/ash/test/test_shell_delegate.cc @@ -66,5 +66,8 @@ LauncherDelegate* TestShellDelegate::CreateLauncherDelegate( return NULL; } +SystemTrayDelegate* TestShellDelegate::CreateSystemTrayDelegate() { + return NULL; +} } // namespace test } // namespace ash diff --git a/ash/test/test_shell_delegate.h b/ash/test/test_shell_delegate.h index 6b11557..7400559 100644 --- a/ash/test/test_shell_delegate.h +++ b/ash/test/test_shell_delegate.h @@ -32,6 +32,7 @@ class TestShellDelegate : public ShellDelegate { ScreenshotDelegate* screenshot_delegate) OVERRIDE; virtual LauncherDelegate* CreateLauncherDelegate( ash::LauncherModel* model) OVERRIDE; + virtual SystemTrayDelegate* CreateSystemTrayDelegate() OVERRIDE; }; } // namespace test |