OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/common/system/chromeos/bluetooth/tray_bluetooth.h" | |
6 | |
7 #include "ash/common/session/session_state_delegate.h" | |
8 #include "ash/common/system/tray/hover_highlight_view.h" | |
9 #include "ash/common/system/tray/system_tray.h" | |
10 #include "ash/common/system/tray/system_tray_delegate.h" | |
11 #include "ash/common/system/tray/system_tray_notifier.h" | |
12 #include "ash/common/system/tray/throbber_view.h" | |
13 #include "ash/common/system/tray/tray_constants.h" | |
14 #include "ash/common/system/tray/tray_details_view.h" | |
15 #include "ash/common/system/tray/tray_item_more.h" | |
16 #include "ash/common/system/tray/tray_popup_item_style.h" | |
17 #include "ash/common/system/tray/tray_popup_utils.h" | |
18 #include "ash/common/system/tray/tri_view.h" | |
19 #include "ash/common/wm_shell.h" | |
20 #include "ash/resources/grit/ash_resources.h" | |
21 #include "ash/resources/vector_icons/vector_icons.h" | |
22 #include "ash/strings/grit/ash_strings.h" | |
23 #include "device/bluetooth/bluetooth_common.h" | |
24 #include "ui/base/l10n/l10n_util.h" | |
25 #include "ui/base/resource/resource_bundle.h" | |
26 #include "ui/gfx/color_palette.h" | |
27 #include "ui/gfx/image/image.h" | |
28 #include "ui/gfx/paint_vector_icon.h" | |
29 #include "ui/gfx/vector_icons_public.h" | |
30 #include "ui/views/controls/button/toggle_button.h" | |
31 #include "ui/views/controls/image_view.h" | |
32 #include "ui/views/controls/label.h" | |
33 #include "ui/views/controls/progress_bar.h" | |
34 #include "ui/views/controls/scroll_view.h" | |
35 #include "ui/views/controls/separator.h" | |
36 #include "ui/views/layout/box_layout.h" | |
37 | |
38 namespace ash { | |
39 namespace tray { | |
40 namespace { | |
41 | |
42 // Updates bluetooth device |device| in the |list|. If it is new, append to the | |
43 // end of the |list|; otherwise, keep it at the same place, but update the data | |
44 // with new device info provided by |device|. | |
45 void UpdateBluetoothDeviceListHelper(BluetoothDeviceList* list, | |
46 const BluetoothDeviceInfo& device) { | |
47 for (BluetoothDeviceList::iterator it = list->begin(); it != list->end(); | |
48 ++it) { | |
49 if ((*it).address == device.address) { | |
50 *it = device; | |
51 return; | |
52 } | |
53 } | |
54 | |
55 list->push_back(device); | |
56 } | |
57 | |
58 // Removes the obsolete BluetoothDevices from |list|, if they are not in the | |
59 // |new_list|. | |
60 void RemoveObsoleteBluetoothDevicesFromList( | |
61 BluetoothDeviceList* list, | |
62 const std::set<std::string>& new_list) { | |
63 for (BluetoothDeviceList::iterator it = list->begin(); it != list->end(); | |
64 ++it) { | |
65 if (new_list.find((*it).address) == new_list.end()) { | |
66 it = list->erase(it); | |
67 if (it == list->end()) | |
68 return; | |
69 } | |
70 } | |
71 } | |
72 | |
73 // Returns corresponding device type icons for given Bluetooth device types and | |
74 // connection states. | |
75 const gfx::VectorIcon& GetBluetoothDeviceIcon( | |
76 device::BluetoothDeviceType device_type, | |
77 bool connected) { | |
78 switch (device_type) { | |
79 case device::BluetoothDeviceType::COMPUTER: | |
80 return ash::kSystemMenuComputerIcon; | |
81 case device::BluetoothDeviceType::PHONE: | |
82 return ash::kSystemMenuPhoneIcon; | |
83 case device::BluetoothDeviceType::AUDIO: | |
84 case device::BluetoothDeviceType::CAR_AUDIO: | |
85 return ash::kSystemMenuHeadsetIcon; | |
86 case device::BluetoothDeviceType::VIDEO: | |
87 return ash::kSystemMenuVideocamIcon; | |
88 case device::BluetoothDeviceType::JOYSTICK: | |
89 case device::BluetoothDeviceType::GAMEPAD: | |
90 return ash::kSystemMenuGamepadIcon; | |
91 case device::BluetoothDeviceType::KEYBOARD: | |
92 case device::BluetoothDeviceType::KEYBOARD_MOUSE_COMBO: | |
93 return ash::kSystemMenuKeyboardIcon; | |
94 case device::BluetoothDeviceType::TABLET: | |
95 return ash::kSystemMenuTabletIcon; | |
96 case device::BluetoothDeviceType::MOUSE: | |
97 return ash::kSystemMenuMouseIcon; | |
98 case device::BluetoothDeviceType::MODEM: | |
99 case device::BluetoothDeviceType::PERIPHERAL: | |
100 return ash::kSystemMenuBluetoothIcon; | |
101 case device::BluetoothDeviceType::UNKNOWN: | |
102 LOG(WARNING) << "Unknown device type icon for Bluetooth was requested."; | |
103 break; | |
104 } | |
105 return connected ? ash::kSystemMenuBluetoothConnectedIcon | |
106 : ash::kSystemMenuBluetoothIcon; | |
107 } | |
108 | |
109 const int kDisabledPanelLabelBaselineY = 20; | |
110 | |
111 } // namespace | |
112 | |
113 class BluetoothDefaultView : public TrayItemMore { | |
114 public: | |
115 explicit BluetoothDefaultView(SystemTrayItem* owner) : TrayItemMore(owner) {} | |
116 ~BluetoothDefaultView() override {} | |
117 | |
118 void Update() { | |
119 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | |
120 const bool enabled = delegate->GetBluetoothEnabled(); | |
121 if (delegate->GetBluetoothAvailable()) { | |
122 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
123 const base::string16 label = rb.GetLocalizedString( | |
124 enabled ? IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED | |
125 : IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED); | |
126 SetLabel(label); | |
127 SetAccessibleName(label); | |
128 SetVisible(true); | |
129 } else { | |
130 SetVisible(false); | |
131 } | |
132 UpdateStyle(); | |
133 } | |
134 | |
135 protected: | |
136 // TrayItemMore: | |
137 std::unique_ptr<TrayPopupItemStyle> HandleCreateStyle() const override { | |
138 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | |
139 std::unique_ptr<TrayPopupItemStyle> style = | |
140 TrayItemMore::HandleCreateStyle(); | |
141 style->set_color_style( | |
142 delegate->GetBluetoothEnabled() | |
143 ? TrayPopupItemStyle::ColorStyle::ACTIVE | |
144 : delegate->GetBluetoothAvailable() | |
145 ? TrayPopupItemStyle::ColorStyle::INACTIVE | |
146 : TrayPopupItemStyle::ColorStyle::DISABLED); | |
147 | |
148 return style; | |
149 } | |
150 | |
151 void UpdateStyle() override { | |
152 TrayItemMore::UpdateStyle(); | |
153 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle(); | |
154 SetImage(gfx::CreateVectorIcon(GetCurrentIcon(), style->GetIconColor())); | |
155 } | |
156 | |
157 private: | |
158 const gfx::VectorIcon& GetCurrentIcon() { | |
159 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | |
160 if (!delegate->GetBluetoothEnabled()) | |
161 return kSystemMenuBluetoothDisabledIcon; | |
162 | |
163 bool has_connected_device = false; | |
164 BluetoothDeviceList list; | |
165 delegate->GetAvailableBluetoothDevices(&list); | |
166 for (size_t i = 0; i < list.size(); ++i) { | |
167 if (list[i].connected) { | |
168 has_connected_device = true; | |
169 break; | |
170 } | |
171 } | |
172 return has_connected_device ? kSystemMenuBluetoothConnectedIcon | |
173 : kSystemMenuBluetoothIcon; | |
174 } | |
175 | |
176 DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView); | |
177 }; | |
178 | |
179 class BluetoothDetailedView : public TrayDetailsView { | |
180 public: | |
181 BluetoothDetailedView(SystemTrayItem* owner, LoginStatus login) | |
182 : TrayDetailsView(owner), | |
183 login_(login), | |
184 toggle_(nullptr), | |
185 settings_(nullptr), | |
186 disabled_panel_(nullptr) { | |
187 CreateItems(); | |
188 } | |
189 | |
190 ~BluetoothDetailedView() override { | |
191 // Stop discovering bluetooth devices when exiting BT detailed view. | |
192 BluetoothStopDiscovering(); | |
193 } | |
194 | |
195 void Update() { | |
196 BluetoothStartDiscovering(); | |
197 UpdateBluetoothDeviceList(); | |
198 | |
199 // Update UI. | |
200 UpdateDeviceScrollList(); | |
201 UpdateHeaderEntry(); | |
202 Layout(); | |
203 } | |
204 | |
205 private: | |
206 void CreateItems() { | |
207 CreateScrollableList(); | |
208 CreateTitleRow(IDS_ASH_STATUS_TRAY_BLUETOOTH); | |
209 } | |
210 | |
211 void BluetoothStartDiscovering() { | |
212 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | |
213 if (delegate->GetBluetoothDiscovering()) { | |
214 ShowLoadingIndicator(); | |
215 return; | |
216 } | |
217 HideLoadingIndicator(); | |
218 if (delegate->GetBluetoothEnabled()) | |
219 delegate->BluetoothStartDiscovering(); | |
220 } | |
221 | |
222 void BluetoothStopDiscovering() { | |
223 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | |
224 if (delegate && delegate->GetBluetoothDiscovering()) { | |
225 delegate->BluetoothStopDiscovering(); | |
226 HideLoadingIndicator(); | |
227 } | |
228 } | |
229 | |
230 void UpdateBluetoothDeviceList() { | |
231 std::set<std::string> new_connecting_devices; | |
232 std::set<std::string> new_connected_devices; | |
233 std::set<std::string> new_paired_not_connected_devices; | |
234 std::set<std::string> new_discovered_not_paired_devices; | |
235 | |
236 BluetoothDeviceList list; | |
237 WmShell::Get()->system_tray_delegate()->GetAvailableBluetoothDevices(&list); | |
238 for (size_t i = 0; i < list.size(); ++i) { | |
239 if (list[i].connecting) { | |
240 new_connecting_devices.insert(list[i].address); | |
241 UpdateBluetoothDeviceListHelper(&connecting_devices_, list[i]); | |
242 } else if (list[i].connected && list[i].paired) { | |
243 new_connected_devices.insert(list[i].address); | |
244 UpdateBluetoothDeviceListHelper(&connected_devices_, list[i]); | |
245 } else if (list[i].paired) { | |
246 new_paired_not_connected_devices.insert(list[i].address); | |
247 UpdateBluetoothDeviceListHelper(&paired_not_connected_devices_, | |
248 list[i]); | |
249 } else { | |
250 new_discovered_not_paired_devices.insert(list[i].address); | |
251 UpdateBluetoothDeviceListHelper(&discovered_not_paired_devices_, | |
252 list[i]); | |
253 } | |
254 } | |
255 RemoveObsoleteBluetoothDevicesFromList(&connecting_devices_, | |
256 new_connecting_devices); | |
257 RemoveObsoleteBluetoothDevicesFromList(&connected_devices_, | |
258 new_connected_devices); | |
259 RemoveObsoleteBluetoothDevicesFromList(&paired_not_connected_devices_, | |
260 new_paired_not_connected_devices); | |
261 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_, | |
262 new_discovered_not_paired_devices); | |
263 } | |
264 | |
265 void UpdateHeaderEntry() { | |
266 bool is_bluetooth_enabled = | |
267 WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled(); | |
268 if (toggle_) | |
269 toggle_->SetIsOn(is_bluetooth_enabled, false); | |
270 } | |
271 | |
272 void UpdateDeviceScrollList() { | |
273 device_map_.clear(); | |
274 scroll_content()->RemoveAllChildViews(true); | |
275 | |
276 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | |
277 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); | |
278 bool bluetooth_available = delegate->GetBluetoothAvailable(); | |
279 | |
280 // If Bluetooth is disabled, show a panel which only indicates that it is | |
281 // disabled, instead of the scroller with Bluetooth devices. | |
282 if (bluetooth_enabled) { | |
283 HideDisabledPanel(); | |
284 } else { | |
285 ShowDisabledPanel(); | |
286 return; | |
287 } | |
288 | |
289 // Add paired devices (and their section header in MD) in the list. | |
290 size_t num_paired_devices = connected_devices_.size() + | |
291 connecting_devices_.size() + | |
292 paired_not_connected_devices_.size(); | |
293 if (num_paired_devices > 0) { | |
294 AddSubHeader(IDS_ASH_STATUS_TRAY_BLUETOOTH_PAIRED_DEVICES); | |
295 AppendSameTypeDevicesToScrollList(connected_devices_, true, true, | |
296 bluetooth_enabled); | |
297 AppendSameTypeDevicesToScrollList(connecting_devices_, true, false, | |
298 bluetooth_enabled); | |
299 AppendSameTypeDevicesToScrollList(paired_not_connected_devices_, false, | |
300 false, bluetooth_enabled); | |
301 } | |
302 | |
303 // Add paired devices (and their section header in MD) in the list. | |
304 if (discovered_not_paired_devices_.size() > 0) { | |
305 if (num_paired_devices > 0) | |
306 AddSubHeader(IDS_ASH_STATUS_TRAY_BLUETOOTH_UNPAIRED_DEVICES); | |
307 AppendSameTypeDevicesToScrollList(discovered_not_paired_devices_, false, | |
308 false, bluetooth_enabled); | |
309 } | |
310 | |
311 // Show user Bluetooth state if there is no bluetooth devices in list. | |
312 if (device_map_.size() == 0) { | |
313 if (bluetooth_available && bluetooth_enabled) { | |
314 HoverHighlightView* container = new HoverHighlightView(this); | |
315 container->AddLabel(l10n_util::GetStringUTF16( | |
316 IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING), | |
317 gfx::ALIGN_LEFT, false); | |
318 scroll_content()->AddChildView(container); | |
319 } | |
320 } | |
321 | |
322 scroll_content()->InvalidateLayout(); | |
323 } | |
324 | |
325 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list, | |
326 bool highlight, | |
327 bool checked, | |
328 bool enabled) { | |
329 for (size_t i = 0; i < list.size(); ++i) { | |
330 HoverHighlightView* container = nullptr; | |
331 gfx::ImageSkia icon_image = CreateVectorIcon( | |
332 GetBluetoothDeviceIcon(list[i].device_type, list[i].connected), | |
333 kMenuIconColor); | |
334 container = AddScrollListItem(list[i].display_name, icon_image, | |
335 list[i].connected, list[i].connecting); | |
336 device_map_[container] = list[i].address; | |
337 } | |
338 } | |
339 | |
340 HoverHighlightView* AddScrollListItem(const base::string16& text, | |
341 const gfx::ImageSkia& image, | |
342 bool connected, | |
343 bool connecting) { | |
344 HoverHighlightView* container = new HoverHighlightView(this); | |
345 if (connected) { | |
346 SetupConnectedItem(container, text, image); | |
347 } else if (connecting) { | |
348 SetupConnectingItem(container, text, image); | |
349 } else { | |
350 container->AddIconAndLabel(image, text, false); | |
351 } | |
352 scroll_content()->AddChildView(container); | |
353 return container; | |
354 } | |
355 | |
356 void AddSubHeader(int message_id) { | |
357 TriView* header = TrayPopupUtils::CreateSubHeaderRowView(); | |
358 TrayPopupUtils::ConfigureAsStickyHeader(header); | |
359 | |
360 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); | |
361 label->SetText(l10n_util::GetStringUTF16(message_id)); | |
362 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER); | |
363 style.SetupLabel(label); | |
364 header->AddView(TriView::Container::CENTER, label); | |
365 | |
366 scroll_content()->AddChildView(header); | |
367 } | |
368 | |
369 void SetupConnectedItem(HoverHighlightView* container, | |
370 const base::string16& text, | |
371 const gfx::ImageSkia& image) { | |
372 container->AddIconAndLabels( | |
373 image, text, l10n_util::GetStringUTF16( | |
374 IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED)); | |
375 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::CAPTION); | |
376 style.set_color_style(TrayPopupItemStyle::ColorStyle::CONNECTED); | |
377 style.SetupLabel(container->sub_text_label()); | |
378 } | |
379 | |
380 void SetupConnectingItem(HoverHighlightView* container, | |
381 const base::string16& text, | |
382 const gfx::ImageSkia& image) { | |
383 container->AddIconAndLabels( | |
384 image, text, l10n_util::GetStringUTF16( | |
385 IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING)); | |
386 ThrobberView* throbber = new ThrobberView; | |
387 throbber->Start(); | |
388 container->AddRightView(throbber); | |
389 } | |
390 | |
391 // Returns true if the device with |device_id| is found in |device_list|, | |
392 // and the display_name of the device will be returned in |display_name| if | |
393 // it's not NULL. | |
394 bool FoundDevice(const std::string& device_id, | |
395 const BluetoothDeviceList& device_list, | |
396 base::string16* display_name, | |
397 device::BluetoothDeviceType* device_type) { | |
398 for (size_t i = 0; i < device_list.size(); ++i) { | |
399 if (device_list[i].address == device_id) { | |
400 if (display_name) | |
401 *display_name = device_list[i].display_name; | |
402 if (device_type) | |
403 *device_type = device_list[i].device_type; | |
404 return true; | |
405 } | |
406 } | |
407 return false; | |
408 } | |
409 | |
410 // Updates UI of the clicked bluetooth device to show it is being connected | |
411 // or disconnected if such an operation is going to be performed underway. | |
412 void UpdateClickedDevice(const std::string& device_id, | |
413 views::View* item_container) { | |
414 base::string16 display_name; | |
415 device::BluetoothDeviceType device_type; | |
416 if (FoundDevice(device_id, paired_not_connected_devices_, &display_name, | |
417 &device_type)) { | |
418 item_container->RemoveAllChildViews(true); | |
419 HoverHighlightView* container = | |
420 static_cast<HoverHighlightView*>(item_container); | |
421 TrayPopupItemStyle style( | |
422 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); | |
423 gfx::ImageSkia icon_image = CreateVectorIcon( | |
424 GetBluetoothDeviceIcon(device_type, false), style.GetIconColor()); | |
425 SetupConnectingItem(container, display_name, icon_image); | |
426 scroll_content()->SizeToPreferredSize(); | |
427 scroller()->Layout(); | |
428 } | |
429 } | |
430 | |
431 // TrayDetailsView: | |
432 void HandleViewClicked(views::View* view) override { | |
433 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | |
434 if (!delegate->GetBluetoothEnabled()) | |
435 return; | |
436 | |
437 std::map<views::View*, std::string>::iterator find; | |
438 find = device_map_.find(view); | |
439 if (find == device_map_.end()) | |
440 return; | |
441 | |
442 const std::string device_id = find->second; | |
443 if (FoundDevice(device_id, connecting_devices_, nullptr, nullptr)) | |
444 return; | |
445 | |
446 UpdateClickedDevice(device_id, view); | |
447 delegate->ConnectToBluetoothDevice(device_id); | |
448 } | |
449 | |
450 void HandleButtonPressed(views::Button* sender, | |
451 const ui::Event& event) override { | |
452 if (sender == toggle_) { | |
453 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | |
454 WmShell::Get()->RecordUserMetricsAction( | |
455 delegate->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED | |
456 : UMA_STATUS_AREA_BLUETOOTH_ENABLED); | |
457 delegate->ToggleBluetooth(); | |
458 } else if (sender == settings_) { | |
459 ShowSettings(); | |
460 } else { | |
461 NOTREACHED(); | |
462 } | |
463 } | |
464 | |
465 void CreateExtraTitleRowButtons() override { | |
466 if (login_ == LoginStatus::LOCKED) | |
467 return; | |
468 | |
469 DCHECK(!toggle_); | |
470 DCHECK(!settings_); | |
471 | |
472 tri_view()->SetContainerVisible(TriView::Container::END, true); | |
473 | |
474 toggle_ = | |
475 TrayPopupUtils::CreateToggleButton(this, IDS_ASH_STATUS_TRAY_BLUETOOTH); | |
476 tri_view()->AddView(TriView::Container::END, toggle_); | |
477 | |
478 settings_ = | |
479 CreateSettingsButton(login_, IDS_ASH_STATUS_TRAY_BLUETOOTH_SETTINGS); | |
480 tri_view()->AddView(TriView::Container::END, settings_); | |
481 } | |
482 | |
483 void ShowSettings() { | |
484 if (TrayPopupUtils::CanOpenWebUISettings(login_)) { | |
485 WmShell::Get()->system_tray_delegate()->ManageBluetoothDevices(); | |
486 owner()->system_tray()->CloseSystemBubble(); | |
487 } | |
488 } | |
489 | |
490 void ShowLoadingIndicator() { | |
491 // Setting a value of -1 gives progress_bar an infinite-loading behavior. | |
492 ShowProgress(-1, true); | |
493 } | |
494 | |
495 void HideLoadingIndicator() { ShowProgress(0, false); } | |
496 | |
497 void ShowDisabledPanel() { | |
498 DCHECK(scroller()); | |
499 if (!disabled_panel_) { | |
500 disabled_panel_ = CreateDisabledPanel(); | |
501 // Insert |disabled_panel_| before the scroller, since the scroller will | |
502 // have unnecessary bottom border when it is not the last child. | |
503 AddChildViewAt(disabled_panel_, GetIndexOf(scroller())); | |
504 // |disabled_panel_| need to fill the remaining space below the title row | |
505 // so that the inner contents of |disabled_panel_| are placed properly. | |
506 box_layout()->SetFlexForView(disabled_panel_, 1); | |
507 } | |
508 disabled_panel_->SetVisible(true); | |
509 scroller()->SetVisible(false); | |
510 } | |
511 | |
512 void HideDisabledPanel() { | |
513 DCHECK(scroller()); | |
514 if (disabled_panel_) | |
515 disabled_panel_->SetVisible(false); | |
516 scroller()->SetVisible(true); | |
517 } | |
518 | |
519 views::View* CreateDisabledPanel() { | |
520 views::View* container = new views::View; | |
521 views::BoxLayout* box_layout = | |
522 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | |
523 box_layout->set_main_axis_alignment( | |
524 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | |
525 container->SetLayoutManager(box_layout); | |
526 | |
527 TrayPopupItemStyle style( | |
528 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); | |
529 style.set_color_style(TrayPopupItemStyle::ColorStyle::DISABLED); | |
530 | |
531 views::ImageView* image_view = new views::ImageView; | |
532 image_view->SetImage(gfx::CreateVectorIcon(kSystemMenuBluetoothDisabledIcon, | |
533 style.GetIconColor())); | |
534 image_view->SetVerticalAlignment(views::ImageView::TRAILING); | |
535 container->AddChildView(image_view); | |
536 | |
537 views::Label* label = new views::Label( | |
538 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | |
539 IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED)); | |
540 style.SetupLabel(label); | |
541 label->SetBorder(views::CreateEmptyBorder( | |
542 kDisabledPanelLabelBaselineY - label->GetBaseline(), 0, 0, 0)); | |
543 container->AddChildView(label); | |
544 | |
545 // Make top padding of the icon equal to the height of the label so that the | |
546 // icon is vertically aligned to center of the container. | |
547 image_view->SetBorder( | |
548 views::CreateEmptyBorder(label->GetPreferredSize().height(), 0, 0, 0)); | |
549 return container; | |
550 } | |
551 | |
552 LoginStatus login_; | |
553 | |
554 std::map<views::View*, std::string> device_map_; | |
555 | |
556 BluetoothDeviceList connected_devices_; | |
557 BluetoothDeviceList connecting_devices_; | |
558 BluetoothDeviceList paired_not_connected_devices_; | |
559 BluetoothDeviceList discovered_not_paired_devices_; | |
560 | |
561 views::ToggleButton* toggle_; | |
562 views::Button* settings_; | |
563 | |
564 // The container of the message "Bluetooth is disabled" and an icon. It should | |
565 // be shown instead of Bluetooth device list when Bluetooth is disabled. | |
566 views::View* disabled_panel_; | |
567 | |
568 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); | |
569 }; | |
570 | |
571 } // namespace tray | |
572 | |
573 TrayBluetooth::TrayBluetooth(SystemTray* system_tray) | |
574 : SystemTrayItem(system_tray, UMA_BLUETOOTH), | |
575 default_(nullptr), | |
576 detailed_(nullptr) { | |
577 WmShell::Get()->system_tray_notifier()->AddBluetoothObserver(this); | |
578 } | |
579 | |
580 TrayBluetooth::~TrayBluetooth() { | |
581 WmShell::Get()->system_tray_notifier()->RemoveBluetoothObserver(this); | |
582 } | |
583 | |
584 views::View* TrayBluetooth::CreateTrayView(LoginStatus status) { | |
585 return NULL; | |
586 } | |
587 | |
588 views::View* TrayBluetooth::CreateDefaultView(LoginStatus status) { | |
589 CHECK(default_ == NULL); | |
590 default_ = new tray::BluetoothDefaultView(this); | |
591 default_->SetEnabled(status != LoginStatus::LOCKED); | |
592 default_->Update(); | |
593 return default_; | |
594 } | |
595 | |
596 views::View* TrayBluetooth::CreateDetailedView(LoginStatus status) { | |
597 if (!WmShell::Get()->system_tray_delegate()->GetBluetoothAvailable()) | |
598 return NULL; | |
599 WmShell::Get()->RecordUserMetricsAction( | |
600 UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW); | |
601 CHECK(detailed_ == NULL); | |
602 detailed_ = new tray::BluetoothDetailedView(this, status); | |
603 detailed_->Update(); | |
604 return detailed_; | |
605 } | |
606 | |
607 void TrayBluetooth::DestroyTrayView() {} | |
608 | |
609 void TrayBluetooth::DestroyDefaultView() { | |
610 default_ = NULL; | |
611 } | |
612 | |
613 void TrayBluetooth::DestroyDetailedView() { | |
614 detailed_ = NULL; | |
615 } | |
616 | |
617 void TrayBluetooth::UpdateAfterLoginStatusChange(LoginStatus status) {} | |
618 | |
619 void TrayBluetooth::OnBluetoothRefresh() { | |
620 if (default_) | |
621 default_->Update(); | |
622 else if (detailed_) | |
623 detailed_->Update(); | |
624 } | |
625 | |
626 void TrayBluetooth::OnBluetoothDiscoveringChanged() { | |
627 if (!detailed_) | |
628 return; | |
629 detailed_->Update(); | |
630 } | |
631 | |
632 } // namespace ash | |
OLD | NEW |