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" | |
20 #include "ash/common/wm_shell.h" | 19 #include "ash/common/wm_shell.h" |
21 #include "grit/ash_resources.h" | 20 #include "grit/ash_resources.h" |
22 #include "grit/ash_strings.h" | 21 #include "grit/ash_strings.h" |
23 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
25 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
26 #include "ui/gfx/paint_vector_icon.h" | 25 #include "ui/gfx/paint_vector_icon.h" |
27 #include "ui/gfx/vector_icons_public.h" | 26 #include "ui/gfx/vector_icons_public.h" |
28 #include "ui/views/controls/image_view.h" | 27 #include "ui/views/controls/image_view.h" |
29 #include "ui/views/controls/label.h" | 28 #include "ui/views/controls/label.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 SetVisible(true); | 99 SetVisible(true); |
101 } else { | 100 } else { |
102 SetVisible(false); | 101 SetVisible(false); |
103 } | 102 } |
104 } | 103 } |
105 | 104 |
106 private: | 105 private: |
107 DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView); | 106 DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView); |
108 }; | 107 }; |
109 | 108 |
110 class BluetoothDetailedView : public TrayDetailsView, | 109 class BluetoothDetailedView : public TrayDetailsView { |
111 public ViewClickListener, | |
112 public views::ButtonListener { | |
113 public: | 110 public: |
114 BluetoothDetailedView(SystemTrayItem* owner, LoginStatus login) | 111 BluetoothDetailedView(SystemTrayItem* owner, LoginStatus login) |
115 : TrayDetailsView(owner), | 112 : TrayDetailsView(owner), |
116 login_(login), | 113 login_(login), |
117 manage_devices_(NULL), | 114 manage_devices_(nullptr), |
118 toggle_bluetooth_(NULL), | 115 toggle_bluetooth_(nullptr), |
119 enable_bluetooth_(NULL) { | 116 enable_bluetooth_(nullptr) { |
120 CreateItems(); | 117 CreateItems(); |
121 } | 118 } |
122 | 119 |
123 ~BluetoothDetailedView() override { | 120 ~BluetoothDetailedView() override { |
124 // Stop discovering bluetooth devices when exiting BT detailed view. | 121 // Stop discovering bluetooth devices when exiting BT detailed view. |
125 BluetoothStopDiscovering(); | 122 BluetoothStopDiscovering(); |
126 } | 123 } |
127 | 124 |
128 void Update() { | 125 void Update() { |
129 BluetoothStartDiscovering(); | 126 BluetoothStartDiscovering(); |
130 UpdateBluetoothDeviceList(); | 127 UpdateBluetoothDeviceList(); |
131 | 128 |
132 // Update UI. | 129 // Update UI. |
133 UpdateDeviceScrollList(); | 130 UpdateDeviceScrollList(); |
134 UpdateHeaderEntry(); | 131 UpdateHeaderEntry(); |
135 Layout(); | 132 Layout(); |
136 } | 133 } |
137 | 134 |
138 private: | 135 private: |
139 void CreateItems() { | 136 void CreateItems() { |
140 CreateScrollableList(); | 137 CreateScrollableList(); |
141 AppendSettingsEntries(); | 138 AppendSettingsEntries(); |
142 AppendHeaderEntry(); | 139 CreateTitleRow(IDS_ASH_STATUS_TRAY_BLUETOOTH); |
143 } | 140 } |
144 | 141 |
145 void BluetoothStartDiscovering() { | 142 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 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); | 147 if (delegate->GetBluetoothDiscovering()) { |
148 bool bluetooth_discovering = delegate->GetBluetoothDiscovering(); | 148 if (throbber_) |
149 if (bluetooth_discovering) { | 149 throbber_->Start(); |
150 throbber_->Start(); | |
151 return; | 150 return; |
152 } | 151 } |
153 throbber_->Stop(); | 152 if (throbber_) |
154 if (bluetooth_enabled) { | 153 throbber_->Stop(); |
| 154 if (delegate->GetBluetoothEnabled()) |
155 delegate->BluetoothStartDiscovering(); | 155 delegate->BluetoothStartDiscovering(); |
156 } | |
157 } | 156 } |
158 | 157 |
159 void BluetoothStopDiscovering() { | 158 void BluetoothStopDiscovering() { |
160 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 159 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
161 if (delegate && delegate->GetBluetoothDiscovering()) { | 160 if (delegate && delegate->GetBluetoothDiscovering()) { |
162 delegate->BluetoothStopDiscovering(); | 161 delegate->BluetoothStopDiscovering(); |
163 throbber_->Stop(); | 162 if (throbber_) |
| 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 | |
232 void UpdateHeaderEntry() { | 204 void UpdateHeaderEntry() { |
233 if (toggle_bluetooth_) { | 205 if (toggle_bluetooth_) { |
234 toggle_bluetooth_->SetToggled( | 206 toggle_bluetooth_->SetToggled( |
235 !WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled()); | 207 !WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled()); |
236 } | 208 } |
237 } | 209 } |
238 | 210 |
239 void UpdateDeviceScrollList() { | 211 void UpdateDeviceScrollList() { |
240 device_map_.clear(); | 212 device_map_.clear(); |
241 scroll_content()->RemoveAllChildViews(true); | 213 scroll_content()->RemoveAllChildViews(true); |
242 enable_bluetooth_ = NULL; | 214 enable_bluetooth_ = nullptr; |
243 | 215 |
244 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 216 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
245 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); | 217 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); |
246 bool blueooth_available = delegate->GetBluetoothAvailable(); | 218 bool blueooth_available = delegate->GetBluetoothAvailable(); |
247 if (blueooth_available && !bluetooth_enabled && toggle_bluetooth_) { | 219 if (blueooth_available && !bluetooth_enabled && toggle_bluetooth_) { |
248 enable_bluetooth_ = AddScrollListItem( | 220 enable_bluetooth_ = AddScrollListItem( |
249 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH), | 221 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH), |
250 false /* highlight */, false /* checked */, true /* enabled */); | 222 false /* highlight */, false /* checked */, true /* enabled */); |
251 } | 223 } |
252 | 224 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTING, display_name); | 318 IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTING, display_name); |
347 | 319 |
348 item_container->RemoveAllChildViews(true); | 320 item_container->RemoveAllChildViews(true); |
349 static_cast<HoverHighlightView*>(item_container) | 321 static_cast<HoverHighlightView*>(item_container) |
350 ->AddCheckableLabel(display_name, true /* highlight */, false); | 322 ->AddCheckableLabel(display_name, true /* highlight */, false); |
351 scroll_content()->SizeToPreferredSize(); | 323 scroll_content()->SizeToPreferredSize(); |
352 static_cast<views::View*>(scroller())->Layout(); | 324 static_cast<views::View*>(scroller())->Layout(); |
353 } | 325 } |
354 } | 326 } |
355 | 327 |
356 // Overridden from ViewClickListener. | 328 // TrayDetailsView: |
357 void OnViewClicked(views::View* sender) override { | 329 void HandleViewClicked(views::View* view) override { |
358 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 330 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
359 if (sender == footer()->content()) { | 331 if (view == manage_devices_) { |
360 TransitionToDefaultView(); | |
361 } else if (sender == manage_devices_) { | |
362 delegate->ManageBluetoothDevices(); | 332 delegate->ManageBluetoothDevices(); |
363 } else if (sender == enable_bluetooth_) { | 333 return; |
| 334 } |
| 335 |
| 336 if (view == enable_bluetooth_) { |
364 WmShell::Get()->RecordUserMetricsAction( | 337 WmShell::Get()->RecordUserMetricsAction( |
365 delegate->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED | 338 delegate->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED |
366 : UMA_STATUS_AREA_BLUETOOTH_ENABLED); | 339 : UMA_STATUS_AREA_BLUETOOTH_ENABLED); |
367 delegate->ToggleBluetooth(); | 340 delegate->ToggleBluetooth(); |
368 } else { | 341 return; |
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); | |
380 } | 342 } |
| 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); |
381 } | 358 } |
382 | 359 |
383 // Overridden from ButtonListener. | 360 void HandleButtonPressed(views::Button* sender, |
384 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 361 const ui::Event& event) override { |
| 362 if (MaterialDesignController::IsSystemTrayMenuMaterial()) |
| 363 return; |
| 364 |
385 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 365 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
386 if (sender == toggle_bluetooth_) | 366 if (sender == toggle_bluetooth_) |
387 delegate->ToggleBluetooth(); | 367 delegate->ToggleBluetooth(); |
388 else | 368 else |
389 NOTREACHED(); | 369 NOTREACHED(); |
390 } | 370 } |
391 | 371 |
| 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 |
392 LoginStatus login_; | 403 LoginStatus login_; |
393 | 404 |
394 std::map<views::View*, std::string> device_map_; | 405 std::map<views::View*, std::string> device_map_; |
395 views::View* manage_devices_; | 406 views::View* manage_devices_; |
| 407 |
| 408 // Not used in material design. |
396 ThrobberView* throbber_; | 409 ThrobberView* throbber_; |
| 410 |
| 411 // Not used in material design. |
397 TrayPopupHeaderButton* toggle_bluetooth_; | 412 TrayPopupHeaderButton* toggle_bluetooth_; |
| 413 |
398 HoverHighlightView* enable_bluetooth_; | 414 HoverHighlightView* enable_bluetooth_; |
399 BluetoothDeviceList connected_devices_; | 415 BluetoothDeviceList connected_devices_; |
400 BluetoothDeviceList connecting_devices_; | 416 BluetoothDeviceList connecting_devices_; |
401 BluetoothDeviceList paired_not_connected_devices_; | 417 BluetoothDeviceList paired_not_connected_devices_; |
402 BluetoothDeviceList discovered_not_paired_devices_; | 418 BluetoothDeviceList discovered_not_paired_devices_; |
403 | 419 |
404 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); | 420 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); |
405 }; | 421 }; |
406 | 422 |
407 } // namespace tray | 423 } // namespace tray |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 detailed_->Update(); | 474 detailed_->Update(); |
459 } | 475 } |
460 | 476 |
461 void TrayBluetooth::OnBluetoothDiscoveringChanged() { | 477 void TrayBluetooth::OnBluetoothDiscoveringChanged() { |
462 if (!detailed_) | 478 if (!detailed_) |
463 return; | 479 return; |
464 detailed_->Update(); | 480 detailed_->Update(); |
465 } | 481 } |
466 | 482 |
467 } // namespace ash | 483 } // namespace ash |
OLD | NEW |