| Index: ash/system/chromeos/bluetooth/tray_bluetooth.cc
|
| diff --git a/ash/system/chromeos/bluetooth/tray_bluetooth.cc b/ash/system/chromeos/bluetooth/tray_bluetooth.cc
|
| index c4e145265322fb3d7c1f268a58f72a61176114be..f1afbe1e744df4e7a51f7241a5619c59286ff86a 100644
|
| --- a/ash/system/chromeos/bluetooth/tray_bluetooth.cc
|
| +++ b/ash/system/chromeos/bluetooth/tray_bluetooth.cc
|
| @@ -6,6 +6,7 @@
|
|
|
| #include "ash/session/session_state_delegate.h"
|
| #include "ash/shell.h"
|
| +#include "ash/system/tray/fixed_sized_image_view.h"
|
| #include "ash/system/tray/fixed_sized_scroll_view.h"
|
| #include "ash/system/tray/hover_highlight_view.h"
|
| #include "ash/system/tray/system_tray.h"
|
| @@ -24,11 +25,19 @@
|
| #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"
|
|
|
| namespace ash {
|
| namespace tray {
|
| namespace {
|
|
|
| +// Constants of special layout for bluetooth device entries.
|
| +const int kDeviceLabelLeftMargin = 7;
|
| +const int kDeviceTypeIconAreaWidth = 60;
|
| +const int kConnectedIconSize = 10;
|
| +const int kConnectedIconOffsetTop = 26;
|
| +const int kConnectedIconOffsetLeft = 33;
|
| +
|
| // Updates bluetooth device |device| in the |list|. If it is new, append to the
|
| // end of the |list|; otherwise, keep it at the same place, but update the data
|
| // with new device info provided by |device|.
|
| @@ -60,6 +69,94 @@ void RemoveObsoleteBluetoothDevicesFromList(
|
| }
|
| }
|
|
|
| +// Returns a resource id of an icon which corresponds to the given device type.
|
| +int GetDeviceIconResourceId(device::BluetoothDevice::DeviceType device_type) {
|
| + switch (device_type) {
|
| + case device::BluetoothDevice::DEVICE_COMPUTER:
|
| + return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_COMPUTER;
|
| + case device::BluetoothDevice::DEVICE_PHONE:
|
| + return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_SMARTPHONE;
|
| + case device::BluetoothDevice::DEVICE_AUDIO:
|
| + case device::BluetoothDevice::DEVICE_CAR_AUDIO:
|
| + return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_HEADSET;
|
| + case device::BluetoothDevice::DEVICE_VIDEO:
|
| + return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_VIDEOCAM;
|
| + case device::BluetoothDevice::DEVICE_JOYSTICK:
|
| + case device::BluetoothDevice::DEVICE_GAMEPAD:
|
| + return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_GAMEPAD;
|
| + case device::BluetoothDevice::DEVICE_KEYBOARD:
|
| + case device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO:
|
| + return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_KEYBOARD;
|
| + case device::BluetoothDevice::DEVICE_TABLET:
|
| + case device::BluetoothDevice::DEVICE_MOUSE:
|
| + return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_MOUSE;
|
| + default:
|
| + return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_BLUETOOTH;
|
| + }
|
| +}
|
| +
|
| +// Special layout for bluetooth device entries.
|
| +class BluetoothDeviceListEntry : public HoverHighlightView {
|
| + public:
|
| + BluetoothDeviceListEntry(ViewClickListener* listener,
|
| + const gfx::ImageSkia& image,
|
| + const base::string16& text,
|
| + bool highlight,
|
| + bool checked,
|
| + bool enabled)
|
| + : HoverHighlightView(listener), device_icon_(nullptr) {
|
| + SetEnabled(enabled);
|
| +
|
| + AddDeviceTypeIcon(image);
|
| + AddDeviceLabel(text, highlight);
|
| + if (checked)
|
| + AddCheckmarkOnDeviceIcon();
|
| +
|
| + // Overwrites the layout mode which was set as FillLayout by AddLabel().
|
| + SetLayoutManager(
|
| + new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
|
| + }
|
| +
|
| + private:
|
| + views::ImageView* device_icon_;
|
| +
|
| + void AddDeviceTypeIcon(const gfx::ImageSkia& image) {
|
| + device_icon_ = new FixedSizedImageView(kDeviceTypeIconAreaWidth, 0);
|
| + device_icon_->SetImage(image);
|
| + device_icon_->SetEnabled(enabled());
|
| + AddChildView(device_icon_);
|
| + }
|
| +
|
| + void AddDeviceLabel(const base::string16& text, bool highlight) {
|
| + AddLabel(text, gfx::ALIGN_LEFT, highlight);
|
| + int left_margin = kDeviceLabelLeftMargin;
|
| + int right_margin = kTrayPopupPaddingHorizontal;
|
| + if (base::i18n::IsRTL())
|
| + std::swap(left_margin, right_margin);
|
| + text_label()->SetBorder(
|
| + views::Border::CreateEmptyBorder(5, left_margin, 5, right_margin));
|
| + }
|
| +
|
| + void AddCheckmarkOnDeviceIcon() {
|
| + device_icon_->SetLayoutManager(new views::FillLayout());
|
| + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
|
| + const gfx::ImageSkia* checkmark =
|
| + rb.GetImageNamed(IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_CONNECTED)
|
| + .ToImageSkia();
|
| + views::ImageView* checkmark_view =
|
| + new FixedSizedImageView(kConnectedIconSize, kConnectedIconSize);
|
| + checkmark_view->SetImage(checkmark);
|
| + checkmark_view->SetEnabled(enabled());
|
| + checkmark_view->SetHorizontalAlignment(views::ImageView::LEADING);
|
| + checkmark_view->SetVerticalAlignment(views::ImageView::LEADING);
|
| + checkmark_view->SetBorder(views::Border::CreateEmptyBorder(
|
| + kConnectedIconOffsetTop, kConnectedIconOffsetLeft, 0,
|
| + kDeviceTypeIconAreaWidth - kConnectedIconOffsetLeft -
|
| + kConnectedIconSize));
|
| + device_icon_->AddChildView(checkmark_view);
|
| + }
|
| +};
|
| +
|
| } // namespace
|
|
|
| class BluetoothDefaultView : public TrayItemMore {
|
| @@ -271,9 +368,12 @@ class BluetoothDetailedView : public TrayDetailsView,
|
| bool highlight,
|
| bool checked,
|
| bool enabled) {
|
| + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
|
| for (size_t i = 0; i < list.size(); ++i) {
|
| - HoverHighlightView* container =
|
| - AddScrollListItem(list[i].display_name, highlight, checked, enabled);
|
| + const gfx::ImageSkia* icon =
|
| + rb.GetImageSkiaNamed(GetDeviceIconResourceId(list[i].device_type));
|
| + HoverHighlightView* container = AddBluetoothDeviceListEntry(
|
| + list[i].display_name, icon, highlight, checked, enabled);
|
| device_map_[container] = list[i].address;
|
| }
|
| }
|
| @@ -290,6 +390,18 @@ class BluetoothDetailedView : public TrayDetailsView,
|
| return container;
|
| }
|
|
|
| + // Add an bluetooth device entry to the scrollable device list.
|
| + HoverHighlightView* AddBluetoothDeviceListEntry(const base::string16& text,
|
| + const gfx::ImageSkia* icon,
|
| + bool highlight,
|
| + bool checked,
|
| + bool enabled) {
|
| + BluetoothDeviceListEntry* container = new BluetoothDeviceListEntry(
|
| + this, *icon, text, highlight, checked, enabled);
|
| + scroll_content()->AddChildView(container);
|
| + return container;
|
| + }
|
| +
|
| // Add settings entries.
|
| void AppendSettingsEntries() {
|
| if (!ash::Shell::GetInstance()
|
|
|