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

Side by Side Diff: ash/system/chromeos/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: Rebase / Removes ash::BluetoothDeviceInfo::DeviceType and uses existing device::BluetoothDevice::De… Created 4 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/system/chromeos/bluetooth/tray_bluetooth.h" 5 #include "ash/system/chromeos/bluetooth/tray_bluetooth.h"
6 6
7 #include "ash/session/session_state_delegate.h" 7 #include "ash/session/session_state_delegate.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/system/tray/fixed_sized_image_view.h"
9 #include "ash/system/tray/fixed_sized_scroll_view.h" 10 #include "ash/system/tray/fixed_sized_scroll_view.h"
10 #include "ash/system/tray/hover_highlight_view.h" 11 #include "ash/system/tray/hover_highlight_view.h"
11 #include "ash/system/tray/system_tray.h" 12 #include "ash/system/tray/system_tray.h"
12 #include "ash/system/tray/system_tray_delegate.h" 13 #include "ash/system/tray/system_tray_delegate.h"
13 #include "ash/system/tray/system_tray_notifier.h" 14 #include "ash/system/tray/system_tray_notifier.h"
14 #include "ash/system/tray/throbber_view.h" 15 #include "ash/system/tray/throbber_view.h"
15 #include "ash/system/tray/tray_constants.h" 16 #include "ash/system/tray/tray_constants.h"
16 #include "ash/system/tray/tray_details_view.h" 17 #include "ash/system/tray/tray_details_view.h"
17 #include "ash/system/tray/tray_item_more.h" 18 #include "ash/system/tray/tray_item_more.h"
18 #include "ash/system/tray/tray_popup_header_button.h" 19 #include "ash/system/tray/tray_popup_header_button.h"
19 #include "grit/ash_resources.h" 20 #include "grit/ash_resources.h"
20 #include "grit/ash_strings.h" 21 #include "grit/ash_strings.h"
21 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/gfx/image/image.h" 24 #include "ui/gfx/image/image.h"
24 #include "ui/views/controls/image_view.h" 25 #include "ui/views/controls/image_view.h"
25 #include "ui/views/controls/label.h" 26 #include "ui/views/controls/label.h"
26 #include "ui/views/layout/box_layout.h" 27 #include "ui/views/layout/box_layout.h"
28 #include "ui/views/layout/fill_layout.h"
27 29
28 namespace ash { 30 namespace ash {
29 namespace tray { 31 namespace tray {
30 namespace { 32 namespace {
31 33
34 // Constants of special layout for bluetooth device entries.
35 const int kDeviceLabelLeftMargin = 7;
36 const int kDeviceTypeIconAreaWidth = 60;
37 const int kConnectedIconSize = 10;
38 const int kConnectedIconOffsetTop = 26;
39 const int kConnectedIconOffsetLeft = 33;
40
32 // Updates bluetooth device |device| in the |list|. If it is new, append to the 41 // Updates bluetooth device |device| in the |list|. If it is new, append to the
33 // end of the |list|; otherwise, keep it at the same place, but update the data 42 // end of the |list|; otherwise, keep it at the same place, but update the data
34 // with new device info provided by |device|. 43 // with new device info provided by |device|.
35 void UpdateBluetoothDeviceListHelper(BluetoothDeviceList* list, 44 void UpdateBluetoothDeviceListHelper(BluetoothDeviceList* list,
36 const BluetoothDeviceInfo& device) { 45 const BluetoothDeviceInfo& device) {
37 for (BluetoothDeviceList::iterator it = list->begin(); it != list->end(); 46 for (BluetoothDeviceList::iterator it = list->begin(); it != list->end();
38 ++it) { 47 ++it) {
39 if ((*it).address == device.address) { 48 if ((*it).address == device.address) {
40 *it = device; 49 *it = device;
41 return; 50 return;
(...skipping 11 matching lines...) Expand all
53 for (BluetoothDeviceList::iterator it = list->begin(); it != list->end(); 62 for (BluetoothDeviceList::iterator it = list->begin(); it != list->end();
54 ++it) { 63 ++it) {
55 if (new_list.find((*it).address) == new_list.end()) { 64 if (new_list.find((*it).address) == new_list.end()) {
56 it = list->erase(it); 65 it = list->erase(it);
57 if (it == list->end()) 66 if (it == list->end())
58 return; 67 return;
59 } 68 }
60 } 69 }
61 } 70 }
62 71
72 // Returns a resource id of an icon which corresponds to the given device type.
73 int GetDeviceIconResourceId(device::BluetoothDevice::DeviceType device_type) {
74 switch (device_type) {
75 case device::BluetoothDevice::DEVICE_COMPUTER:
76 return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_COMPUTER;
77 case device::BluetoothDevice::DEVICE_PHONE:
78 return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_SMARTPHONE;
79 case device::BluetoothDevice::DEVICE_AUDIO:
80 case device::BluetoothDevice::DEVICE_CAR_AUDIO:
81 return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_HEADSET;
82 case device::BluetoothDevice::DEVICE_VIDEO:
83 return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_VIDEOCAM;
84 case device::BluetoothDevice::DEVICE_JOYSTICK:
85 case device::BluetoothDevice::DEVICE_GAMEPAD:
86 return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_GAMEPAD;
87 case device::BluetoothDevice::DEVICE_KEYBOARD:
88 case device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO:
89 return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_KEYBOARD;
90 case device::BluetoothDevice::DEVICE_TABLET:
91 case device::BluetoothDevice::DEVICE_MOUSE:
92 return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_MOUSE;
93 default:
94 return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_BLUETOOTH;
95 }
96 }
97
98 // Special layout for bluetooth device entries.
99 class BluetoothDeviceListEntry : public HoverHighlightView {
100 public:
101 BluetoothDeviceListEntry(ViewClickListener* listener,
102 const gfx::ImageSkia& image,
103 const base::string16& text,
104 bool highlight,
105 bool checked,
106 bool enabled)
107 : HoverHighlightView(listener), device_icon_(nullptr) {
108 SetEnabled(enabled);
109
110 AddDeviceTypeIcon(image);
111 AddDeviceLabel(text, highlight);
112 if (checked)
113 AddCheckmarkOnDeviceIcon();
114
115 // Overwrites the layout mode which was set as FillLayout by AddLabel().
116 SetLayoutManager(
117 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
118 }
119
120 private:
121 views::ImageView* device_icon_;
122
123 void AddDeviceTypeIcon(const gfx::ImageSkia& image) {
124 device_icon_ = new FixedSizedImageView(kDeviceTypeIconAreaWidth, 0);
125 device_icon_->SetImage(image);
126 device_icon_->SetEnabled(enabled());
127 AddChildView(device_icon_);
128 }
129
130 void AddDeviceLabel(const base::string16& text, bool highlight) {
131 AddLabel(text, gfx::ALIGN_LEFT, highlight);
132 int left_margin = kDeviceLabelLeftMargin;
133 int right_margin = kTrayPopupPaddingHorizontal;
134 if (base::i18n::IsRTL())
135 std::swap(left_margin, right_margin);
136 text_label()->SetBorder(
137 views::Border::CreateEmptyBorder(5, left_margin, 5, right_margin));
138 }
139
140 void AddCheckmarkOnDeviceIcon() {
141 device_icon_->SetLayoutManager(new views::FillLayout());
142 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
143 const gfx::ImageSkia* checkmark =
144 rb.GetImageNamed(IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_CONNECTED)
145 .ToImageSkia();
146 views::ImageView* checkmark_view =
147 new FixedSizedImageView(kConnectedIconSize, kConnectedIconSize);
148 checkmark_view->SetImage(checkmark);
149 checkmark_view->SetEnabled(enabled());
150 checkmark_view->SetHorizontalAlignment(views::ImageView::LEADING);
151 checkmark_view->SetVerticalAlignment(views::ImageView::LEADING);
152 checkmark_view->SetBorder(views::Border::CreateEmptyBorder(
153 kConnectedIconOffsetTop, kConnectedIconOffsetLeft, 0,
154 kDeviceTypeIconAreaWidth - kConnectedIconOffsetLeft -
155 kConnectedIconSize));
156 device_icon_->AddChildView(checkmark_view);
157 }
158 };
159
63 } // namespace 160 } // namespace
64 161
65 class BluetoothDefaultView : public TrayItemMore { 162 class BluetoothDefaultView : public TrayItemMore {
66 public: 163 public:
67 BluetoothDefaultView(SystemTrayItem* owner, bool show_more) 164 BluetoothDefaultView(SystemTrayItem* owner, bool show_more)
68 : TrayItemMore(owner, show_more) { 165 : TrayItemMore(owner, show_more) {
69 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 166 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
70 SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_BLUETOOTH).ToImageSkia()); 167 SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_BLUETOOTH).ToImageSkia());
71 UpdateLabel(); 168 UpdateLabel();
72 } 169 }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 361 }
265 } 362 }
266 363
267 scroll_content()->SizeToPreferredSize(); 364 scroll_content()->SizeToPreferredSize();
268 } 365 }
269 366
270 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list, 367 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list,
271 bool highlight, 368 bool highlight,
272 bool checked, 369 bool checked,
273 bool enabled) { 370 bool enabled) {
371 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
274 for (size_t i = 0; i < list.size(); ++i) { 372 for (size_t i = 0; i < list.size(); ++i) {
275 HoverHighlightView* container = 373 const gfx::ImageSkia* icon =
276 AddScrollListItem(list[i].display_name, highlight, checked, enabled); 374 rb.GetImageSkiaNamed(GetDeviceIconResourceId(list[i].device_type));
375 HoverHighlightView* container = AddBluetoothDeviceListEntry(
376 list[i].display_name, icon, highlight, checked, enabled);
277 device_map_[container] = list[i].address; 377 device_map_[container] = list[i].address;
278 } 378 }
279 } 379 }
280 380
281 HoverHighlightView* AddScrollListItem(const base::string16& text, 381 HoverHighlightView* AddScrollListItem(const base::string16& text,
282 bool highlight, 382 bool highlight,
283 bool checked, 383 bool checked,
284 bool enabled) { 384 bool enabled) {
285 HoverHighlightView* container = new HoverHighlightView(this); 385 HoverHighlightView* container = new HoverHighlightView(this);
286 views::Label* label = 386 views::Label* label =
287 container->AddCheckableLabel(text, highlight, checked); 387 container->AddCheckableLabel(text, highlight, checked);
288 label->SetEnabled(enabled); 388 label->SetEnabled(enabled);
289 scroll_content()->AddChildView(container); 389 scroll_content()->AddChildView(container);
290 return container; 390 return container;
291 } 391 }
292 392
393 // Add an bluetooth device entry to the scrollable device list.
394 HoverHighlightView* AddBluetoothDeviceListEntry(const base::string16& text,
395 const gfx::ImageSkia* icon,
396 bool highlight,
397 bool checked,
398 bool enabled) {
399 BluetoothDeviceListEntry* container = new BluetoothDeviceListEntry(
400 this, *icon, text, highlight, checked, enabled);
401 scroll_content()->AddChildView(container);
402 return container;
403 }
404
293 // Add settings entries. 405 // Add settings entries.
294 void AppendSettingsEntries() { 406 void AppendSettingsEntries() {
295 if (!ash::Shell::GetInstance() 407 if (!ash::Shell::GetInstance()
296 ->system_tray_delegate() 408 ->system_tray_delegate()
297 ->ShouldShowSettings()) { 409 ->ShouldShowSettings()) {
298 return; 410 return;
299 } 411 }
300 412
301 // Add bluetooth device requires a browser window, hide it for non logged in 413 // Add bluetooth device requires a browser window, hide it for non logged in
302 // user. 414 // user.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 detailed_->Update(); 571 detailed_->Update();
460 } 572 }
461 573
462 void TrayBluetooth::OnBluetoothDiscoveringChanged() { 574 void TrayBluetooth::OnBluetoothDiscoveringChanged() {
463 if (!detailed_) 575 if (!detailed_)
464 return; 576 return;
465 detailed_->Update(); 577 detailed_->Update();
466 } 578 }
467 579
468 } // namespace ash 580 } // namespace ash
OLDNEW
« no previous file with comments | « ash/resources/default_200_percent/cros/bluetooth/videocam.png ('k') | ash/system/tray/system_tray_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698