bluetooth_device_list_controller_impl.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2021 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_DEVICE_LIST_CONTROLLER_IMPL_H_
  5. #define ASH_SYSTEM_BLUETOOTH_BLUETOOTH_DEVICE_LIST_CONTROLLER_IMPL_H_
  6. #include <string>
  7. #include <vector>
  8. #include "ash/ash_export.h"
  9. #include "ash/system/bluetooth/bluetooth_device_list_controller.h"
  10. #include "base/containers/flat_map.h"
  11. #include "chromeos/services/bluetooth_config/public/mojom/cros_bluetooth_config.mojom.h"
  12. namespace views {
  13. class Separator;
  14. } // namespace views
  15. namespace ash {
  16. class BluetoothDetailedView;
  17. class BluetoothDeviceListItemView;
  18. class TriView;
  19. // BluetoothDeviceListController implementation.
  20. class ASH_EXPORT BluetoothDeviceListControllerImpl
  21. : public BluetoothDeviceListController {
  22. public:
  23. explicit BluetoothDeviceListControllerImpl(
  24. BluetoothDetailedView* bluetooth_detailed_view);
  25. BluetoothDeviceListControllerImpl(const BluetoothDeviceListControllerImpl&) =
  26. delete;
  27. BluetoothDeviceListControllerImpl& operator=(
  28. const BluetoothDeviceListControllerImpl&) = delete;
  29. ~BluetoothDeviceListControllerImpl() override;
  30. private:
  31. friend class BluetoothDeviceListControllerTest;
  32. // BluetoothDeviceListController:
  33. void UpdateBluetoothEnabledState(bool enabled) override;
  34. void UpdateDeviceList(
  35. const PairedBluetoothDevicePropertiesPtrs& connected,
  36. const PairedBluetoothDevicePropertiesPtrs& previously_connected) override;
  37. // Creates a sub-header with text represented by the |text_id| message ID when
  38. // |sub_header| is |nullptr|, otherwise uses the provided |sub_header|. The
  39. // used sub-header is then moved to index |index| within the device list and
  40. // returned.
  41. TriView* CreateSubHeaderIfMissingAndReorder(TriView* sub_header,
  42. int text_id,
  43. size_t index);
  44. // Creates and initializes a view for each of the device properties within
  45. // |device_property_list| if a view does not already exist, otherwise re-using
  46. // the existing view to avoid disrupting a11y. Each view will be reordered to
  47. // start at |index| and will be removed from |previous_views|. The index of
  48. // the position after the final view that was added is returned.
  49. size_t CreateViewsIfMissingAndReorder(
  50. const PairedBluetoothDevicePropertiesPtrs& device_property_list,
  51. base::flat_map<std::string, BluetoothDeviceListItemView*>* previous_views,
  52. size_t index);
  53. BluetoothDetailedView* const bluetooth_detailed_view_;
  54. bool is_bluetooth_enabled_ = false;
  55. base::flat_map<std::string, BluetoothDeviceListItemView*>
  56. device_id_to_view_map_;
  57. views::Separator* device_list_separator_ = nullptr;
  58. TriView* connected_sub_header_ = nullptr;
  59. TriView* no_device_connected_sub_header_ = nullptr;
  60. TriView* previously_connected_sub_header_ = nullptr;
  61. };
  62. } // namespace ash
  63. #endif // ASH_SYSTEM_BLUETOOTH_BLUETOOTH_DEVICE_LIST_CONTROLLER_IMPL_H_