network_list_network_header_view.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2022 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_NETWORK_NETWORK_LIST_NETWORK_HEADER_VIEW_H_
  5. #define ASH_SYSTEM_NETWORK_NETWORK_LIST_NETWORK_HEADER_VIEW_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/system/network/network_list_header_view.h"
  8. #include "ash/system/network/network_row_title_view.h"
  9. #include "ash/system/tray/tri_view.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "ui/views/controls/button/toggle_button.h"
  12. #include "ui/views/view.h"
  13. namespace ash {
  14. class TrayNetworkStateModel;
  15. // This class is used for the headers of networks (Mobile and Wifi), and
  16. // implements the functionality shared between the headers of Mobile and Wifi
  17. // network headers.
  18. class ASH_EXPORT NetworkListNetworkHeaderView : public NetworkListHeaderView {
  19. public:
  20. class Delegate {
  21. public:
  22. Delegate() = default;
  23. virtual ~Delegate() = default;
  24. virtual void OnMobileToggleClicked(bool new_state) = 0;
  25. virtual void OnWifiToggleClicked(bool new_state) = 0;
  26. };
  27. NetworkListNetworkHeaderView(Delegate* delegate, int label_id);
  28. NetworkListNetworkHeaderView(const NetworkListNetworkHeaderView&) = delete;
  29. NetworkListNetworkHeaderView& operator=(const NetworkListNetworkHeaderView&) =
  30. delete;
  31. ~NetworkListNetworkHeaderView() override;
  32. virtual void SetToggleState(bool enabled, bool is_on);
  33. void SetToggleVisibility(bool visible);
  34. protected:
  35. virtual void AddExtraButtons();
  36. // Called when |toggle_| is clicked and toggled. Subclasses should override to
  37. // enabled/disable their respective technology.
  38. virtual void OnToggleToggled(bool is_on);
  39. Delegate* delegate() const { return delegate_; };
  40. TrayNetworkStateModel* model() { return model_; }
  41. // Used for testing.
  42. static constexpr int kToggleButtonId =
  43. NetworkListHeaderView::kTitleLabelViewId + 1;
  44. private:
  45. friend class NetworkListNetworkHeaderViewTest;
  46. friend class NetworkListMobileHeaderViewTest;
  47. friend class NetworkListWifiHeaderViewTest;
  48. friend class NetworkListViewControllerTest;
  49. void ToggleButtonPressed();
  50. TrayNetworkStateModel* model_;
  51. // ToggleButton to toggle section on or off.
  52. views::ToggleButton* toggle_ = nullptr;
  53. Delegate* delegate_ = nullptr;
  54. base::WeakPtrFactory<NetworkListNetworkHeaderView> weak_factory_{this};
  55. };
  56. } // namespace ash
  57. #endif // ASH_SYSTEM_NETWORK_NETWORK_LIST_NETWORK_HEADER_VIEW_H_