Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2702)

Unified Diff: ash/system/bluetooth/tray_bluetooth.cc

Issue 1931563002: Add Bluetooth device type icons on the device list in system tray. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/system/bluetooth/tray_bluetooth.cc
diff --git a/ash/system/bluetooth/tray_bluetooth.cc b/ash/system/bluetooth/tray_bluetooth.cc
index 27a3ae836e2f4796919780b7827d0f53bc13c8d1..d79523871b3622f87d449f4fcf0fc7a4c8d07a39 100644
--- a/ash/system/bluetooth/tray_bluetooth.cc
+++ b/ash/system/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,95 @@ void RemoveObsoleteBluetoothDevicesFromList(
}
}
+// Returns a resource id of an icon which corresponds to the given device type.
+int GetDeviceIconResourceId(ash::BluetoothDeviceInfo::DeviceType device_type) {
+ switch (device_type) {
+ case ash::BluetoothDeviceInfo::DEVICE_COMPUTER:
+ return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_COMPUTER;
+ case ash::BluetoothDeviceInfo::DEVICE_PHONE:
+ return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_SMARTPHONE;
+ case ash::BluetoothDeviceInfo::DEVICE_AUDIO:
+ case ash::BluetoothDeviceInfo::DEVICE_CAR_AUDIO:
+ return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_HEADSET;
+ case ash::BluetoothDeviceInfo::DEVICE_VIDEO:
+ return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_VIDEOCAM;
+ case ash::BluetoothDeviceInfo::DEVICE_JOYSTICK:
+ case ash::BluetoothDeviceInfo::DEVICE_GAMEPAD:
+ return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_GAMEPAD;
+ case ash::BluetoothDeviceInfo::DEVICE_KEYBOARD:
+ case ash::BluetoothDeviceInfo::DEVICE_KEYBOARD_MOUSE_COMBO:
+ return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_KEYBOARD;
+ case ash::BluetoothDeviceInfo::DEVICE_TABLET:
+ case ash::BluetoothDeviceInfo::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);
+ ;
jennyz 2016/04/27 23:27:38 nit: Remove empty ";" line.
+ }
+};
+
} // namespace
class BluetoothDefaultView : public TrayItemMore {
@@ -272,9 +370,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;
}
}
@@ -291,6 +392,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()->

Powered by Google App Engine
This is Rietveld 408576698