OLD | NEW |
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/common/system/chromeos/bluetooth/tray_bluetooth.h" | 5 #include "ash/common/system/chromeos/bluetooth/tray_bluetooth.h" |
6 | 6 |
7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
9 #include "ash/common/system/tray/fixed_sized_scroll_view.h" | 9 #include "ash/common/system/tray/fixed_sized_scroll_view.h" |
10 #include "ash/common/system/tray/hover_highlight_view.h" | 10 #include "ash/common/system/tray/hover_highlight_view.h" |
11 #include "ash/common/system/tray/system_tray.h" | 11 #include "ash/common/system/tray/system_tray.h" |
12 #include "ash/common/system/tray/system_tray_delegate.h" | 12 #include "ash/common/system/tray/system_tray_delegate.h" |
13 #include "ash/common/system/tray/system_tray_notifier.h" | 13 #include "ash/common/system/tray/system_tray_notifier.h" |
14 #include "ash/common/system/tray/throbber_view.h" | 14 #include "ash/common/system/tray/throbber_view.h" |
15 #include "ash/common/system/tray/tray_constants.h" | 15 #include "ash/common/system/tray/tray_constants.h" |
16 #include "ash/common/system/tray/tray_details_view.h" | 16 #include "ash/common/system/tray/tray_details_view.h" |
17 #include "ash/common/system/tray/tray_item_more.h" | 17 #include "ash/common/system/tray/tray_item_more.h" |
18 #include "ash/common/system/tray/tray_popup_header_button.h" | 18 #include "ash/common/system/tray/tray_popup_header_button.h" |
| 19 #include "ash/common/system/tray/view_click_listener.h" |
19 #include "ash/common/wm_shell.h" | 20 #include "ash/common/wm_shell.h" |
20 #include "grit/ash_resources.h" | 21 #include "grit/ash_resources.h" |
21 #include "grit/ash_strings.h" | 22 #include "grit/ash_strings.h" |
22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
24 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
25 #include "ui/gfx/paint_vector_icon.h" | 26 #include "ui/gfx/paint_vector_icon.h" |
26 #include "ui/gfx/vector_icons_public.h" | 27 #include "ui/gfx/vector_icons_public.h" |
27 #include "ui/views/controls/image_view.h" | 28 #include "ui/views/controls/image_view.h" |
28 #include "ui/views/controls/label.h" | 29 #include "ui/views/controls/label.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 SetVisible(true); | 100 SetVisible(true); |
100 } else { | 101 } else { |
101 SetVisible(false); | 102 SetVisible(false); |
102 } | 103 } |
103 } | 104 } |
104 | 105 |
105 private: | 106 private: |
106 DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView); | 107 DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView); |
107 }; | 108 }; |
108 | 109 |
109 class BluetoothDetailedView : public TrayDetailsView { | 110 class BluetoothDetailedView : public TrayDetailsView, |
| 111 public ViewClickListener, |
| 112 public views::ButtonListener { |
110 public: | 113 public: |
111 BluetoothDetailedView(SystemTrayItem* owner, LoginStatus login) | 114 BluetoothDetailedView(SystemTrayItem* owner, LoginStatus login) |
112 : TrayDetailsView(owner), | 115 : TrayDetailsView(owner), |
113 login_(login), | 116 login_(login), |
114 manage_devices_(nullptr), | 117 manage_devices_(NULL), |
115 toggle_bluetooth_(nullptr), | 118 toggle_bluetooth_(NULL), |
116 enable_bluetooth_(nullptr) { | 119 enable_bluetooth_(NULL) { |
117 CreateItems(); | 120 CreateItems(); |
118 } | 121 } |
119 | 122 |
120 ~BluetoothDetailedView() override { | 123 ~BluetoothDetailedView() override { |
121 // Stop discovering bluetooth devices when exiting BT detailed view. | 124 // Stop discovering bluetooth devices when exiting BT detailed view. |
122 BluetoothStopDiscovering(); | 125 BluetoothStopDiscovering(); |
123 } | 126 } |
124 | 127 |
125 void Update() { | 128 void Update() { |
126 BluetoothStartDiscovering(); | 129 BluetoothStartDiscovering(); |
127 UpdateBluetoothDeviceList(); | 130 UpdateBluetoothDeviceList(); |
128 | 131 |
129 // Update UI. | 132 // Update UI. |
130 UpdateDeviceScrollList(); | 133 UpdateDeviceScrollList(); |
131 UpdateHeaderEntry(); | 134 UpdateHeaderEntry(); |
132 Layout(); | 135 Layout(); |
133 } | 136 } |
134 | 137 |
135 private: | 138 private: |
136 void CreateItems() { | 139 void CreateItems() { |
137 CreateScrollableList(); | 140 CreateScrollableList(); |
138 AppendSettingsEntries(); | 141 AppendSettingsEntries(); |
139 CreateTitleRow(IDS_ASH_STATUS_TRAY_BLUETOOTH); | 142 AppendHeaderEntry(); |
140 } | 143 } |
141 | 144 |
142 void BluetoothStartDiscovering() { | 145 void BluetoothStartDiscovering() { |
143 // TODO(tdanderson|fukino): The material design version of the detailed | |
144 // view should use an infinite loader bar instead of a throbber. See | |
145 // crbug.com/632128. | |
146 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 146 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
147 if (delegate->GetBluetoothDiscovering()) { | 147 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); |
148 if (throbber_) | 148 bool bluetooth_discovering = delegate->GetBluetoothDiscovering(); |
149 throbber_->Start(); | 149 if (bluetooth_discovering) { |
| 150 throbber_->Start(); |
150 return; | 151 return; |
151 } | 152 } |
152 if (throbber_) | 153 throbber_->Stop(); |
153 throbber_->Stop(); | 154 if (bluetooth_enabled) { |
154 if (delegate->GetBluetoothEnabled()) | |
155 delegate->BluetoothStartDiscovering(); | 155 delegate->BluetoothStartDiscovering(); |
| 156 } |
156 } | 157 } |
157 | 158 |
158 void BluetoothStopDiscovering() { | 159 void BluetoothStopDiscovering() { |
159 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 160 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
160 if (delegate && delegate->GetBluetoothDiscovering()) { | 161 if (delegate && delegate->GetBluetoothDiscovering()) { |
161 delegate->BluetoothStopDiscovering(); | 162 delegate->BluetoothStopDiscovering(); |
162 if (throbber_) | 163 throbber_->Stop(); |
163 throbber_->Stop(); | |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 void UpdateBluetoothDeviceList() { | 167 void UpdateBluetoothDeviceList() { |
168 std::set<std::string> new_connecting_devices; | 168 std::set<std::string> new_connecting_devices; |
169 std::set<std::string> new_connected_devices; | 169 std::set<std::string> new_connected_devices; |
170 std::set<std::string> new_paired_not_connected_devices; | 170 std::set<std::string> new_paired_not_connected_devices; |
171 std::set<std::string> new_discovered_not_paired_devices; | 171 std::set<std::string> new_discovered_not_paired_devices; |
172 | 172 |
173 BluetoothDeviceList list; | 173 BluetoothDeviceList list; |
(...skipping 20 matching lines...) Expand all Loading... |
194 RemoveObsoleteBluetoothDevicesFromList(&connecting_devices_, | 194 RemoveObsoleteBluetoothDevicesFromList(&connecting_devices_, |
195 new_connecting_devices); | 195 new_connecting_devices); |
196 RemoveObsoleteBluetoothDevicesFromList(&connected_devices_, | 196 RemoveObsoleteBluetoothDevicesFromList(&connected_devices_, |
197 new_connected_devices); | 197 new_connected_devices); |
198 RemoveObsoleteBluetoothDevicesFromList(&paired_not_connected_devices_, | 198 RemoveObsoleteBluetoothDevicesFromList(&paired_not_connected_devices_, |
199 new_paired_not_connected_devices); | 199 new_paired_not_connected_devices); |
200 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_, | 200 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_, |
201 new_discovered_not_paired_devices); | 201 new_discovered_not_paired_devices); |
202 } | 202 } |
203 | 203 |
| 204 void AppendHeaderEntry() { |
| 205 CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this); |
| 206 |
| 207 if (login_ == LoginStatus::LOCKED) |
| 208 return; |
| 209 |
| 210 throbber_ = new ThrobberView; |
| 211 throbber_->SetTooltipText( |
| 212 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING)); |
| 213 footer()->AddView(throbber_, false /* separator */); |
| 214 |
| 215 // Do not allow toggling bluetooth in the lock screen. |
| 216 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 217 toggle_bluetooth_ = |
| 218 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, |
| 219 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED, |
| 220 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER, |
| 221 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER, |
| 222 IDS_ASH_STATUS_TRAY_BLUETOOTH); |
| 223 toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled()); |
| 224 toggle_bluetooth_->SetTooltipText( |
| 225 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH)); |
| 226 toggle_bluetooth_->SetToggledTooltipText( |
| 227 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH)); |
| 228 toggle_bluetooth_->EnableCanvasFlippingForRTLUI(false); |
| 229 footer()->AddButton(toggle_bluetooth_); |
| 230 } |
| 231 |
204 void UpdateHeaderEntry() { | 232 void UpdateHeaderEntry() { |
205 if (toggle_bluetooth_) { | 233 if (toggle_bluetooth_) { |
206 toggle_bluetooth_->SetToggled( | 234 toggle_bluetooth_->SetToggled( |
207 !WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled()); | 235 !WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled()); |
208 } | 236 } |
209 } | 237 } |
210 | 238 |
211 void UpdateDeviceScrollList() { | 239 void UpdateDeviceScrollList() { |
212 device_map_.clear(); | 240 device_map_.clear(); |
213 scroll_content()->RemoveAllChildViews(true); | 241 scroll_content()->RemoveAllChildViews(true); |
214 enable_bluetooth_ = nullptr; | 242 enable_bluetooth_ = NULL; |
215 | 243 |
216 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 244 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
217 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); | 245 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); |
218 bool blueooth_available = delegate->GetBluetoothAvailable(); | 246 bool blueooth_available = delegate->GetBluetoothAvailable(); |
219 if (blueooth_available && !bluetooth_enabled && toggle_bluetooth_) { | 247 if (blueooth_available && !bluetooth_enabled && toggle_bluetooth_) { |
220 enable_bluetooth_ = AddScrollListItem( | 248 enable_bluetooth_ = AddScrollListItem( |
221 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH), | 249 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH), |
222 false /* highlight */, false /* checked */, true /* enabled */); | 250 false /* highlight */, false /* checked */, true /* enabled */); |
223 } | 251 } |
224 | 252 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTING, display_name); | 346 IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTING, display_name); |
319 | 347 |
320 item_container->RemoveAllChildViews(true); | 348 item_container->RemoveAllChildViews(true); |
321 static_cast<HoverHighlightView*>(item_container) | 349 static_cast<HoverHighlightView*>(item_container) |
322 ->AddCheckableLabel(display_name, true /* highlight */, false); | 350 ->AddCheckableLabel(display_name, true /* highlight */, false); |
323 scroll_content()->SizeToPreferredSize(); | 351 scroll_content()->SizeToPreferredSize(); |
324 static_cast<views::View*>(scroller())->Layout(); | 352 static_cast<views::View*>(scroller())->Layout(); |
325 } | 353 } |
326 } | 354 } |
327 | 355 |
328 // TrayDetailsView: | 356 // Overridden from ViewClickListener. |
329 void HandleViewClicked(views::View* view) override { | 357 void OnViewClicked(views::View* sender) override { |
330 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 358 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
331 if (view == manage_devices_) { | 359 if (sender == footer()->content()) { |
| 360 TransitionToDefaultView(); |
| 361 } else if (sender == manage_devices_) { |
332 delegate->ManageBluetoothDevices(); | 362 delegate->ManageBluetoothDevices(); |
333 return; | 363 } else if (sender == enable_bluetooth_) { |
334 } | |
335 | |
336 if (view == enable_bluetooth_) { | |
337 WmShell::Get()->RecordUserMetricsAction( | 364 WmShell::Get()->RecordUserMetricsAction( |
338 delegate->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED | 365 delegate->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED |
339 : UMA_STATUS_AREA_BLUETOOTH_ENABLED); | 366 : UMA_STATUS_AREA_BLUETOOTH_ENABLED); |
340 delegate->ToggleBluetooth(); | 367 delegate->ToggleBluetooth(); |
341 return; | 368 } else { |
| 369 if (!delegate->GetBluetoothEnabled()) |
| 370 return; |
| 371 std::map<views::View*, std::string>::iterator find; |
| 372 find = device_map_.find(sender); |
| 373 if (find == device_map_.end()) |
| 374 return; |
| 375 const std::string device_id = find->second; |
| 376 if (FoundDevice(device_id, connecting_devices_, NULL)) |
| 377 return; |
| 378 UpdateClickedDevice(device_id, sender); |
| 379 delegate->ConnectToBluetoothDevice(device_id); |
342 } | 380 } |
343 | |
344 if (!delegate->GetBluetoothEnabled()) | |
345 return; | |
346 | |
347 std::map<views::View*, std::string>::iterator find; | |
348 find = device_map_.find(view); | |
349 if (find == device_map_.end()) | |
350 return; | |
351 | |
352 const std::string device_id = find->second; | |
353 if (FoundDevice(device_id, connecting_devices_, nullptr)) | |
354 return; | |
355 | |
356 UpdateClickedDevice(device_id, view); | |
357 delegate->ConnectToBluetoothDevice(device_id); | |
358 } | 381 } |
359 | 382 |
360 void HandleButtonPressed(views::Button* sender, | 383 // Overridden from ButtonListener. |
361 const ui::Event& event) override { | 384 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
362 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
363 return; | |
364 | |
365 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 385 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
366 if (sender == toggle_bluetooth_) | 386 if (sender == toggle_bluetooth_) |
367 delegate->ToggleBluetooth(); | 387 delegate->ToggleBluetooth(); |
368 else | 388 else |
369 NOTREACHED(); | 389 NOTREACHED(); |
370 } | 390 } |
371 | 391 |
372 void CreateExtraTitleRowButtons() override { | |
373 // TODO(tdanderson|fukino): The material design version of the detailed | |
374 // view requires different buttons. See crbug.com/632128. | |
375 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
376 return; | |
377 | |
378 if (login_ == LoginStatus::LOCKED) | |
379 return; | |
380 | |
381 throbber_ = new ThrobberView; | |
382 throbber_->SetTooltipText( | |
383 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING)); | |
384 title_row()->AddView(throbber_, false /* separator */); | |
385 | |
386 // Do not allow toggling bluetooth in the lock screen. | |
387 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | |
388 toggle_bluetooth_ = | |
389 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, | |
390 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED, | |
391 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER, | |
392 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER, | |
393 IDS_ASH_STATUS_TRAY_BLUETOOTH); | |
394 toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled()); | |
395 toggle_bluetooth_->SetTooltipText( | |
396 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH)); | |
397 toggle_bluetooth_->SetToggledTooltipText( | |
398 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH)); | |
399 toggle_bluetooth_->EnableCanvasFlippingForRTLUI(false); | |
400 title_row()->AddButton(toggle_bluetooth_); | |
401 } | |
402 | |
403 LoginStatus login_; | 392 LoginStatus login_; |
404 | 393 |
405 std::map<views::View*, std::string> device_map_; | 394 std::map<views::View*, std::string> device_map_; |
406 views::View* manage_devices_; | 395 views::View* manage_devices_; |
407 | |
408 // Not used in material design. | |
409 ThrobberView* throbber_; | 396 ThrobberView* throbber_; |
410 | |
411 // Not used in material design. | |
412 TrayPopupHeaderButton* toggle_bluetooth_; | 397 TrayPopupHeaderButton* toggle_bluetooth_; |
413 | |
414 HoverHighlightView* enable_bluetooth_; | 398 HoverHighlightView* enable_bluetooth_; |
415 BluetoothDeviceList connected_devices_; | 399 BluetoothDeviceList connected_devices_; |
416 BluetoothDeviceList connecting_devices_; | 400 BluetoothDeviceList connecting_devices_; |
417 BluetoothDeviceList paired_not_connected_devices_; | 401 BluetoothDeviceList paired_not_connected_devices_; |
418 BluetoothDeviceList discovered_not_paired_devices_; | 402 BluetoothDeviceList discovered_not_paired_devices_; |
419 | 403 |
420 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); | 404 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); |
421 }; | 405 }; |
422 | 406 |
423 } // namespace tray | 407 } // namespace tray |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 detailed_->Update(); | 458 detailed_->Update(); |
475 } | 459 } |
476 | 460 |
477 void TrayBluetooth::OnBluetoothDiscoveringChanged() { | 461 void TrayBluetooth::OnBluetoothDiscoveringChanged() { |
478 if (!detailed_) | 462 if (!detailed_) |
479 return; | 463 return; |
480 detailed_->Update(); | 464 detailed_->Update(); |
481 } | 465 } |
482 | 466 |
483 } // namespace ash | 467 } // namespace ash |
OLD | NEW |