Chromium Code Reviews| 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, this); |
| 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 const bool md = MaterialDesignController::IsSystemTrayMenuMaterial(); | |
|
varkha
2016/08/31 20:28:13
nit: s/md/material for consistency and I thought w
tdanderson
2016/08/31 22:24:15
Removed.
| |
| 146 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 147 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 147 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); | 148 if (delegate->GetBluetoothDiscovering()) { |
| 148 bool bluetooth_discovering = delegate->GetBluetoothDiscovering(); | 149 if (!md) |
|
varkha
2016/08/31 20:28:14
What do you think about replacing this with "if (t
tdanderson
2016/08/31 22:24:15
Good idea, changed.
| |
| 149 if (bluetooth_discovering) { | 150 throbber_->Start(); |
| 150 throbber_->Start(); | |
| 151 return; | 151 return; |
| 152 } | 152 } |
| 153 throbber_->Stop(); | 153 if (!md) |
|
varkha
2016/08/31 20:28:14
ditto.
tdanderson
2016/08/31 22:24:15
Done.
| |
| 154 if (bluetooth_enabled) { | 154 throbber_->Stop(); |
| 155 if (delegate->GetBluetoothEnabled()) | |
| 155 delegate->BluetoothStartDiscovering(); | 156 delegate->BluetoothStartDiscovering(); |
| 156 } | |
| 157 } | 157 } |
| 158 | 158 |
| 159 void BluetoothStopDiscovering() { | 159 void BluetoothStopDiscovering() { |
| 160 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 160 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 161 if (delegate && delegate->GetBluetoothDiscovering()) { | 161 if (delegate && delegate->GetBluetoothDiscovering()) { |
| 162 delegate->BluetoothStopDiscovering(); | 162 delegate->BluetoothStopDiscovering(); |
| 163 throbber_->Stop(); | 163 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) |
|
varkha
2016/08/31 20:28:14
ditto.
tdanderson
2016/08/31 22:24:15
Done.
| |
| 164 throbber_->Stop(); | |
| 164 } | 165 } |
| 165 } | 166 } |
| 166 | 167 |
| 167 void UpdateBluetoothDeviceList() { | 168 void UpdateBluetoothDeviceList() { |
| 168 std::set<std::string> new_connecting_devices; | 169 std::set<std::string> new_connecting_devices; |
| 169 std::set<std::string> new_connected_devices; | 170 std::set<std::string> new_connected_devices; |
| 170 std::set<std::string> new_paired_not_connected_devices; | 171 std::set<std::string> new_paired_not_connected_devices; |
| 171 std::set<std::string> new_discovered_not_paired_devices; | 172 std::set<std::string> new_discovered_not_paired_devices; |
| 172 | 173 |
| 173 BluetoothDeviceList list; | 174 BluetoothDeviceList list; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 194 RemoveObsoleteBluetoothDevicesFromList(&connecting_devices_, | 195 RemoveObsoleteBluetoothDevicesFromList(&connecting_devices_, |
| 195 new_connecting_devices); | 196 new_connecting_devices); |
| 196 RemoveObsoleteBluetoothDevicesFromList(&connected_devices_, | 197 RemoveObsoleteBluetoothDevicesFromList(&connected_devices_, |
| 197 new_connected_devices); | 198 new_connected_devices); |
| 198 RemoveObsoleteBluetoothDevicesFromList(&paired_not_connected_devices_, | 199 RemoveObsoleteBluetoothDevicesFromList(&paired_not_connected_devices_, |
| 199 new_paired_not_connected_devices); | 200 new_paired_not_connected_devices); |
| 200 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_, | 201 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_, |
| 201 new_discovered_not_paired_devices); | 202 new_discovered_not_paired_devices); |
| 202 } | 203 } |
| 203 | 204 |
| 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() { | 205 void UpdateHeaderEntry() { |
| 233 if (toggle_bluetooth_) { | 206 if (toggle_bluetooth_) { |
| 234 toggle_bluetooth_->SetToggled( | 207 toggle_bluetooth_->SetToggled( |
| 235 !WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled()); | 208 !WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled()); |
| 236 } | 209 } |
| 237 } | 210 } |
| 238 | 211 |
| 239 void UpdateDeviceScrollList() { | 212 void UpdateDeviceScrollList() { |
| 240 device_map_.clear(); | 213 device_map_.clear(); |
| 241 scroll_content()->RemoveAllChildViews(true); | 214 scroll_content()->RemoveAllChildViews(true); |
| 242 enable_bluetooth_ = NULL; | 215 enable_bluetooth_ = nullptr; |
| 243 | 216 |
| 244 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 217 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 245 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); | 218 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); |
| 246 bool blueooth_available = delegate->GetBluetoothAvailable(); | 219 bool blueooth_available = delegate->GetBluetoothAvailable(); |
| 247 if (blueooth_available && !bluetooth_enabled && toggle_bluetooth_) { | 220 if (blueooth_available && !bluetooth_enabled && toggle_bluetooth_) { |
| 248 enable_bluetooth_ = AddScrollListItem( | 221 enable_bluetooth_ = AddScrollListItem( |
| 249 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH), | 222 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH), |
| 250 false /* highlight */, false /* checked */, true /* enabled */); | 223 false /* highlight */, false /* checked */, true /* enabled */); |
| 251 } | 224 } |
| 252 | 225 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTING, display_name); | 319 IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTING, display_name); |
| 347 | 320 |
| 348 item_container->RemoveAllChildViews(true); | 321 item_container->RemoveAllChildViews(true); |
| 349 static_cast<HoverHighlightView*>(item_container) | 322 static_cast<HoverHighlightView*>(item_container) |
| 350 ->AddCheckableLabel(display_name, true /* highlight */, false); | 323 ->AddCheckableLabel(display_name, true /* highlight */, false); |
| 351 scroll_content()->SizeToPreferredSize(); | 324 scroll_content()->SizeToPreferredSize(); |
| 352 static_cast<views::View*>(scroller())->Layout(); | 325 static_cast<views::View*>(scroller())->Layout(); |
| 353 } | 326 } |
| 354 } | 327 } |
| 355 | 328 |
| 356 // Overridden from ViewClickListener. | 329 // TrayDetailsView: |
| 357 void OnViewClicked(views::View* sender) override { | 330 void HandleViewClicked(views::View* view) override { |
| 358 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 331 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 359 if (sender == footer()->content()) { | 332 if (view == manage_devices_) { |
| 360 TransitionToDefaultView(); | |
| 361 } else if (sender == manage_devices_) { | |
| 362 delegate->ManageBluetoothDevices(); | 333 delegate->ManageBluetoothDevices(); |
| 363 } else if (sender == enable_bluetooth_) { | 334 return; |
| 335 } | |
| 336 | |
| 337 if (view == enable_bluetooth_) { | |
| 364 WmShell::Get()->RecordUserMetricsAction( | 338 WmShell::Get()->RecordUserMetricsAction( |
| 365 delegate->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED | 339 delegate->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED |
| 366 : UMA_STATUS_AREA_BLUETOOTH_ENABLED); | 340 : UMA_STATUS_AREA_BLUETOOTH_ENABLED); |
| 367 delegate->ToggleBluetooth(); | 341 delegate->ToggleBluetooth(); |
| 368 } else { | 342 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 } | 343 } |
| 344 | |
| 345 if (!delegate->GetBluetoothEnabled()) | |
| 346 return; | |
| 347 | |
| 348 std::map<views::View*, std::string>::iterator find; | |
| 349 find = device_map_.find(view); | |
| 350 if (find == device_map_.end()) | |
| 351 return; | |
| 352 | |
| 353 const std::string device_id = find->second; | |
| 354 if (FoundDevice(device_id, connecting_devices_, nullptr)) | |
| 355 return; | |
| 356 | |
| 357 UpdateClickedDevice(device_id, view); | |
| 358 delegate->ConnectToBluetoothDevice(device_id); | |
| 381 } | 359 } |
| 382 | 360 |
| 383 // Overridden from ButtonListener. | 361 void HandleButtonPressed(views::Button* sender, |
| 384 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 362 const ui::Event& event) override { |
| 363 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
| 364 return; | |
| 365 | |
| 385 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 366 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 386 if (sender == toggle_bluetooth_) | 367 if (sender == toggle_bluetooth_) |
| 387 delegate->ToggleBluetooth(); | 368 delegate->ToggleBluetooth(); |
| 388 else | 369 else |
| 389 NOTREACHED(); | 370 NOTREACHED(); |
| 390 } | 371 } |
| 391 | 372 |
| 373 void CreateExtraTitleRowButtons() override { | |
| 374 // TODO(tdanderson|fukino): The material design version of the detailed | |
| 375 // view requires different buttons. See crbug.com/632128. | |
| 376 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
| 377 return; | |
| 378 | |
| 379 if (login_ == LoginStatus::LOCKED) | |
| 380 return; | |
| 381 | |
| 382 throbber_ = new ThrobberView; | |
| 383 throbber_->SetTooltipText( | |
| 384 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING)); | |
| 385 title_row()->AddView(throbber_, false /* separator */); | |
| 386 | |
| 387 // Do not allow toggling bluetooth in the lock screen. | |
| 388 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | |
| 389 toggle_bluetooth_ = | |
| 390 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, | |
| 391 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED, | |
| 392 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER, | |
| 393 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER, | |
| 394 IDS_ASH_STATUS_TRAY_BLUETOOTH); | |
| 395 toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled()); | |
| 396 toggle_bluetooth_->SetTooltipText( | |
| 397 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH)); | |
| 398 toggle_bluetooth_->SetToggledTooltipText( | |
| 399 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH)); | |
| 400 toggle_bluetooth_->EnableCanvasFlippingForRTLUI(false); | |
| 401 title_row()->AddButton(toggle_bluetooth_); | |
| 402 } | |
| 403 | |
| 392 LoginStatus login_; | 404 LoginStatus login_; |
| 393 | 405 |
| 394 std::map<views::View*, std::string> device_map_; | 406 std::map<views::View*, std::string> device_map_; |
| 395 views::View* manage_devices_; | 407 views::View* manage_devices_; |
| 408 | |
| 409 // Not used in material design. | |
| 396 ThrobberView* throbber_; | 410 ThrobberView* throbber_; |
| 411 | |
| 412 // Not used in material design. | |
| 397 TrayPopupHeaderButton* toggle_bluetooth_; | 413 TrayPopupHeaderButton* toggle_bluetooth_; |
| 414 | |
| 398 HoverHighlightView* enable_bluetooth_; | 415 HoverHighlightView* enable_bluetooth_; |
| 399 BluetoothDeviceList connected_devices_; | 416 BluetoothDeviceList connected_devices_; |
| 400 BluetoothDeviceList connecting_devices_; | 417 BluetoothDeviceList connecting_devices_; |
| 401 BluetoothDeviceList paired_not_connected_devices_; | 418 BluetoothDeviceList paired_not_connected_devices_; |
| 402 BluetoothDeviceList discovered_not_paired_devices_; | 419 BluetoothDeviceList discovered_not_paired_devices_; |
| 403 | 420 |
| 404 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); | 421 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); |
| 405 }; | 422 }; |
| 406 | 423 |
| 407 } // namespace tray | 424 } // namespace tray |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 detailed_->Update(); | 475 detailed_->Update(); |
| 459 } | 476 } |
| 460 | 477 |
| 461 void TrayBluetooth::OnBluetoothDiscoveringChanged() { | 478 void TrayBluetooth::OnBluetoothDiscoveringChanged() { |
| 462 if (!detailed_) | 479 if (!detailed_) |
| 463 return; | 480 return; |
| 464 detailed_->Update(); | 481 detailed_->Update(); |
| 465 } | 482 } |
| 466 | 483 |
| 467 } // namespace ash | 484 } // namespace ash |
| OLD | NEW |