bluetooth_detailed_view_legacy.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Copyright 2018 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. #ifndef ASH_SYSTEM_BLUETOOTH_BLUETOOTH_DETAILED_VIEW_LEGACY_H_
  5. #define ASH_SYSTEM_BLUETOOTH_BLUETOOTH_DETAILED_VIEW_LEGACY_H_
  6. #include <unordered_map>
  7. #include "ash/login_status.h"
  8. #include "ash/system/bluetooth/tray_bluetooth_helper.h"
  9. #include "ash/system/tray/tray_detailed_view.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. namespace views {
  12. class ToggleButton;
  13. } // namespace views
  14. namespace ash {
  15. class TriView;
  16. class TrayInfoLabel;
  17. // TODO(crbug.com/1234138): Remove this class when the
  18. // |ash::features::kBluetoothRevamp| feature flag is fully launched.
  19. class BluetoothDetailedViewLegacy : public TrayDetailedView {
  20. public:
  21. // ID for scroll content view. Used in testing.
  22. static const int kScrollContentID = 1;
  23. BluetoothDetailedViewLegacy(DetailedViewDelegate* delegate,
  24. LoginStatus login);
  25. BluetoothDetailedViewLegacy(const BluetoothDetailedViewLegacy&) = delete;
  26. BluetoothDetailedViewLegacy& operator=(const BluetoothDetailedViewLegacy&) =
  27. delete;
  28. ~BluetoothDetailedViewLegacy() override;
  29. // Shows/hides the loading indicator below the header.
  30. void ShowLoadingIndicator();
  31. void HideLoadingIndicator();
  32. // Shows/hides the container of the message "Bluetooth is disabled". It should
  33. // be shown instead of the device list when Bluetooth is disabled.
  34. void ShowBluetoothDisabledPanel();
  35. void HideBluetoothDisabledPanel();
  36. // Returns true if the device list has any devices, false otherwise.
  37. bool IsDeviceScrollListEmpty() const;
  38. // Updates the device list.
  39. void UpdateDeviceScrollList(
  40. const BluetoothDeviceList& connected_devices,
  41. const BluetoothDeviceList& connecting_devices,
  42. const BluetoothDeviceList& paired_not_connected_devices,
  43. const BluetoothDeviceList& discovered_not_paired_devices);
  44. // Sets the state of the toggle in the header.
  45. void SetToggleIsOn(bool is_on);
  46. // views::View:
  47. const char* GetClassName() const override;
  48. private:
  49. void CreateItems();
  50. // Adds subheading with given |text_id| at given |child_index|. If
  51. // |sub_heading_view| is nullptr, then a new view is created. Returns
  52. // |sub_heading_view| or the newly created view.
  53. TriView* AddSubHeading(int text_id,
  54. TriView* sub_heading_view,
  55. size_t child_index);
  56. // Adds devices from |list| into the scroll list at given |child_index|.
  57. // To avoid disrupting a11y, list items are re-used from |old_device_list| if
  58. // it exists. Returns index position for next scroll list item.
  59. size_t AddSameTypeDevicesToScrollList(
  60. const BluetoothDeviceList& list,
  61. const std::unordered_map<HoverHighlightView*, BluetoothAddress>&
  62. old_device_list,
  63. size_t child_index,
  64. bool highlight,
  65. bool checked);
  66. // Returns true if the device with |device_id| is found in |device_list|.
  67. bool FoundDevice(const BluetoothAddress& device_id,
  68. const BluetoothDeviceList& device_list) const;
  69. // Updates UI of the clicked bluetooth device to show it is being connected
  70. // or disconnected if such an operation is going to be performed underway.
  71. void UpdateClickedDevice(const BluetoothAddress& device_id,
  72. HoverHighlightView* item_container);
  73. void ToggleButtonPressed();
  74. void ShowSettings();
  75. absl::optional<BluetoothAddress> GetFocusedDeviceAddress() const;
  76. void FocusDeviceByAddress(const BluetoothAddress& address) const;
  77. // TrayDetailedView:
  78. void HandleViewClicked(views::View* view) override;
  79. void CreateExtraTitleRowButtons() override;
  80. // TODO(jamescook): Don't cache this.
  81. LoginStatus login_;
  82. std::unordered_map<HoverHighlightView*, BluetoothAddress> device_map_;
  83. BluetoothDeviceList connecting_devices_;
  84. BluetoothDeviceList paired_not_connected_devices_;
  85. views::ToggleButton* toggle_ = nullptr;
  86. views::Button* settings_ = nullptr;
  87. TriView* paired_devices_heading_ = nullptr;
  88. TriView* unpaired_devices_heading_ = nullptr;
  89. TrayInfoLabel* bluetooth_discovering_label_ = nullptr;
  90. // The container of the message "Bluetooth is disabled" and an icon. It should
  91. // be shown instead of Bluetooth device list when Bluetooth is disabled.
  92. views::View* disabled_panel_ = nullptr;
  93. };
  94. } // namespace ash
  95. #endif // ASH_SYSTEM_BLUETOOTH_BLUETOOTH_DETAILED_VIEW_LEGACY_H_