diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-22 20:40:37 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-22 20:40:37 +0000 |
commit | 64257caf8b43768388970bd84b83e7d2fab5bbdb (patch) | |
tree | 9f6d8d7a88ed96109bec1fd3196ef4392728fc2e | |
parent | 64b2a008b7112e1147e407c056c442c657f3c5cd (diff) | |
download | chromium_src-64257caf8b43768388970bd84b83e7d2fab5bbdb.zip chromium_src-64257caf8b43768388970bd84b83e7d2fab5bbdb.tar.gz chromium_src-64257caf8b43768388970bd84b83e7d2fab5bbdb.tar.bz2 |
ash: Bluetooth popup: list the devices, and allow connecting/disconnecting from the list.
BUG=110130
TEST=none
Review URL: https://chromiumcodereview.appspot.com/9815021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128292 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/shell.cc | 3 | ||||
-rw-r--r-- | ash/system/bluetooth/tray_bluetooth.cc | 44 | ||||
-rw-r--r-- | ash/system/network/tray_network.cc | 52 | ||||
-rw-r--r-- | ash/system/tray/system_tray_delegate.h | 3 | ||||
-rw-r--r-- | ash/system/tray/tray_views.cc | 41 | ||||
-rw-r--r-- | ash/system/tray/tray_views.h | 26 | ||||
-rw-r--r-- | chrome/browser/chromeos/system/ash_system_tray_delegate.cc | 20 |
7 files changed, 133 insertions, 56 deletions
diff --git a/ash/shell.cc b/ash/shell.cc index c0e4e44..197808e 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -345,6 +345,9 @@ class DummySystemTrayDelegate : public SystemTrayDelegate { BluetoothDeviceList* list) OVERRIDE { } + virtual void ToggleBluetoothConnection(const std::string& address) OVERRIDE { + } + virtual void GetAvailableIMEList(IMEInfoList* list) { } diff --git a/ash/system/bluetooth/tray_bluetooth.cc b/ash/system/bluetooth/tray_bluetooth.cc index 4ae6262..9e4a715 100644 --- a/ash/system/bluetooth/tray_bluetooth.cc +++ b/ash/system/bluetooth/tray_bluetooth.cc @@ -18,6 +18,10 @@ #include "ui/views/controls/label.h" #include "ui/views/layout/box_layout.h" +namespace { +const int kDeviceListHeight = 190; +} + namespace ash { namespace internal { @@ -36,7 +40,6 @@ class BluetoothDefaultView : public TrayItemMore { IDR_AURA_UBER_TRAY_BLUETOOTH_LARGE).ToSkBitmap()); AddChildView(icon); - // TODO(sad): Use the correct label depending on the status. label_ = new views::Label; AddChildView(label_); UpdateLabel(); @@ -79,7 +82,7 @@ class BluetoothDetailedView : public views::View, virtual ~BluetoothDetailedView() {} - void Update(BluetoothDeviceList& list) { + void Update(const BluetoothDeviceList& list) { RemoveAllChildViews(true); header_ = NULL; @@ -87,7 +90,7 @@ class BluetoothDetailedView : public views::View, toggle_bluetooth_ = NULL; AppendHeaderEntry(); - AppendDeviceList(); + AppendDeviceList(list); AppendSettingsEntries(); Layout(); @@ -111,7 +114,28 @@ class BluetoothDetailedView : public views::View, header_ = container; } - void AppendDeviceList() { + void AppendDeviceList(const BluetoothDeviceList& list) { + views::View* devices = new views::View; + devices->SetLayoutManager(new views::BoxLayout( + views::BoxLayout::kVertical, 0, 0, 1)); + + for (size_t i = 0; i < list.size(); i++) { + HoverHighlightView* container = new HoverHighlightView(this); + container->AddLabel(list[i].display_name, + list[i].connected ? gfx::Font::BOLD : gfx::Font::NORMAL); + devices->AddChildView(container); + device_map_[container] = list[i].address; + } + + FixedSizedScrollView* scroller = new FixedSizedScrollView; + scroller->set_border(views::Border::CreateSolidSidedBorder(1, 0, 1, 0, + SkColorSetARGB(25, 0, 0, 0))); + scroller->set_fixed_size( + gfx::Size(devices->GetPreferredSize().width() + + scroller->GetScrollBarWidth(), + kDeviceListHeight)); + scroller->SetContentsView(devices); + AddChildView(scroller); } void AppendSettingsEntries() { @@ -122,13 +146,13 @@ class BluetoothDetailedView : public views::View, container->AddLabel(rb.GetLocalizedString( delegate->GetBluetoothEnabled() ? IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH : - IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH)); + IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH), gfx::Font::NORMAL); AddChildView(container); toggle_bluetooth_ = container; container = new HoverHighlightView(this); container->AddLabel(rb.GetLocalizedString( - IDS_ASH_STATUS_TRAY_BLUETOOTH_ADD_DEVICE)); + IDS_ASH_STATUS_TRAY_BLUETOOTH_ADD_DEVICE), gfx::Font::NORMAL); AddChildView(container); add_device_ = container; } @@ -144,10 +168,16 @@ class BluetoothDetailedView : public views::View, } else if (sender == add_device_) { delegate->AddBluetoothDevice(); } else { - // TODO: Connect/disconnect from the device list. + std::map<views::View*, std::string>::iterator find; + find = device_map_.find(sender); + if (find != device_map_.end()) { + std::string device_id = find->second; + delegate->ToggleBluetoothConnection(device_id); + } } } + std::map<views::View*, std::string> device_map_; views::View* header_; views::View* add_device_; views::View* toggle_bluetooth_; diff --git a/ash/system/network/tray_network.cc b/ash/system/network/tray_network.cc index 009cc7f5..ea670b4 100644 --- a/ash/system/network/tray_network.cc +++ b/ash/system/network/tray_network.cc @@ -29,49 +29,6 @@ namespace { // Height of the list of networks in the popup. const int kNetworkListHeight = 160; -// A custom scroll-view that has a specified dimension. -class FixedSizedScrollView : public views::ScrollView { - public: - FixedSizedScrollView() { - set_focusable(true); - set_notify_enter_exit_on_child(true); - } - - virtual ~FixedSizedScrollView() {} - - void SetContentsView(View* view) { - SetContents(view); - view->SetBoundsRect(gfx::Rect(view->GetPreferredSize())); - } - - void set_fixed_size(gfx::Size size) { fixed_size_ = size; } - - private: - // Overridden from views::View. - virtual gfx::Size GetPreferredSize() OVERRIDE { - return fixed_size_; - } - - virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE { - views::View* contents = GetContents(); - gfx::Rect bounds = contents->bounds(); - bounds.set_width(width() - GetScrollBarWidth()); - contents->SetBoundsRect(bounds); - } - - virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE { - RequestFocus(); - } - - virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE { - // Do not paint the focus border. - } - - gfx::Size fixed_size_; - - DISALLOW_COPY_AND_ASSIGN(FixedSizedScrollView); -}; - } namespace ash { @@ -230,7 +187,7 @@ class NetworkDetailedView : public views::View, HoverHighlightView* container = new HoverHighlightView(this); container->AddLabel(rb.GetLocalizedString(delegate->GetWifiEnabled() ? IDS_ASH_STATUS_TRAY_DISABLE_WIFI : - IDS_ASH_STATUS_TRAY_ENABLE_WIFI)); + IDS_ASH_STATUS_TRAY_ENABLE_WIFI), gfx::Font::NORMAL); AddChildView(container); toggle_wifi_ = container; } @@ -239,7 +196,8 @@ class NetworkDetailedView : public views::View, HoverHighlightView* container = new HoverHighlightView(this); container->AddLabel(rb.GetLocalizedString( delegate->GetCellularEnabled() ? IDS_ASH_STATUS_TRAY_DISABLE_MOBILE : - IDS_ASH_STATUS_TRAY_ENABLE_MOBILE)); + IDS_ASH_STATUS_TRAY_ENABLE_MOBILE), + gfx::Font::NORMAL); AddChildView(container); toggle_mobile_ = container; } @@ -264,14 +222,14 @@ class NetworkDetailedView : public views::View, // Settings, only if logged in. HoverHighlightView* container = new HoverHighlightView(this); container->AddLabel(rb.GetLocalizedString( - IDS_ASH_STATUS_TRAY_NETWORK_SETTINGS)); + IDS_ASH_STATUS_TRAY_NETWORK_SETTINGS), gfx::Font::NORMAL); AddChildView(container); settings_ = container; } else { // Allow changing proxy settings in the login screen. HoverHighlightView* container = new HoverHighlightView(this); container->AddLabel(rb.GetLocalizedString( - IDS_ASH_STATUS_TRAY_NETWORK_PROXY_SETTINGS)); + IDS_ASH_STATUS_TRAY_NETWORK_PROXY_SETTINGS), gfx::Font::NORMAL); AddChildView(container); proxy_settings_ = container; } diff --git a/ash/system/tray/system_tray_delegate.h b/ash/system/tray/system_tray_delegate.h index 5a1759a..d665081 100644 --- a/ash/system/tray/system_tray_delegate.h +++ b/ash/system/tray/system_tray_delegate.h @@ -125,6 +125,9 @@ class SystemTrayDelegate { // Returns a list of available bluetooth devices. virtual void GetAvailableBluetoothDevices(BluetoothDeviceList* devices) = 0; + // Toggles connection to a specific bluetooth device. + virtual void ToggleBluetoothConnection(const std::string& address) = 0; + // Returns a list of availble IMEs. virtual void GetAvailableIMEList(IMEInfoList* list) = 0; diff --git a/ash/system/tray/tray_views.cc b/ash/system/tray/tray_views.cc index 73f856f..1cdf525 100644 --- a/ash/system/tray/tray_views.cc +++ b/ash/system/tray/tray_views.cc @@ -58,12 +58,14 @@ void HoverHighlightView::AddIconAndLabel(const SkBitmap& image, AddChildView(label); } -void HoverHighlightView::AddLabel(const string16& text) { +void HoverHighlightView::AddLabel(const string16& text, + gfx::Font::FontStyle style) { SetLayoutManager(new views::FillLayout()); views::Label* label = new views::Label(text); label->set_border(views::Border::CreateEmptyBorder( 5, kTrayPopupDetailsIconWidth + kIconPaddingLeft, 5, 0)); label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + label->SetFont(label->font().DeriveFont(0, style)); AddChildView(label); } @@ -85,6 +87,43 @@ void HoverHighlightView::OnMouseExited(const views::MouseEvent& event) { SchedulePaint(); } +//////////////////////////////////////////////////////////////////////////////// +// FixedSizedScrollView + +FixedSizedScrollView::FixedSizedScrollView() { + set_focusable(true); + set_notify_enter_exit_on_child(true); +} + +FixedSizedScrollView::~FixedSizedScrollView() {} + +void FixedSizedScrollView::SetContentsView(View* view) { + SetContents(view); + view->SetBoundsRect(gfx::Rect(view->GetPreferredSize())); +} + +gfx::Size FixedSizedScrollView::GetPreferredSize() { + return fixed_size_; +} + +void FixedSizedScrollView::OnBoundsChanged(const gfx::Rect& previous_bounds) { + views::View* contents = GetContents(); + gfx::Rect bounds = contents->bounds(); + bounds.set_width(width() - GetScrollBarWidth()); + contents->SetBoundsRect(bounds); +} + +void FixedSizedScrollView::OnMouseEntered(const views::MouseEvent& event) { + // TODO(sad): This is done to make sure that the scroll view scrolls on + // mouse-wheel events. This is ugly, and Ben thinks this is weird. There + // should be a better fix for this. + RequestFocus(); +} + +void FixedSizedScrollView::OnPaintFocusBorder(gfx::Canvas* canvas) { + // Do not paint the focus border. +} + void SetupLabelForTray(views::Label* label) { label->SetFont( label->font().DeriveFont(2, gfx::Font::BOLD)); diff --git a/ash/system/tray/tray_views.h b/ash/system/tray/tray_views.h index bf0267a..44127f6 100644 --- a/ash/system/tray/tray_views.h +++ b/ash/system/tray/tray_views.h @@ -9,6 +9,7 @@ #include "ui/gfx/font.h" #include "ui/gfx/size.h" #include "ui/views/controls/image_view.h" +#include "ui/views/controls/scroll_view.h" #include "ui/views/view.h" class SkBitmap; @@ -52,7 +53,7 @@ class HoverHighlightView : public views::View { // Convenience function for adding a label with padding on the left for a // blank icon. - void AddLabel(const string16& text); + void AddLabel(const string16& text, gfx::Font::FontStyle style); private: // Overridden from views::View. @@ -65,6 +66,29 @@ class HoverHighlightView : public views::View { DISALLOW_COPY_AND_ASSIGN(HoverHighlightView); }; +// A custom scroll-view that has a specified dimension. +class FixedSizedScrollView : public views::ScrollView { + public: + FixedSizedScrollView(); + + virtual ~FixedSizedScrollView(); + + void SetContentsView(View* view); + + void set_fixed_size(gfx::Size size) { fixed_size_ = size; } + + private: + // Overridden from views::View. + virtual gfx::Size GetPreferredSize() OVERRIDE; + virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; + virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; + virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; + + gfx::Size fixed_size_; + + DISALLOW_COPY_AND_ASSIGN(FixedSizedScrollView); +}; + // Sets up a Label properly for the tray (sets color, font etc.). void SetupLabelForTray(views::Label* label); diff --git a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc index dc06d58..9cc7d80 100644 --- a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc +++ b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc @@ -77,6 +77,14 @@ void BluetoothDiscoveryFailure() { // TODO(sad): Show an error bubble? } +void BluetoothDeviceDisconnectError() { + // TODO(sad): Do something? +} + +void BluetoothDeviceConnectError() { + // TODO(sad): Do something? +} + class SystemTrayDelegate : public ash::SystemTrayDelegate, public AudioHandler::VolumeObserver, public PowerManagerClient::Observer, @@ -269,6 +277,8 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); for (size_t i = 0; i < devices.size(); ++i) { BluetoothDevice* device = devices[i]; + if (!device->IsPaired()) + continue; ash::BluetoothDeviceInfo info; info.address = device->address(); info.display_name = device->GetName(); @@ -277,6 +287,16 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, } } + virtual void ToggleBluetoothConnection(const std::string& address) OVERRIDE { + BluetoothDevice* device = bluetooth_adapter_->GetDevice(address); + if (!device) + return; + if (device->IsConnected()) + device->Disconnect(base::Bind(&BluetoothDeviceDisconnectError)); + else if (device->IsPaired()) + device->Connect(NULL, base::Bind(&BluetoothDeviceConnectError)); + } + virtual void GetAvailableIMEList(ash::IMEInfoList* list) OVERRIDE { input_method::InputMethodManager* manager = input_method::InputMethodManager::GetInstance(); |